KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > deployment > impl > InstancePropertiesImpl


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 /*
22  * InstancePropertiesImpl.java
23  *
24  * Created on December 4, 2003, 6:11 PM
25  */

26
27 package org.netbeans.modules.j2ee.deployment.impl;
28
29 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties;
30 import org.openide.filesystems.FileObject;
31 import org.openide.util.NbBundle;
32 import java.beans.PropertyChangeEvent JavaDoc;
33 import org.netbeans.modules.j2ee.deployment.devmodules.spi.InstanceListener;
34
35 /**
36  *
37  * @author nn136682
38  */

39 public class InstancePropertiesImpl extends InstanceProperties implements InstanceListener {
40     private final String JavaDoc url;
41     private transient FileObject fo;
42     
43     /** Creates a new instance of InstancePropertiesImpl */
44     public InstancePropertiesImpl(ServerInstance instance) {
45         this(instance.getUrl());
46     }
47
48     /** Creates a new instance of InstancePropertiesImpl */
49     public InstancePropertiesImpl(String JavaDoc url) {
50         this.url = url;
51     }
52     
53     private FileObject getFO() {
54         if (fo == null) {
55             ServerInstance instance = ServerRegistry.getInstance().getServerInstance(url);
56             if (instance == null)
57                 throw new IllegalStateException JavaDoc(
58                 (NbBundle.getMessage(InstancePropertiesImpl.class, "MSG_InstanceNotExists", url))); //NOI18N
59
fo = ServerRegistry.getInstance().getInstanceFileObject(url);
60             if (fo == null)
61                 throw new IllegalStateException JavaDoc(
62                 (NbBundle.getMessage(InstancePropertiesImpl.class, "MSG_InstanceNotExists", url))); //NOI18N
63

64         }
65         return fo;
66     }
67     
68     // InstanceListener methods
69
public void instanceRemoved(String JavaDoc instance) {
70         if (instance != null && url.equals(instance))
71             fo = null;
72     }
73     public void instanceAdded(String JavaDoc instance) {}
74     public void changeDefaultInstance(String JavaDoc oldInstance, String JavaDoc newInstance){
75     }
76     
77     public String JavaDoc getProperty(String JavaDoc propname) throws IllegalStateException JavaDoc {
78         Object JavaDoc propValue = getFO().getAttribute(propname);
79         return propValue == null ? null : propValue.toString();
80     }
81
82     public java.util.Enumeration JavaDoc propertyNames() throws IllegalStateException JavaDoc {
83         return getFO().getAttributes();
84     }
85     
86     public void setProperty(String JavaDoc propname, String JavaDoc value) throws IllegalStateException JavaDoc {
87         try {
88             String JavaDoc oldValue = getProperty(propname);
89             getFO().setAttribute(propname, value);
90             firePropertyChange(new PropertyChangeEvent JavaDoc(this, propname, oldValue, value));
91         } catch (java.io.IOException JavaDoc ioe) {
92             throw (IllegalStateException JavaDoc) org.openide.ErrorManager.getDefault().annotate(
93             new IllegalStateException JavaDoc(NbBundle.getMessage(InstancePropertiesImpl.class, "MSG_InstanceNotExists", url)),ioe);
94         }
95     }
96     
97     public void setProperties(java.util.Properties JavaDoc props) throws IllegalStateException JavaDoc {
98         java.util.Enumeration JavaDoc propNames = props.propertyNames();
99         while (propNames.hasMoreElements()) {
100             String JavaDoc propName = (String JavaDoc) propNames.nextElement();
101             String JavaDoc propValue = props.getProperty(propName);
102             setProperty(propName, propValue);
103         }
104     }
105     
106     public javax.enterprise.deploy.spi.DeploymentManager JavaDoc getDeploymentManager() {
107         ServerRegistry registry = ServerRegistry.getInstance();
108         ServerInstance inst = registry.getServerInstance(url);
109         return inst.getDeploymentManager();
110     }
111     
112     public javax.enterprise.deploy.spi.Target JavaDoc getDefaultTarget() {
113         ServerRegistry registry = ServerRegistry.getInstance();
114         ServerString ss = registry.getDefaultInstance();
115         javax.enterprise.deploy.spi.Target JavaDoc[] targets = ss.toTargets();
116         if (targets != null && targets.length > 0)
117             return targets[0];
118         return null;
119     }
120     
121     public void setAsDefaultServer(String JavaDoc targetName) {
122         ServerRegistry registry = ServerRegistry.getInstance();
123         ServerInstance inst = registry.getServerInstance(url);
124         ServerString server = new ServerString(inst, targetName);
125         registry.setDefaultInstance(server);
126     }
127     
128     public boolean isDefaultInstance() {
129         ServerRegistry registry = ServerRegistry.getInstance();
130         ServerString ss = registry.getDefaultInstance();
131         return ss.getUrl().equals(url);
132     }
133     
134     public void refreshServerInstance() {
135         ServerRegistry registry = ServerRegistry.getInstance();
136         ServerInstance inst = registry.getServerInstance(url);
137         if (inst != null) {
138             inst.refresh();
139         }
140     }
141 }
142
Popular Tags