KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > internal > ejb > cmp3 > JavaSECMPInitializerAgent


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 // Copyright (c) 1998, 2005, Oracle. All rights reserved.
22
package oracle.toplink.essentials.internal.ejb.cmp3;
23
24 import java.lang.instrument.*;
25 import java.lang.reflect.Field JavaDoc;
26 import java.lang.reflect.Method JavaDoc;
27
28
29 /**
30  * This agent is intended to be run prior to start up on a CMP3 JavaSE application.
31  * It gets the globalInstrumentation and makes it available to TopLink's initialization code.
32  * There are two kinds of initialization. Normally, initialization occurs through reflective
33  * creation and invokation of TopLink JavaSECMPInitializer.
34  * It is possible to run it with the "main" argument to the agent in which case it will simply
35  * try to set the globalInstrumentation field on the JavaSECMPInitializer. This type of initialization
36  * is useful when debugging, but imposes some restrictions on the user. One such restriction is
37  * that no domain classes that use lazy loading may be references in any way other than reflective in the application
38  */

39 public class JavaSECMPInitializerAgent {
40     public static void premain(String JavaDoc agentArgs, Instrumentation instr) throws Exception JavaDoc {
41         // Reflection allows:
42
// JavaSECMPInitializerAgent to be the *ONLY* class is the jar file specified in -javaagent;
43
// Loading JavaSECMPInitializer class using SystemClassLoader.
44
if ((agentArgs != null) && agentArgs.equals("main")) {
45             initializeFromMain(instr);
46         } else {
47             initializeFromAgent(instr);
48         }
49     }
50     
51     public static void initializeFromAgent(Instrumentation instr) throws Exception JavaDoc {
52             Class JavaDoc cls = Class.forName("oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitializer");
53             Method JavaDoc method = cls.getDeclaredMethod("initializeFromAgent", new Class JavaDoc[] { Instrumentation.class });
54             method.invoke(null, new Object JavaDoc[] { instr });
55     }
56     
57     public static void initializeFromMain(Instrumentation instr) throws Exception JavaDoc {
58             Class JavaDoc cls = Class.forName("oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitializer");
59             Field JavaDoc field = cls.getField("globalInstrumentation");
60             field.set(null, instr);
61     }
62 }
63
Popular Tags