Produced by Araxis Merge on 9/25/2018 2:13:11 PM 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 | build 3.zip\build 3\MHLTH_YS_137_Source\JavaScript\resources\javaJDF-1.8.0\src\javax\management\loading | MLet.java | Mon Jan 22 14:46:52 2018 UTC |
2 | build 3.zip\build 3\MHLTH_YS_137_Source\JavaScript\resources\javaJDF-1.8.0\src\javax\management\loading | MLet.java | Wed Sep 12 17:20:19 2018 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 2 | 2674 |
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 | * Copyrig ht (c) 199 9, 2013, O racle and/ or its aff iliates. A ll rights reserved. | |
3 | * DO NOT ALTER OR R EMOVE COPY RIGHT NOTI CES OR THI S FILE HEA DER. | |
4 | * | |
5 | * This co de is free software; you can r edistribut e it and/o r modify i t | |
6 | * under t he terms o f the GNU General Pu blic Licen se version 2 only, a s | |
7 | * publish ed by the Free Softw are Founda tion. Ora cle design ates this | |
8 | * particu lar file a s subject to the "Cl asspath" e xception a s provided | |
9 | * by Orac le in the LICENSE fi le that ac companied this code. | |
10 | * | |
11 | * This co de is dist ributed in the hope that it wi ll be usef ul, but WI THOUT | |
12 | * ANY WAR RANTY; wit hout even the implie d warranty of MERCHA NTABILITY or | |
13 | * FITNESS FOR A PAR TICULAR PU RPOSE. Se e the GNU General Pu blic Licen se | |
14 | * version 2 for mor e details (a copy is included in the LIC ENSE file that | |
15 | * accompa nied this code). | |
16 | * | |
17 | * You sho uld have r eceived a copy of th e GNU Gene ral Public License v ersion | |
18 | * 2 along with this work; if not, write to the Fr ee Softwar e Foundati on, | |
19 | * Inc., 5 1 Franklin St, Fifth Floor, Bo ston, MA 0 2110-1301 USA. | |
20 | * | |
21 | * Please contact Or acle, 500 Oracle Par kway, Redw ood Shores , CA 94065 USA | |
22 | * or visi t www.orac le.com if you need a dditional informatio n or have any | |
23 | * questio ns. | |
24 | */ | |
25 | ||
26 | package ja vax.manage ment.loadi ng; | |
27 | ||
28 | // Java im port | |
29 | import com .sun.jmx.d efaults.Jm xPropertie s; | |
30 | ||
31 | import com .sun.jmx.d efaults.Se rviceName; | |
32 | ||
33 | import com .sun.jmx.r emote.util .EnvHelp; | |
34 | ||
35 | import jav a.io.Exter nalizable; | |
36 | import jav a.io.File; | |
37 | import jav a.io.FileO utputStrea m; | |
38 | import jav a.io.IOExc eption; | |
39 | import jav a.io.Input Stream; | |
40 | import jav a.io.Objec tInput; | |
41 | import jav a.io.Objec tInputStre am; | |
42 | import jav a.io.Objec tOutput; | |
43 | import jav a.lang.ref lect.Const ructor; | |
44 | import jav a.net.Malf ormedURLEx ception; | |
45 | import jav a.net.URL; | |
46 | import jav a.net.URLS treamHandl erFactory; | |
47 | import jav a.nio.file .Files; | |
48 | import jav a.security .AccessCon troller; | |
49 | import jav a.security .Privilege dAction; | |
50 | import jav a.util.Arr ayList; | |
51 | import jav a.util.Arr ays; | |
52 | import jav a.util.Has hMap; | |
53 | import jav a.util.Has hSet; | |
54 | import jav a.util.Lis t; | |
55 | import jav a.util.log ging.Level ; | |
56 | import jav a.util.Map ; | |
57 | import jav a.util.Set ; | |
58 | import jav a.util.Str ingTokeniz er; | |
59 | ||
60 | import jav ax.managem ent.Instan ceAlreadyE xistsExcep tion; | |
61 | import jav ax.managem ent.Instan ceNotFound Exception; | |
62 | import jav ax.managem ent.MBeanE xception; | |
63 | import jav ax.managem ent.MBeanR egistratio n; | |
64 | import jav ax.managem ent.MBeanR egistratio nException ; | |
65 | import jav ax.managem ent.MBeanS erver; | |
66 | import jav ax.managem ent.NotCom pliantMBea nException ; | |
67 | import jav ax.managem ent.Object Instance; | |
68 | import jav ax.managem ent.Object Name; | |
69 | import jav ax.managem ent.Reflec tionExcept ion; | |
70 | ||
71 | import sta tic com.su n.jmx.defa ults.JmxPr operties.M LET_LIB_DI R; | |
72 | import sta tic com.su n.jmx.defa ults.JmxPr operties.M LET_LOGGER ; | |
73 | import com .sun.jmx.d efaults.Se rviceName; | |
74 | import jav ax.managem ent.Servic eNotFoundE xception; | |
75 | ||
76 | /** | |
77 | * Allows you to ins tantiate a nd registe r one or s everal MBe ans in the MBean ser ver | |
78 | * coming from a rem ote URL. M -let is a shortcut f or managem ent applet . The m-le t service does this | |
79 | * by load ing an m-l et text fi le, which specifies informatio n on the M Beans to b e obtained . | |
80 | * The inf ormation o n each MBe an is spec ified in a single in stance of a tag, cal led the ML ET tag. | |
81 | * The loc ation of t he m-let t ext file i s specifie d by a URL . | |
82 | * <p> | |
83 | * The <CO DE>MLET</C ODE> tag h as the fol lowing syn tax: | |
84 | * <p> | |
85 | * <<CO DE>MLET</C ODE><BR> | |
86 | * <C ODE>CODE = </CODE><V AR>class</ VAR><CODE> | OBJECT = </CODE>< VAR>serfil e</VAR><BR > | |
87 | * <C ODE>ARCHIV E = " </CODE><VA R>archiveL ist</VAR>< CODE>" ;</CODE><B R> | |
88 | * <C ODE>[CODEB ASE = </CO DE><VAR>co debaseURL< /VAR><CODE >]</CODE>< BR> | |
89 | * <C ODE>[NAME = </CODE>< VAR>mbeann ame</VAR>< CODE>]</CO DE><BR> | |
90 | * <C ODE>[VERSI ON = </COD E><VAR>ver sion</VAR> <CODE>]</C ODE><BR> | |
91 | * ><BR > | |
92 | * <C ODE>[</COD E><VAR>arg list</VAR> <CODE>]</C ODE><BR> | |
93 | * <<CO DE>/MLET</ CODE>> | |
94 | * <p> | |
95 | * where: | |
96 | * <DL> | |
97 | * <DT><CO DE>CODE = </CODE><VA R>class</V AR></DT> | |
98 | * <DD> | |
99 | * This at tribute sp ecifies th e full Jav a class na me, includ ing packag e name, of the MBean to be obt ained. | |
100 | * The com piled <COD E>.class</ CODE> file of the MB ean must b e containe d in one o f the <COD E>.jar</CO DE> files specified by the <CO DE>ARCHIVE </CODE> | |
101 | * attribu te. Either <CODE>COD E</CODE> o r <CODE>OB JECT</CODE > must be present. | |
102 | * </DD> | |
103 | * <DT><CO DE>OBJECT = </CODE>< VAR>serfil e</VAR></D T> | |
104 | * <DD> | |
105 | * This at tribute sp ecifies th e <CODE>.s er</CODE> file that contains a serialize d represen tation of the MBean to be obta ined. | |
106 | * This fi le must be contained in one of the <CODE >.jar</COD E> files s pecified b y the <COD E>ARCHIVE< /CODE> att ribute. If the <CODE >.jar</COD E> file co ntains a d irectory h ierarchy, specify th e path of the file w ithin this hierarchy . Otherwis e a match will not be found. Either <CO DE>CODE</C ODE> or <C ODE>OBJECT </CODE> mu st be pres ent. | |
107 | * </DD> | |
108 | * <DT><CO DE>ARCHIVE = "< /CODE><VAR >archiveLi st</VAR><C ODE>" </CODE></D T> | |
109 | * <DD> | |
110 | * This ma ndatory at tribute sp ecifies on e or more <CODE>.jar </CODE> fi les | |
111 | * contain ing MBeans or other resources used by | |
112 | * the MBe an to be o btained. O ne of the <CODE>.jar </CODE> fi les must c ontain the file spec ified by t he <CODE>C ODE</CODE> or <CODE> OBJECT</CO DE> attrib ute. | |
113 | * If arch ivelist co ntains mor e than one file: | |
114 | * <UL> | |
115 | * <LI>Eac h file mus t be separ ated from the one th at follows it by a c omma (,). | |
116 | * <LI><VA R>archivel ist</VAR> must be en closed in double quo te marks. | |
117 | * </UL> | |
118 | * All <CO DE>.jar</C ODE> files in <VAR>a rchivelist </VAR> mus t be store d in the d irectory s pecified b y the code base URL. | |
119 | * </DD> | |
120 | * <DT><CO DE>CODEBAS E = </CODE ><VAR>code baseURL</V AR></DT> | |
121 | * <DD> | |
122 | * This op tional att ribute spe cifies the code base URL of th e MBean to be obtain ed. It ide ntifies th e director y that con tains | |
123 | * the <CO DE>.jar</C ODE> files specified by the <C ODE>ARCHIV E</CODE> a ttribute. Specify th is attribu te only if the <CODE >.jar</COD E> files a re not in the same | |
124 | * directo ry as the m-let text file. If this attri bute is no t specifie d, the bas e URL of t he m-let t ext file i s used. | |
125 | * </DD> | |
126 | * <DT><CO DE>NAME = </CODE><VA R>mbeannam e</VAR></D T> | |
127 | * <DD> | |
128 | * This op tional att ribute spe cifies the object na me to be a ssigned to the | |
129 | * MBean i nstance wh en the m-l et service registers it. If | |
130 | * <VAR>mb eanname</V AR> starts with the colon char acter (:), the domai n | |
131 | * part of the objec t name is the defaul t domain o f the MBea n server, | |
132 | * as retu rned by {@ link javax .managemen t.MBeanSer ver#getDef aultDomain ()}. | |
133 | * </DD> | |
134 | * <DT><CO DE>VERSION = </CODE> <VAR>versi on</VAR></ DT> | |
135 | * <DD> | |
136 | * This op tional att ribute spe cifies the version n umber of t he MBean a nd | |
137 | * associa ted <CODE> .jar</CODE > files to be obtain ed. This v ersion num ber can | |
138 | * be used to specif y that the <CODE>.ja r</CODE> f iles are l oaded from the | |
139 | * server to update those stor ed locally in the ca che the ne xt time th e m-let | |
140 | * text fi le is load ed. <VAR>v ersion</VA R> must be a series of non-neg ative | |
141 | * decimal integers each separ ated by a period fro m the one that prece des it. | |
142 | * </DD> | |
143 | * <DT><VA R>arglist< /VAR></DT> | |
144 | * <DD> | |
145 | * This op tional att ribute spe cifies a l ist of one or more p arameters for the | |
146 | * MBean t o be insta ntiated. T his list d escribes t he paramet ers to be passed the MBean's c onstructor . | |
147 | * Use the following syntax to specify e ach item i n | |
148 | * <VAR>ar glist</VAR >: | |
149 | * <DL> | |
150 | * <DT>< ;<CODE>ARG TYPE=</CO DE><VAR>ar gumentType </VAR> <CO DE>VALUE=< /CODE><VAR >value</VA R>></DT > | |
151 | * <DD>whe re: | |
152 | * <UL> | |
153 | * <LI><VA R>argument Type</VAR> is the ty pe of the argument t hat will b e passed a s paramete r to the M Bean's con structor.< /UL> | |
154 | * </DD> | |
155 | * </DL> | |
156 | * <P>The arguments' type in t he argumen t list sho uld be a J ava primit ive type o r a Java b asic type | |
157 | * (<CODE> java.lang. Boolean, j ava.lang.B yte, java. lang.Short , java.lan g.Long, ja va.lang.In teger, jav a.lang.Flo at, java.l ang.Double , java.lan g.String</ CODE>). | |
158 | * </DD> | |
159 | * </DL> | |
160 | * | |
161 | * When an m-let tex t file is loaded, an | |
162 | * instanc e of each MBean spec ified in t he file is created a nd registe red. | |
163 | * <P> | |
164 | * The m-l et service extends t he <CODE>j ava.net.UR LClassLoad er</CODE> and can be used to l oad remote classes | |
165 | * and jar files in the VM of the agent. | |
166 | * <p><STR ONG>Note - </STRONG> The <CODE >MLet</COD E> class l oader uses the {@lin k javax.ma nagement.M BeanServer Factory#ge tClassLoad erReposito ry(javax.m anagement. MBeanServe r)} | |
167 | * to load classes t hat could not be fou nd in the loaded jar files. | |
168 | * | |
169 | * @since 1.5 | |
170 | */ | |
171 | public cla ss MLet ex tends java .net.URLCl assLoader | |
172 | imple ments MLet MBean, MBe anRegistra tion, Exte rnalizable { | |
173 | ||
174 | priva te static final long serialVer sionUID = 3636148327 800330130L ; | |
175 | ||
176 | /* | |
177 | * --- ---------- ---------- ---------- --------- | |
178 | * P RIVATE VAR IABLES | |
179 | * --- ---------- ---------- ---------- --------- | |
180 | */ | |
181 | ||
182 | /** | |
183 | * Th e referenc e to the M Bean serve r. | |
184 | * @s erial | |
185 | */ | |
186 | priva te MBeanSe rver serve r = null; | |
187 | ||
188 | ||
189 | /** | |
190 | * Th e list of instances of the <CO DE>MLetCon tent</CODE > | |
191 | * cl ass found at the spe cified URL . | |
192 | * @s erial | |
193 | */ | |
194 | priva te List<ML etContent> mletList = new Arra yList<MLet Content>() ; | |
195 | ||
196 | ||
197 | /** | |
198 | * Th e director y used for storing l ibraries l ocally bef ore they a re loaded. | |
199 | */ | |
200 | priva te String libraryDir ectory; | |
201 | ||
202 | ||
203 | /** | |
204 | * Th e object n ame of the MLet Serv ice. | |
205 | * @s erial | |
206 | */ | |
207 | priva te ObjectN ame mletOb jectName = null; | |
208 | ||
209 | /** | |
210 | * Th e URLs of the MLet S ervice. | |
211 | * @s erial | |
212 | */ | |
213 | priva te URL[] m yUrls = nu ll; | |
214 | ||
215 | /** | |
216 | * Wh at ClassLo aderReposi tory, if a ny, to use if this M Let | |
217 | * do esn't find an asked- for class. | |
218 | */ | |
219 | priva te transie nt ClassLo aderReposi tory curre ntClr; | |
220 | ||
221 | /** | |
222 | * Tr ue if we s hould cons ult the {@ link Class LoaderRepo sitory} | |
223 | * wh en we do n ot find a class ours elves. | |
224 | */ | |
225 | priva te transie nt boolean delegateT oCLR; | |
226 | ||
227 | /** | |
228 | * ob jects maps from prim itive clas ses to pri mitive obj ect classe s. | |
229 | */ | |
230 | priva te Map<Str ing,Class< ?>> primit iveClasses = | |
231 | n ew HashMap <String,Cl ass<?>>(8) ; | |
232 | { | |
233 | p rimitiveCl asses.put( Boolean.TY PE.toStrin g(), Boole an.class); | |
234 | p rimitiveCl asses.put( Character. TYPE.toStr ing(), Cha racter.cla ss); | |
235 | p rimitiveCl asses.put( Byte.TYPE. toString() , Byte.cla ss); | |
236 | p rimitiveCl asses.put( Short.TYPE .toString( ), Short.c lass); | |
237 | p rimitiveCl asses.put( Integer.TY PE.toStrin g(), Integ er.class); | |
238 | p rimitiveCl asses.put( Long.TYPE. toString() , Long.cla ss); | |
239 | p rimitiveCl asses.put( Float.TYPE .toString( ), Float.c lass); | |
240 | p rimitiveCl asses.put( Double.TYP E.toString (), Double .class); | |
241 | ||
242 | } | |
243 | ||
244 | ||
245 | /* | |
246 | * -- ---------- ---------- ---------- ---------- | |
247 | * C ONSTRUCTOR S | |
248 | * -- ---------- ---------- ---------- ---------- | |
249 | */ | |
250 | ||
251 | /* | |
252 | * Th e construc tor stuff would be c onsiderabl y simplifi ed if our | |
253 | * pa rent, URLC lassLoader , specifie d that its one- and | |
254 | * tw o-argument construct ors were e quivalent to its | |
255 | * th ree-argume nt constru ctor with trailing n ull argume nts. But | |
256 | * it doesn't, which prev ents us fr om having all the co nstructors | |
257 | * bu t one call this(...a rgs...). | |
258 | */ | |
259 | ||
260 | /** | |
261 | * Co nstructs a new MLet using the default de legation p arent Clas sLoader. | |
262 | */ | |
263 | publi c MLet() { | |
264 | t his(new UR L[0]); | |
265 | } | |
266 | ||
267 | /** | |
268 | * Co nstructs a new MLet for the sp ecified UR Ls using t he default | |
269 | * de legation p arent Clas sLoader. The URLs w ill be sea rched in | |
270 | * th e order sp ecified fo r classes and resour ces after first | |
271 | * se arching in the paren t class lo ader. | |
272 | * | |
273 | * @p aram urls The URLs from whic h to load classes an d resource s. | |
274 | * | |
275 | */ | |
276 | publi c MLet(URL [] urls) { | |
277 | t his(urls, true); | |
278 | } | |
279 | ||
280 | /** | |
281 | * Co nstructs a new MLet for the gi ven URLs. The URLs w ill be | |
282 | * se arched in the order specified for classe s and reso urces | |
283 | * af ter first searching in the spe cified par ent class loader. | |
284 | * Th e parent a rgument wi ll be used as the pa rent class loader | |
285 | * fo r delegati on. | |
286 | * | |
287 | * @p aram urls The URLs from whic h to load classes an d resource s. | |
288 | * @p aram pare nt The par ent class loader for delegatio n. | |
289 | * | |
290 | */ | |
291 | publi c MLet(URL [] urls, C lassLoader parent) { | |
292 | t his(urls, parent, tr ue); | |
293 | } | |
294 | ||
295 | /** | |
296 | * Co nstructs a new MLet for the sp ecified UR Ls, parent class | |
297 | * lo ader, and URLStreamH andlerFact ory. The p arent argu ment will | |
298 | * be used as t he parent class load er for del egation. T he factory | |
299 | * ar gument wil l be used as the str eam handle r factory to obtain | |
300 | * pr otocol han dlers when creating new URLs. | |
301 | * | |
302 | * @p aram urls The URLs from whic h to load classes an d resource s. | |
303 | * @p aram pare nt The par ent class loader for delegatio n. | |
304 | * @p aram fact ory The U RLStreamHa ndlerFacto ry to use when creat ing URLs. | |
305 | * | |
306 | */ | |
307 | publi c MLet(URL [] urls, | |
308 | Cla ssLoader p arent, | |
309 | URL StreamHand lerFactory factory) { | |
310 | t his(urls, parent, fa ctory, tru e); | |
311 | } | |
312 | ||
313 | /** | |
314 | * Co nstructs a new MLet for the sp ecified UR Ls using t he default | |
315 | * de legation p arent Clas sLoader. The URLs w ill be sea rched in | |
316 | * th e order sp ecified fo r classes and resour ces after first | |
317 | * se arching in the paren t class lo ader. | |
318 | * | |
319 | * @p aram urls The URLs from whic h to load classes an d resource s. | |
320 | * @p aram dele gateToCLR True if, when a cla ss is not found in | |
321 | * ei ther the p arent Clas sLoader or the URLs, the MLet should del egate | |
322 | * to its conta ining MBea nServer's {@link Cla ssLoaderRe pository}. | |
323 | * | |
324 | */ | |
325 | publi c MLet(URL [] urls, b oolean del egateToCLR ) { | |
326 | s uper(urls) ; | |
327 | i nit(delega teToCLR); | |
328 | } | |
329 | ||
330 | /** | |
331 | * Co nstructs a new MLet for the gi ven URLs. The URLs w ill be | |
332 | * se arched in the order specified for classe s and reso urces | |
333 | * af ter first searching in the spe cified par ent class loader. | |
334 | * Th e parent a rgument wi ll be used as the pa rent class loader | |
335 | * fo r delegati on. | |
336 | * | |
337 | * @p aram urls The URLs from whic h to load classes an d resource s. | |
338 | * @p aram pare nt The par ent class loader for delegatio n. | |
339 | * @p aram dele gateToCLR True if, when a cla ss is not found in | |
340 | * ei ther the p arent Clas sLoader or the URLs, the MLet should del egate | |
341 | * to its conta ining MBea nServer's {@link Cla ssLoaderRe pository}. | |
342 | * | |
343 | */ | |
344 | publi c MLet(URL [] urls, C lassLoader parent, b oolean del egateToCLR ) { | |
345 | s uper(urls, parent); | |
346 | i nit(delega teToCLR); | |
347 | } | |
348 | ||
349 | /** | |
350 | * Co nstructs a new MLet for the sp ecified UR Ls, parent class | |
351 | * lo ader, and URLStreamH andlerFact ory. The p arent argu ment will | |
352 | * be used as t he parent class load er for del egation. T he factory | |
353 | * ar gument wil l be used as the str eam handle r factory to obtain | |
354 | * pr otocol han dlers when creating new URLs. | |
355 | * | |
356 | * @p aram urls The URLs from whic h to load classes an d resource s. | |
357 | * @p aram pare nt The par ent class loader for delegatio n. | |
358 | * @p aram fact ory The U RLStreamHa ndlerFacto ry to use when creat ing URLs. | |
359 | * @p aram dele gateToCLR True if, when a cla ss is not found in | |
360 | * ei ther the p arent Clas sLoader or the URLs, the MLet should del egate | |
361 | * to its conta ining MBea nServer's {@link Cla ssLoaderRe pository}. | |
362 | * | |
363 | */ | |
364 | publi c MLet(URL [] urls, | |
365 | Cla ssLoader p arent, | |
366 | URL StreamHand lerFactory factory, | |
367 | boo lean deleg ateToCLR) { | |
368 | s uper(urls, parent, f actory); | |
369 | i nit(delega teToCLR); | |
370 | } | |
371 | ||
372 | priva te void in it(boolean delegateT oCLR) { | |
373 | t his.delega teToCLR = delegateTo CLR; | |
374 | ||
375 | t ry { | |
376 | library Directory = System.g etProperty (MLET_LIB_ DIR); | |
377 | if (lib raryDirect ory == nul l) | |
378 | lib raryDirect ory = getT mpDir(); | |
379 | } catch (Se curityExce ption e) { | |
380 | // OK : We don't do AccessC ontroller. doPrivileg ed, but we don't | |
381 | // stop the user from creating a n MLet jus t because they | |
382 | // can't rea d the MLET _LIB_DIR o r java.io. tmpdir pro perties | |
383 | // either. | |
384 | } | |
385 | } | |
386 | ||
387 | ||
388 | /* | |
389 | * -- ---------- ---------- ---------- ---------- | |
390 | * P UBLIC METH ODS | |
391 | * -- ---------- ---------- ---------- ---------- | |
392 | */ | |
393 | ||
394 | ||
395 | /** | |
396 | * Ap pends the specified URL to the list of U RLs to sea rch for cl asses and | |
397 | * re sources. | |
398 | */ | |
399 | publi c void add URL(URL ur l) { | |
400 | i f (!Arrays .asList(ge tURLs()).c ontains(ur l)) | |
401 | super.a ddURL(url) ; | |
402 | } | |
403 | ||
404 | /** | |
405 | * Ap pends the specified URL to the list of U RLs to sea rch for cl asses and | |
406 | * re sources. | |
407 | * @e xception S erviceNotF oundExcept ion The sp ecified UR L is malfo rmed. | |
408 | */ | |
409 | publi c void add URL(String url) thro ws Service NotFoundEx ception { | |
410 | t ry { | |
411 | URL ur = new URL( url); | |
412 | if (!Ar rays.asLis t(getURLs( )).contain s(ur)) | |
413 | sup er.addURL( ur); | |
414 | } catch (Ma lformedURL Exception e) { | |
415 | if (MLE T_LOGGER.i sLoggable( Level.FINE ST)) { | |
416 | MLE T_LOGGER.l ogp(Level. FINEST, ML et.class.g etName(), | |
417 | "addU rl", "Malf ormed URL: " + url, e); | |
418 | } | |
419 | throw n ew | |
420 | Ser viceNotFou ndExceptio n("The spe cified URL is malfor med"); | |
421 | } | |
422 | } | |
423 | ||
424 | /** R eturns the search pa th of URLs for loadi ng classes and resou rces. | |
425 | * Th is include s the orig inal list of URLs sp ecified to the const ructor, | |
426 | * al ong with a ny URLs su bsequently appended by the add URL() meth od. | |
427 | */ | |
428 | publi c URL[] ge tURLs() { | |
429 | r eturn supe r.getURLs( ); | |
430 | } | |
431 | ||
432 | /** | |
433 | * Lo ads a text file cont aining MLE T tags tha t define t he MBeans to | |
434 | * be added to the MBean server. Th e location of the te xt file is specified by | |
435 | * a URL. The M Beans spec ified in t he MLET fi le will be instantia ted and | |
436 | * re gistered i n the MBea n server. | |
437 | * | |
438 | * @p aram url T he URL of the text f ile to be loaded as URL object . | |
439 | * | |
440 | * @r eturn A s et contain ing one en try per ML ET tag in the m-let text file loaded. | |
441 | * Ea ch entry s pecifies e ither the ObjectInst ance for t he created MBean, or a throwab le object | |
442 | * (t hat is, an error or an excepti on) if the MBean cou ld not be created. | |
443 | * | |
444 | * @e xception S erviceNotF oundExcept ion One of the follo wing error s has occu rred: The m-let text file does | |
445 | * no t contain an MLET ta g, the m-l et text fi le is not found, a m andatory | |
446 | * at tribute of the MLET tag is not specified , the valu e of url i s | |
447 | * nu ll. | |
448 | * @e xception I llegalStat eException MLet MBea n is not r egistered with an MB eanServer. | |
449 | */ | |
450 | publi c Set<Obje ct> getMBe ansFromURL (URL url) | |
451 | throws ServiceNot FoundExcep tion { | |
452 | i f (url == null) { | |
453 | throw n ew Service NotFoundEx ception("T he specifi ed URL is null"); | |
454 | } | |
455 | r eturn getM BeansFromU RL(url.toS tring()); | |
456 | } | |
457 | ||
458 | /** | |
459 | * Lo ads a text file cont aining MLE T tags tha t define t he MBeans to | |
460 | * be added to the MBean server. Th e location of the te xt file is specified by | |
461 | * a URL. The M Beans spec ified in t he MLET fi le will be instantia ted and | |
462 | * re gistered i n the MBea n server. | |
463 | * | |
464 | * @p aram url T he URL of the text f ile to be loaded as String obj ect. | |
465 | * | |
466 | * @r eturn A se t containi ng one ent ry per MLE T tag in t he m-let | |
467 | * te xt file lo aded. Eac h entry sp ecifies ei ther the | |
468 | * Ob jectInstan ce for the created M Bean, or a throwable object | |
469 | * (t hat is, an error or an excepti on) if the MBean cou ld not be | |
470 | * cr eated. | |
471 | * | |
472 | * @e xception S erviceNotF oundExcept ion One of the follo wing | |
473 | * er rors has o ccurred: T he m-let t ext file d oes not co ntain an | |
474 | * ML ET tag, th e m-let te xt file is not found , a mandat ory | |
475 | * at tribute of the MLET tag is not specified , the url is | |
476 | * ma lformed. | |
477 | * @e xception I llegalStat eException MLet MBea n is not r egistered | |
478 | * wi th an MBea nServer. | |
479 | * | |
480 | */ | |
481 | publi c Set<Obje ct> getMBe ansFromURL (String ur l) | |
482 | throws ServiceNot FoundExcep tion { | |
483 | ||
484 | S tring mth = "getMBea nsFromURL" ; | |
485 | ||
486 | i f (server == null) { | |
487 | throw n ew Illegal StateExcep tion("This MLet MBea n is not " + | |
488 | "regi stered wit h an MBean Server."); | |
489 | } | |
490 | / / Parse ar guments | |
491 | i f (url == null) { | |
492 | MLET_LO GGER.logp( Level.FINE R, MLet.cl ass.getNam e(), | |
493 | mth, "URL is null") ; | |
494 | throw n ew Service NotFoundEx ception("T he specifi ed URL is null"); | |
495 | } else { | |
496 | url = u rl.replace (File.sepa ratorChar, '/'); | |
497 | } | |
498 | i f (MLET_LO GGER.isLog gable(Leve l.FINER)) { | |
499 | MLET_LO GGER.logp( Level.FINE R, MLet.cl ass.getNam e(), | |
500 | mth, "<UR L = " + ur l + ">"); | |
501 | } | |
502 | ||
503 | / / Parse UR L | |
504 | t ry { | |
505 | MLetPar ser parser = new MLe tParser(); | |
506 | mletLis t = parser .parseURL( url); | |
507 | } catch (Ex ception e) { | |
508 | final S tring msg = | |
509 | "Pr oblems whi le parsing URL [" + url + | |
510 | "], got excep tion [" + e.toString () + "]"; | |
511 | MLET_LO GGER.logp( Level.FINE R, MLet.cl ass.getNam e(), mth, msg); | |
512 | throw E nvHelp.ini tCause(new ServiceNo tFoundExce ption(msg) , e); | |
513 | } | |
514 | ||
515 | / / Check th at the lis t of MLets is not em pty | |
516 | i f (mletLis t.size() = = 0) { | |
517 | final S tring msg = | |
518 | "Fi le " + url + " not f ound or ML ET tag not defined i n file"; | |
519 | MLET_LO GGER.logp( Level.FINE R, MLet.cl ass.getNam e(), mth, msg); | |
520 | throw n ew Service NotFoundEx ception(ms g); | |
521 | } | |
522 | ||
523 | / / Walk thr ough the l ist of MLe ts | |
524 | S et<Object> mbeans = new HashSe t<Object>( ); | |
525 | f or (MLetCo ntent elmt : mletLis t) { | |
526 | // Init ialize loc al variabl es | |
527 | String code = elm t.getCode( ); | |
528 | if (cod e != null) { | |
529 | if (code.ends With(".cla ss")) { | |
530 | code = co de.substri ng(0, code .length() - 6); | |
531 | } | |
532 | } | |
533 | String name = elm t.getName( ); | |
534 | URL cod ebase = el mt.getCode Base(); | |
535 | String version = elmt.getVe rsion(); | |
536 | String serName = elmt.getSe rializedOb ject(); | |
537 | String jarFiles = elmt.getJ arFiles(); | |
538 | URL doc umentBase = elmt.get DocumentBa se(); | |
539 | ||
540 | // Disp lay debug informatio n | |
541 | if (MLE T_LOGGER.i sLoggable( Level.FINE R)) { | |
542 | fin al StringB uilder str b = new St ringBuilde r() | |
543 | .ap pend("\n\t MLET TAG = ").ap pend(elmt. getAttribu tes()) | |
544 | .ap pend("\n\t CODEBASE = ").ap pend(codeb ase) | |
545 | .ap pend("\n\t ARCHIVE = ").ap pend(jarFi les) | |
546 | .ap pend("\n\t CODE = ").ap pend(code) | |
547 | .ap pend("\n\t OBJECT = ").ap pend(serNa me) | |
548 | .ap pend("\n\t NAME = ").ap pend(name) | |
549 | .ap pend("\n\t VERSION = ").ap pend(versi on) | |
550 | .ap pend("\n\t DOCUMENT U RL = ").ap pend(docum entBase); | |
551 | MLE T_LOGGER.l ogp(Level. FINER, MLe t.class.ge tName(), | |
552 | mth, strb.toStr ing()); | |
553 | } | |
554 | ||
555 | // Load classes f rom JAR fi les | |
556 | StringT okenizer s t = new St ringTokeni zer(jarFil es, ",", f alse); | |
557 | while ( st.hasMore Tokens()) { | |
558 | Str ing tok = st.nextTok en().trim( ); | |
559 | if (MLET_LOGG ER.isLogga ble(Level. FINER)) { | |
560 | MLET_LOGG ER.logp(Le vel.FINER, MLet.clas s.getName( ), mth, | |
561 | " Load archi ve for cod ebase <" + codebase + | |
562 | " >, file <" + tok + " >"); | |
563 | } | |
564 | // Check whic h is the c odebase to be used f or loading the jar f ile. | |
565 | // If we are using the base MLet implementa tion then it will be | |
566 | // always the remote se rver but i f the serv ice has be en extende d in | |
567 | // order to s upport cac hing and v ersioning then this method wil l | |
568 | // return the appropria te one. | |
569 | // | |
570 | try { | |
571 | codebase = check(ve rsion, cod ebase, tok , elmt); | |
572 | } c atch (Exce ption ex) { | |
573 | MLET_LOGG ER.logp(Le vel.FINEST , MLet.cla ss.getName (), | |
574 | m th, "Got u nexpected exception" , ex); | |
575 | mbeans.ad d(ex); | |
576 | continue; | |
577 | } | |
578 | ||
579 | // Appends th e specifie d JAR file URL to th e list of | |
580 | // URLs to se arch for c lasses and resources . | |
581 | try { | |
582 | if (!Arra ys.asList( getURLs()) | |
583 | .cont ains(new U RL(codebas e.toString () + tok)) ) { | |
584 | addUR L(codebase + tok); | |
585 | } | |
586 | } c atch (Malf ormedURLEx ception me ) { | |
587 | // OK : I gnore jar file if it s name pro vokes the | |
588 | // URL to be an inv alid one. | |
589 | } | |
590 | ||
591 | } | |
592 | // Inst antiate th e class sp ecified in the | |
593 | // CODE or OBJECT section o f the MLet tag | |
594 | // | |
595 | Object o; | |
596 | ObjectI nstance ob jInst; | |
597 | ||
598 | if (cod e != null && serName != null) { | |
599 | fin al String msg = | |
600 | "CODE and OBJECT pa rameters c annot be s pecified a t the " + | |
601 | "same tim e in tag M LET"; | |
602 | MLE T_LOGGER.l ogp(Level. FINER, MLe t.class.ge tName(), m th, msg); | |
603 | mbe ans.add(ne w Error(ms g)); | |
604 | con tinue; | |
605 | } | |
606 | if (cod e == null && serName == null) { | |
607 | fin al String msg = | |
608 | "Either C ODE or OBJ ECT parame ter must b e specifie d in " + | |
609 | "tag MLET "; | |
610 | MLE T_LOGGER.l ogp(Level. FINER, MLe t.class.ge tName(), m th, msg); | |
611 | mbe ans.add(ne w Error(ms g)); | |
612 | con tinue; | |
613 | } | |
614 | try { | |
615 | if (code != n ull) { | |
616 | ||
617 | List<Stri ng> signat = elmt.ge tParameter Types(); | |
618 | List<Stri ng> string Pars = elm t.getParam eterValues (); | |
619 | List<Obje ct> object Pars = new ArrayList <Object>() ; | |
620 | ||
621 | for (int i = 0; i < signat.si ze(); i++) { | |
622 | objec tPars.add( constructP arameter(s tringPars. get(i), | |
623 | s ignat.get( i))); | |
624 | } | |
625 | if (signa t.isEmpty( )) { | |
626 | if (n ame == nul l) { | |
627 | o bjInst = s erver.crea teMBean(co de, null, | |
628 | ml etObjectNa me); | |
629 | } els e { | |
630 | o bjInst = s erver.crea teMBean(co de, | |
631 | ne w ObjectNa me(name), | |
632 | ml etObjectNa me); | |
633 | } | |
634 | } else { | |
635 | Objec t[] parms = objectPa rs.toArray (); | |
636 | Strin g[] signat ure = new String[sig nat.size() ]; | |
637 | signa t.toArray( signature) ; | |
638 | if (M LET_LOGGER .isLoggabl e(Level.FI NEST)) { | |
639 | f inal Strin gBuilder s trb = new StringBuil der(); | |
640 | f or (int i = 0; i < s ignature.l ength; i++ ) { | |
641 | strb.ap pend("\n\t Signature = ") | |
642 | .append (signature [i]) | |
643 | .append ("\t\nPara ms = ") | |
644 | .append (parms[i]) ; | |
645 | } | |
646 | M LET_LOGGER .logp(Leve l.FINEST, | |
647 | MLe t.class.ge tName(), | |
648 | mth , strb.toS tring()); | |
649 | } | |
650 | if (n ame == nul l) { | |
651 | o bjInst = | |
652 | server. createMBea n(code, nu ll, mletOb jectName, | |
653 | parms, s ignature); | |
654 | } els e { | |
655 | o bjInst = | |
656 | server. createMBea n(code, ne w ObjectNa me(name), | |
657 | mletObje ctName, pa rms, | |
658 | signatur e); | |
659 | } | |
660 | } | |
661 | } e lse { | |
662 | o = loadS erializedO bject(code base,serNa me); | |
663 | if (name == null) { | |
664 | serve r.register MBean(o, n ull); | |
665 | } else { | |
666 | serve r.register MBean(o, new Object Name(name) ); | |
667 | } | |
668 | objInst = new Objec tInstance( name, o.ge tClass().g etName()); | |
669 | } | |
670 | } catch (Reflecti onExceptio n ex) { | |
671 | MLE T_LOGGER.l ogp(Level. FINER, MLe t.class.ge tName(), m th, | |
672 | "Refl ectionExce ption", ex ); | |
673 | mbe ans.add(ex ); | |
674 | con tinue; | |
675 | } catch (Instance AlreadyExi stsExcepti on ex) { | |
676 | MLE T_LOGGER.l ogp(Level. FINER, MLe t.class.ge tName(), m th, | |
677 | "Inst anceAlread yExistsExc eption", e x); | |
678 | mbe ans.add(ex ); | |
679 | con tinue; | |
680 | } catch (MBeanReg istrationE xception e x) { | |
681 | MLE T_LOGGER.l ogp(Level. FINER, MLe t.class.ge tName(), m th, | |
682 | "MBea nRegistrat ionExcepti on", ex); | |
683 | mbe ans.add(ex ); | |
684 | con tinue; | |
685 | } catch (MBeanExc eption ex ) { | |
686 | MLE T_LOGGER.l ogp(Level. FINER, MLe t.class.ge tName(), m th, | |
687 | "MBea nException ", ex); | |
688 | mbe ans.add(ex ); | |
689 | con tinue; | |
690 | } catch (NotCompl iantMBeanE xception ex) { | |
691 | MLE T_LOGGER.l ogp(Level. FINER, MLe t.class.ge tName(), m th, | |
692 | "NotC ompliantMB eanExcepti on", ex); | |
693 | mbe ans.add(ex ); | |
694 | con tinue; | |
695 | } catch (Instance NotFoundEx ception ex) { | |
696 | MLE T_LOGGER.l ogp(Level. FINER, MLe t.class.ge tName(), m th, | |
697 | "Inst anceNotFou ndExceptio n", ex); | |
698 | mbe ans.add(ex ); | |
699 | con tinue; | |
700 | } catch (IOExcept ion ex) { | |
701 | MLE T_LOGGER.l ogp(Level. FINER, MLe t.class.ge tName(), m th, | |
702 | "IOEx ception", ex); | |
703 | mbe ans.add(ex ); | |
704 | con tinue; | |
705 | } catch (Security Exception ex) { | |
706 | MLE T_LOGGER.l ogp(Level. FINER, MLe t.class.ge tName(), m th, | |
707 | "Secu rityExcept ion", ex); | |
708 | mbe ans.add(ex ); | |
709 | con tinue; | |
710 | } catch (Exceptio n ex) { | |
711 | MLE T_LOGGER.l ogp(Level. FINER, MLe t.class.ge tName(), m th, | |
712 | "Exce ption", ex ); | |
713 | mbe ans.add(ex ); | |
714 | con tinue; | |
715 | } catch (Error ex ) { | |
716 | MLE T_LOGGER.l ogp(Level. FINER, MLe t.class.ge tName(), m th, | |
717 | "Erro r", ex); | |
718 | mbe ans.add(ex ); | |
719 | con tinue; | |
720 | } | |
721 | mbeans. add(objIns t); | |
722 | } | |
723 | r eturn mbea ns; | |
724 | } | |
725 | ||
726 | /** | |
727 | * Ge ts the cur rent direc tory used by the lib rary loade r for | |
728 | * st oring nati ve librari es before they are l oaded into memory. | |
729 | * | |
730 | * @r eturn The current di rectory us ed by the library lo ader. | |
731 | * | |
732 | * @s ee #setLib raryDirect ory | |
733 | * | |
734 | * @t hrows Unsu pportedOpe rationExce ption if t his implem entation | |
735 | * do es not sup port stori ng native libraries in this wa y. | |
736 | */ | |
737 | publi c synchron ized Strin g getLibra ryDirector y() { | |
738 | r eturn libr aryDirecto ry; | |
739 | } | |
740 | ||
741 | /** | |
742 | * Se ts the dir ectory use d by the l ibrary loa der for st oring | |
743 | * na tive libra ries befor e they are loaded in to memory. | |
744 | * | |
745 | * @p aram libdi r The dire ctory used by the li brary load er. | |
746 | * | |
747 | * @s ee #getLib raryDirect ory | |
748 | * | |
749 | * @t hrows Unsu pportedOpe rationExce ption if t his implem entation | |
750 | * do es not sup port stori ng native libraries in this wa y. | |
751 | */ | |
752 | publi c synchron ized void setLibrary Directory( String lib dir) { | |
753 | l ibraryDire ctory = li bdir; | |
754 | } | |
755 | ||
756 | /** | |
757 | * Al lows the m -let to pe rform any operations it needs before | |
758 | * be ing regist ered in th e MBean se rver. If t he ObjectN ame is | |
759 | * nu ll, the m- let provid es a defau lt name fo r its regi stration | |
760 | * &l t;defaultD omain>: type=MLet | |
761 | * | |
762 | * @p aram serve r The MBea n server i n which th e m-let wi ll be regi stered. | |
763 | * @p aram name The object name of t he m-let. | |
764 | * | |
765 | * @r eturn The name of t he m-let r egistered. | |
766 | * | |
767 | * @e xception j ava.lang.E xception T his except ion should be caught by the MB ean server and re-th rown | |
768 | *as an MBeanRe gistration Exception. | |
769 | */ | |
770 | publi c ObjectNa me preRegi ster(MBean Server ser ver, Objec tName name ) | |
771 | throws Exception { | |
772 | ||
773 | / / Initiali ze local p ointer to the MBean server | |
774 | s etMBeanSer ver(server ); | |
775 | ||
776 | / / If no na me is spec ified retu rn a defau lt name fo r the MLet | |
777 | i f (name == null) { | |
778 | name = new Object Name(serve r.getDefau ltDomain() + ":" + S erviceName .MLET); | |
779 | } | |
780 | ||
781 | th is.mletObj ectName = name; | |
782 | re turn this. mletObject Name; | |
783 | } | |
784 | ||
785 | /** | |
786 | * Al lows the m -let to pe rform any operations needed af ter having been | |
787 | * re gistered i n the MBea n server o r after th e registra tion has f ailed. | |
788 | * | |
789 | * @p aram regis trationDon e Indicate s whether or not the m-let has | |
790 | * be en success fully regi stered in the MBean server. Th e value | |
791 | * fa lse means that eithe r the regi stration p hase has f ailed. | |
792 | * | |
793 | */ | |
794 | publi c void pos tRegister (Boolean r egistratio nDone) { | |
795 | } | |
796 | ||
797 | /** | |
798 | * Al lows the m -let to pe rform any operations it needs before bei ng unregis tered | |
799 | * by the MBean server. | |
800 | * | |
801 | * @e xception j ava.lang.E xception T his except ion should be caught | |
802 | * by the MBean server an d re-throw n as an | |
803 | * MB eanRegistr ationExcep tion. | |
804 | */ | |
805 | publi c void pre Deregister () throws java.lang. Exception { | |
806 | } | |
807 | ||
808 | ||
809 | /** | |
810 | * Al lows the m -let to pe rform any operations needed af ter having been | |
811 | * un registered in the MB ean server . | |
812 | */ | |
813 | publi c void pos tDeregiste r() { | |
814 | } | |
815 | ||
816 | /** | |
817 | * <p >Save this MLet's co ntents to the given {@link Obj ectOutput} . | |
818 | * No t all impl ementation s support this metho d. Those that do no t | |
819 | * th row {@link Unsupport edOperatio nException }. A subc lass may | |
820 | * ov erride thi s method t o support it or to c hange the format of | |
821 | * th e written data.</p> | |
822 | * | |
823 | * <p >The forma t of the w ritten dat a is not s pecified, but if | |
824 | * an implement ation supp orts {@lin k #writeEx ternal} it must | |
825 | * al so support {@link #r eadExterna l} in such a way tha t what is | |
826 | * wr itten by t he former can be rea d by the l atter.</p> | |
827 | * | |
828 | * @p aram out T he object output str eam to wri te to. | |
829 | * | |
830 | * @e xception I OException If a prob lem occurr ed while w riting. | |
831 | * @e xception U nsupported OperationE xception I f this | |
832 | * im plementati on does no t support this opera tion. | |
833 | */ | |
834 | publi c void wri teExternal (ObjectOut put out) | |
835 | throws IOExceptio n, Unsuppo rtedOperat ionExcepti on { | |
836 | t hrow new U nsupported OperationE xception(" MLet.write External") ; | |
837 | } | |
838 | ||
839 | /** | |
840 | * <p >Restore t his MLet's contents from the g iven {@lin k ObjectIn put}. | |
841 | * No t all impl ementation s support this metho d. Those that do no t | |
842 | * th row {@link Unsupport edOperatio nException }. A subc lass may | |
843 | * ov erride thi s method t o support it or to c hange the format of | |
844 | * th e read dat a.</p> | |
845 | * | |
846 | * <p >The forma t of the r ead data i s not spec ified, but if an | |
847 | * im plementati on support s {@link # readExtern al} it mus t also | |
848 | * su pport {@li nk #writeE xternal} i n such a w ay that wh at is | |
849 | * wr itten by t he latter can be rea d by the f ormer.</p> | |
850 | * | |
851 | * @p aram in Th e object i nput strea m to read from. | |
852 | * | |
853 | * @e xception I OException if a prob lem occurr ed while r eading. | |
854 | * @e xception C lassNotFou ndExceptio n if the c lass for t he object | |
855 | * be ing restor ed cannot be found. | |
856 | * @e xception U nsupported OperationE xception i f this | |
857 | * im plementati on does no t support this opera tion. | |
858 | */ | |
859 | publi c void rea dExternal( ObjectInpu t in) | |
860 | throws IOExceptio n, ClassNo tFoundExce ption, | |
861 | Unsupporte dOperation Exception { | |
862 | t hrow new U nsupported OperationE xception(" MLet.readE xternal"); | |
863 | } | |
864 | ||
865 | /* | |
866 | * -- ---------- ---------- ---------- ---------- | |
867 | * P ACKAGE MET HODS | |
868 | * -- ---------- ---------- ---------- ---------- | |
869 | */ | |
870 | ||
871 | /** | |
872 | * <p >Load a cl ass, using the given {@link Cl assLoaderR epository} if | |
873 | * th e class is not found in this M Let's URLs . The giv en | |
874 | * Cl assLoaderR epository can be nul l, in whic h case a { @link | |
875 | * Cl assNotFoun dException } occurs i mmediately if the cl ass is not | |
876 | * fo und in thi s MLet's U RLs.</p> | |
877 | * | |
878 | * @p aram name The name o f the clas s we want to load. | |
879 | * @p aram clr The ClassL oaderRepos itory that will be u sed to sea rch | |
880 | * for the gi ven class, if it is not found in this | |
881 | * ClassLoade r. May be null. | |
882 | * @r eturn The resulting Class obje ct. | |
883 | * @e xception C lassNotFou ndExceptio n The spec ified clas s could no t be | |
884 | * f ound in th is ClassLo ader nor i n the give n | |
885 | * C lassLoader Repository . | |
886 | * | |
887 | */ | |
888 | publi c synchron ized Class <?> loadCl ass(String name, | |
889 | ClassL oaderRepos itory clr) | |
890 | throws ClassNotF oundExcept ion { | |
891 | f inal Class LoaderRepo sitory bef ore=curren tClr; | |
892 | t ry { | |
893 | current Clr = clr; | |
894 | return loadClass( name); | |
895 | } finally { | |
896 | current Clr = befo re; | |
897 | } | |
898 | } | |
899 | ||
900 | /* | |
901 | * -- ---------- ---------- ---------- ---------- | |
902 | * P ROTECTED M ETHODS | |
903 | * -- ---------- ---------- ---------- ---------- | |
904 | */ | |
905 | ||
906 | /** | |
907 | * Th is is the main metho d for clas s loaders that is be ing redefi ned. | |
908 | * | |
909 | * @p aram name The name o f the clas s. | |
910 | * | |
911 | * @r eturn The resulting Class obje ct. | |
912 | * | |
913 | * @e xception C lassNotFou ndExceptio n The spec ified clas s could no t be | |
914 | * f ound. | |
915 | */ | |
916 | prote cted Class <?> findCl ass(String name) thr ows ClassN otFoundExc eption { | |
917 | / * currentC lr is cont ext sensit ive - used to avoid recursion | |
918 | in the c lass loade r reposito ry. (This is no lon ger | |
919 | necessar y with the new CLR s emantics b ut is kept for | |
920 | compatib ility with code that might hav e called t he | |
921 | two-para meter load Class expl icitly.) */ | |
922 | r eturn find Class(name , currentC lr); | |
923 | } | |
924 | ||
925 | /** | |
926 | * Ca lled by {@ link MLet# findClass( java.lang. String)}. | |
927 | * | |
928 | * @p aram name The name o f the clas s that we want to lo ad/find. | |
929 | * @p aram clr T he ClassLo aderReposi tory that can be use d to searc h | |
930 | * f or the giv en class. This param eter is | |
931 | * < code>null< /code> whe n called f rom within the | |
932 | * { @link java x.manageme nt.MBeanSe rverFactor y#getClass LoaderRepo sitory(jav ax.managem ent.MBeanS erver) Cla ss Loader Repository }. | |
933 | * @e xception C lassNotFou ndExceptio n The spec ified clas s could no t be | |
934 | * f ound. | |
935 | * | |
936 | **/ | |
937 | Class <?> findCl ass(String name, Cla ssLoaderRe pository c lr) | |
938 | t hrows Clas sNotFoundE xception { | |
939 | C lass<?> c = null; | |
940 | M LET_LOGGER .logp(Leve l.FINER, M Let.class. getName(), "findClas s", name); | |
941 | / / Try look ing in the JAR: | |
942 | t ry { | |
943 | c = sup er.findCla ss(name); | |
944 | if (MLE T_LOGGER.i sLoggable( Level.FINE R)) { | |
945 | MLE T_LOGGER.l ogp(Level. FINER, MLe t.class.ge tName(), | |
946 | "find Class", | |
947 | "Clas s " + name + " loade d through MLet class loader"); | |
948 | } | |
949 | } catch (Cl assNotFoun dException e) { | |
950 | // Drop through | |
951 | if (MLE T_LOGGER.i sLoggable( Level.FINE ST)) { | |
952 | MLE T_LOGGER.l ogp(Level. FINEST, ML et.class.g etName(), | |
953 | "find Class", | |
954 | "Clas s " + name + " not f ound local ly"); | |
955 | } | |
956 | } | |
957 | / / if we ar e not call ed from th e ClassLoa derReposit ory | |
958 | i f (c == nu ll && dele gateToCLR && clr != null) { | |
959 | // Try the classl oader repo sitory: | |
960 | // | |
961 | try { | |
962 | if (MLET_LOGG ER.isLogga ble(Level. FINEST)) { | |
963 | MLET_LOGG ER.logp(Le vel.FINEST , MLet.cla ss.getName (), | |
964 | " findClass" , | |
965 | " Class " + name + " : looking i n CLR"); | |
966 | } | |
967 | c = clr.loadC lassBefore (this, nam e); | |
968 | // The loadCl assBefore method nev er returns null. | |
969 | // If the cla ss is not found we g et an exce ption. | |
970 | if (MLET_LOGG ER.isLogga ble(Level. FINER)) { | |
971 | MLET_LOGG ER.logp(Le vel.FINER, MLet.clas s.getName( ), | |
972 | " findClass" , | |
973 | " Class " + name + " l oaded thro ugh " + | |
974 | " the defaul t classloa der reposi tory"); | |
975 | } | |
976 | } catch (ClassNot FoundExcep tion e) { | |
977 | // Drop throu gh | |
978 | if (MLET_LOGG ER.isLogga ble(Level. FINEST)) { | |
979 | MLET_LOGG ER.logp(Le vel.FINEST , MLet.cla ss.getName (), | |
980 | " findClass" , | |
981 | " Class " + name + " n ot found i n CLR"); | |
982 | } | |
983 | } | |
984 | } | |
985 | i f (c == nu ll) { | |
986 | MLET_LO GGER.logp( Level.FINE ST, MLet.c lass.getNa me(), | |
987 | "findClas s", "Faile d to load class " + name); | |
988 | throw n ew ClassNo tFoundExce ption(name ); | |
989 | } | |
990 | r eturn c; | |
991 | } | |
992 | ||
993 | /** | |
994 | * Re turns the absolute p ath name o f a native library. The VM | |
995 | * in vokes this method to locate th e native l ibraries t hat belong | |
996 | * to classes l oaded with this clas s loader. Libraries are | |
997 | * se arched in the JAR fi les using first just the nativ e library | |
998 | * na me and if not found the native library n ame togeth er with | |
999 | * th e architec ture-speci fic path n ame | |
1000 | * (< code>OSNam e/OSArch/O SVersion/l ib/nativel ibname</co de>), i.e. | |
1001 | * <p > | |
1002 | * th e library stat on So laris SPAR C 5.7 will be search ed in the JAR file a s: | |
1003 | * <O L> | |
1004 | * <L I>libstat. so | |
1005 | * <L I>SunOS/sp arc/5.7/li b/libstat. so | |
1006 | * </ OL> | |
1007 | * th e library stat on Wi ndows NT 4 .0 will be searched in the JAR file as: | |
1008 | * <O L> | |
1009 | * <L I>stat.dll | |
1010 | * <L I>WindowsN T/x86/4.0/ lib/stat.d ll | |
1011 | * </ OL> | |
1012 | * | |
1013 | * <p >More spec ifically, let <em>{@ code nativ elibname}< /em> be th e result o f | |
1014 | * {@ link Syste m#mapLibra ryName(jav a.lang.Str ing) | |
1015 | * Sy stem.mapLi braryName} {@code (li bname)}. Then the f ollowing n ames are | |
1016 | * se arched in the JAR fi les, in or der:<br> | |
1017 | * <e m>{@code n ativelibna me}</em><b r> | |
1018 | * {@ code <os.n ame>/<os.a rch>/<os.v ersion>/li b/}<em>{@c ode native libname}</ em><br> | |
1019 | * wh ere {@code <X>} mean s {@code S ystem.getP roperty(X) } with any | |
1020 | * sp aces in th e result r emoved, an d {@code / } stands f or the | |
1021 | * fi le separat or charact er ({@link File#sepa rator}). | |
1022 | * <p > | |
1023 | * If this meth od returns <code>nul l</code>, i.e. the l ibraries | |
1024 | * we re not fou nd in any of the JAR files loa ded with t his class | |
1025 | * lo ader, the VM searche s the libr ary along the path s pecified | |
1026 | * as the <code >java.libr ary.path</ code> prop erty. | |
1027 | * | |
1028 | * @p aram libna me The lib rary name. | |
1029 | * | |
1030 | * @r eturn The absolute p ath of the native li brary. | |
1031 | */ | |
1032 | prote cted Strin g findLibr ary(String libname) { | |
1033 | ||
1034 | S tring abs_ path; | |
1035 | S tring mth = "findLib rary"; | |
1036 | ||
1037 | / / Get the platform-s pecific st ring repre senting a native lib rary. | |
1038 | / / | |
1039 | S tring nati velibname = System.m apLibraryN ame(libnam e); | |
1040 | ||
1041 | / / | |
1042 | / / See if t he native library is accessibl e as a res ource thro ugh the JA R file. | |
1043 | / / | |
1044 | i f (MLET_LO GGER.isLog gable(Leve l.FINER)) { | |
1045 | MLET_LO GGER.logp( Level.FINE R, MLet.cl ass.getNam e(), mth, | |
1046 | "Search " + libname + " in al l JAR file s"); | |
1047 | } | |
1048 | ||
1049 | / / First tr y to locat e the libr ary in the JAR file using only | |
1050 | / / the nati ve library name. e. g. if user requested a load | |
1051 | / / for "foo " on Solar is SPARC 5 .7 we try to load "l ibfoo.so" | |
1052 | / / from the JAR file. | |
1053 | / / | |
1054 | i f (MLET_LO GGER.isLog gable(Leve l.FINER)) { | |
1055 | MLET_LO GGER.logp( Level.FINE R, MLet.cl ass.getNam e(), mth, | |
1056 | "loadLibr aryAsResou rce(" + na tivelibnam e + ")"); | |
1057 | } | |
1058 | a bs_path = loadLibrar yAsResourc e(nativeli bname); | |
1059 | i f (abs_pat h != null) { | |
1060 | if (MLE T_LOGGER.i sLoggable( Level.FINE R)) { | |
1061 | MLE T_LOGGER.l ogp(Level. FINER, MLe t.class.ge tName(), m th, | |
1062 | nativ elibname + " loaded, absolute path = " + abs_path) ; | |
1063 | } | |
1064 | return abs_path; | |
1065 | } | |
1066 | ||
1067 | / / Next try to locate it using the native library n ame and | |
1068 | / / the arch itecture-s pecific pa th name. e.g. if us er | |
1069 | / / requeste d a load f or "foo" o n Solaris SPARC 5.7 we try to | |
1070 | / / load "Su nOS/sparc/ 5.7/lib/li bfoo.so" f rom the JA R file. | |
1071 | / / | |
1072 | n ativelibna me = remov eSpace(Sys tem.getPro perty("os. name")) + File.separ ator + | |
1073 | removeS pace(Syste m.getPrope rty("os.ar ch")) + Fi le.separat or + | |
1074 | removeS pace(Syste m.getPrope rty("os.ve rsion")) + File.sepa rator + | |
1075 | "lib" + File.sepa rator + na tivelibnam e; | |
1076 | i f (MLET_LO GGER.isLog gable(Leve l.FINER)) { | |
1077 | MLET_LO GGER.logp( Level.FINE R, MLet.cl ass.getNam e(), mth, | |
1078 | "loadLibr aryAsResou rce(" + na tivelibnam e + ")"); | |
1079 | } | |
1080 | ||
1081 | a bs_path = loadLibrar yAsResourc e(nativeli bname); | |
1082 | i f (abs_pat h != null) { | |
1083 | if (MLE T_LOGGER.i sLoggable( Level.FINE R)) { | |
1084 | MLE T_LOGGER.l ogp(Level. FINER, MLe t.class.ge tName(), m th, | |
1085 | nativ elibname + " loaded, absolute path = " + abs_path) ; | |
1086 | } | |
1087 | return abs_path; | |
1088 | } | |
1089 | ||
1090 | / / | |
1091 | / / All path s exhauste d, library not found in JAR fi le. | |
1092 | / / | |
1093 | ||
1094 | i f (MLET_LO GGER.isLog gable(Leve l.FINER)) { | |
1095 | MLET_LO GGER.logp( Level.FINE R, MLet.cl ass.getNam e(), mth, | |
1096 | libname + " not fou nd in any JAR file") ; | |
1097 | MLET_LO GGER.logp( Level.FINE R, MLet.cl ass.getNam e(), mth, | |
1098 | "Search " + libname + " along the path " + | |
1099 | "specifie d as the j ava.librar y.path pro perty"); | |
1100 | } | |
1101 | ||
1102 | / / Let the VM search the librar y along th e path | |
1103 | / / specifie d as the j ava.librar y.path pro perty. | |
1104 | / / | |
1105 | r eturn null ; | |
1106 | } | |
1107 | ||
1108 | ||
1109 | /* | |
1110 | * -- ---------- ---------- ---------- ---------- | |
1111 | * PRI D A N E S M T ODS | |
1112 | * -- ---------- ---------- ---------- ---------- | |
1113 | */ | |
1114 | ||
1115 | priva te String getTmpDir( ) { | |
1116 | / / JDK 1.4 | |
1117 | S tring tmpD ir = Syste m.getPrope rty("java. io.tmpdir" ); | |
1118 | i f (tmpDir != null) r eturn tmpD ir; | |
1119 | ||
1120 | / / JDK < 1. 4 | |
1121 | F ile tmpFil e = null; | |
1122 | t ry { | |
1123 | // Try to guess t he system temporary dir... | |
1124 | tmpFile = File.cr eateTempFi le("tmp"," jmx"); | |
1125 | if (tmp File == nu ll) return null; | |
1126 | final F ile tmpDir File = tmp File.getPa rentFile() ; | |
1127 | if (tmp DirFile == null) ret urn null; | |
1128 | return tmpDirFile .getAbsolu tePath(); | |
1129 | } catch (Ex ception x) { | |
1130 | MLET_LO GGER.logp( Level.FINE ST, MLet.c lass.getNa me(), | |
1131 | "getTmpDi r", "Faile d to deter mine syste m temporar y dir"); | |
1132 | return null; | |
1133 | } finally { | |
1134 | // Clea nup ... | |
1135 | if (tmp File!=null ) { | |
1136 | try { | |
1137 | boolean d eleted = t mpFile.del ete(); | |
1138 | if (!dele ted) { | |
1139 | MLET_ LOGGER.log p(Level.FI NEST, MLet .class.get Name(), | |
1140 | "getTmp Dir", "Fai led to del ete temp f ile"); | |
1141 | } | |
1142 | } c atch (Exce ption x) { | |
1143 | MLET_LOGG ER.logp(Le vel.FINEST , MLet.cla ss.getName (), | |
1144 | " getTmpDir" , "Failed to delete temporary file", x); | |
1145 | } | |
1146 | } | |
1147 | } | |
1148 | } | |
1149 | ||
1150 | /** | |
1151 | * Se arch the s pecified n ative libr ary in any of the JA R files | |
1152 | * lo aded by th is classlo ader. If the librar y is found copy it | |
1153 | * in to the lib rary direc tory and r eturn the absolute p ath. If | |
1154 | * th e library is not fou nd then re turn null. | |
1155 | */ | |
1156 | priva te synchro nized Stri ng loadLib raryAsReso urce(Strin g libname) { | |
1157 | t ry { | |
1158 | InputSt ream is = getResourc eAsStream( | |
1159 | libname.r eplace(Fil e.separato rChar,'/') ); | |
1160 | if (is != null) { | |
1161 | try { | |
1162 | File dire ctory = ne w File(lib raryDirect ory); | |
1163 | directory .mkdirs(); | |
1164 | File file = Files.c reateTempF ile(direct ory.toPath (), | |
1165 | libnam e + ".", n ull) | |
1166 | .t oFile(); | |
1167 | file.dele teOnExit() ; | |
1168 | FileOutpu tStream fi leOutput = new FileO utputStrea m(file); | |
1169 | try { | |
1170 | byte[ ] buf = ne w byte[409 6]; | |
1171 | int n ; | |
1172 | while ((n = is. read(buf)) >= 0) { | |
1173 | fi leOutput.w rite(buf, 0, n); | |
1174 | } | |
1175 | } finally { | |
1176 | fileO utput.clos e(); | |
1177 | } | |
1178 | if (file. exists()) { | |
1179 | retur n file.get AbsolutePa th(); | |
1180 | } | |
1181 | } f inally { | |
1182 | is.close( ); | |
1183 | } | |
1184 | } | |
1185 | } catch (Ex ception e) { | |
1186 | MLET_LO GGER.logp( Level.FINE ST, MLet.c lass.getNa me(), | |
1187 | "loadLibr aryAsResou rce", | |
1188 | "Failed t o load lib rary : " + libname, e); | |
1189 | return null; | |
1190 | } | |
1191 | r eturn null ; | |
1192 | } | |
1193 | ||
1194 | /** | |
1195 | * Remo ves any wh ite space from a str ing. This is used to | |
1196 | * conv ert string s such as "Windows N T" to "Win dowsNT". | |
1197 | */ | |
1198 | priva te static String rem oveSpace(S tring s) { | |
1199 | r eturn s.tr im().repla ce(" ", "" ); | |
1200 | } | |
1201 | ||
1202 | /** | |
1203 | * <p >This meth od is to b e overridd en when ex tending th is service to | |
1204 | * su pport cach ing and ve rsioning. It is cal led from { @link | |
1205 | * #g etMBeansFr omURL getM BeansFromU RL} when t he version , | |
1206 | * co debase, an d jarfile have been extracted from the M Let file, | |
1207 | * an d can be u sed to ver ify that i t is all r ight to lo ad the | |
1208 | * gi ven MBean, or to rep lace the g iven URL w ith a diff erent one. </p> | |
1209 | * | |
1210 | * <p >The defau lt impleme ntation of this meth od returns | |
1211 | * <c ode>codeba se</code> unchanged. </p> | |
1212 | * | |
1213 | * @p aram versi on The ver sion numbe r of the < CODE>.jar< /CODE> | |
1214 | * fi le stored locally. | |
1215 | * @p aram codeb ase The ba se URL of the remote <CODE>.ja r</CODE> f ile. | |
1216 | * @p aram jarfi le The nam e of the < CODE>.jar< /CODE> fil e to be lo aded. | |
1217 | * @p aram mlet The <CODE> MLetConten t</CODE> i nstance th at | |
1218 | * re presents t he <CODE>M LET</CODE> tag. | |
1219 | * | |
1220 | * @r eturn the codebase t o use for the loaded MBean. T he returne d | |
1221 | * va lue should not be nu ll. | |
1222 | * | |
1223 | * @e xception E xception i f the MBea n is not t o be loade d for some | |
1224 | * re ason. The exception will be a dded to th e set retu rned by | |
1225 | * {@ link #getM BeansFromU RL getMBea nsFromURL} . | |
1226 | * | |
1227 | */ | |
1228 | prote cted URL c heck(Strin g version, URL codeb ase, Strin g jarfile, | |
1229 | MLetC ontent mle t) | |
1230 | throws Exception { | |
1231 | r eturn code base; | |
1232 | } | |
1233 | ||
1234 | /** | |
1235 | * Loa ds the ser ialized ob ject speci fied by th e <CODE>OB JECT</CODE > | |
1236 | * att ribute of the <CODE> MLET</CODE > tag. | |
1237 | * | |
1238 | * @pa ram codeba se The <CO DE>codebas e</CODE>. | |
1239 | * @pa ram filena me The nam e of the f ile contai ning the s erialized object. | |
1240 | * @re turn The s erialized object. | |
1241 | * @ex ception Cl assNotFoun dException The speci fied seria lized | |
1242 | * obj ect could not be fou nd. | |
1243 | * @ex ception IO Exception An I/O err or occurre d while lo ading | |
1244 | * ser ialized ob ject. | |
1245 | */ | |
1246 | priva te Object loadSerial izedObject (URL codeb ase, Strin g filename ) | |
1247 | throws IOExceptio n, ClassNo tFoundExce ption { | |
1248 | if (filename != null) { | |
1249 | filename = filenam e.replace( File.separ atorChar,' /'); | |
1250 | } | |
1251 | if (MLET_LOG GER.isLogg able(Level .FINER)) { | |
1252 | MLET_LOG GER.logp(L evel.FINER , MLet.cla ss.getName (), | |
1253 | "loadSeria lizedObjec t", codeba se.toStrin g() + file name); | |
1254 | } | |
1255 | In putStream is = getRe sourceAsSt ream(filen ame); | |
1256 | if (is != nu ll) { | |
1257 | try { | |
1258 | Obje ctInputStr eam ois = new MLetOb jectInputS tream(is, this); | |
1259 | Obje ct serObje ct = ois.r eadObject( ); | |
1260 | ois. close(); | |
1261 | retu rn serObje ct; | |
1262 | } catch (IOExcepti on e) { | |
1263 | if ( MLET_LOGGE R.isLoggab le(Level.F INEST)) { | |
1264 | MLET_LOGGE R.logp(Lev el.FINEST, MLet.clas s.getName( ), | |
1265 | "l oadSeriali zedObject" , | |
1266 | "E xception w hile deser ializing " + filenam e, e); | |
1267 | } | |
1268 | thro w e; | |
1269 | } catch (ClassNotF oundExcept ion e) { | |
1270 | if ( MLET_LOGGE R.isLoggab le(Level.F INEST)) { | |
1271 | MLET_LOGGE R.logp(Lev el.FINEST, MLet.clas s.getName( ), | |
1272 | "l oadSeriali zedObject" , | |
1273 | "E xception w hile deser ializing " + filenam e, e); | |
1274 | } | |
1275 | thro w e; | |
1276 | } | |
1277 | } else { | |
1278 | if (MLET _LOGGER.is Loggable(L evel.FINES T)) { | |
1279 | MLET _LOGGER.lo gp(Level.F INEST, MLe t.class.ge tName(), | |
1280 | "loadS erializedO bject", "E rror: File " + filen ame + | |
1281 | " cont aining ser ialized ob ject not f ound"); | |
1282 | } | |
1283 | throw ne w Error("F ile " + fi lename + " containin g serializ ed object not found" ); | |
1284 | } | |
1285 | } | |
1286 | ||
1287 | /** | |
1288 | * Co nverts the String va lue of the construct or's param eter to | |
1289 | * a basic Java object wi th the typ e of the p arameter. | |
1290 | */ | |
1291 | priva te Object construct Parameter( String par am, String type) { | |
1292 | / / check if it is a p rimitive t ype | |
1293 | C lass<?> c = primitiv eClasses.g et(type); | |
1294 | i f (c != nu ll) { | |
1295 | try { | |
1296 | Cons tructor<?> cons = | |
1297 | c.getConst ructor(Str ing.class) ; | |
1298 | Obje ct[] oo = new Object [1]; | |
1299 | oo[0 ]=param; | |
1300 | retu rn(cons.ne wInstance( oo)); | |
1301 | ||
1302 | } catch (Exception e) { | |
1303 | MLET _LOGGER.lo gp(Level.F INEST, MLe t.class.ge tName(), | |
1304 | "const ructParame ter", "Got unexpecte d exceptio n", e); | |
1305 | } | |
1306 | } | |
1307 | if (type.com pareTo("ja va.lang.Bo olean") == 0) | |
1308 | return Boolean.va lueOf(para m); | |
1309 | if (type.com pareTo("ja va.lang.By te") == 0) | |
1310 | return new Byte(p aram); | |
1311 | if (type.com pareTo("ja va.lang.Sh ort") == 0 ) | |
1312 | return new Short( param); | |
1313 | if (type.com pareTo("ja va.lang.Lo ng") == 0) | |
1314 | return new Long(p aram); | |
1315 | if (type.com pareTo("ja va.lang.In teger") == 0) | |
1316 | return new Intege r(param); | |
1317 | if (type.com pareTo("ja va.lang.Fl oat") == 0 ) | |
1318 | return new Float( param); | |
1319 | if (type.com pareTo("ja va.lang.Do uble") == 0) | |
1320 | return new Double (param); | |
1321 | if (type.com pareTo("ja va.lang.St ring") == 0) | |
1322 | return param; | |
1323 | ||
1324 | re turn param ; | |
1325 | } | |
1326 | ||
1327 | privat e synchron ized void setMBeanSe rver(final MBeanServ er server) { | |
1328 | th is.server = server; | |
1329 | Pr ivilegedAc tion<Class LoaderRepo sitory> ac t = | |
1330 | new Priv ilegedActi on<ClassLo aderReposi tory>() { | |
1331 | publ ic ClassLo aderReposi tory run() { | |
1332 | return ser ver.getCla ssLoaderRe pository() ; | |
1333 | } | |
1334 | }; | |
1335 | cu rrentClr = AccessCon troller.do Privileged (act); | |
1336 | } | |
1337 | ||
1338 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.