KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > ruby > railsprojects > classpath > BootClassPathImplementation


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.ruby.railsprojects.classpath;
20
21 import java.beans.PropertyChangeEvent JavaDoc;
22 import org.netbeans.modules.ruby.rubyproject.RubyProjectUtil;
23 import org.netbeans.modules.ruby.rubyproject.api.RubyInstallation;
24 import org.netbeans.spi.java.classpath.ClassPathImplementation;
25 import org.netbeans.spi.java.classpath.PathResourceImplementation;
26 import org.netbeans.spi.java.classpath.support.ClassPathSupport;
27 import org.netbeans.api.java.classpath.ClassPath;
28 import java.beans.PropertyChangeListener JavaDoc;
29 import java.beans.PropertyChangeSupport JavaDoc;
30 import java.util.List JavaDoc;
31 import java.util.ArrayList JavaDoc;
32 import java.util.Collections JavaDoc;
33 import org.netbeans.modules.ruby.spi.project.support.rake.PropertyEvaluator;
34 import org.openide.util.WeakListeners;
35
36 final class BootClassPathImplementation implements ClassPathImplementation, PropertyChangeListener JavaDoc {
37
38 // private static final String PLATFORM_ACTIVE = "platform.active"; //NOI18N
39
// private static final String ANT_NAME = "platform.ant.name"; //NOI18N
40
// private static final String J2SE = "j2se"; //NOI18N
41

42     private final PropertyEvaluator evaluator;
43 // private JavaPlatformManager platformManager;
44
//name of project active platform
45
private String JavaDoc activePlatformName;
46     //active platform is valid (not broken reference)
47
private boolean isActivePlatformValid;
48     private List JavaDoc<PathResourceImplementation> resourcesCache;
49     private PropertyChangeSupport JavaDoc support = new PropertyChangeSupport JavaDoc(this);
50
51     public BootClassPathImplementation(PropertyEvaluator evaluator) {
52         assert evaluator != null;
53         this.evaluator = evaluator;
54         evaluator.addPropertyChangeListener(WeakListeners.propertyChange(this, evaluator));
55     }
56
57     public synchronized List JavaDoc<PathResourceImplementation> getResources() {
58         if (this.resourcesCache == null) {
59 // JavaPlatform jp = findActivePlatform ();
60
// if (jp != null) {
61
//TODO: May also listen on CP, but from Platform it should be fixed.
62
List JavaDoc<PathResourceImplementation> result = new ArrayList JavaDoc<PathResourceImplementation>();
63 // for (ClassPath.Entry entry : jp.getBootstrapLibraries().entries()) {
64
for (ClassPath.Entry entry : RubyInstallation.getInstance().getClassPathEntries()) {
65                     result.add(ClassPathSupport.createResource(entry.getURL()));
66                 }
67                 resourcesCache = Collections.unmodifiableList (result);
68 // }
69
// else {
70
// resourcesCache = Collections.emptyList();
71
// }
72
}
73         return this.resourcesCache;
74     }
75
76     public void addPropertyChangeListener(PropertyChangeListener JavaDoc listener) {
77         this.support.addPropertyChangeListener (listener);
78     }
79
80     public void removePropertyChangeListener(PropertyChangeListener JavaDoc listener) {
81         this.support.removePropertyChangeListener (listener);
82     }
83
84 // private JavaPlatform findActivePlatform () {
85
// if (this.platformManager == null) {
86
// this.platformManager = JavaPlatformManager.getDefault();
87
// this.platformManager.addPropertyChangeListener(WeakListeners.propertyChange(this, this.platformManager));
88
// }
89
// this.activePlatformName = evaluator.getProperty(PLATFORM_ACTIVE);
90
// final JavaPlatform activePlatform = RubyProjectUtil.getActivePlatform (this.activePlatformName);
91
// this.isActivePlatformValid = activePlatform != null;
92
// return activePlatform;
93
// }
94
//
95
public void propertyChange(PropertyChangeEvent JavaDoc evt) {
96 // if (evt.getSource() == this.evaluator && evt.getPropertyName().equals(PLATFORM_ACTIVE)) {
97
// //Active platform was changed
98
// resetCache ();
99
// }
100
// else if (evt.getSource() == this.platformManager && JavaPlatformManager.PROP_INSTALLED_PLATFORMS.equals(evt.getPropertyName()) && activePlatformName != null) {
101
// //Platform definitions were changed, check if the platform was not resolved or deleted
102
// if (this.isActivePlatformValid) {
103
// if (RubyProjectUtil.getActivePlatform (this.activePlatformName) == null) {
104
// //the platform was not removed
105
// this.resetCache();
106
// }
107
// }
108
// else {
109
// if (RubyProjectUtil.getActivePlatform (this.activePlatformName) != null) {
110
// this.resetCache();
111
// }
112
// }
113
// }
114
}
115     
116     /**
117      * Resets the cache and firesPropertyChange
118      */

119     private void resetCache () {
120         synchronized (this) {
121             resourcesCache = null;
122         }
123         support.firePropertyChange(PROP_RESOURCES, null, null);
124     }
125     
126 }
127
Popular Tags