~ubuntu-branches/ubuntu/quantal/netbeans/quantal

« back to all changes in this revision

Viewing changes to j2ee/ejbfreeform/src/org/netbeans/modules/j2ee/ejbfreeform/EJBFreeformModule.java

  • Committer: Bazaar Package Importer
  • Author(s): Marek Slama
  • Date: 2008-01-29 14:11:22 UTC
  • Revision ID: james.westby@ubuntu.com-20080129141122-fnzjbo11ntghxfu7
Tags: upstream-6.0.1
ImportĀ upstreamĀ versionĀ 6.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
3
 *
 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
 
5
 *
 
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]"
 
23
 *
 
24
 * Contributor(s):
 
25
 *
 
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.
 
29
 *
 
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.
 
40
 */
 
41
 
 
42
package org.netbeans.modules.j2ee.ejbfreeform;
 
43
 
 
44
import java.beans.PropertyChangeEvent;
 
45
import java.beans.PropertyChangeListener;
 
46
import java.beans.PropertyChangeSupport;
 
47
import java.io.File;
 
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;
 
62
 
 
63
/**
 
64
 *
 
65
 * @author martin
 
66
 */
 
67
public class EJBFreeformModule implements J2eeModuleImplementation, PropertyChangeListener {
 
68
    
 
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;
 
74
    
 
75
    /** Creates a new instance of EJBFreeformModule */
 
76
    public EJBFreeformModule(Project project, AntProjectHelper helper, PropertyEvaluator evaluator) {
 
77
        this.project = project;
 
78
        this.helper = helper;
 
79
        this.evaluator = evaluator;
 
80
    }
 
81
    
 
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) {
 
86
                ejbImpl = modules[0];
 
87
            }
 
88
        }
 
89
        return ejbImpl;
 
90
    }
 
91
    
 
92
    public void setUrl(String url) {
 
93
    }
 
94
  
 
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();
 
101
//        }
 
102
//        return null;
 
103
//    }
 
104
//    
 
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();
 
109
        } else {
 
110
        // TODO MetadataModel: rewrite when MetadataModel<WebservicesMode> is ready
 
111
        // } else if (type == WebservicesMetadata.class) {
 
112
        //     return getWebservices();
 
113
            throw new NotImplementedException();
 
114
        }
 
115
//        return null;
 
116
    }
 
117
    
 
118
    public String getUrl() {
 
119
        return "";
 
120
    }
 
121
    
 
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();
 
127
    }
 
128
    
 
129
    public Object getModuleType() {
 
130
        return J2eeModule.EJB;
 
131
    }
 
132
    
 
133
    public FileObject getContentDirectory() throws java.io.IOException {
 
134
        return null;
 
135
    }
 
136
    
 
137
    public Iterator getArchiveContents() throws java.io.IOException {
 
138
        return null;
 
139
    }
 
140
    
 
141
    public FileObject getArchive() throws java.io.IOException {
 
142
        return null;
 
143
    }
 
144
    
 
145
    // private methods
 
146
    
 
147
// TODO MetadataModel: rewrite when MetadataModel is ready
 
148
//    private EjbJar getEjbJar() {
 
149
//        try {
 
150
//            return DDProvider.getDefault().getDDRoot(getEjbModule().getDeploymentDescriptor());
 
151
//        } catch (java.io.IOException e) {
 
152
//            org.openide.ErrorManager.getDefault().log(e.getLocalizedMessage());
 
153
//        }
 
154
//        return null;
 
155
//    }
 
156
//    
 
157
//    private Webservices getWebservices() {
 
158
//        FileObject wsdd = getDD();
 
159
//        if(wsdd != null) {
 
160
//            try {
 
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());
 
164
//            }
 
165
//        }
 
166
//        
 
167
//        return null;
 
168
//    }
 
169
    
 
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));
 
176
            return null;
 
177
        }
 
178
        return getEjbModule().getMetaInf().getFileObject("webservices", "xml"); //NOI18N
 
179
    }
 
180
    
 
181
    private FileObject getFileObject(String propname) {
 
182
        String prop = evaluator.getProperty(propname);
 
183
        if (prop != null) {
 
184
            return helper.resolveFileObject(prop);
 
185
        }
 
186
        
 
187
        return null;
 
188
    }
 
189
 
 
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);
 
194
    }
 
195
 
 
196
    public void addPropertyChangeListener(PropertyChangeListener listener) {
 
197
        getPropertyChangeSupport().addPropertyChangeListener(listener);
 
198
    }
 
199
 
 
200
    public void removePropertyChangeListener(PropertyChangeListener listener) {
 
201
        synchronized (this) {
 
202
            if (propertyChangeSupport == null) {
 
203
                return;
 
204
            }
 
205
        }
 
206
        propertyChangeSupport.removePropertyChangeListener(listener);
 
207
    }
 
208
    
 
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);
 
218
//                }
 
219
            }
 
220
            return propertyChangeSupport;
 
221
        }
 
222
    }
 
223
 
 
224
    public File getResourceDirectory() {
 
225
        return getFile(EjbFreeformProperties.RESOURCE_DIR);
 
226
    }
 
227
    
 
228
    private File getFile(String propname) {
 
229
        String prop = evaluator.getProperty(propname);
 
230
        if (prop != null) {
 
231
            return helper.resolveFile(prop);
 
232
        }
 
233
        return null;
 
234
    }
 
235
 
 
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));
 
244
        }
 
245
    }
 
246
}