1 23 24 29 30 package javax.enterprise.deploy.shared.factories; 31 32 33 import java.util.Vector ; 34 import java.util.Iterator ; 35 import javax.enterprise.deploy.spi.DeploymentManager ; 36 import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException ; 37 import javax.enterprise.deploy.spi.factories.DeploymentFactory ; 38 39 63 public final class DeploymentFactoryManager { 64 65 private Vector deploymentFactories = null; 66 67 private static DeploymentFactoryManager deploymentFactoryManager = null; 69 70 71 private DeploymentFactoryManager() { 72 deploymentFactories = new Vector (); 73 } 74 79 public static DeploymentFactoryManager getInstance() { 80 if(deploymentFactoryManager == null){ 81 deploymentFactoryManager = new DeploymentFactoryManager (); 82 } 83 return deploymentFactoryManager; 84 } 85 86 92 public DeploymentFactory [] getDeploymentFactories() { 93 Vector deploymentFactoriesSnapShot = null; 94 synchronized(this){ 95 deploymentFactoriesSnapShot = 96 (Vector )this.deploymentFactories.clone(); 97 } 98 DeploymentFactory [] factoriesArray = 99 new DeploymentFactory [deploymentFactoriesSnapShot.size()]; 100 deploymentFactoriesSnapShot.copyInto(factoriesArray); 101 return factoriesArray; 102 } 103 104 123 public DeploymentManager getDeploymentManager(String uri, String username, 124 String password) throws DeploymentManagerCreationException { 125 try{ 126 DeploymentFactory [] factories = this.getDeploymentFactories(); 127 for(int factoryIndex=0; factoryIndex < factories.length; 128 factoryIndex++){ 129 if(factories[factoryIndex].handlesURI(uri)){ 130 return factories[factoryIndex].getDeploymentManager(uri, 131 username,password); 132 } 133 } 134 throw new DeploymentManagerCreationException ("URL ["+uri+ 136 "] not supported by any available factories"); 137 }catch(Throwable t){ 138 throw new DeploymentManagerCreationException ( 139 "Could not get DeploymentManager"); 140 } 141 } 142 143 147 public void registerDeploymentFactory(DeploymentFactory factory){ 148 this.deploymentFactories.add(factory); 149 } 150 151 160 public DeploymentManager getDisconnectedDeploymentManager(String uri) 161 throws DeploymentManagerCreationException { 162 try{ 163 DeploymentFactory [] factories = this.getDeploymentFactories(); 164 for(int factoryIndex=0; factoryIndex < factories.length; 165 factoryIndex++){ 166 if(factories[factoryIndex].handlesURI(uri)){ 167 return factories[factoryIndex].getDisconnectedDeploymentManager(uri); 168 } 169 } 170 throw new DeploymentManagerCreationException ("URL ["+uri+ 172 "] not supported by any available factories"); 173 }catch(Throwable t){ 174 throw new DeploymentManagerCreationException ( 175 "Could not get DeploymentManager"); 176 } 177 } 178 } 179 | Popular Tags |