001 // Copyright 2004, 2005 The Apache Software Foundation
002 //
003 // Licensed under the Apache License, Version 2.0 (the "License");
004 // you may not use this file except in compliance with the License.
005 // You may obtain a copy of the License at
006 //
007 // http://www.apache.org/licenses/LICENSE-2.0
008 //
009 // Unless required by applicable law or agreed to in writing, software
010 // distributed under the License is distributed on an "AS IS" BASIS,
011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012 // See the License for the specific language governing permissions and
013 // limitations under the License.
014
015 package org.apache.hivemind.lib;
016
017 /**
018 * Service interface for a source of beans of a particular type.
019 * Bean instances are retrieved using a <em>locator string</em> which is of the form:
020 * <code><em>name</em>[,<em>initializer</em>]</code>. That is, an optional initializer is
021 * may be specified, separated by a comma.
022 *
023 * <p>
024 * Beans may be cached or not.
025 *
026 * <p>
027 * The <code>hivemind.lib.BeanFactoryBuilder</code> service is used to create services
028 * implementing this interface (driven from a configuration).
029 *
030 * @author Howard Lewis Ship
031 */
032 public interface BeanFactory
033 {
034 /**
035 * Returns true if a bean matching the provided locator has been
036 * defined.
037 *
038 * @param locator the name or name and initializer
039 * @return true if a bean matching the provided locator has ben defined
040 */
041 public boolean contains(String locator);
042
043 /**
044 * Gets a bean via its locator (it's name plus, optionally, an initializer).
045 *
046 * @param locator the name or name and initializer
047 * @return a bean instance
048 * @throws org.apache.hivemind.ApplicationRuntimeException if no bean matching the provided
049 * name has been defined.
050 */
051 public Object get(String locator);
052 }