1   
2   
3   
4   
5   
6   
7   
8   package it.imolinfo.jbi4ejb.webservice.generator;
9   
10  import it.imolinfo.jbi4ejb.Logger;
11  import it.imolinfo.jbi4ejb.LoggerFactory;
12  import it.imolinfo.jbi4ejb.exception.ClassGenerationException;
13  import it.imolinfo.jbi4ejb.exception.EJBDeployException;
14  import it.imolinfo.jbi4ejb.exception.EJBWSDLGenerationException;
15  import it.imolinfo.jbi4ejb.jbi.Messages;
16  import it.imolinfo.jbi4ejb.runtime.ejbproxy.StatelessEJBProxyFactory;
17  
18  import java.io.File;
19  import java.io.IOException;
20  import java.io.ObjectStreamClass;
21  import java.util.ArrayList;
22  import java.util.Hashtable;
23  import java.util.Iterator;
24  import java.util.List;
25  import java.util.Set;
26  
27  
28  
29  
30  
31  
32  public final class DynamicEJBWSDLGenerator {        
33  
34      private static final Logger LOG
35          = LoggerFactory.getLogger(DynamicEJBWSDLGenerator.class);
36      private static final Messages MESSAGES
37      = Messages.getMessages(DynamicEJBWSDLGenerator.class);
38      
39      
40  
41  
42      private DynamicEJBWSDLGenerator() {}
43      
44      
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58      public static String generateWSDLFromRemoteInterface(String remoteInterfaceClassName, 
59                  String ejbJarPath, WSDLDescriptor descriptor) throws EJBWSDLGenerationException {
60                  
61          
62          File tempDir;
63          try {
64              tempDir = EJBUtils.createTempDir();
65          } catch (IOException e) {
66          	String msg=MESSAGES.getString("EJB001001_generateWSDLFromRemoteInterface", new Object[]{e.getMessage()});
67              LOG.error(msg,e);
68              throw new EJBWSDLGenerationException(msg,e);
69          }
70          String wsdlFileName = tempDir.getAbsolutePath() + File.separatorChar + remoteInterfaceClassName + ".wsdl";
71          File interfaceWSDL = WSDLGenerator.createWsdlFromJar(remoteInterfaceClassName, ejbJarPath, wsdlFileName, descriptor, tempDir);
72          return interfaceWSDL.getAbsolutePath();
73      }
74      
75      
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87      @SuppressWarnings("unchecked")
88      public static Hashtable getClassesID(String remoteInterface, String ejbJarPath) throws EJBWSDLGenerationException {
89          
90          Hashtable classesID = new Hashtable();
91  
92          File tempDir;
93          try {
94              tempDir = File.createTempFile("EJBCLASSES_", null);
95          } catch (IOException e) {
96          	String msg=MESSAGES.getString("EJB001002_getClassesID", new Object[]{e.getMessage()});
97              LOG.error(msg,e);
98              throw new EJBWSDLGenerationException(msg,e);
99          } 
100         tempDir.delete();
101         tempDir.mkdir();
102 
103         try {
104             JarUtil.unjar(new File(ejbJarPath), tempDir);
105         } catch (IOException e) {
106         	String msg=MESSAGES.getString("EJB001002_getClassesID", new Object[]{e.getMessage()});
107             LOG.error(msg,e);
108             throw new EJBWSDLGenerationException(msg,e);
109         }
110 
111         String remoteInterfaceFileName = remoteInterface.replace('.',File.separatorChar);
112 
113         LOG.debug("remoteInterfaceFileName: " + remoteInterfaceFileName);
114         List<File> list = new ArrayList<File>();
115         list.add(new File(tempDir.getAbsolutePath() + File.separatorChar + remoteInterfaceFileName));
116 
117         
118         Set<Class> classesToSerialize;
119         try {
120             classesToSerialize = Util.findClassUsed(tempDir.getAbsolutePath(), list);
121         } catch (ClassGenerationException e) {
122         	String msg=MESSAGES.getString("EJB001002_getClassesID", new Object[]{e.getMessage()});
123             LOG.error(msg,e);
124             throw new EJBWSDLGenerationException(msg,e);
125         }
126 
127         Iterator iter = classesToSerialize.iterator();
128         while (iter.hasNext()) {
129             Class classToSerialize = (Class)iter.next();
130             LOG.debug(classToSerialize.getName());
131                         
132             ObjectStreamClass objectStreamClass = ObjectStreamClass.lookup(classToSerialize);
133                         
134             long uid = objectStreamClass.getSerialVersionUID();
135              
136 
137 
138 
139 
140 
141 
142 
143             
144 
145             LOG.debug(classToSerialize.getName() + " uid: " + uid);            
146             classesID.put(classToSerialize.getName() , Long.valueOf(uid));
147         }            
148 
149         return classesID;
150         
151     }        
152     
153     
154 }