1 package org.jboss.enterprise.deploy.spi.factories; 2 3 import java.util.StringTokenizer ; 4 import java.util.Vector ; 5 import javax.enterprise.deploy.spi.DeploymentManager ; 6 import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException ; 7 import javax.enterprise.deploy.spi.factories.DeploymentFactory ; 8 import javax.enterprise.deploy.spi.factories.DeploymentFactoryManager; 9 10 16 public class JBossDeploymentFactoryManager implements DeploymentFactoryManager 17 { 18 19 private static Vector factories = new Vector (); 20 21 private static boolean initialized = false; 22 23 24 25 public JBossDeploymentFactoryManager() { } 26 27 28 33 public DeploymentFactory [] getDeploymentFactories() 34 { 35 this.initialize(); 36 37 return (DeploymentFactory []) this.factories.toArray(new DeploymentFactory [0]); 38 } 39 40 41 53 public DeploymentManager getDeploymentManager(String uri, String username, String password) throws DeploymentManagerCreationException 54 { 55 this.initialize(); 56 57 for (int i = 0; i < this.factories.size(); i++) 58 { 59 DeploymentFactory factory = (DeploymentFactory ) this.factories.elementAt(i); 60 if (factory.handlesURI(uri)) 61 { 62 return factory.getDeploymentManager(uri, username, password); 63 } 64 } 65 66 return null; 67 } 68 69 70 78 public DeploymentManager getDisconnectedDeploymentManager(String uri) throws DeploymentManagerCreationException 79 { 80 this.initialize(); 81 82 for (int i = 0; i < this.factories.size(); i++) 83 { 84 DeploymentFactory factory = (DeploymentFactory ) this.factories.elementAt(i); 85 if (factory.handlesURI(uri)) 86 { 87 return factory.getDisconnectedDeploymentManager(uri); 88 } 89 } 90 91 return null; 92 } 93 94 95 100 public void registerDeploymentFactory(DeploymentFactory factory) 101 { 102 this.initialize(); 103 104 this.factories.add(factory); 105 } 106 107 108 109 private void initialize() 110 { 111 if (this.initialized) 112 { 113 return; 114 } 115 this.initialized = true; 116 this.loadInitialFactories(); 117 } 118 119 120 121 private void loadInitialFactories() 122 { 123 String factoriesToLoad; 124 125 factoriesToLoad = System.getProperty("javax.enterprise.deploy.spi.factories"); 126 System.out.println("ENV " + factoriesToLoad); 127 128 if (factoriesToLoad == null) 129 { 130 return; 131 } 132 133 StringTokenizer tokenizer = new StringTokenizer (factoriesToLoad, ":"); 134 while (tokenizer.hasMoreTokens()) 135 { 136 String factoryToLoad = tokenizer.nextToken(); 137 System.out.println("NEXT " + factoryToLoad); 138 139 try 140 { 141 DeploymentFactory factory = (DeploymentFactory ) Class.forName(factoryToLoad).newInstance(); 142 this.registerDeploymentFactory(factory); 143 } 144 catch (ClassNotFoundException ex) 145 { 146 } 147 catch (Exception ex) 148 { 149 } 150 } 151 } 152 } 153 154 | Popular Tags |