KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > metadata > StrippedClassPathImpl


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.metadata;
21
22 import java.beans.PropertyChangeEvent JavaDoc;
23 import java.beans.PropertyChangeListener JavaDoc;
24 import java.beans.PropertyChangeSupport JavaDoc;
25 import java.io.File JavaDoc;
26 import java.net.MalformedURLException JavaDoc;
27 import java.net.URL JavaDoc;
28 import java.util.ArrayList JavaDoc;
29 import java.util.HashSet JavaDoc;
30 import java.util.List JavaDoc;
31 import java.util.Set JavaDoc;
32 import org.netbeans.api.java.classpath.ClassPath;
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.openide.ErrorManager;
37 import org.openide.filesystems.FileUtil;
38 import org.openide.util.WeakListeners;
39
40 /**
41  * Use this class to create classpath without some roots.
42  *
43  * @author Tomas Zezula
44  */

45 public class StrippedClassPathImpl implements ClassPathImplementation, PropertyChangeListener JavaDoc {
46     
47     private final ClassPath orig;
48     private final Set JavaDoc<URL JavaDoc> appSrvRoots;
49     private final PropertyChangeSupport JavaDoc support;
50     private List JavaDoc<PathResourceImplementation> resources;
51     
52     public StrippedClassPathImpl(final ClassPath orig, final File JavaDoc[] appSrvRoots) {
53         assert orig != null;
54         assert appSrvRoots != null;
55         this.orig = orig;
56         this.appSrvRoots = new HashSet JavaDoc<URL JavaDoc>();
57         this.support = new PropertyChangeSupport JavaDoc(this);
58         for (File JavaDoc f : appSrvRoots) {
59             URL JavaDoc fileRoot = null;
60             try {
61                 fileRoot = f.toURI().toURL();
62             } catch (MalformedURLException JavaDoc ex) {
63                 ErrorManager.getDefault().notify(ex);
64             }
65             if (FileUtil.isArchiveFile(fileRoot)) {
66                 fileRoot = FileUtil.getArchiveRoot(fileRoot);
67             }
68             this.appSrvRoots.add(fileRoot);
69         }
70         this.orig.addPropertyChangeListener(WeakListeners.propertyChange(this, this.orig));
71     }
72     
73     public synchronized List JavaDoc<PathResourceImplementation> getResources() {
74         if (resources == null) {
75             this.resources = new ArrayList JavaDoc<PathResourceImplementation> ();
76             List JavaDoc<ClassPath.Entry> entries = orig.entries();
77             for (ClassPath.Entry entry : entries) {
78                 URL JavaDoc url = entry.getURL();
79                 if (!this.appSrvRoots.contains(url)) {
80                     this.resources.add(ClassPathSupport.createResource(url));
81                 }
82             }
83         }
84         return this.resources;
85     }
86     
87     public void addPropertyChangeListener(PropertyChangeListener JavaDoc listener) {
88         assert listener != null;
89         this.support.addPropertyChangeListener(listener);
90     }
91     
92     public void removePropertyChangeListener(PropertyChangeListener JavaDoc listener) {
93         assert listener != null;
94         this.support.removePropertyChangeListener(listener);
95     }
96     
97     public void propertyChange(PropertyChangeEvent JavaDoc event) {
98         synchronized (this) {
99             this.resources = null;
100         }
101         this.support.firePropertyChange(PROP_RESOURCES, null, null);
102     }
103     
104 }
105
106
Popular Tags