KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > deployment > plugins > api > InstanceProperties


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 /*
21  * InstanceProperties.java
22  *
23  */

24
25 package org.netbeans.modules.j2ee.deployment.plugins.api;
26
27 import javax.enterprise.deploy.spi.DeploymentManager JavaDoc;
28 import javax.enterprise.deploy.spi.Target JavaDoc;
29 import org.netbeans.modules.j2ee.deployment.impl.ServerRegistry;
30 import org.netbeans.modules.j2ee.deployment.impl.ServerInstance;
31 import org.netbeans.modules.j2ee.deployment.impl.InstancePropertiesImpl;
32 import java.beans.PropertyChangeListener JavaDoc;
33 import java.beans.PropertyChangeEvent JavaDoc;
34 import java.util.*;
35
36
37 /**
38  * A way to ask the IDE to store customized information about a server instance
39  * and make it available to a plugin.
40  *
41  * Typical usage for create new instance would be like this:
42  * InstanceProperties props = InstanceProperties.getInstanceProperties(url);
43  * if (props == null)
44  * props = InstanceProperties.createInstanceProperties(url, user, password,
45  * displayName);
46  * props.setProperty(prop1, value1);
47  * . . .
48  *
49  * @author George FinKlang
50  * @author nn136682
51  * @version 0.1
52  */

