1 23 24 package com.sun.enterprise.instance; 25 26 import javax.enterprise.deploy.shared.ModuleType ; 27 28 import com.sun.enterprise.config.ConfigBean; 29 import com.sun.enterprise.config.ConfigContext; 30 import com.sun.enterprise.config.ConfigException; 31 import com.sun.enterprise.config.serverbeans.*; 32 import com.sun.enterprise.deployment.Application; 33 import com.sun.enterprise.deployment.archivist.ApplicationArchivist; 34 import com.sun.enterprise.deployment.archivist.ConnectorArchivist; 35 import com.sun.enterprise.deployment.backend.DeployableObjectInfo; 36 import com.sun.enterprise.deployment.backend.DeployableObjectType; 37 import com.sun.enterprise.deployment.ConnectorDescriptor; 38 import com.sun.enterprise.deployment.deploy.shared.FileArchive; 39 import com.sun.enterprise.deployment.RootDeploymentDescriptor; 40 import com.sun.enterprise.util.io.FileUtils; 41 import com.sun.enterprise.util.RelativePathResolver; 42 import com.sun.enterprise.util.SystemPropertyConstants; 43 import com.sun.enterprise.Switch; 44 import com.sun.enterprise.server.ResourcesUtil; 45 46 import java.io.File ; 47 import java.io.IOException ; 48 import java.util.ArrayList ; 49 import java.util.Enumeration ; 50 import java.util.Iterator ; 51 import java.util.List ; 52 import java.util.logging.Level ; 53 import java.util.Properties ; 54 import java.util.Set ; 55 56 public class ConnectorModulesManager extends ModulesManager { 57 public ConnectorModulesManager(InstanceEnvironment env) throws ConfigException { 58 super(env, true); 59 } 60 61 public ConnectorModulesManager(InstanceEnvironment env, boolean useBackupServerXml) throws ConfigException { 62 super(env, useBackupServerXml); 63 ConnectorModule[] jArray = ((Applications)configBean).getConnectorModule(); 65 if(jArray!=null) { 66 for(int i=0;i<jArray.length;i++) { 67 jArray[i].setConfigContext(configContext); 68 jArray[i].setXPath(ServerXPathHelper.getConnectorModuleIdXpathExpression(jArray[i].getName())); 69 } 70 } 71 73 } 74 75 78 public ModuleType getModuleType() { 79 return ModuleType.RAR; 80 } 81 82 85 public ConnectorModule[] listConnectorModules() { 86 ConnectorModule[] mods = ((Applications)this.configBean).getConnectorModule(); 87 if(mods == null) return new ConnectorModule[0]; 88 89 ArrayList list = new ArrayList (); 90 for (int i=0; i<mods.length; i++) { 91 if ( isReferenced(mods[i].getName()) ) { 94 list.add(mods[i]); 95 } 96 } 97 ConnectorModule[] refList = new ConnectorModule[list.size()]; 99 return ( (ConnectorModule[]) list.toArray(refList) ); 100 } 101 102 105 public List listIds() { 106 ArrayList arr = new ArrayList (); 107 ConnectorModule[] mods = ((Applications)this.configBean).getConnectorModule(); 108 if(mods == null) return arr; 109 for (int i=0;i<mods.length;i++) { 110 String name = mods[i].getName(); 111 if ( isReferenced(name) ) { 114 arr.add(name); 115 } 116 } 117 return arr; 118 } 119 120 private ConnectorModule getConnectorModule(String modId) throws ConfigException { 121 ConnectorModule mod = (ConnectorModule) 122 ((Applications)this.configBean).getConnectorModuleByName(modId); 123 124 if(mod == null) 125 throw new ConfigException(Localizer.getValue(ExceptionType.NO_SUCH_CON_MOD)); 126 127 return mod; 128 129 } 130 131 public String getGeneratedXMLLocation(String name){ 132 ModuleEnvironment menv = instanceEnvironment.getModuleEnvironment(name, 133 DeployableObjectType.CONN); 134 return menv.getModuleGeneratedXMLPath(); 135 } 136 137 public void remove(String modId) throws ConfigException { 138 ConnectorModule backEm = (ConnectorModule)((Applications)configBean).getConnectorModuleByName(modId); 139 ((Applications)configBean).removeConnectorModule(backEm); 140 } 141 142 protected boolean isRegistered(String modId, ConfigBean bean) { 143 ConfigBean cb = null; 144 try { 145 cb = ((Applications)bean).getConnectorModuleByName(modId); 146 } catch(Exception cn) { 147 } 148 149 if(cb != null) return true; 150 return false; 151 } 152 153 public boolean isEnabled(String modId) throws ConfigException{ 154 return getConnectorModule(modId).isEnabled(); 155 } 156 157 162 public boolean isSystem(String modId) throws ConfigException{ 163 ConnectorModule cm = getConnectorModule(modId); 164 String resourceType = cm.getObjectType(); 165 if(resourceType.startsWith(SYSTEM_PREFIX)) 166 return true; 167 else 168 return false; 169 } 170 171 176 public boolean isSystemAdmin(String modId) throws ConfigException{ 177 ConnectorModule cm = getConnectorModule(modId); 178 String resourceType = cm.getObjectType(); 179 if(resourceType.startsWith(SYSTEM_ADMIN_PREFIX)) 180 return true; 181 else 182 return false; 183 } 184 185 public void setEnable(String modId, boolean enable) throws ConfigException{ 186 getConnectorModule(modId).setEnabled(enable); 187 } 188 189 195 public void setOptionalAttributes(String modId, Properties optionalAttributes) 196 throws ConfigException { 197 if(optionalAttributes!=null) { 198 ConnectorModule cm = getConnectorModule(modId); 199 Enumeration tags = optionalAttributes.keys(); 200 while(tags.hasMoreElements()) 201 { 202 String tag = (String )tags.nextElement(); 203 String value = optionalAttributes.getProperty(tag); 204 cm.setAttributeValue(tag, value); 205 } 206 } 207 } 208 209 public String getLocation(String name) { 210 String location = null; 211 if (ResourcesUtil.getInstance().belongToSystemRar(name)) { 212 location = Switch.getSwitch(). 213 getResourceInstaller().getSystemModuleLocation(name); 214 } else { 215 ConnectorModule connectorModule = (ConnectorModule) 216 ((Applications)this.configBean).getConnectorModuleByName(name); 217 location = connectorModule.getLocation(); 218 } 219 return resolvePath(location); 220 } 221 222 public void setLocation(String modId, String location) throws ConfigException{ 223 ConnectorModule connectorModule = (ConnectorModule) 224 ((Applications)this.configBean).getConnectorModuleByName(modId); 225 connectorModule.setLocation(location); 226 } 227 228 public String getDescription(String modId) throws ConfigException { 229 return getConnectorModule(modId).getDescription(); 230 } 231 232 public void setDescription(String modId, String desc) throws ConfigException { 233 getConnectorModule(modId).setDescription(desc); 234 } 235 236 249 public Application getDescriptor(String modId, ClassLoader cl, 250 String modDir, boolean validateXml) throws ConfigException { 251 252 Application application = getRegisteredDescriptor(modId); 253 if (application!=null) { 254 application.setClassLoader(cl); 255 return application; 256 } 257 try { 258 ConnectorArchivist connectorArchivist = new ConnectorArchivist(); 259 connectorArchivist.setXMLValidation(validateXml); 260 connectorArchivist.setClassLoader(cl); 261 262 FileArchive archive = new FileArchive(); 263 archive.open(modDir); 264 application = ApplicationArchivist.openArchive(modId, connectorArchivist, archive, true); 265 application.setClassLoader(cl); 266 application.setGeneratedXMLDirectory(getGeneratedXMLLocation(modId)); 267 268 registerDescriptor(modId, application); 269 270 return application; 271 272 } catch (IOException ioe) { 273 throw new ConfigException(Localizer.getValue( 274 ExceptionType.IO_ERROR_LOADING_DD, modId), ioe); 275 } catch (Throwable t) { 276 throw new ConfigException(Localizer.getValue( 277 ExceptionType.FAIL_DD_LOAD, modId), t); 278 } 279 } 280 281 } 282 | Popular Tags |