KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ejbjarproject > classpath > SourcePathImplementation


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 package org.netbeans.modules.j2ee.ejbjarproject.classpath;
20
21 import java.beans.PropertyChangeEvent JavaDoc;
22 import java.io.File JavaDoc;
23 import java.net.MalformedURLException JavaDoc;
24 import java.util.List JavaDoc;
25 import java.util.ArrayList JavaDoc;
26 import java.util.Collections JavaDoc;
27 import java.beans.PropertyChangeListener JavaDoc;
28 import java.beans.PropertyChangeSupport JavaDoc;
29 import java.net.URL JavaDoc;
30 import org.netbeans.modules.j2ee.api.ejbjar.EjbProjectConstants;
31 import org.netbeans.modules.j2ee.ejbjarproject.SourceRoots;
32 import org.netbeans.modules.j2ee.ejbjarproject.ui.customizer.EjbJarProjectProperties;
33 import org.netbeans.spi.java.classpath.ClassPathImplementation;
34 import org.netbeans.spi.java.classpath.PathResourceImplementation;
35 import org.netbeans.spi.java.classpath.support.ClassPathSupport;
36 import org.netbeans.spi.project.support.ant.AntProjectHelper;
37 import org.openide.ErrorManager;
38
39
40 /**
41  * Implementation of a single classpath that is derived from one Ant property.
42  */

43 final class SourcePathImplementation implements ClassPathImplementation, PropertyChangeListener JavaDoc {
44
45     private PropertyChangeSupport JavaDoc support = new PropertyChangeSupport JavaDoc(this);
46     private List JavaDoc resources;
47     private SourceRoots sourceRoots;
48     private AntProjectHelper projectHelper;
49
50     /**
51      * Construct the implementation.
52      * @param sourceRoots used to get the roots information and events
53      */

54     public SourcePathImplementation(SourceRoots sourceRoots, AntProjectHelper projectHelper) {
55         assert sourceRoots != null;
56         this.sourceRoots = sourceRoots;
57         this.projectHelper=projectHelper;
58         this.sourceRoots.addPropertyChangeListener (this);
59     }
60
61     public List JavaDoc /*<PathResourceImplementation>*/ getResources() {
62         synchronized (this) {
63             if (this.resources != null) {
64                 return this.resources;
65             }
66         }
67         URL JavaDoc[] roots = this.sourceRoots.getRootURLs();
68         String JavaDoc buildDir = projectHelper.getStandardPropertyEvaluator().getProperty(EjbJarProjectProperties.BUILD_DIR);
69         synchronized (this) {
70             if (this.resources == null) {
71                 List JavaDoc result = new ArrayList JavaDoc (roots.length);
72                 for (int i = 0; i < roots.length; i++) {
73                     PathResourceImplementation res = ClassPathSupport.createResource(roots[i]);
74                     result.add (res);
75                 }
76                 // adds build/generated/wsimport/client and build/generated/wsimport/service to resources to be available for code completion
77
if (projectHelper!=null) {
78                     try {
79                         if (buildDir!=null) {
80                             // generated/wsimport/client
81
File JavaDoc f = new File JavaDoc (projectHelper.resolveFile(buildDir),"generated/wsimport/client"); //NOI18N
82
URL JavaDoc url = f.toURI().toURL();
83                             if (!f.exists()) { //NOI18N
84
assert !url.toExternalForm().endsWith("/"); //NOI18N
85
url = new URL JavaDoc (url.toExternalForm()+'/'); //NOI18N
86
}
87                             result.add(ClassPathSupport.createResource(url));
88                             // generated/wsimport/service
89
f = new File JavaDoc (projectHelper.resolveFile(buildDir),"generated/wsimport/service"); //NOI18N
90
url = f.toURI().toURL();
91                             if (!f.exists()) { //NOI18N
92
assert !url.toExternalForm().endsWith("/"); //NOI18N
93
url = new URL JavaDoc (url.toExternalForm()+'/'); //NOI18N
94
}
95                             result.add(ClassPathSupport.createResource(url));
96                         }
97                     } catch (MalformedURLException JavaDoc ex) {
98                         ErrorManager.getDefault ().notify (ex);
99                     }
100                 }
101                 this.resources = Collections.unmodifiableList(result);
102             }
103         }
104         return this.resources;
105     }
106
107     public void addPropertyChangeListener(PropertyChangeListener JavaDoc listener) {
108         support.addPropertyChangeListener (listener);
109     }
110
111     public void removePropertyChangeListener(PropertyChangeListener JavaDoc listener) {
112         support.removePropertyChangeListener (listener);
113     }
114
115
116     public void propertyChange(PropertyChangeEvent JavaDoc evt) {
117         if (SourceRoots.PROP_ROOTS.equals (evt.getPropertyName())) {
118             synchronized (this) {
119                 this.resources = null;
120             }
121             this.support.firePropertyChange (PROP_RESOURCES,null,null);
122         }
123     }
124
125 }
126
Popular Tags