1 23 24 25 package com.sun.enterprise.cli.commands; 26 import com.sun.enterprise.cli.framework.*; 27 import javax.management.MBeanServerConnection ; 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 ; 38 import java.util.Map ; 39 40 41 45 abstract public class BaseTransformationRuleCommand extends GenericCommand 46 { 47 protected static final String WEB_SERVICE_OPTION = "webservicename"; 48 49 54 protected WebServiceEndpointConfig getWebServiceEndpointConfig( 55 MBeanServerConnection mbsc, String fqWebServiceName, 56 boolean isCreateIfNone) 57 throws CommandException, CommandValidationException 58 { 59 int firstHashIdx = fqWebServiceName.indexOf("#"); 63 String 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 regName = fqWebServiceName.substring(0,firstHashIdx); 75 StringTokenizer sTok = new StringTokenizer (fqWebServiceName,"#"); 76 int numTokens = sTok.countTokens(); 77 if ( numTokens == 3 ) { 78 J2EEApplicationConfig appConfig = getApplicationConfigMBean(mbsc, regName); 80 if ( appConfig == null){ 81 throw new CommandException ( 82 getLocalizedString("NoAppFoundForWS", 83 new Object [] {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 moduleName = fqWebServiceName.substring(firstHashIdx + 1, 91 fqWebServiceName.lastIndexOf("#")); 92 throw new CommandException(getLocalizedString("NoModuleOrEndpointFoundForWS", 93 new Object []{fqWebServiceName})); 94 } 95 Map 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 String 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 [] {regName})); 119 } 120 Map 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 [] {regName})); 138 } 139 Map 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 throw new CommandException ( 155 getLocalizedString("InvalidModuleTypeForWS")); 156 } 157 } else { 158 throw new CommandValidationException(getLocalizedString("InvalidFormatForWebservice")); 160 } 161 163 return null; 164 } 165 166 167 private J2EEApplicationConfig getApplicationConfigMBean (MBeanServerConnection mbsc, String appName) { 168 DomainRoot domainRoot = ProxyFactory.getInstance(mbsc).getDomainRoot(); 169 DomainConfig domainConfig = domainRoot.getDomainConfig(); 170 Map 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 mbsc, String moduleName) { 179 DomainRoot domainRoot = ProxyFactory.getInstance(mbsc).getDomainRoot(); 180 DomainConfig domainConfig = domainRoot.getDomainConfig(); 181 Map 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 mbsc, String moduleName) { 190 DomainRoot domainRoot = ProxyFactory.getInstance(mbsc).getDomainRoot(); 191 DomainConfig domainConfig = domainRoot.getDomainConfig(); 192 Map appCfgMap = domainConfig.getWebModuleConfigMap(); 193 if ( appCfgMap != null){ 194 return (WebModuleConfig) appCfgMap.get(moduleName); 195 } else { 196 return null; 197 } 198 } 199 200 private String getStandAloneModuleType(MBeanServerConnection mbsc, String 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 []{fqName})); 210 } 211 return info.getServiceImplType(); 212 } 213 214 215 219 protected void validateWebServiceName(String fqWebServiceName, boolean validateIfNull) 220 throws CommandValidationException 221 { 222 if ((fqWebServiceName == null) && (!validateIfNull)) 225 { 226 return; 227 } 228 else 229 { 230 } 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 |