53 public abstract class InstanceProperties {
54
55     /**
56      * URL property, its value is used as a connection string to get the deployment
57      * manager (e.g. "tomcat:home=jakarta-tomcat-5.0.27:base=jakarta-tomcat-5.0.27_base"
58      * for Tomcat).
59      */

60     public static final String JavaDoc URL_ATTR = "url"; //NOI18N
61

62     /**
63      * Username property, its value is used by the deployment manager.
64      */

65     public static final String JavaDoc USERNAME_ATTR = "username"; //NOI18N
66

67     /**
68      * Password property, its value is used by the deployment manager.
69      */

70     public static final String JavaDoc PASSWORD_ATTR = "password"; //NOI18N
71

72     /**
73      * Display name property, its value is used by IDE to represent server instance.
74      */

75     public static final String JavaDoc DISPLAY_NAME_ATTR = "displayName"; //NOI18N
76

77     /**
78      * Remove forbidden property, if its value is set to <code>true</code>, it
79      * won't be allowed to remove the server instance from the server registry.
80      */

81     public static final String JavaDoc REMOVE_FORBIDDEN = "removeForbidden"; //NOI18N
82

83     /**
84      * HTTP port property, The port where the instance runs
85      */

86     public static final String JavaDoc HTTP_PORT_NUMBER = "httpportnumber";
87     
88     /**
89      * List of listeners which listen to instance properties changes
90      */

91     private List/*<PropertyChangeListener>*/ changeListeners = Collections.synchronizedList(new LinkedList());
92
93     /**
94      * Returns instance properties for the server instance.
95      *
96      * @param url the url connection string to get the instance deployment manager.
97      * @return the InstanceProperties object, null if instance does not exists.
98      */

99     public static InstanceProperties getInstanceProperties(String JavaDoc url) {
100         ServerInstance inst = ServerRegistry.getInstance().getServerInstance(url);
101         if (inst == null)
102             return null;
103         return inst.getInstanceProperties();
104     }
105     
106     /**
107      * Create new instance and returns instance properties for the server instance.
108      *
109      * @param url the url connection string to get the instance deployment manager
110      * @param username username which is used by the deployment manager.
111      * @param password password which is used by the deployment manager.
112      * @return the <code>InstanceProperties</code> object, <code>null</code> if
113      * instance does not exists
114      * @exception InstanceCreationException when instance with same url already
115      * registered.
116      *
117      * @deprecated use the factory method with displayName parameter.
118      */

119     public static InstanceProperties createInstanceProperties(
120             String JavaDoc url, String JavaDoc username, String JavaDoc password) throws InstanceCreationException {
121         return createInstanceProperties(url, username, password, null);
122     }
123
124     /**
125      * Create new instance and returns instance properties for the server instance.
126      *
127      * @param url the url connection string to get the instance deployment manager.
128      * @param username username which is used by the deployment manager.
129      * @param password password which is used by the deployment manager.
130      * @param displayName display name which is used by IDE to represent this
131      * server instance.
132      * @return the <code>InstanceProperties</code> object, <code>null</code> if
133      * instance does not exists.
134      * @exception InstanceCreationException when instance with same url already
135      * registered.
136      */

137     public static InstanceProperties createInstanceProperties(String JavaDoc url, String JavaDoc username,
138             String JavaDoc password, String JavaDoc displayName) throws InstanceCreationException {
139         ServerRegistry registry = ServerRegistry.getInstance();
140         registry.addInstance(url, username, password, displayName);
141         ServerInstance inst = registry.getServerInstance(url);
142         InstanceProperties ip = inst.getInstanceProperties();
143         return ip;
144     }
145     
146     /**
147      * Returns list of URL strings of all registered instances
148      * @return array of URL strings
149      */

150     public static String JavaDoc[] getInstanceList() {
151         return ServerRegistry.getInstance().getInstanceURLs();
152     }
153
154     /**
155      * Return default instance properties.
156      */

157     public static InstanceProperties getDefaultInstance() {
158         return new InstancePropertiesImpl(ServerRegistry.getInstance().getDefaultInstance().getServerInstance());
159     }
160     
161     /**
162      * Set instance properties.
163      * @param props properties to set for this server instance.
164      * @exception IllegalStateException when instance already removed or not created yet
165      */

166     public abstract void setProperties(java.util.Properties JavaDoc props) throws IllegalStateException JavaDoc;
167
168     /**
169      * Set instance property
170      * @param propname name of property
171      * @param value property string value
172      * @exception IllegalStateException when instance already removed or not created yet
173      */

174     public abstract void setProperty(String JavaDoc propname, String JavaDoc value) throws IllegalStateException JavaDoc;
175     
176     /**
177      * Get instance property
178      * @param propname name of property
179      * @return property string value
180      * @exception IllegalStateException when instance already removed or not created yet
181      */

182     public abstract String JavaDoc getProperty(String JavaDoc propname) throws IllegalStateException JavaDoc;
183     
184     /**
185      * Get instance property keys
186      * @return property key enunmeration
187      * @exception IllegalStateException when instance already removed or not created yet
188      */

189     public abstract java.util.Enumeration JavaDoc propertyNames() throws IllegalStateException JavaDoc;
190     
191     /**
192      * Is the target server the default J2EE server for deployment?
193      * @return true if the target server or admin server is the default.
194      */

195     public abstract boolean isDefaultInstance();
196     
197     /**
198      * Return DeploymentManager associated with this instance.
199      */

200     public abstract DeploymentManager JavaDoc getDeploymentManager();
201     
202     /**
203      * Return default Target object for the target server from this instance, if any.
204      */

205     public abstract Target JavaDoc getDefaultTarget();
206     
207     /**
208      * Set the target server the default server.
209      * @param targetName name of the target server; null if admin server is also single target.
210      */

211     public abstract void setAsDefaultServer(String JavaDoc targetName);
212     
213     /**
214      * Ask the server instance to reset cached deployment manager, J2EE
215      * management objects and refresh it UI elements.
216      */

217     public abstract void refreshServerInstance();
218     
219     /**
220      * Add <code>PropertyChangeListener</code> which will be notified of
221      * <code>InstanceProperties</code> changes.
222      *
223      * @param <code>PropertyChangeListener</code> which will be notified of
224      * <code>InstanceProperties</code> changes.
225      *
226      */

227     public void addPropertyChangeListener(PropertyChangeListener JavaDoc listener) {
228         changeListeners.add(listener);
229     }
230     
231     /**
232      * This method should be called to notify interested listeners when
233      * InstanceProperties change.
234      *
235      * @param evt A PropertyChangeEvent object describing the event source
236      * and the property that has changed.
237      */

238     protected void firePropertyChange(PropertyChangeEvent JavaDoc evt) {
239         ArrayList cloned = null;
240         synchronized (this) {
241             if (changeListeners != null) {
242                 cloned = new ArrayList();
243                 cloned.addAll(changeListeners);
244             }
245         }
246         if (cloned != null) {
247             Iterator i = cloned.iterator();
248             while (i.hasNext()) {
249                 ((PropertyChangeListener JavaDoc)i.next()).propertyChange(evt);
250             }
251         }
252     }
253 }
254
Popular Tags