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.util.TurbineException;
023:
024: /**
025: * Factory is an interface for object factories. Object factories
026: * can be registered with the Factory Service to support customized
027: * functionality during instantiation of specific classes that
028: * the service itself cannot provide. Examples include
029: * instantiation of XML parsers and secure sockets requiring
030: * provider specific initializations before instantiation.
031: *
032: * @author <a href="mailto:ilkka.priha@simsoft.fi">Ilkka Priha</a>
033: * @version $Id: Factory.java 534527 2007-05-02 16:10:59Z tv $
034: */
035: public interface Factory {
036: /**
037: * Initializes the factory. This method is called by
038: * the Factory Service before the factory is used.
039: *
040: * @param className the name of the production class
041: * @throws TurbineException if initialization fails.
042: */
043: void init(String className) throws TurbineException;
044:
045: /**
046: * Gets an instance of a class.
047: *
048: * @return the instance.
049: * @throws TurbineException if instantiation fails.
050: */
051: Object getInstance() throws TurbineException;
052:
053: /**
054: * Gets an instance of a class using a specified class loader.
055: *
056: * <p>Class loaders are supported only if the isLoaderSupported
057: * method returns true. Otherwise the loader parameter is ignored.
058: *
059: * @param loader the class loader.
060: * @return the instance.
061: * @throws TurbineException if instantiation fails.
062: */
063: Object getInstance(ClassLoader loader) throws TurbineException;
064:
065: /**
066: * Gets an instance of a named class.
067: * Parameters for its constructor are given as an array of objects,
068: * primitive types must be wrapped with a corresponding class.
069: *
070: * @param params an array containing the parameters of the constructor.
071: * @param signature an array containing the signature of the constructor.
072: * @return the instance.
073: * @throws TurbineException if instantiation fails.
074: */
075: Object getInstance(Object[] params, String[] signature)
076: throws TurbineException;
077:
078: /**
079: * Gets an instance of a named class using a specified class loader.
080: * Parameters for its constructor are given as an array of objects,
081: * primitive types must be wrapped with a corresponding class.
082: *
083: * <p>Class loaders are supported only if the isLoaderSupported
084: * method returns true. Otherwise the loader parameter is ignored.
085: *
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(ClassLoader loader, Object[] params,
093: String[] signature) throws TurbineException;
094:
095: /**
096: * Tests if this object factory supports specified class loaders.
097: *
098: * @return true if class loaders are supported, false otherwise.
099: */
100: boolean isLoaderSupported();
101: }
|