001: package org.apache.turbine.services.factory;
002:
003: /*
004: * Copyright 2001-2005 The Apache Software Foundation.
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License")
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: import org.apache.turbine.services.TurbineServices;
020: import org.apache.turbine.util.TurbineException;
021:
022: /**
023: * The Factory Service instantiates objects using either default
024: * class loaders or a specified one. Whether specified class
025: * loaders are supported for a class depends on implementation
026: * and can be tested with the isLoaderSupported method.
027: *
028: * @author <a href="mailto:ilkka.priha@simsoft.fi">Ilkka Priha</a>
029: * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
030: * @version $Id: TurbineFactory.java 264148 2005-08-29 14:21:04Z henning $
031: */
032: public abstract class TurbineFactory {
033: /**
034: * Utility method for accessing the service
035: * implementation
036: *
037: * @return An AssemblerBroker implementation instance
038: */
039: public static FactoryService getService() {
040: return (FactoryService) TurbineServices.getInstance()
041: .getService(FactoryService.SERVICE_NAME);
042: }
043:
044: /**
045: * Gets an instance of a named class.
046: *
047: * @param className the name of the class.
048: * @return the instance.
049: * @throws TurbineException if instantiation fails.
050: */
051: public static Object getInstance(String className)
052: throws TurbineException {
053: return getService().getInstance(className);
054: }
055:
056: /**
057: * Gets an instance of a named class using a specified class loader.
058: *
059: * <p>Class loaders are supported only if the isLoaderSupported
060: * method returns true. Otherwise the loader parameter is ignored.
061: *
062: * @param className the name of the class.
063: * @param loader the class loader.
064: * @return the instance.
065: * @throws TurbineException if instantiation fails.
066: */
067: public static Object getInstance(String className,
068: ClassLoader loader) throws TurbineException {
069: return getService().getInstance(className, loader);
070: }
071:
072: /**
073: * Gets an instance of a named class.
074: * Parameters for its constructor are given as an array of objects,
075: * primitive types must be wrapped with a corresponding class.
076: *
077: * @param className the name of the class.
078: * @param params an array containing the parameters of the constructor.
079: * @param signature an array containing the signature of the constructor.
080: * @return the instance.
081: * @throws TurbineException if instantiation fails.
082: */
083: public static Object getInstance(String className, Object[] params,
084: String[] signature) throws TurbineException {
085: return getService().getInstance(className, params, signature);
086: }
087:
088: /**
089: * Gets an instance of a named class using a specified class loader.
090: * Parameters for its constructor are given as an array of objects,
091: * primitive types must be wrapped with a corresponding class.
092: *
093: * <p>Class loaders are supported only if the isLoaderSupported
094: * method returns true. Otherwise the loader parameter is ignored.
095: *
096: * @param className the name of the class.
097: * @param loader the class loader.
098: * @param params an array containing the parameters of the constructor.
099: * @param signature an array containing the signature of the constructor.
100: * @return the instance.
101: * @throws TurbineException if instantiation fails.
102: */
103: public static Object getInstance(String className,
104: ClassLoader loader, Object[] params, String[] signature)
105: throws TurbineException {
106: return getService().getInstance(className, loader, params,
107: signature);
108: }
109:
110: /**
111: * Tests if specified class loaders are supported for a named class.
112: *
113: * @param className the name of the class.
114: * @return true if class loaders are supported, false otherwise.
115: * @throws TurbineException if test fails.
116: */
117: public static boolean isLoaderSupported(String className)
118: throws TurbineException {
119: return getService().isLoaderSupported(className);
120: }
121:
122: /**
123: * Gets the signature classes for parameters of a method of a class.
124: *
125: * @param clazz the class.
126: * @param params an array containing the parameters of the method.
127: * @param signature an array containing the signature of the method.
128: * @return an array of signature classes. Note that in some cases
129: * objects in the parameter array can be switched to the context
130: * of a different class loader.
131: * @throws ClassNotFoundException if any of the classes is not found.
132: */
133: public static Class[] getSignature(Class clazz, Object params[],
134: String signature[]) throws ClassNotFoundException {
135: return getService().getSignature(clazz, params, signature);
136: }
137: }
|