KickJava   Java API By Example, From Geeks To Geeks.

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


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.beans.PropertyChangeEvent JavaDoc;
23 import java.beans.PropertyChangeListener JavaDoc;
24 import java.io.File JavaDoc;
25 import org.netbeans.api.java.project.JavaProjectConstants;
26 import org.netbeans.api.project.Project;
27 import org.netbeans.api.project.ProjectUtils;
28 import org.netbeans.api.project.SourceGroup;
29 import org.netbeans.api.project.Sources;
30 import org.netbeans.modules.j2ee.api.ejbjar.EjbJar;
31 import org.netbeans.modules.j2ee.deployment.common.api.EjbChangeDescriptor;
32 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
33 import org.netbeans.modules.j2ee.deployment.devmodules.api.ModuleChangeReporter;
34 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider;
35 import org.netbeans.spi.project.support.ant.AntProjectHelper;
36 import org.netbeans.spi.project.support.ant.PropertyEvaluator;
37 import org.openide.filesystems.FileObject;
38 import org.openide.filesystems.FileUtil;
39
40
41 /**
42  * An ejb module implementation on top of project.
43  *
44  * @author Martin Adamek
45  */

46 public class EJBFreeformProvider extends J2eeModuleProvider implements ModuleChangeReporter,
47         EjbChangeDescriptor, PropertyChangeListener JavaDoc {
48     
49     private Project project;
50     private AntProjectHelper helper;
51     private PropertyEvaluator evaluator;
52     private EJBFreeformModule ejbModule;
53     
54     /** Creates a new instance of EJBFreeformProvider */
55     public EJBFreeformProvider(Project project, AntProjectHelper helper, PropertyEvaluator evaluator) {
56         this.project = project;
57         this.helper = helper;
58         this.evaluator = evaluator;
59         evaluator.addPropertyChangeListener(this);
60     }
61     
62     // from J2eeModuleProvider
63

64     
65     
66     public File JavaDoc getDeploymentConfigurationFile(String JavaDoc name) {
67         FileObject moduleFolder = EjbJar.getEjbJars(project)[0].getMetaInf();
68         File JavaDoc configFolder = FileUtil.toFile(moduleFolder);
69         return new File JavaDoc(configFolder, name);
70     }
71     
72     public FileObject findDeploymentConfigurationFile(String JavaDoc name) {
73         return EjbJar.getEjbJars(project)[0].getMetaInf().getFileObject(name);
74     }
75     
76     public ModuleChangeReporter getModuleChangeReporter() {
77         return this;
78     }
79     
80     void setJ2eeModule(EJBFreeformModule ejbFreeMod) {
81         ejbModule = ejbFreeMod;
82     }
83     
84     public J2eeModule getJ2eeModule() {
85         return ejbModule;
86     }
87     
88     // from ModuleChangeReporter
89

90     public boolean isManifestChanged(long timestamp) {
91         return false;
92     }
93     
94     public EjbChangeDescriptor getEjbChanges(long timestamp) {
95         return this;
96     }
97     
98     // from EjbChangeDescriptor
99

100     public String JavaDoc[] getChangedEjbs() {
101         return new String JavaDoc[] {};
102     }
103     
104     public boolean ejbsChanged() {
105         return false;
106     }
107     
108     public File JavaDoc getEnterpriseResourceDirectory() {
109         return getFile(EjbFreeformProperties.RESOURCE_DIR);
110     }
111     
112     public boolean useDefaultServer() {
113         return false;
114     }
115     
116     public FileObject[] getSourceRoots() {
117         Sources sources = ProjectUtils.getSources(project);
118         SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
119         FileObject[] roots = new FileObject[groups.length+1];
120         roots[0] = EjbJar.getEjbJars(project)[0].getMetaInf();
121         for (int i=0; i < groups.length; i++) {
122             roots[i+1] = groups[i].getRootFolder();
123         }
124         
125         return roots;
126     }
127     
128     public void setServerInstanceID(String JavaDoc severInstanceID) {
129         // TODO implement when needed
130
}
131     
132     public String JavaDoc getServerInstanceID() {
133         return evaluator.getProperty(EjbFreeformProperties.J2EE_SERVER_INSTANCE);
134     }
135     
136     public String JavaDoc getServerID() {
137         return evaluator.getProperty(EjbFreeformProperties.J2EE_SERVER_TYPE);
138     }
139     
140     // private methods
141

142     private File JavaDoc getFile(String JavaDoc propname) {
143         String JavaDoc prop = evaluator.getProperty(propname);
144         if (prop != null) {
145             return helper.resolveFile(prop);
146         }
147         return null;
148     }
149     
150     public void propertyChange(PropertyChangeEvent JavaDoc evt) {
151 // if (EjbFreeformProperties.RESOURCE_DIR.equals(evt.getPropertyName())) {
152
// String oldValue = (String)evt.getOldValue();
153
// String newValue = (String)evt.getNewValue();
154
// firePropertyChange(
155
// PROP_ENTERPRISE_RESOURCE_DIRECTORY,
156
// oldValue == null ? null : new File(oldValue),
157
// newValue == null ? null : new File(newValue));
158
// }
159
// TODO: temporary fix to work-around the above code where evt.getPropertyName()
160
// always returns null
161
firePropertyChange(PROP_ENTERPRISE_RESOURCE_DIRECTORY, null, getEnterpriseResourceDirectory());
162     }
163 }
164
Popular Tags