KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > modules > ModuleInfo


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.openide.modules;
20
21 import java.beans.*;
22
23 // THIS CLASS OUGHT NOT USE NbBundle NOR org.openide CLASSES
24
// OUTSIDE OF openide-util.jar! UI AND FILESYSTEM/DATASYSTEM
25
// INTERACTIONS SHOULD GO ELSEWHERE.
26
import java.util.*;
27
28
29 /** General information about a module.
30  * Immutable from an API perspective, serves as
31  * a source of information only.
32  * All instances may be gotten via lookup.
33  * It is forbidden for module code to register instances of this class.
34  * @author Jesse Glick
35  * @since 1.24
36  */

37 public abstract class ModuleInfo {
38     /** Property name fired when enabled or disabled.
39      * For changes in other attributes, property name
40      * can match manifest attribute name, for example
41      * OpenIDE-Module-Specification-Version after upgrade.
42      */

43     public static final String JavaDoc PROP_ENABLED = "enabled"; // NOI18N
44
private final PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
45
46     /** Do-nothing constructor. */
47     protected ModuleInfo() {
48     }
49
50     /** The code name of the module, sans release version. */
51     public abstract String JavaDoc getCodeNameBase();
52
53     /** The release version (-1 if undefined). */
54     public abstract int getCodeNameRelease();
55
56     /** The full code name, with release version after slash if defined. */
57     public abstract String JavaDoc getCodeName();
58
59     /** Get a localized display name, if available.
60      * As a fallback provides the code name (base).
61      * Convenience method only.
62      */

63     public String JavaDoc getDisplayName() {
64         String JavaDoc dn = (String JavaDoc) getLocalizedAttribute("OpenIDE-Module-Name"); // NOI18N
65

66         if (dn != null) {
67             return dn;
68         }
69
70         return getCodeNameBase();
71     }
72
73     /** The specification version, or null. */
74     public abstract SpecificationVersion getSpecificationVersion();
75
76     /** The implementation version, or null.
77      * Convenience method only.
78      */

79     public String JavaDoc getImplementationVersion() {
80         return (String JavaDoc) getAttribute("OpenIDE-Module-Implementation-Version"); // NOI18N
81
}
82
83     /** The identification of the build version. Usually build number.
84      * If no specific build version is provided then this method delegates to {@link #getImplementationVersion}.
85      *
86      * @return textual identification of build version or the value for implementation version
87      * @since 4.18
88      */

89     public String JavaDoc getBuildVersion() {
90         String JavaDoc bld = (String JavaDoc) getAttribute("OpenIDE-Module-Build-Version"); // NOI18N
91

92         return (bld == null) ? getImplementationVersion() : bld;
93     }
94
95     /** Whether the module is currently enabled. */
96     public abstract boolean isEnabled();
97
98     /** Get some attribute, for example OpenIDE-Module-Name.
99      * Not all manifest attributes need be supported here.
100      * Attributes not present in the manifest may be available.
101      */

102     public abstract Object JavaDoc getAttribute(String JavaDoc attr);
103
104     /** Get an attribute with localization.
105      * That is, if there is a suitable locale variant of the attribute
106      * name, return its value rather than the value of the base attribute.
107      */

108     public abstract Object JavaDoc getLocalizedAttribute(String JavaDoc attr);
109
110     /** Add a change listener. */
111     public final void addPropertyChangeListener(PropertyChangeListener l) {
112         if (l == null) {
113             throw new NullPointerException JavaDoc(
114                 "If you see this stack trace, please attach to: http://www.netbeans.org/issues/show_bug.cgi?id=22379"
115             ); // NOI18N
116
}
117
118         changeSupport.addPropertyChangeListener(l);
119     }
120
121     /** Remove a change listener. */
122     public final void removePropertyChangeListener(PropertyChangeListener l) {
123         changeSupport.removePropertyChangeListener(l);
124     }
125
126     /** Indicate that something changed, as a subclass.
127      * Changes are fired synchronously (but this method need not be called synchronously).
128      */

129     protected final void firePropertyChange(String JavaDoc prop, Object JavaDoc old, Object JavaDoc nue) {
130         changeSupport.firePropertyChange(prop, old, nue);
131     }
132
133     /** Get a list of all dependencies this module has. */
134     public abstract Set<Dependency> getDependencies();
135
136     /** Determine if the provided class
137      * was loaded as a part of this module, and thus will only be
138      * loadable later if this module is enabled.
139      * If in doubt, return <code>false</code>.
140      * @since 1.28
141      */

142     public abstract boolean owns(Class JavaDoc<?> clazz);
143
144     /**
145      * Get a class loader associated with this module that can load
146      * classes defined in the module.
147      * <p>
148      * You can only call this method on an enabled module, and the
149      * result may change if the module is disabled and re&euml;nabled.
150      * <p>
151      * The class loader may or may not be shared with any other
152      * module, or be the application's startup class loader, etc.
153      * <p>
154      * For reasons of backward compatibility, this method is not abstract
155      * but will throw {@link UnsupportedOperationException} if not
156      * overridden. The instances obtainable from default lookup will
157      * override the method to return a real value.
158      * @return a module class loader
159      * @throws IllegalArgumentException if this module is disabled
160      * @since 4.21
161      */

162     public ClassLoader JavaDoc getClassLoader() throws IllegalArgumentException JavaDoc {
163         throw new UnsupportedOperationException JavaDoc("Must be overridden"); // NOI18N
164
}
165
166     /** Get a set of capabilities which this module provides to others that may
167      * require it.
168      * The default implementation returns an empty array.
169      * @return an array of tokens, possibly empty but not null
170      * @since 2.3
171      */

172     public String JavaDoc[] getProvides() {
173         return new String JavaDoc[] { };
174     }
175 }
176
Popular Tags