KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > bull > eclipse > jonas > actions > ejb > BuildFacadeEjbActionDelegate


1 package com.bull.eclipse.jonas.actions.ejb;
2
3 import java.io.File JavaDoc;
4 import java.util.Enumeration JavaDoc;
5 import java.util.Hashtable JavaDoc;
6 import java.util.Vector JavaDoc;
7
8 import org.eclipse.core.resources.IResource;
9 import org.eclipse.jdt.core.IPackageFragment;
10
11 import com.bull.eclipse.jonas.JonasLauncherPlugin;
12 import com.bull.eclipse.jonas.JonasProject;
13 import com.bull.eclipse.jonas.actions.JonasPackageAbstractActionDelegate;
14 import com.bull.eclipse.jonas.utils.AntUtils;
15 import com.bull.eclipse.jonas.utils.EjbManagement;
16 import com.bull.eclipse.jonas.utils.UpdatePropsFile;
17 import com.bull.eclipse.jonas.utils.xml.FileXmlUtils;
18 import com.bull.eclipse.jonas.utils.xml.UpdateXmlFile;
19 import com.bull.eclipse.jonas.utils.xml.XMLUtils;
20 import com.bull.eclipse.newbean.FacadeEJBGenerate;
21 import com.bull.eclipse.newbean.EntityDescValue;
22 import com.bull.eclipse.newbean.NewFacadeValue;
23
24
25
26 public class BuildFacadeEjbActionDelegate extends JonasPackageAbstractActionDelegate
27 {
28
29     public boolean doActionOn(IPackageFragment pack) throws Exception JavaDoc {
30         // Update build.properties with JONAS_ROOT
31
if (pack.containsJavaResources())
32             throw new Exception JavaDoc("You must execute this function on a deployment unit !");
33         
34         JonasProject jp = (JonasProject)pack.getJavaProject().getProject().getNature(JonasLauncherPlugin.NATURE_ID);
35         UpdatePropsFile.updatePropsProject(jp);
36         
37         String JavaDoc projDir = jp.getProject().getLocation().toOSString();
38         String JavaDoc packName = pack.getPath().removeFirstSegments(1).toOSString();
39         File JavaDoc ejb_standard_xml = new File JavaDoc(projDir , pack.getPath().removeFirstSegments(1).append("ejb-jar.xml").toOSString());
40         File JavaDoc ejb_jonas_xml = new File JavaDoc(projDir , pack.getPath().removeFirstSegments(1).append("jonas-ejb-jar.xml").toOSString());
41         if ((!ejb_standard_xml.exists()) || (!ejb_jonas_xml.exists()))
42             throw new Exception JavaDoc("The deployment unit must be create by the middlegen functionnality");
43         
44         Hashtable JavaDoc hashtable = FileXmlUtils.getAllNameAndPackageEJBEntity(ejb_standard_xml);
45         Enumeration JavaDoc nameEnum = hashtable.keys();
46         Enumeration JavaDoc packageNameEnum = hashtable.elements();
47         File JavaDoc tempFile = new File JavaDoc(jp.getProject().getLocation().append("temp").toOSString());
48         if (!tempFile.exists())
49             tempFile.mkdirs();
50         while (nameEnum.hasMoreElements()) {
51             String JavaDoc packageName = (String JavaDoc) packageNameEnum.nextElement();
52             String JavaDoc name = (String JavaDoc) nameEnum.nextElement();
53             FacadeEJBGenerate feg = new FacadeEJBGenerate(jp);
54             NewFacadeValue nfv = new NewFacadeValue();
55             nfv.setBeanName(name);
56             nfv.setPackageName(packageName);
57             EntityDescValue napv = new EntityDescValue();
58             napv.setBeanName(name);
59             napv.setPackageName(packageName);
60             Vector JavaDoc vecValue = new Vector JavaDoc();
61             vecValue.add(napv);
62             vecValue = AggregateFacadeEjbActionDelegate.getMethods(vecValue,pack.getJavaProject(),jp);
63             nfv.setVecValue(vecValue);
64             feg.runNewFacade(nfv);
65             // Update standard deployment descriptor
66
UpdateXmlFile.updateEjbStandardXmlFile(ejb_standard_xml, new File JavaDoc(tempFile, "facadeNode.xml"));
67             UpdateXmlFile.updateEjbJOnASXmlFile(ejb_jonas_xml, new File JavaDoc(tempFile, "JOnASFacadeNode.xml"));
68
69         }
70         
71         
72         jp.getProject().refreshLocal( IResource.DEPTH_INFINITE, null );
73         
74         
75         
76         return false;
77     }
78
79 }
80
81
Popular Tags