Produced by Araxis Merge on 12/5/2017 12:06:49 PM Central Standard Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | IV-eHMP_CIF.zip\IMAG_Source\VISA\Java\TransactionContext\main\src\java\gov\va\med | ApplicationPropertyAccessor.java | Mon Dec 4 21:34:24 2017 UTC |
| 2 | IV-eHMP_CIF.zip\IMAG_Source\VISA\Java\TransactionContext\main\src\java\gov\va\med | ApplicationPropertyAccessor.java | Mon Dec 4 22:06:01 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 2 | 158 |
| Changed | 1 | 2 |
| Inserted | 0 | 0 |
| Removed | 0 | 0 |
| Whitespace | |
|---|---|
| Character case | Differences in character case are significant |
| Line endings | Differences in line endings (CR and LF characters) are ignored |
| CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
| 1 | package go v.va.med; | |
| 2 | ||
| 3 | import jav a.lang.ref lect.Metho d; | |
| 4 | ||
| 5 | import org .apache.lo gging.log4 j.LogManag er; | |
| 6 | import org .apache.lo gging.log4 j.Logger; | |
| 7 | ||
| 8 | /** | |
| 9 | * A littl e helper t hat wraps up the ugl y casting and typing into a | |
| 10 | * templat ed class. To use th is class c reate an i nstance wi th the tar get | |
| 11 | * type sp ecified fo r the temp late, e.g. | |
| 12 | * Applica tionProper tyAccessor <Short> sh ortPropert yAccessor = | |
| 13 | * new A pplication PropertyAc cessor<Sho rt>("short Value", "p arseShort" ); | |
| 14 | * The met hod names should be the method to conver t from oth er base ty pes to the | |
| 15 | * target type and f rom a Stri ng to the target typ e. | |
| 16 | * | |
| 17 | * For an example of usage, se e | |
| 18 | * @see go v.va.med.i maging.tra nsactionco ntext.Tran sactionCon textProxyI nvocationH andler | |
| 19 | * | |
| 20 | * @author
|
|
| 21 | * | |
| 22 | * @param <D> - the type of Ob ject that we are con verting to . | |
| 23 | */ | |
| 24 | public cla ss Applica tionProper tyAccessor <D> | |
| 25 | { | |
| 26 | // the insta nce logger | |
| 27 | pr ivate Logg er logger = LogManag er.getLogg er(this.ge tClass()); | |
| 28 | ||
| 29 | pr ivate fina l String c onversionM ethodName; | |
| 30 | pr ivate fina l Method p arseMethod ; | |
| 31 | // the name of a stati c method o n the targ et class t hat will t ake a Stri ng and ret urn an Obj ect of the target cl ass | |
| 32 | ||
| 33 | /* * | |
| 34 | * | |
| 35 | * / | |
| 36 | pu blic Appli cationProp ertyAccess or(String conversion MethodName , Method p arseMethod ) | |
| 37 | { | |
| 38 | this .conversio nMethodNam e = conver sionMethod Name; | |
| 39 | this .parseMeth od = parse Method; | |
| 40 | } | |
| 41 | ||
| 42 | @S uppressWar nings("unc hecked") | |
| 43 | pu blic D get ValueAs(Ob ject value ) | |
| 44 | { | |
| 45 | if(v alue == nu ll) | |
| 46 | return (D)null; | |
| 47 | ||
| 48 | // i f there is no conver sion or pa rsing meth od availab le, just r eturn the object cas t | |
| 49 | // t o the corr ect type | |
| 50 | if(t his.parseM ethod == n ull && thi s.conversi onMethodNa me == null ) | |
| 51 | return (D)value; | |
| 52 | ||
| 53 | // t he type of the objec t we are c onverting from | |
| 54 | Clas s<?> value Class = va lue.getCla ss(); | |
| 55 | ||
| 56 | try | |
| 57 | { | |
| 58 | // con verting fr om String to the tar get class usually me ans callin g a parse method | |
| 59 | if(val ueClass == String.cl ass && par seMethod ! = null) | |
| 60 | { | |
| 61 | D conv ertedValue = (D)pars eMethod.in voke(null, new Objec t[]{value} ); | |
| 62 | return converted Value; | |
| 63 | } | |
| 64 | ||
| 65 | // con verting an ything els e to the t arget type requires that the o bject bein g converte d from | |
| 66 | // has a method with the e xpected na me (someth ing like i ntValue, f loatValue, etc ...) | |
| 67 | else i f(conversi onMethodNa me != null ) | |
| 68 | { | |
| 69 | Method conversio nMethod = valueClass .getMethod (conversio nMethodNam e, new Cla ss[]{}); | |
| 70 | D conv ertedValue = (D)conv ersionMeth od.invoke( value, new Object[]{ }); | |
| 71 | return converted Value; | |
| 72 | } | |
| 73 | } | |
| 74 | catc h (Excepti on e) | |
| 75 | { | |
| 76 | logger .warn(e); | |
| 77 | } | |
| 78 | re turn null; | |
| 79 | } | |
| 80 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.