KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployapi > actions > ClientConfigurationImpl


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.actions;
25
26 import java.io.*;
27
28 import javax.enterprise.deploy.spi.exceptions.ClientExecuteException JavaDoc;
29 import javax.enterprise.deploy.spi.status.ClientConfiguration JavaDoc;
30 import javax.enterprise.deploy.spi.TargetModuleID JavaDoc;
31
32 import com.sun.enterprise.deployapi.SunTarget;
33 import com.sun.enterprise.deployapi.SunTargetModuleID;
34 import com.sun.enterprise.util.LocalStringManagerImpl;
35
36
37 /**
38  * This implementation of the ClientConfiguration interface allow
39  * for limited support of Application Client
40  *
41  * @author Jerome Dochez
42  */

43 public class ClientConfigurationImpl implements ClientConfiguration JavaDoc {
44     
45     SunTargetModuleID targetModuleID;
46     String JavaDoc originalArchivePath;
47     
48     private static LocalStringManagerImpl localStrings =
49       new LocalStringManagerImpl(ClientConfigurationImpl.class);
50     
51     /** Creates a new instance of ClientConfigurationImpl */
52     public ClientConfigurationImpl(SunTargetModuleID targetModuleID) {
53         this.targetModuleID = targetModuleID;
54     }
55                 
56     /** This method performs an exec and starts the
57      * application client running in another process.
58      *
59      * @throws ClientExecuteException when the configuration
60      * is incomplete.
61      */

62     public void execute() throws ClientExecuteException JavaDoc {
63         if (targetModuleID==null) {
64             throw new ClientExecuteException JavaDoc(localStrings.getLocalString(
65                 "enterprise.deployapi.actions.clientconfigurationimpl.nomoduleid",
66                 "No moduleID for deployed application found"));
67         }
68         SunTarget target = (SunTarget) targetModuleID.getTarget();
69         String JavaDoc moduleID;
70         if (targetModuleID.getParentTargetModuleID()!=null) {
71             moduleID = targetModuleID.getParentTargetModuleID().getModuleID();
72         } else {
73             moduleID = targetModuleID.getModuleID();
74         }
75         
76         
77         try {
78             // retrieve the stubs from the server
79
String JavaDoc location = target.exportClientStubs(moduleID, 0, System.getProperty("java.io.tmpdir"));
80        
81             // get the module id for the appclient
82
String JavaDoc id = targetModuleID.getModuleID();
83             if (id.indexOf('#')!=-1) {
84                 id = id.substring(id.indexOf('#')+1);
85             }
86         
87             // invoke now the appclient...
88
String JavaDoc j2eeHome = System.getProperty("com.sun.aas.installRoot");
89             String JavaDoc appClientBinary = j2eeHome + File.separatorChar + "bin" + File.separatorChar + "appclient";
90             String JavaDoc command = appClientBinary + " -client " + location;
91             
92             Process JavaDoc p = Runtime.getRuntime().exec(command);
93             InputStream is = p.getInputStream();
94             
95         } catch(Exception JavaDoc e) {
96             e.printStackTrace();
97             throw new ClientExecuteException JavaDoc(localStrings.getLocalString(
98                 "enterprise.deployapi.actions.clientconfigurationimpl.exception",
99                 "Exception while invoking application client : \n {0}", new Object JavaDoc[] { e.getMessage() }));
100         }
101     }
102 }
103
Popular Tags