2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
42
package org.netbeans.modules.j2ee.ejbfreeform;
44
import java.beans.PropertyChangeEvent;
45
import java.beans.PropertyChangeListener;
46
import java.beans.PropertyChangeSupport;
48
import java.util.Iterator;
49
import org.netbeans.api.project.Project;
50
import org.netbeans.modules.j2ee.dd.api.ejb.EjbJarMetadata;
51
import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
52
import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleImplementation;
53
import org.netbeans.modules.j2ee.metadata.model.api.MetadataModel;
54
import org.netbeans.spi.project.support.ant.AntProjectHelper;
55
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
56
import org.openide.DialogDisplayer;
57
import org.openide.NotifyDescriptor;
58
import org.openide.filesystems.FileObject;
59
import org.openide.filesystems.FileUtil;
60
import org.openide.util.NbBundle;
61
import org.openide.util.NotImplementedException;
67
public class EJBFreeformModule implements J2eeModuleImplementation, PropertyChangeListener {
69
private Project project;
70
private AntProjectHelper helper;
71
private PropertyEvaluator evaluator;
72
private org.netbeans.modules.j2ee.api.ejbjar.EjbJar ejbImpl;
73
private PropertyChangeSupport propertyChangeSupport;
75
/** Creates a new instance of EJBFreeformModule */
76
public EJBFreeformModule(Project project, AntProjectHelper helper, PropertyEvaluator evaluator) {
77
this.project = project;
79
this.evaluator = evaluator;
82
private org.netbeans.modules.j2ee.api.ejbjar.EjbJar getEjbModule () {
83
if (ejbImpl == null) {
84
org.netbeans.modules.j2ee.api.ejbjar.EjbJar modules[] = org.netbeans.modules.j2ee.api.ejbjar.EjbJar.getEjbJars(project);
85
if (modules.length > 0) {
92
public void setUrl(String url) {
95
// TODO MetadataModel: rewrite when MetadataModel is ready
96
// public RootInterface getDeploymentDescriptor(String location) {
97
// if (J2eeModule.EJBJAR_XML.equals(location)){
98
// return getEjbJar();
99
// } else if(J2eeModule.EJBSERVICES_XML.equals(location)){
100
// return getWebservices();
105
public <T> MetadataModel<T> getMetadataModel(Class<T> type) {
106
if (type == EjbJarMetadata.class) {
107
// return (MetadataModel<T>) project.getAPIEjbJar().getMetadataModel();
108
throw new NotImplementedException();
110
// TODO MetadataModel: rewrite when MetadataModel<WebservicesMode> is ready
111
// } else if (type == WebservicesMetadata.class) {
112
// return getWebservices();
113
throw new NotImplementedException();
118
public String getUrl() {
122
public String getModuleVersion() {
123
// TODO MetadataModel: rewrite when MetadataModel is ready
124
// EjbJar ejbJar = getEjbJar();
125
// return ejbJar.getVersion().toString();
126
throw new NotImplementedException();
129
public Object getModuleType() {
130
return J2eeModule.EJB;
133
public FileObject getContentDirectory() throws java.io.IOException {
137
public Iterator getArchiveContents() throws java.io.IOException {
141
public FileObject getArchive() throws java.io.IOException {
147
// TODO MetadataModel: rewrite when MetadataModel is ready
148
// private EjbJar getEjbJar() {
150
// return DDProvider.getDefault().getDDRoot(getEjbModule().getDeploymentDescriptor());
151
// } catch (java.io.IOException e) {
152
// org.openide.ErrorManager.getDefault().log(e.getLocalizedMessage());
157
// private Webservices getWebservices() {
158
// FileObject wsdd = getDD();
159
// if(wsdd != null) {
161
// return org.netbeans.modules.j2ee.dd.api.webservices.DDProvider.getDefault().getDDRoot(getDD());
162
// } catch (java.io.IOException e) {
163
// org.openide.ErrorManager.getDefault().log(e.getLocalizedMessage());
170
public FileObject getDD() {
171
FileObject metaInfFo = getEjbModule().getMetaInf();
172
if (metaInfFo==null) {
173
DialogDisplayer.getDefault().notify(
174
new NotifyDescriptor.Message(NbBundle.getMessage(EJBFreeformModule.class,"MSG_ConfigFilesCorrupted"),
175
NotifyDescriptor.ERROR_MESSAGE));
178
return getEjbModule().getMetaInf().getFileObject("webservices", "xml"); //NOI18N
181
private FileObject getFileObject(String propname) {
182
String prop = evaluator.getProperty(propname);
184
return helper.resolveFileObject(prop);
190
public File getDeploymentConfigurationFile(String name) {
191
FileObject moduleFolder = org.netbeans.modules.j2ee.api.ejbjar.EjbJar.getEjbJars(project)[0].getMetaInf();
192
File configFolder = FileUtil.toFile(moduleFolder);
193
return new File(configFolder, name);
196
public void addPropertyChangeListener(PropertyChangeListener listener) {
197
getPropertyChangeSupport().addPropertyChangeListener(listener);
200
public void removePropertyChangeListener(PropertyChangeListener listener) {
201
synchronized (this) {
202
if (propertyChangeSupport == null) {
206
propertyChangeSupport.removePropertyChangeListener(listener);
209
private PropertyChangeSupport getPropertyChangeSupport() {
210
// TODO MetadataModel: rewrite when MetadataModel is ready
211
// EjbJar ejbJar = getEjbJar();
212
synchronized (this) {
213
if (propertyChangeSupport == null) {
214
propertyChangeSupport = new PropertyChangeSupport(this);
215
// if (ejbJar != null) {
216
// PropertyChangeListener l = (PropertyChangeListener) WeakListeners.create(PropertyChangeListener.class, this, ejbJar);
217
// ejbJar.addPropertyChangeListener(l);
220
return propertyChangeSupport;
224
public File getResourceDirectory() {
225
return getFile(EjbFreeformProperties.RESOURCE_DIR);
228
private File getFile(String propname) {
229
String prop = evaluator.getProperty(propname);
231
return helper.resolveFile(prop);
236
public void propertyChange(PropertyChangeEvent evt) {
237
if (EjbFreeformProperties.RESOURCE_DIR.equals(evt.getPropertyName())) {
238
String oldValue = (String) evt.getOldValue();
239
String newValue = (String) evt.getNewValue();
240
getPropertyChangeSupport().firePropertyChange(
241
J2eeModule.PROP_RESOURCE_DIRECTORY,
242
oldValue == null ? null : new File(oldValue),
243
newValue == null ? null : new File(newValue));