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.Service;
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: * @version $Id: FactoryService.java 264148 2005-08-29 14:21:04Z henning $
030: */
031: public interface FactoryService extends Service {
032: /**
033: * The key under which this service is stored in TurbineServices.
034: */
035: String SERVICE_NAME = "FactoryService";
036:
037: /**
038: * Gets an instance of a named class.
039: *
040: * @param className the name of the class.
041: * @return the instance.
042: * @throws TurbineException if instantiation fails.
043: */
044: Object getInstance(String className) throws TurbineException;
045:
046: /**
047: * Gets an instance of a named class using a specified class loader.
048: *
049: * <p>Class loaders are supported only if the isLoaderSupported
050: * method returns true. Otherwise the loader parameter is ignored.
051: *
052: * @param className the name of the class.
053: * @param loader the class loader.
054: * @return the instance.
055: * @throws TurbineException if instantiation fails.
056: */
057: Object getInstance(String className, ClassLoader loader)
058: throws TurbineException;
059:
060: /**
061: * Gets an instance of a named class.
062: * Parameters for its constructor are given as an array of objects,
063: * primitive types must be wrapped with a corresponding class.
064: *
065: * @param className the name of the class.
066: * @param params an array containing the parameters of the constructor.
067: * @param signature an array containing the signature of the constructor.
068: * @return the instance.
069: * @throws TurbineException if instantiation fails.
070: */
071: Object getInstance(String className, Object[] params,
072: String[] signature) throws TurbineException;
073:
074: /**
075: * Gets an instance of a named class using a specified class loader.
076: * Parameters for its constructor are given as an array of objects,
077: * primitive types must be wrapped with a corresponding class.
078: *
079: * <p>Class loaders are supported only if the isLoaderSupported
080: * method returns true. Otherwise the loader parameter is ignored.
081: *
082: * @param className the name of the class.
083: * @param loader the class loader.
084: * @param params an array containing the parameters of the constructor.
085: * @param signature an array containing the signature of the constructor.
086: * @return the instance.
087: * @throws TurbineException if instantiation fails.
088: */
089: Object getInstance(String className, ClassLoader loader,
090: Object[] params, String[] signature)
091: throws TurbineException;
092:
093: /**
094: * Tests if specified class loaders are supported for a named class.
095: *
096: * @param className the name of the class.
097: * @return true if class loaders are supported, false otherwise.
098: * @throws TurbineException if test fails.
099: */
100: boolean isLoaderSupported(String className) throws TurbineException;
101:
102: /**
103: * Gets the signature classes for parameters of a method of a class.
104: *
105: * @param clazz the class.
106: * @param params an array containing the parameters of the method.
107: * @param signature an array containing the signature of the method.
108: * @return an array of signature classes. Note that in some cases
109: * objects in the parameter array can be switched to the context
110: * of a different class loader.
111: * @throws ClassNotFoundException if any of the classes is not found.
112: */
113: Class[] getSignature(Class clazz, Object params[],
114: String signature[]) throws ClassNotFoundException;
115: }
|