KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > ejb > cmp3 > StaticWeaver


1 package oracle.toplink.essentials.ejb.cmp3;
2
3 import java.net.URL JavaDoc;
4 import java.util.Iterator JavaDoc;
5 import java.util.List JavaDoc;
6 import java.util.Set JavaDoc;
7
8 import javax.persistence.Persistence;
9 import javax.persistence.spi.PersistenceUnitInfo;
10
11 import oracle.toplink.essentials.ejb.cmp3.persistence.PersistenceUnitProcessor;
12 import oracle.toplink.essentials.ejb.cmp3.persistence.SEPersistenceUnitInfo;import oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerSetupImpl;
13
14 /**
15  * Utility used to statically weave entities for use in TopLink EJB 3.0
16  *
17  * The main method of this class should be invoked with the -javaagent tag to initiate weaving.
18  *
19  * The following system arguments should be provided:
20  * -javaagent:<toplink_agent_jar_location>
21  * -Dtoplink.weaving.output.path=<location_to_put_weaved_classes>
22  * -Dtoplink.validation-only=true
23  * -Dtoplink.weaving.overwrite.existing=true if you wish the output of static weaving to overwrite existing classes
24  *
25  * Weaving will occur for all persistence units found on the classpath.
26  */

27 public class StaticWeaver {
28
29
30     /**
31      * This method will search for all of the persistence archives on the classpath and weave
32      * all the classes associated with those persistence units.
33      */

34     public static void main(String JavaDoc[] args) {
35         Set JavaDoc<URL JavaDoc> urls = PersistenceUnitProcessor.findPersistenceArchives();
36         Iterator JavaDoc<URL JavaDoc> urlIterator = urls.iterator();
37         while (urlIterator.hasNext()){
38             List JavaDoc<SEPersistenceUnitInfo> puInfoList = PersistenceUnitProcessor.getPersistenceUnits(urlIterator.next(), Thread.currentThread().getContextClassLoader());
39             Iterator JavaDoc<SEPersistenceUnitInfo> puInfoListIterator = puInfoList.iterator();
40             while (puInfoListIterator.hasNext()){
41                 Persistence.createEntityManagerFactory(puInfoListIterator.next().getPersistenceUnitName());
42             }
43         }
44     }
45
46 }
47
Popular Tags