1 20 package org.apache.cactus.integration.ant.container; 21 22 import java.util.MissingResourceException ; 23 import java.util.PropertyResourceBundle ; 24 import java.util.ResourceBundle ; 25 26 import org.apache.tools.ant.BuildException; 27 28 33 public class ContainerFactory 34 { 35 36 38 42 private static final String DEFAULT_CONTAINERS_BUNDLE = 43 "org.apache.cactus.integration.ant.container.default"; 44 45 47 50 private ResourceBundle defaultContainers; 51 52 54 57 public ContainerFactory() 58 { 59 defaultContainers = 60 PropertyResourceBundle.getBundle(DEFAULT_CONTAINERS_BUNDLE); 61 } 62 63 65 73 public final Container createContainer(String theName) throws BuildException 74 { 75 Container container = null; 76 try 77 { 78 String className = defaultContainers.getString(theName); 79 if (className == null) 80 { 81 throw unsupportedContainer(theName, null); 82 } 83 Class clazz = Class.forName(className); 84 container = (Container) clazz.newInstance(); 85 } 86 catch (MissingResourceException mre) 87 { 88 throw unsupportedContainer(theName, mre); 89 } 90 catch (ClassCastException cce) 91 { 92 throw unsupportedContainer(theName, cce); 93 } 94 catch (ClassNotFoundException cnfe) 95 { 96 throw unsupportedContainer(theName, cnfe); 97 } 98 catch (InstantiationException ie) 99 { 100 throw unsupportedContainer(theName, ie); 101 } 102 catch (IllegalAccessException iae) 103 { 104 throw unsupportedContainer(theName, iae); 105 } 106 return container; 107 } 108 109 111 119 private BuildException unsupportedContainer(String theName, 120 Exception theCause) 121 { 122 if (theCause != null) 123 { 124 return new BuildException("The container '" + theName 125 + "' is not supported", theCause); 126 } 127 else 128 { 129 return new BuildException("The container '" + theName 130 + "' is not supported"); 131 } 132 } 133 134 } 135 | Popular Tags |