KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > jboss4 > ide > ui > AddServerPropertiesPanel


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.j2ee.jboss4.ide.ui;
20
21 import java.awt.Component JavaDoc;
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.util.HashSet JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.MissingResourceException JavaDoc;
27 import java.util.Set JavaDoc;
28 import javax.swing.event.ChangeEvent JavaDoc;
29 import javax.swing.event.ChangeListener JavaDoc;
30 import org.netbeans.modules.j2ee.deployment.impl.ServerInstance;
31 import org.netbeans.modules.j2ee.deployment.impl.ServerRegistry;
32 import org.openide.WizardDescriptor;
33 import org.openide.util.HelpCtx;
34 import org.openide.util.NbBundle;
35
36 /**
37  *
38  * @author Ivan Sidorkin
39  */

40 public class AddServerPropertiesPanel implements WizardDescriptor.Panel, ChangeListener JavaDoc {
41
42     private final static String JavaDoc PROP_ERROR_MESSAGE = "WizardPanel_errorMessage"; // NOI18N
43
private WizardDescriptor wizard;
44     private AddServerPropertiesVisualPanel component;
45     private JBInstantiatingIterator instantiatingIterator;
46     
47     /** Creates a new instance of AddServerPropertiesPanel */
48     public AddServerPropertiesPanel(JBInstantiatingIterator instantiatingIterator) {
49         this.instantiatingIterator = instantiatingIterator;
50     }
51     
52     public boolean isValid() {
53         AddServerPropertiesVisualPanel panel = (AddServerPropertiesVisualPanel)getComponent();
54         
55         String JavaDoc host = panel.getHost();
56         String JavaDoc port = panel.getPort();
57         
58         if(panel.isLocalServer()){
59             // wrong domain path
60
String JavaDoc path = panel.getDomainPath();
61             if (!JBPluginUtils.isGoodJBInstanceLocation4x(new File JavaDoc(path)) &&
62                 !JBPluginUtils.isGoodJBInstanceLocation5x(new File JavaDoc(path)))
63             {
64                 wizard.putProperty(PROP_ERROR_MESSAGE,NbBundle.getMessage(AddServerPropertiesPanel.class, "MSG_WrongDomainPath"));
65                 return false;
66             }
67             
68             ServerInstance[] si = ServerRegistry.getInstance().getServerInstances();
69             
70             for(int i=0;i<si.length;i++) {
71                 try {
72                     String JavaDoc property = si[i].getInstanceProperties().getProperty(JBPluginProperties.PROPERTY_SERVER_DIR);
73                     
74                     if(property == null)
75                         continue;
76                     
77                     String JavaDoc root = new File JavaDoc(property).getCanonicalPath();
78                     
79                     if(root.equals(new File JavaDoc(path).getCanonicalPath())) {
80                         wizard.putProperty(PROP_ERROR_MESSAGE,NbBundle.getMessage(AddServerPropertiesPanel.class, "MSG_InstanceExists"));
81                         return false;
82                     }
83                 } catch (MissingResourceException JavaDoc ex) {
84                     // It's normal behaviour when si[i] is something else then jboss instance
85
continue;
86                 } catch (IOException JavaDoc ex) {
87                     // It's normal behaviour when si[i] is something else then jboss instance
88
continue;
89                 }
90             }
91             
92             try{
93                 new Integer JavaDoc(port);
94             }catch(Exception JavaDoc e){
95                 wizard.putProperty(PROP_ERROR_MESSAGE,NbBundle.getMessage(AddServerPropertiesPanel.class, "MSG_InvalidPort"));
96                 return false;
97             }
98             
99             
100         }else{ //remote
101
if ( (host.equals("")) ){
102                 wizard.putProperty(PROP_ERROR_MESSAGE,NbBundle.getMessage(AddServerPropertiesPanel.class, "MSG_EnterHost"));
103                 return false;
104             }
105             if (port.equals("")) {
106                 wizard.putProperty(PROP_ERROR_MESSAGE,NbBundle.getMessage(AddServerPropertiesPanel.class, "MSG_EnterPort"));
107                 return false;
108             }
109         }
110         
111         wizard.putProperty(PROP_ERROR_MESSAGE,null);
112         
113         // JBTargetServerData ts = JBPluginProperties.getInstance().getTargetServerData();
114
instantiatingIterator.setHost(host);
115         instantiatingIterator.setPort(port);
116         instantiatingIterator.setServer(panel.getDomain());
117         instantiatingIterator.setServerPath(panel.getDomainPath());
118         instantiatingIterator.setDeployDir(JBPluginUtils.getDeployDir( panel.getDomainPath()));
119         
120         JBPluginProperties.getInstance().setDomainLocation(panel.getDomainPath());
121         
122         return true;
123     }
124     
125     public Component JavaDoc getComponent() {
126         if (component == null) {
127             component = new AddServerPropertiesVisualPanel();
128             component.addChangeListener(this);
129         }
130         return component;
131     }
132     
133     public void stateChanged(ChangeEvent JavaDoc ev) {
134         fireChangeEvent(ev);
135     }
136     
137     private void fireChangeEvent(ChangeEvent JavaDoc ev) {
138         //@todo implement it
139
Iterator JavaDoc it;
140         synchronized (listeners) {
141             it = new HashSet JavaDoc(listeners).iterator();
142         }
143         while (it.hasNext()) {
144             ((ChangeListener JavaDoc)it.next()).stateChanged(ev);
145         }
146     }
147     
148     private transient Set JavaDoc listeners = new HashSet JavaDoc(1);
149     public void removeChangeListener(ChangeListener JavaDoc l) {
150         synchronized (listeners) {
151             listeners.remove(l);
152         }
153     }
154     
155     public void addChangeListener(ChangeListener JavaDoc l) {
156         synchronized (listeners) {
157             listeners.add(l);
158         }
159     }
160     
161     public void readSettings(Object JavaDoc settings) {
162         if (wizard == null)
163             wizard = (WizardDescriptor)settings;
164     }
165     
166     public void storeSettings(Object JavaDoc settings) {
167     }
168     
169     public HelpCtx getHelp() {
170         return new HelpCtx("j2eeplugins_registering_app_server_jboss_properties"); //NOI18N
171
}
172     
173     void installLocationChanged() {
174         if (component != null)
175             component.installLocationChanged();
176     }
177 }
178
Popular Tags