001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: /*
043: * WebServiceClassPathProvider.java
044: *
045: * Created on September 14, 2005, 4:03 PM
046: *
047: */
048: package org.netbeans.modules.mobility.end2end.util;
049:
050: import java.beans.PropertyChangeSupport;
051: import java.net.URL;
052: import java.util.ArrayList;
053: import java.util.Arrays;
054: import java.util.Enumeration;
055: import java.util.List;
056: import org.netbeans.api.java.classpath.ClassPath;
057: import org.netbeans.api.project.FileOwnerQuery;
058: import org.netbeans.api.project.Project; //import org.netbeans.modules.javacore.api.JavaModel;
059: import org.netbeans.spi.java.classpath.ClassPathFactory;
060: import org.netbeans.spi.java.classpath.ClassPathImplementation;
061: import org.netbeans.spi.java.classpath.ClassPathProvider;
062: import org.netbeans.spi.java.classpath.PathResourceImplementation;
063: import org.openide.filesystems.FileObject;
064: import org.openide.filesystems.FileStateInvalidException;
065:
066: /**
067: *
068: * @author suchys
069: */
070: public class WebServiceClassPathProvider implements ClassPathProvider {
071:
072: protected Project webProject;
073: private ClassPath cp;
074:
075: public ClassPath findClassPath(final FileObject file,
076: final String type) {
077: if (ClassPath.SOURCE.equals(type)) {
078: assert file != null;
079: webProject = FileOwnerQuery.getOwner(file);
080: assert webProject != null;
081: //if (cp == null){
082: cp = ClassPathFactory
083: .createClassPath(new WSProjectClassPathImpl());
084: //}
085: return cp;
086: }
087: return null;
088: }
089:
090: private class WSProjectClassPathImpl implements
091: ClassPathImplementation {
092: final protected PropertyChangeSupport support = new PropertyChangeSupport(
093: this );
094:
095: WSProjectClassPathImpl() {
096: //to avoid creation of accessor class
097: }
098:
099: public List<PathResourceImplementation> getResources() {
100: return Arrays
101: .asList(new PathResourceImplementation[] { new PathResourceImplementation() {
102:
103: public ClassPathImplementation getContent() {
104: return null;
105: }
106:
107: public URL[] getRoots() {
108: final List<URL> urls = new ArrayList<URL>();
109: FileObject fo = webProject
110: .getProjectDirectory()
111: .getFileObject(
112: "build/generated/wsclient/"); //NOI18N
113: if (fo != null) {
114: try {
115: urls.add(fo.getURL());
116: } catch (FileStateInvalidException ex) {
117: }
118: // JavaModel.getJavaRepository().beginTrans(false);
119: // try {
120: // for (final Enumeration<? extends FileObject> enu = fo.getChildren(true); enu.hasMoreElements();) {
121: // final FileObject elem = enu.nextElement();
122: // JavaModel.getResource(elem);
123: // }
124: // } catch (Exception e){
125: // } finally {
126: // JavaModel.getJavaRepository().endTrans();
127: // }
128: }
129: fo = webProject
130: .getProjectDirectory()
131: .getFileObject(
132: "build/generated/wsbinary/"); //NOI18N
133: if (fo != null) {
134: try {
135: urls.add(fo.getURL());
136: } catch (FileStateInvalidException ex) {
137: }
138: }
139: //support.firePropertyChange(ClassPathImplementation.PROP_RESOURCES, null, null);
140: return urls.toArray(new URL[urls.size()]);
141: }
142:
143: /**
144: * Registers PropertyChangeListener to receive events.
145: * @param listener The listener to register.
146: */
147: public synchronized void addPropertyChangeListener(
148: java.beans.PropertyChangeListener listener) {
149: support.addPropertyChangeListener(listener);
150: }
151:
152: /**
153: * Removes PropertyChangeListener from the list of listeners.
154: * @param listener The listener to remove.
155: */
156: public synchronized void removePropertyChangeListener(
157: java.beans.PropertyChangeListener listener) {
158: support
159: .removePropertyChangeListener(listener);
160: }
161:
162: } });
163: }
164:
165: /**
166: * Utility field holding list of PropertyChangeListeners.
167: */
168: private transient java.util.ArrayList<java.beans.PropertyChangeListener> propertyChangeListenerList;
169:
170: /**
171: * Registers PropertyChangeListener to receive events.
172: * @param listener The listener to register.
173: */
174: public synchronized void addPropertyChangeListener(
175: final java.beans.PropertyChangeListener listener) {
176: if (propertyChangeListenerList == null) {
177: propertyChangeListenerList = new java.util.ArrayList<java.beans.PropertyChangeListener>();
178: }
179: propertyChangeListenerList.add(listener);
180: }
181:
182: /**
183: * Removes PropertyChangeListener from the list of listeners.
184: * @param listener The listener to remove.
185: */
186: public synchronized void removePropertyChangeListener(
187: final java.beans.PropertyChangeListener listener) {
188: if (propertyChangeListenerList != null) {
189: propertyChangeListenerList.remove(listener);
190: }
191: }
192:
193: /**
194: * Notifies all registered listeners about the event.
195: *
196: * @param event The event to be fired
197: */
198: @SuppressWarnings("unused")
199: private void firePropertyChangeListenerPropertyChange(
200: final java.beans.PropertyChangeEvent event) {
201: java.util.ArrayList<java.beans.PropertyChangeListener> list;
202: synchronized (this ) {
203: if (propertyChangeListenerList == null)
204: return;
205: list = new ArrayList<java.beans.PropertyChangeListener>(
206: propertyChangeListenerList);
207: }
208: for (java.beans.PropertyChangeListener cl : list) {
209: cl.propertyChange(event);
210: }
211: }
212: }
213:
214: }
|