KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployapi > SunTarget


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.deployapi;
25
26 import com.sun.appserv.management.client.ConnectionSource;
27 import com.sun.enterprise.admin.common.exception.AFException;
28 import com.sun.enterprise.deployment.client.DeploymentClientUtils;
29 import com.sun.enterprise.deployment.client.ServerConnectionIdentifier;
30 import com.sun.enterprise.util.i18n.StringManager;
31
32 import java.io.File JavaDoc;
33 import java.io.FileOutputStream JavaDoc;
34 import java.io.IOException JavaDoc;
35 import java.io.Serializable JavaDoc;
36
37 import javax.enterprise.deploy.spi.Target JavaDoc;
38 import javax.management.MBeanServerConnection JavaDoc;
39
40 /**
41  * The Sun RI does not support clustering for now, we cannot
42  * group several servers in one logical target so we have a
43  * one to one mapping between a Target and a server
44  *
45  * @author Jerome Dochez
46  */

47 public class SunTarget implements Target JavaDoc, Serializable JavaDoc {
48     
49     private ServerConnectionIdentifier connectionInfo;
50     private String JavaDoc appServer;
51     private boolean connected=false;
52     private ConnectionSource dasConnection = null;
53     private MBeanServerConnection JavaDoc mbsc = null;
54     private String JavaDoc targetType;
55
56     private static StringManager localStrings = StringManager.getManager(SunTarget.class);
57     
58     private static final String JavaDoc DAS_TARGET_NAME = "server";
59     
60     public SunTarget(ServerConnectionIdentifier svi) {
61         this.connectionInfo = svi;
62     }
63     
64     public SunTarget(SunTarget other) {
65         this.connectionInfo = other.connectionInfo;
66         this.appServer = other.appServer;
67         this.dasConnection = other.dasConnection;
68         this.mbsc = other.mbsc;
69         this.targetType = other.targetType;
70     }
71     
72     /** Retrieve other descriptive information
73      * about the target.
74      */

75     public String JavaDoc getDescription() {
76         //@@@ or connect to the server for a full version
77
String JavaDoc version = localStrings.getString(
78                              "enterprise.deployapi.spi.ProductVersion", "9.0");
79                              
80         return localStrings.getString(
81                     "enterprise.deployapi.spi.suntargetdescription",
82                     version, getHostName());
83     }
84     
85     /** Retrieve the name of the target server.
86      */

87     public String JavaDoc getName() {
88         return appServer;
89     }
90    
91    /**
92     * Release our ressources
93     */

94    public void release() {
95        connected=false;
96    }
97    
98    /**
99     * @return the hostname that this target represents
100     */

101    public String JavaDoc getHostName(){
102        return connectionInfo.getHostName();
103    }
104    
105    /**
106     * @return the port name to connect to the host
107     */

108    public String JavaDoc getPort() {
109        return (new Integer JavaDoc(connectionInfo.getHostPort())).toString();
110    }
111    
112    /**
113     * @return the connection info for this target
114     */

115    public ServerConnectionIdentifier getConnectionInfo() {
116        return connectionInfo;
117    }
118    
119    /**
120     * @return true if the deployment manager is connected to the server
121     */

122    public boolean isConnected() {
123        return connected;
124    }
125     
126    /**
127     * @return a meaningful string about myself
128     */

129    public String JavaDoc toString() {
130        return getHostName() + ":" + (getPort()!=null?getPort():"DefaultPort") + "_" + appServer;
131    }
132
133    /**
134     * @return a meaningful string about myself
135     */

136    public String JavaDoc debugString() {
137        String JavaDoc s = "";
138        if (connected) {
139            s = "Connected ";
140        }
141        return s + "Server " + getHostName() + ":" + (getPort()!=null?getPort():"DefaultPort") + "; Name: " + appServer;
142    }
143    
144    
145     /**
146      * @return true if I am the equals to the other object
147      */

148     public boolean equals(Object JavaDoc other) {
149         
150         if (other instanceof SunTarget) {
151             SunTarget theOther = (SunTarget) other;
152             return (connectionInfo.equals(theOther.connectionInfo)
153                  && getName() != null && getName().equals(theOther.getName())
154                  && getTargetType() != null && getTargetType().equals(theOther.getTargetType()));
155         }
156         return false;
157     }
158
159     /**
160      * @return true if I am managed by the same DAS as the other object
161      */

162     public boolean isManagedBySameDAS(Object JavaDoc other) {
163         if (other instanceof SunTarget) {
164             SunTarget theOther = (SunTarget) other;
165             return connectionInfo.equals(theOther.connectionInfo);
166         }
167         return false;
168     }
169
170     /**
171      *Returns whether this target is a DAS.
172      *@return true if the target is a DAS
173      */

174     public boolean isDAS() {
175         return (appServer.equals(DAS_TARGET_NAME));
176     }
177     
178     /**
179      * @return the application server associated with this target
180      */

181     public String JavaDoc getAppServerInstance() {
182         return appServer;
183     }
184     
185     /**
186      * Set the application server instance associated with this target
187      */

188     public void setAppServerInstance(String JavaDoc appServer) {
189         this.appServer = appServer;
190     }
191
192     /**
193      * Set the type of this target
194      */

195     public void setTargetType(String JavaDoc type) {
196         this.targetType = type;
197     }
198     
199     /**
200      * @return the type of this target
201      */

202     public String JavaDoc getTargetType() {
203         return this.targetType;
204     }
205     
206     public void setConnectionSource(ConnectionSource conn){
207         this.dasConnection = conn;
208     }
209
210     public ConnectionSource getConnectionSource() {
211         return this.dasConnection;
212     }
213
214     public MBeanServerConnection JavaDoc getMBeanServerConnection() {
215         return this.dasConnection.getExistingMBeanServerConnection();
216     }
217    
218     /**
219      * Exports the Client stub jar to the given location.
220      * @param appName The name of the application or module.
221      * @param destDir The directory into which the stub jar file
222      * should be exported.
223      * @return Retruns the absolute location to the exported jar file.
224      * @throws AFException
225      */

226     public String JavaDoc exportClientStubs(String JavaDoc appName,
227                                     int appType,
228                                     String JavaDoc destDir)
229         throws AFException
230     {
231         try{
232             return DeploymentClientUtils.downloadClientStubs(
233                         appName, destDir, dasConnection);
234         }catch(Exception JavaDoc e){
235             e.printStackTrace();
236             throw new AFException(e.getMessage());
237         }
238     }
239 }
240
Popular Tags