KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > cli > commands > BaseTransformationRuleCommand


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
25 package com.sun.enterprise.cli.commands;
26 import com.sun.enterprise.cli.framework.*;
27 import javax.management.MBeanServerConnection JavaDoc;
28 import com.sun.appserv.management.client.ProxyFactory;
29 import com.sun.appserv.management.DomainRoot;
30 import com.sun.appserv.management.config.DomainConfig;
31 import com.sun.appserv.management.config.J2EEApplicationConfig;
32 import com.sun.appserv.management.config.EJBModuleConfig;
33 import com.sun.appserv.management.config.WebModuleConfig;
34 import com.sun.appserv.management.base.XTypes;
35 import com.sun.appserv.management.config.WebServiceEndpointConfig;
36 import com.sun.appserv.management.ext.wsmgmt.WebServiceEndpointInfo;
37 import java.util.StringTokenizer JavaDoc;
38 import java.util.Map JavaDoc;
39
40
41 /**
42  *Abstract base class for the Transformation Rule commands
43  *
44  */

45 abstract public class BaseTransformationRuleCommand extends GenericCommand
46 {
47     protected static final String JavaDoc WEB_SERVICE_OPTION = "webservicename";
48     
49     /**
50      * parse the operand to get the web service name
51      * return the webservice endpoint config.
52      * @throws CommandException
53      */

54     protected WebServiceEndpointConfig getWebServiceEndpointConfig(
55                             MBeanServerConnection JavaDoc mbsc, String JavaDoc fqWebServiceName,
56                             boolean isCreateIfNone)
57                             throws CommandException, CommandValidationException
58     {
59         // this webserviceName is fully qualified name
60
//String fqWebServiceName = getOption(WEB_SERVICE_OPTION);
61
// extract the partially qualified web service endpoing config name
62
int firstHashIdx = fqWebServiceName.indexOf("#");
63         String JavaDoc wsName= null;
64         if ( firstHashIdx != -1 ) {
65             if ( firstHashIdx+1 == fqWebServiceName.length()) {
66                 throw new CommandException(getLocalizedString("InvalidFormatForWebservice"));
67             }
68             wsName = fqWebServiceName.substring(firstHashIdx +1);
69         }
70         else
71         {
72             throw new CommandException(getLocalizedString("InvalidFormatForWebservice"));
73         }
74         String JavaDoc regName = fqWebServiceName.substring(0,firstHashIdx);
75         StringTokenizer JavaDoc sTok = new StringTokenizer JavaDoc(fqWebServiceName,"#");
76         int numTokens = sTok.countTokens();
77         if ( numTokens == 3 ) {
78             // this is an application
79
J2EEApplicationConfig appConfig = getApplicationConfigMBean(mbsc, regName);
80              if ( appConfig == null){
81                  throw new CommandException (
82                             getLocalizedString("NoAppFoundForWS",
83                                                 new Object JavaDoc[] {regName}));
84              }
85             DomainRoot domainRoot = ProxyFactory.getInstance(mbsc).getDomainRoot();
86             final WebServiceEndpointInfo info =
87                 domainRoot.getWebServiceMgr().getWebServiceEndpointInfo(fqWebServiceName);
88             if (info == null)
89             {
90                 String JavaDoc moduleName = fqWebServiceName.substring(firstHashIdx + 1,
91                                             fqWebServiceName.lastIndexOf("#"));
92                 throw new CommandException(getLocalizedString("NoModuleOrEndpointFoundForWS",
93                                                 new Object JavaDoc[]{fqWebServiceName}));
94             }
95              Map JavaDoc epMap = appConfig.getWebServiceEndpointConfigMap();
96                 if (epMap == null) {
97                     if (isCreateIfNone)
98                     {
99                         return appConfig.createWebServiceEndpointConfig(wsName,null);
100                     }
101                 } else {
102                     WebServiceEndpointConfig wsEpConfig = (WebServiceEndpointConfig) epMap.get(wsName);
103                     if ((wsEpConfig == null) && (isCreateIfNone)) {
104                          return appConfig.createWebServiceEndpointConfig(wsName,null);
105                     } else {
106                         return wsEpConfig;
107                     }
108                 }
109         } else if ( numTokens == 2 ) {
110             // this is a stand alone module
111
// we need to figure out a type
112
String JavaDoc modType = getStandAloneModuleType(mbsc, fqWebServiceName);
113             if ( modType.equals(WebServiceEndpointInfo.EJB_IMPL)) {
114                 EJBModuleConfig ejbModuleConfig = getEJBModuleConfigMBean(mbsc, regName);
115                  if ( ejbModuleConfig == null){
116                      throw new CommandException (
117                                 getLocalizedString("NoEJBModuleFoundForWS",
118                                                     new Object JavaDoc[] {regName}));
119                 }
120                 Map JavaDoc epMap = ejbModuleConfig.getWebServiceEndpointConfigMap();
121                 if ( epMap == null) {
122                     if (isCreateIfNone)
123                        return ejbModuleConfig.createWebServiceEndpointConfig(wsName,null);
124                 } else {
125                     WebServiceEndpointConfig wsEpConfig = (WebServiceEndpointConfig) epMap.get(wsName);
126                     if ((wsEpConfig == null) && (isCreateIfNone)) {
127                          return ejbModuleConfig.createWebServiceEndpointConfig(wsName,null);
128                     } else {
129                         return wsEpConfig;
130                     }
131                 }
132             } else if (modType.equals(WebServiceEndpointInfo.SERVLET_IMPL) ) {
133                 WebModuleConfig webModuleConfig = getWebModuleConfigMBean(mbsc, regName);
134                 if ( webModuleConfig == null){
135                      throw new CommandException (
136                                 getLocalizedString("NoWebModuleFoundForWS",
137                                                      new Object JavaDoc[] {regName}));
138                 }
139                 Map JavaDoc epMap = webModuleConfig.getWebServiceEndpointConfigMap();
140                 if ( epMap == null) {
141                     if (isCreateIfNone)
142                        return webModuleConfig.createWebServiceEndpointConfig(wsName, null);
143                 } else {
144                     WebServiceEndpointConfig wsEpConfig = (WebServiceEndpointConfig) epMap.get(wsName);
145                      if ((wsEpConfig == null) && (isCreateIfNone)){
146                          return webModuleConfig.createWebServiceEndpointConfig(wsName,null);
147                     } else {
148                         return wsEpConfig;
149                     }
150                 }
151                 
152             } else {
153                 // user entered non servlet/ejb module
154
throw new CommandException (
155                             getLocalizedString("InvalidModuleTypeForWS"));
156             }
157         } else {
158             // format of FQN is wrong
159
throw new CommandValidationException(getLocalizedString("InvalidFormatForWebservice"));
160         }
161         // this wsc does not exist
162

163         return null;
164     }
165
166
167     private J2EEApplicationConfig getApplicationConfigMBean (MBeanServerConnection JavaDoc mbsc, String JavaDoc appName) {
168         DomainRoot domainRoot = ProxyFactory.getInstance(mbsc).getDomainRoot();
169         DomainConfig domainConfig = domainRoot.getDomainConfig();
170         Map JavaDoc appCfgMap = domainConfig.getJ2EEApplicationConfigMap();
171         if ( appCfgMap != null){
172             return (J2EEApplicationConfig) appCfgMap.get(appName);
173         } else {
174             return null;
175         }
176     }
177     
178     private EJBModuleConfig getEJBModuleConfigMBean(MBeanServerConnection JavaDoc mbsc, String JavaDoc moduleName) {
179         DomainRoot domainRoot = ProxyFactory.getInstance(mbsc).getDomainRoot();
180         DomainConfig domainConfig = domainRoot.getDomainConfig();
181         Map JavaDoc appCfgMap = domainConfig.getEJBModuleConfigMap();
182         if ( appCfgMap != null){
183             return (EJBModuleConfig) appCfgMap.get(moduleName);
184         } else {
185             return null;
186         }
187     }
188     
189     private WebModuleConfig getWebModuleConfigMBean(MBeanServerConnection JavaDoc mbsc, String JavaDoc moduleName) {
190         DomainRoot domainRoot = ProxyFactory.getInstance(mbsc).getDomainRoot();
191         DomainConfig domainConfig = domainRoot.getDomainConfig();
192         Map JavaDoc appCfgMap = domainConfig.getWebModuleConfigMap();
193         if ( appCfgMap != null){
194             return (WebModuleConfig) appCfgMap.get(moduleName);
195         } else {
196             return null;
197         }
198     }
199     
200     private String JavaDoc getStandAloneModuleType(MBeanServerConnection JavaDoc mbsc, String JavaDoc fqName)
201                     throws CommandException
202     {
203          DomainRoot domainRoot = ProxyFactory.getInstance(mbsc).getDomainRoot();
204          final WebServiceEndpointInfo info =
205             domainRoot.getWebServiceMgr().getWebServiceEndpointInfo(
206                     fqName);
207          if (info == null){
208              throw new CommandException (
209                         getLocalizedString("NoStandaloneModuleFoundForWS", new Object JavaDoc[]{fqName}));
210          }
211          return info.getServiceImplType();
212     }
213
214
215     /**
216      * validate the webservice name format.
217      * @throws CommandException
218      */

219     protected void validateWebServiceName(String JavaDoc fqWebServiceName, boolean validateIfNull)
220                     throws CommandValidationException
221     {
222          // this webserviceName is fully qualified name
223
//String fqWebServiceName = getOption(WEB_SERVICE_OPTION);
224
if ((fqWebServiceName == null) && (!validateIfNull))
225         {
226             return;
227         }
228         else
229         {
230             //This will not happen as the webservicename is required option
231
// for create & delete commands
232
}
233         int hashIdx = fqWebServiceName.lastIndexOf("#");
234         if ( hashIdx != -1 ) {
235             if ( hashIdx+1 == fqWebServiceName.length()) {
236                 throw new CommandValidationException(getLocalizedString("InvalidFormatForWebservice"));
237             }
238         }
239         else
240         {
241             throw new CommandValidationException(getLocalizedString("InvalidFormatForWebservice"));
242         }
243     }
244 }
245
246
Popular Tags