KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > oc4j > ui > wizards > 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
20 package org.netbeans.modules.j2ee.oc4j.ui.wizards;
21
22 import java.awt.Component JavaDoc;
23 import java.net.InetAddress JavaDoc;
24 import java.net.InetSocketAddress JavaDoc;
25 import java.net.UnknownHostException JavaDoc;
26 import java.util.HashSet JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.Set JavaDoc;
29 import javax.swing.event.ChangeEvent JavaDoc;
30 import javax.swing.event.ChangeListener JavaDoc;
31 import org.netbeans.modules.j2ee.oc4j.util.OC4JPluginProperties;
32 import org.netbeans.modules.j2ee.oc4j.util.OC4JPluginUtils;
33 import org.openide.WizardDescriptor;
34 import org.openide.util.HelpCtx;
35 import org.openide.util.NbBundle;
36
37 /**
38  * @author pblaha
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 OC4JInstantiatingIterator instantiatingIterator;
46     private transient Set JavaDoc <ChangeListener JavaDoc> listeners = new HashSet JavaDoc<ChangeListener JavaDoc>(1);
47     
48     /** Creates a new instance of AddServerPropertiesPanel */
49     public AddServerPropertiesPanel(OC4JInstantiatingIterator instantiatingIterator) {
50         this.instantiatingIterator = instantiatingIterator;
51     }
52     
53     public boolean isValid() {
54         AddServerPropertiesVisualPanel panel = (AddServerPropertiesVisualPanel)getComponent();
55         
56         if (panel.getType().equals(AddServerPropertiesVisualPanel.LOCAL)) {
57             if(!OC4JPluginUtils.isUserActivated(instantiatingIterator.getOC4JHomeLocation(), "oc4jadmin")) {
58                 panel.setInitialization(true);
59                 wizard.putProperty(PROP_ERROR_MESSAGE,NbBundle.getMessage(AddServerPropertiesPanel.class, "MSG_Initialization"));
60                 return false;
61             }
62         }
63         
64         if(panel.getHost().length() == 0 ||
65                 panel.getUser().length() == 0 ||
66                 panel.getPassword().length() == 0 ||
67                 panel.getWebSite().length() == 0 ) {
68             wizard.putProperty(PROP_ERROR_MESSAGE,NbBundle.getMessage(AddServerPropertiesPanel.class, "MSG_MissingData"));
69             return false;
70         }
71         
72         try {
73             new Integer JavaDoc(panel.getPort());
74             new Integer JavaDoc(panel.getAdminPort());
75             
76             String JavaDoc host = panel.getHost();
77             
78             if(OC4JPluginProperties.isRunning(host, panel.getPort())
79                     && !OC4JPluginProperties.isRunning(host, panel.getAdminPort())
80                     || !OC4JPluginProperties.isRunning(host, panel.getPort())
81                     && OC4JPluginProperties.isRunning(host, panel.getAdminPort()))
82                 throw new NumberFormatException JavaDoc();
83             
84         } catch(NumberFormatException JavaDoc ex) {
85             wizard.putProperty(PROP_ERROR_MESSAGE,NbBundle.getMessage(AddServerPropertiesPanel.class,
86                     "MSG_WrongPort", panel.getHost()));
87             return false;
88         }
89         
90         if (panel.getType().equals(AddServerPropertiesVisualPanel.REMOTE)) {
91             try {
92                 InetAddress JavaDoc ia = InetAddress.getByName(panel.getHost());
93                 new InetSocketAddress JavaDoc(ia, Integer.parseInt(panel.getAdminPort()));
94             } catch (UnknownHostException JavaDoc uhe) {
95                 wizard.putProperty(PROP_ERROR_MESSAGE, NbBundle.getMessage(AddServerPropertiesPanel.class,
96                         "MSG_UnknownHost",panel.getHost()));
97                 return false;
98             } catch (IllegalArgumentException JavaDoc iae) {
99                 wizard.putProperty(PROP_ERROR_MESSAGE, NbBundle.getMessage(AddServerPropertiesPanel.class,
100                         "Msg_ValidPortNumber"));
101                 return false;
102             }
103         }
104         
105         wizard.putProperty(PROP_ERROR_MESSAGE,null);
106         instantiatingIterator.setHost(panel.getHost());
107         instantiatingIterator.setPassword(panel.getPassword());
108         instantiatingIterator.setUserName(panel.getUser());
109         instantiatingIterator.setWebSite(panel.getWebSite());
110         instantiatingIterator.setAdminPort(new Integer JavaDoc(panel.getAdminPort()));
111         instantiatingIterator.setHttpPort(new Integer JavaDoc(panel.getPort()));
112         return true;
113     }
114     
115     public Component JavaDoc getComponent() {
116         if (component == null) {
117             component = new AddServerPropertiesVisualPanel(instantiatingIterator.getOC4JHomeLocation());
118             component.addChangeListener(this);
119         }
120         return component;
121     }
122     
123     public void stateChanged(ChangeEvent JavaDoc ev) {
124         fireChangeEvent(ev);
125     }
126     
127     private void fireChangeEvent(ChangeEvent JavaDoc ev) {
128         Iterator JavaDoc it;
129         synchronized (listeners) {
130             it = new HashSet JavaDoc<ChangeListener JavaDoc>(listeners).iterator();
131         }
132         while (it.hasNext()) {
133             ((ChangeListener JavaDoc)it.next()).stateChanged(ev);
134         }
135     }
136     
137     
138     public void removeChangeListener(ChangeListener JavaDoc l) {
139         synchronized (listeners) {
140             listeners.remove(l);
141         }
142     }
143     
144     public void addChangeListener(ChangeListener JavaDoc l) {
145         synchronized (listeners) {
146             listeners.add(l);
147         }
148     }
149     
150     public void readSettings(Object JavaDoc settings) {
151         if (wizard == null)
152             wizard = (WizardDescriptor)settings;
153     }
154     
155     public void storeSettings(Object JavaDoc settings) {
156     }
157     
158     public HelpCtx getHelp() {
159         return new HelpCtx("j2eeplugins_registering_app_server_oc4j_properties"); //NOI18N
160
}
161 }
Popular Tags