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