Produced by Araxis Merge on 6/5/2018 10:24:08 AM Central Daylight 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 | patch_205_build_9.zip\Java\DataSourceServiceProvider\main\src\java\gov\va\med\imaging\datasource | ProviderConfiguration.java | Wed May 30 14:35:23 2018 UTC |
2 | patch_205_build_9.zip\Java\DataSourceServiceProvider\main\src\java\gov\va\med\imaging\datasource | ProviderConfiguration.java | Fri Jun 1 19:27:05 2018 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 2 | 630 |
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 | /** | |
2 | * | |
3 | */ | |
4 | package go v.va.med.i maging.dat asource; | |
5 | ||
6 | import jav a.beans.XM LDecoder; | |
7 | import jav a.beans.XM LEncoder; | |
8 | import jav a.io.ByteA rrayInputS tream; | |
9 | import jav a.io.ByteA rrayOutput Stream; | |
10 | import jav a.io.File; | |
11 | import jav a.io.FileI nputStream ; | |
12 | import jav a.io.FileO utputStrea m; | |
13 | import jav a.io.IOExc eption; | |
14 | import jav a.io.Input Stream; | |
15 | import jav a.io.Outpu tStream; | |
16 | ||
17 | import org .apache.lo gging.log4 j.LogManag er; | |
18 | import org .apache.lo gging.log4 j.Logger; | |
19 | ||
20 | import com .thoughtwo rks.xstrea m.XStream; | |
21 | ||
22 | /** | |
23 | * A class to manage configura tion persi stence in a standard fashion | |
24 | * that su pports bot h XMLEncod er and XSt ream persi stence. T his is lar gely | |
25 | * based u pon but sh ould repla ce the con figuration managemen t that is | |
26 | * within the Provid er class. | |
27 | * | |
28 | * The mod e property determine s the pers istence me chanism to use | |
29 | * XMLENCO DER - uses the Java XMLEncoder | |
30 | * XSTREAM - uses th e XStream encoding | |
31 | * HYBRID (default) - preferen tially rea ds using X MLENCODER then tries XSTREAM, | |
32 | * always w rites usin g XSTREAM | |
33 | * | |
34 | * The HYB RID mode i s intended as a brid ge until t he configu ration fil es are all | |
35 | * updated to use XS tream pers istence, a fter which usage of the freaki sh nightma re | |
36 | * that is the XMLEn coder will be mercif ully over. | |
37 | * | |
38 | * @author PII | |
39 | * | |
40 | */ | |
41 | public cla ss Provide rConfigura tion<T> | |
42 | { | |
43 | pr otected st atic Logge r getLogge r() | |
44 | { | |
45 | retu rn LogMana ger.getLog ger(Provid erConfigur ation.clas s); | |
46 | } | |
47 | ||
48 | pr ivate tran sient Logg er logger = LogManag er.getLogg er(this.ge tClass()); | |
49 | pr ivate fina l String p roviderNam e; | |
50 | pr ivate fina l double p roviderVer sion; | |
51 | ||
52 | /* * | |
53 | * | |
54 | * @param pr oviderName | |
55 | * @param pr oviderVers ion | |
56 | * @param mo de | |
57 | * / | |
58 | pu blic Provi derConfigu ration(Str ing provid erName, do uble provi derVersion ) | |
59 | { | |
60 | supe r(); | |
61 | this .providerN ame = prov iderName; | |
62 | this .providerV ersion = p roviderVer sion; | |
63 | } | |
64 | ||
65 | pu blic Strin g getProvi derName() | |
66 | { | |
67 | retu rn this.pr oviderName ; | |
68 | } | |
69 | ||
70 | pu blic doubl e getProvi derVersion () | |
71 | { | |
72 | retu rn this.pr oviderVers ion; | |
73 | } | |
74 | ||
75 | /* * | |
76 | * Get the c onfigurati on directo ry. Usuall y, derived classes d o not need to | |
77 | * access th e director y and just rely on t he storeCo nfiguratio n)( and | |
78 | * loadConfi guration() methods. This metho d is provi ded for ex ceptional | |
79 | * cases. | |
80 | * / | |
81 | pu blic File getConfigu rationDire ctory() | |
82 | { | |
83 | Stri ng configu rationDire ctoryName = System.g etenv("vix config"); | |
84 | if ( configurat ionDirecto ryName == null) | |
85 | config urationDir ectoryName = System. getPropert y("user.ho me"); | |
86 | if ( configurat ionDirecto ryName == null) | |
87 | config urationDir ectoryName = "/"; | |
88 | ||
89 | File configura tionDirect ory = new File(confi gurationDi rectoryNam e); | |
90 | if ( !configura tionDirect ory.exists ()) | |
91 | config urationDir ectory.mkd irs(); // make the d irectories if they | |
92 | // d on't exist | |
93 | ||
94 | retu rn configu rationDire ctory; | |
95 | } | |
96 | ||
97 | /* * | |
98 | * | |
99 | * @param pr oviderName | |
100 | * @param pr oviderVers ion | |
101 | * @return | |
102 | * / | |
103 | pu blic Strin g getConfi gurationFi leName() | |
104 | { | |
105 | File configura tionDirect ory = getC onfigurati onDirector y(); | |
106 | ||
107 | retu rn configu rationDire ctory.getA bsolutePat h() + "/" + | |
108 | getPro viderName( ) + "-" + | |
109 | Double .toString( getProvide rVersion() ) + ".conf ig"; | |
110 | } | |
111 | ||
112 | /* * | |
113 | * | |
114 | * @param co nfiguratio nFileName | |
115 | * @return | |
116 | * @throws I OException | |
117 | * / | |
118 | pu blic File getConfigu rationFile () | |
119 | th rows IOExc eption | |
120 | { | |
121 | File configura tionFile = new File( getConfigu rationFile Name()); | |
122 | if ( !configura tionFile.e xists()) | |
123 | config urationFil e.createNe wFile(); | |
124 | ||
125 | retu rn configu rationFile ; | |
126 | } | |
127 | ||
128 | /* * | |
129 | * This meth od reads t he first O bject from the confi guration f ile and | |
130 | * returns i t. This me thod does the class loader swi tching nec essary. | |
131 | * | |
132 | * @return | |
133 | * @throws I OException | |
134 | * / | |
135 | pu blic T loa dConfigura tion() | |
136 | th rows IOExc eption | |
137 | { | |
138 | Clas sLoader lo ader = nul l; | |
139 | Stri ng compone ntIdentifi cation = " <unknown>" ; | |
140 | ||
141 | try | |
142 | { | |
143 | try | |
144 | { | |
145 | // hold onto the p revious lo ader | |
146 | loader = Thread.cu rrentThrea d().getCon textClassL oader(); | |
147 | // set t he current thread cl ass loader to the cl ass loader of the | |
148 | Thread.c urrentThre ad().setCo ntextClass Loader(thi s.getClass ().getClas sLoader()) ; | |
149 | componen tIdentific ation = "< unknown, a fter class loader sw itch>"; | |
150 | } | |
151 | catch (Throwable t) | |
152 | { | |
153 | // error s caught h ere indica te that we don't hav e the perm ission | |
154 | // neede d | |
155 | // to ch ange Class Loader, ch eck and fi x the java policy fi le. | |
156 | getLogge r().error( "Error loa ding confi guration i n '" + com ponentIden tification | |
157 | + "', the java secur ity policy may be se t too tigh t.", t); | |
158 | return n ull; | |
159 | } | |
160 | try | |
161 | { | |
162 | return i nternalLoa d(); | |
163 | } | |
164 | catch( IOExceptio n ioX) | |
165 | { | |
166 | getLogge r().error( "Error loa ding confi guration i n '" + com ponentIden tification + "'.", i oX); | |
167 | throw io X; | |
168 | } | |
169 | catch( com.though tworks.xst ream.io.St reamExcept ion sX) | |
170 | { | |
171 | getLogge r().error( "Error par sing confi guration i n '" + com ponentIden tification + "'.", s X); | |
172 | throw ne w IOExcept ion(sX); | |
173 | } | |
174 | } | |
175 | fina lly | |
176 | { | |
177 | // set the curre nt thread class load er back | |
178 | if (lo ader != nu ll) | |
179 | Thread.c urrentThre ad().setCo ntextClass Loader(loa der); | |
180 | } | |
181 | } | |
182 | ||
183 | /* * | |
184 | * | |
185 | * @param co nfigFile | |
186 | * @return | |
187 | * / | |
188 | pr ivate T in ternalLoad () | |
189 | th rows IOExc eption | |
190 | { | |
191 | Inpu tStream in Stream = n ull; | |
192 | ||
193 | try | |
194 | { | |
195 | logger .info("Loa ding confi guration f rom '" + g etConfigur ationFile( ) + "'."); | |
196 | inStre am = new F ileInputSt ream(getCo nfiguratio nFile()); | |
197 | assert inStream != null; | |
198 | ||
199 | // swi tched the order to X Stream fir st and the n XMLDecod er, becaus e the | |
200 | // con fig files are all be ing switch ed to XStr eam | |
201 | try | |
202 | { | |
203 | return l oadUsingXS tream(inSt ream); | |
204 | } | |
205 | catch( com.though tworks.xst ream.conve rters.Conv ersionExce ption cX) | |
206 | { | |
207 | logger.d ebug(cX.ge tMessage() ); | |
208 | ||
209 | // close and re-op en config file | |
210 | try{inSt ream.close ();} | |
211 | catch(Th rowable t) {} | |
212 | inStream = new Fil eInputStre am(getConf igurationF ile()); | |
213 | ||
214 | return l oadUsingXM LEncoder(i nStream); | |
215 | } | |
216 | // NoS uchElement Exception is the exc eption tha t XMLDecod er throws when | |
217 | // it is asked t o decode a string th at XMLEnco der did no t write, d etermined empiricall y | |
218 | //catc h(NoSuchEl ementExcep tion nseX) | |
219 | //{ | |
220 | //} | |
221 | } | |
222 | catc h (IOExcep tion ioX) | |
223 | { | |
224 | throw ioX; | |
225 | } | |
226 | fina lly | |
227 | { | |
228 | try{in Stream.clo se();} | |
229 | catch( Throwable t){} | |
230 | } | |
231 | } | |
232 | ||
233 | /* * | |
234 | * Store the configura tion objec t to the c onfigurati on file. W hat the | |
235 | * configura tion objec t is, is u p to the i mplementat ion classe s. | |
236 | * | |
237 | * @param co nfiguratio n | |
238 | * / | |
239 | pu blic void store(T co nfiguratio n) | |
240 | th rows IOExc eption | |
241 | { | |
242 | File OutputStre am outStre am = null; | |
243 | try | |
244 | { | |
245 | outStr eam = new FileOutput Stream(get Configurat ionFile()) ; | |
246 | // alw ays store in XStream now | |
247 | storeU singXStrea m(outStrea m, configu ration); | |
248 | } | |
249 | catc h(IOExcept ion ioX) | |
250 | { | |
251 | throw ioX; | |
252 | } | |
253 | fina lly | |
254 | { | |
255 | try{ou tStream.cl ose();} | |
256 | catch( Throwable t){} | |
257 | } | |
258 | } | |
259 | ||
260 | pr ivate void storeUsin gXStream(O utputStrea m outStrea m, T confi guration) | |
261 | th rows IOExc eption | |
262 | { | |
263 | logg er.info("S aving conf iguration '" + confi guration.t oString() + "' using XStream." ); | |
264 | XStr eam xstrea m = new XS tream(); | |
265 | xstr eam.toXML( configurat ion, outSt ream); | |
266 | logg er.info("C onfigurati on saved u sing XStre am."); | |
267 | } | |
268 | ||
269 | @S uppressWar nings("unc hecked") | |
270 | pr ivate T lo adUsingXSt ream(Input Stream inS tream) | |
271 | { | |
272 | logg er.info("L oading con figuration using XSt ream"); | |
273 | XStr eam xstrea m = new XS tream(); | |
274 | T co nfig = (T) xstream.fr omXML(inSt ream); | |
275 | logg er.info("C onfigurati on loaded using XStr eam and is " + (conf ig == null ? "NULL" : "NOT NUL L") ); | |
276 | ||
277 | retu rn config; | |
278 | } | |
279 | ||
280 | pr ivate void storeUsin gXMLEncode r(OutputSt ream outSt ream, T co nfiguratio n) | |
281 | th rows IOExc eption | |
282 | { | |
283 | logg er.info("S aving conf iguration '" + confi guration.t oString() + "' using XMLEncode r."); | |
284 | ||
285 | XMLE ncoder xml Encoder = new XMLEnc oder(outSt ream); | |
286 | xmlE ncoder.wri teObject(c onfigurati on); | |
287 | xmlE ncoder.clo se(); | |
288 | } | |
289 | ||
290 | @S uppressWar nings("unc hecked") | |
291 | pr ivate T lo adUsingXML Encoder(In putStream inStream) | |
292 | th rows IOExc eption | |
293 | { | |
294 | logg er.info("L oading con figuration using XML Decoder"); | |
295 | ||
296 | XMLD ecoder xml Decoder = new XMLDec oder(inStr eam); | |
297 | T co nfig = (T) xmlDecoder .readObjec t(); | |
298 | logg er.info("C onfigurati on loaded using XMLD ecoder and is " + (c onfig == n ull ? "NUL L" : "NOT NULL") ); | |
299 | xmlD ecoder.clo se(); | |
300 | retu rn config; | |
301 | } | |
302 | ||
303 | @S uppressWar nings("unc hecked") | |
304 | pu blic stati c <T exten ds Object> T seriali zeAndDeser ializeByXS treamTest( T src) | |
305 | { | |
306 | Byte ArrayOutpu tStream ou tStream = new ByteAr rayOutputS tream(4096 ); | |
307 | XStr eam xstrea mOut = new XStream() ; | |
308 | xstr eamOut.toX ML(src, ou tStream); | |
309 | ||
310 | Byte ArrayInput Stream inS tream = ne w ByteArra yInputStre am( outStr eam.toByte Array() ); | |
311 | XStr eam xstrea mIn = new XStream(); | |
312 | T re sult = (T) xstreamIn. fromXML(in Stream); | |
313 | retu rn result; | |
314 | } | |
315 | ||
316 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.