KickJava   Java API By Example, From Geeks To Geeks.

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


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.deployment.impl;
21
22 import javax.enterprise.deploy.spi.Target JavaDoc;
23
24 public class ServerString implements java.io.Serializable JavaDoc {
25
26     private final String JavaDoc plugin;
27     private final String JavaDoc instance;
28     private final String JavaDoc[] targets;
29     private final transient ServerInstance serverInstance;
30     private transient String JavaDoc[] theTargets;
31     private static final long serialVersionUID = 923457209372L;
32
33     public ServerString(String JavaDoc plugin, String JavaDoc instance, String JavaDoc[] targets) {
34         if (targets == null)
35             this.targets = new String JavaDoc[0];
36         else
37             this.targets = targets;
38         this.plugin = plugin; this.instance = instance; this.serverInstance = null;
39     }
40     
41     public ServerString(Server server) {
42         this.plugin = server.getShortName();
43         this.instance = null;
44         this.targets = new String JavaDoc[0];
45         this.serverInstance = null;
46     }
47     
48     public ServerString(ServerInstance instance) {
49     assert instance != null;
50         this.plugin = instance.getServer().getShortName();
51         this.instance = instance.getUrl();
52         this.serverInstance = instance;
53
54         this.targets = null;
55         /*if (! instance.isRunning()) {
56             this.targets = new String[0];
57             return;
58         }
59         
60         ServerTarget[] serverTargets;
61         try {
62             serverTargets = instance.getTargets();
63         } catch (Exception e) {
64             ErrorManager.getDefault().notify(ErrorManager.WARNING, e);
65             this.targets = new String[0];
66             return;
67         }
68         this.targets = new String[serverTargets.length];
69         for (int i=0; i<serverTargets.length; i++) {
70             targets[i] = serverTargets[i].getName();
71         }*/

72     }
73     
74     public ServerString(ServerTarget target) {
75         this.plugin = target.getInstance().getServer().getShortName();
76         this.instance = target.getInstance().getUrl();
77         this.targets = new String JavaDoc[] { target.getName() };
78         this.serverInstance = null;
79     }
80     
81     public ServerString(ServerInstance instance, String JavaDoc targetName) {
82         this.plugin = instance.getServer().getShortName();
83         this.instance = instance.getUrl();
84         this.serverInstance = instance;
85         if (targetName != null && ! "".equals(targetName.trim())) //NOI18N
86
this.targets = new String JavaDoc[] { targetName };
87         else
88             this.targets = null;
89     }
90     
91     public String JavaDoc getPlugin() {
92         return plugin;
93     }
94     
95     public String JavaDoc getUrl() {
96         return instance;
97     }
98     
99     public String JavaDoc[] getTargets() {
100         return getTargets(false);
101     }
102
103     public String JavaDoc[] getTargets(boolean concrete) {
104         if (! concrete) {
105             if (targets == null) return new String JavaDoc[0];
106             return targets;
107          }
108
109         if (targets != null && targets.length > 0)
110             return targets;
111
112         if (theTargets != null)
113             return theTargets;
114         
115         ServerTarget[] serverTargets = getServerInstance().getTargets();
116         theTargets = new String JavaDoc[serverTargets.length];
117         for (int i=0; i<theTargets.length; i++)
118             theTargets[i] = serverTargets[i].getName();
119         return theTargets;
120     }
121
122     public Server getServer() {
123         return ServerRegistry.getInstance().getServer(plugin);
124     }
125     
126     public ServerInstance getServerInstance() {
127         if (serverInstance != null)
128             return serverInstance;
129         return ServerRegistry.getInstance().getServerInstance(instance);
130     }
131     
132     public String JavaDoc toString() {
133         if (targets == null) return "Server " + plugin + " Instance " + instance + " Targets none"; // NOI18N
134
return "Server " + plugin + " Instance " + instance + " Targets " + targets.length; // NOI18N
135
}
136     
137     public static ServerString fromTarget(ServerInstance instance, Target JavaDoc target) {
138         return new ServerString(new ServerTarget(instance, target));
139     }
140     
141     public Target JavaDoc[] toTargets() {
142         String JavaDoc[] targetNames = getTargets(true);
143         Target JavaDoc[] ret = new Target JavaDoc[targetNames.length];
144         for (int i=0; i<targetNames.length; i++)
145             ret[i] = getServerInstance().getServerTarget(targetNames[i]).getTarget();
146         return ret;
147     }
148 }
149
Popular Tags