KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ejbfreeform > EJBFreeformModule


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.ejbfreeform;
21
22 import java.util.Iterator JavaDoc;
23 import org.netbeans.api.project.Project;
24 import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar;
25 import org.netbeans.modules.j2ee.dd.api.ejb.DDProvider;
26 import org.netbeans.modules.j2ee.dd.api.webservices.Webservices;
27 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
28 import org.netbeans.modules.schema2beans.BaseBean;
29 import org.netbeans.spi.project.support.ant.AntProjectHelper;
30 import org.netbeans.spi.project.support.ant.PropertyEvaluator;
31 import org.openide.DialogDisplayer;
32 import org.openide.NotifyDescriptor;
33 import org.openide.filesystems.FileObject;
34 import org.openide.util.NbBundle;
35
36 /**
37  *
38  * @author martin
39  */

40 public class EJBFreeformModule implements J2eeModule {
41     
42     private Project project;
43     private AntProjectHelper helper;
44     private PropertyEvaluator evaluator;
45     private org.netbeans.modules.j2ee.api.ejbjar.EjbJar ejbImpl;
46     
47     /** Creates a new instance of EJBFreeformModule */
48     public EJBFreeformModule(Project project, AntProjectHelper helper, PropertyEvaluator evaluator) {
49         this.project = project;
50         this.helper = helper;
51         this.evaluator = evaluator;
52     }
53     
54     private org.netbeans.modules.j2ee.api.ejbjar.EjbJar getEjbModule () {
55         if (ejbImpl == null) {
56             org.netbeans.modules.j2ee.api.ejbjar.EjbJar modules[] = org.netbeans.modules.j2ee.api.ejbjar.EjbJar.getEjbJars(project);
57             if (modules.length > 0) {
58                 ejbImpl = modules[0];
59             }
60         }
61         return ejbImpl;
62     }
63     
64     public void setUrl(String JavaDoc url) {
65     }
66     
67     public BaseBean getDeploymentDescriptor(String JavaDoc location) {
68         if (J2eeModule.EJBJAR_XML.equals(location)){
69             EjbJar webApp = getEjbJar();
70             if (webApp != null) {
71                 //PENDING find a better way to get the BB from WApp and remove the HACK from DDProvider!!
72
return DDProvider.getDefault().getBaseBean(webApp);
73             }
74         } else if(J2eeModule.EJBSERVICES_XML.equals(location)){
75             Webservices webServices = getWebservices();
76             if(webServices != null){
77                 return DDProvider.getDefault().getBaseBean(webServices);
78             }
79         }
80         return null;
81     }
82     
83     public void removeVersionListener(org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule.VersionListener listener) {
84     }
85     
86     public void addVersionListener(org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule.VersionListener listener) {
87     }
88     
89     public String JavaDoc getUrl() {
90         return "";
91     }
92     
93     public String JavaDoc getModuleVersion() {
94         EjbJar ejbJar = getEjbJar();
95         return ejbJar.getVersion().toString();
96     }
97     
98     public Object JavaDoc getModuleType() {
99         return J2eeModule.EJB;
100     }
101     
102     public FileObject getContentDirectory() throws java.io.IOException JavaDoc {
103         return null;
104     }
105     
106     public Iterator JavaDoc getArchiveContents() throws java.io.IOException JavaDoc {
107         return null;
108     }
109     
110     public FileObject getArchive() throws java.io.IOException JavaDoc {
111         return null;
112     }
113     
114     // private methods
115

116     private EjbJar getEjbJar() {
117         try {
118             return DDProvider.getDefault().getMergedDDRoot(getEjbModule().getMetadataUnit());
119         } catch (java.io.IOException JavaDoc e) {
120             org.openide.ErrorManager.getDefault().log(e.getLocalizedMessage());
121         }
122         return null;
123     }
124     
125     private Webservices getWebservices() {
126         FileObject wsdd = getDD();
127         if(wsdd != null) {
128             try {
129                 return org.netbeans.modules.j2ee.dd.api.webservices.DDProvider.getDefault().getDDRoot(getDD());
130             } catch (java.io.IOException JavaDoc e) {
131                 org.openide.ErrorManager.getDefault().log(e.getLocalizedMessage());
132             }
133         }
134         
135         return null;
136     }
137     
138     public FileObject getDD() {
139         FileObject metaInfFo = getEjbModule().getMetaInf();
140         if (metaInfFo==null) {
141             DialogDisplayer.getDefault().notify(
142                     new NotifyDescriptor.Message(NbBundle.getMessage(EJBFreeformModule.class,"MSG_ConfigFilesCorrupted"),
143                     NotifyDescriptor.ERROR_MESSAGE));
144             return null;
145         }
146         return getEjbModule().getMetaInf().getFileObject("webservices", "xml"); //NOI18N
147
}
148     
149     private FileObject getFileObject(String JavaDoc propname) {
150         String JavaDoc prop = evaluator.getProperty(propname);
151         if (prop != null) {
152             return helper.resolveFileObject(prop);
153         }
154         
155         return null;
156     }
157
158 }
159
Popular Tags