001// SECTION-START[License Header]
002// <editor-fold defaultstate="collapsed" desc=" Generated License ">
003/*
004 * Java Object Management and Configuration
005 * Copyright (C) Christian Schulte <cs@schulte.it>, 2005-206
006 * All rights reserved.
007 *
008 * Redistribution and use in source and binary forms, with or without
009 * modification, are permitted provided that the following conditions
010 * are met:
011 *
012 *   o Redistributions of source code must retain the above copyright
013 *     notice, this list of conditions and the following disclaimer.
014 *
015 *   o Redistributions in binary form must reproduce the above copyright
016 *     notice, this list of conditions and the following disclaimer in
017 *     the documentation and/or other materials provided with the
018 *     distribution.
019 *
020 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
021 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
022 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
023 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
024 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
025 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
026 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
027 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
028 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
029 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
030 *
031 * $JOMC: ObjectManager.java 5061 2015-05-31 13:20:40Z schulte $
032 *
033 */
034// </editor-fold>
035// SECTION-END
036package org.jomc;
037
038import java.util.Locale;
039
040// SECTION-START[Documentation]
041// <editor-fold defaultstate="collapsed" desc=" Generated Documentation ">
042/**
043 * Manages objects.
044 *
045 * <dl>
046 *   <dt><b>Identifier:</b></dt><dd>org.jomc.ObjectManager</dd>
047 *   <dt><b>Multiplicity:</b></dt><dd>One</dd>
048 *   <dt><b>Scope:</b></dt><dd>Singleton</dd>
049 * </dl>
050 *
051 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a> 1.0
052 * @version 1.0
053 * @see org.jomc.ObjectManager#getObject(java.lang.Class) getObject(ObjectManager.class)
054 * @see org.jomc.ObjectManager#getObject(java.lang.Class,java.lang.String) getObject(ObjectManager.class, "<i>implementation name</i>")
055 * @see org.jomc.ObjectManagerFactory
056 */
057// </editor-fold>
058// SECTION-END
059// SECTION-START[Annotations]
060// <editor-fold defaultstate="collapsed" desc=" Generated Annotations ">
061@javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.9", comments = "See http://www.jomc.org/jomc/1.9/jomc-tools-1.9" )
062// </editor-fold>
063// SECTION-END
064public interface ObjectManager
065{
066    // SECTION-START[ObjectManager]
067
068    /**
069     * Gets an instance of an implementation of a specification.
070     * <p>
071     * <b>Note:</b><br/>
072     * Implementations must use the class loader associated with the given class as returned by method
073     * {@link Class#getClassLoader() specification.getClassLoader()} for loading classes. Only if that method returns
074     * {@code null}, indicating the class has been loaded by the bootstrap class loader, use of the bootstrap class
075     * loader is recommended.
076     * </p>
077     *
078     * @param <T> The type of the instance.
079     * @param specification The specification class to return an implementation instance of.
080     *
081     * @return An instance of an implementation of the specification class {@code specification} or {@code null}, if no
082     * such instance is available.
083     *
084     * @throws NullPointerException if {@code specification} is {@code null}.
085     * @throws ObjectManagementException if getting the object fails.
086     */
087    <T> T getObject( Class<T> specification )
088        throws NullPointerException, ObjectManagementException;
089
090    /**
091     * Gets an instance of an implementation of a specification.
092     * <p>
093     * <b>Note:</b><br/>
094     * Implementations must use the class loader associated with the given class as returned by method
095     * {@link Class#getClassLoader() specification.getClassLoader()} for loading classes. Only if that method returns
096     * {@code null}, indicating the class has been loaded by the bootstrap class loader, use of the bootstrap class
097     * loader is recommended.
098     * </p>
099     *
100     * @param <T> The type of the instance.
101     * @param specification The specification class to return an implementation instance of.
102     * @param implementationName The name of the implementation to return an instance of.
103     *
104     * @return An instance of the implementation named {@code implementationName} of the specification class
105     * {@code specification} or {@code null}, if no such instance is available.
106     *
107     * @throws NullPointerException if {@code specification} or {@code implementationName} is {@code null}.
108     * @throws ObjectManagementException if getting the object fails.
109     */
110    <T> T getObject( Class<T> specification, String implementationName )
111        throws NullPointerException, ObjectManagementException;
112
113    /**
114     * Gets an instance of a dependency of an object.
115     * <p>
116     * <b>Note:</b><br/>
117     * Implementations must use the class loader associated with the class of the given object as returned by method
118     * {@link Class#getClassLoader() object.getClass().getClassLoader()} for loading classes. Only if that method
119     * returns {@code null}, indicating the class has been loaded by the bootstrap class loader, use of the bootstrap
120     * class loader is recommended.
121     * </p>
122     *
123     * @param object The object to return a dependency instance of.
124     * @param dependencyName The name of the dependency of {@code object} to return an instance of.
125     *
126     * @return An instance of the dependency named {@code dependencyName} of {@code object} or {@code null}, if no such
127     * instance is available.
128     *
129     * @throws NullPointerException if {@code object} or {@code dependencyName} is {@code null}.
130     * @throws ObjectManagementException if getting the dependency instance fails.
131     */
132    Object getDependency( Object object, String dependencyName )
133        throws NullPointerException, ObjectManagementException;
134
135    /**
136     * Gets an instance of a property of an object.
137     * <p>
138     * <b>Note:</b><br/>
139     * Implementations must use the class loader associated with the class of the given object as returned by method
140     * {@link Class#getClassLoader() object.getClass().getClassLoader()} for loading classes. Only if that method
141     * returns {@code null}, indicating the class has been loaded by the bootstrap class loader, use of the bootstrap
142     * class loader is recommended.
143     * </p>
144     *
145     * @param object The object to return a property instance of.
146     * @param propertyName The name of the property of {@code object} to return an instance of.
147     *
148     * @return An instance of the property named {@code propertyName} of {@code object} or {@code null}, if no such
149     * instance is available.
150     *
151     * @throws NullPointerException if {@code object} or {@code propertyName} is {@code null}.
152     * @throws ObjectManagementException if getting the property instance fails.
153     */
154    Object getProperty( Object object, String propertyName )
155        throws NullPointerException, ObjectManagementException;
156
157    /**
158     * Gets an instance of a message of an object.
159     * <p>
160     * <b>Note:</b><br/>
161     * Implementations must use the class loader associated with the class of the given object as returned by method
162     * {@link Class#getClassLoader() object.getClass().getClassLoader()} for loading classes. Only if that method
163     * returns {@code null}, indicating the class has been loaded by the bootstrap class loader, use of the bootstrap
164     * class loader is recommended.
165     * </p>
166     *
167     * @param object The object to return a message instance of.
168     * @param messageName The name of the message of {@code object} to return an instance of.
169     * @param locale The locale of the message instance to return.
170     * @param arguments Arguments to format the message instance with.
171     *
172     * @return An instance of the message named {@code messageName} of {@code object} formatted with {@code arguments}
173     * for {@code locale} or {@code null}, if no such instance is available.
174     *
175     * @throws NullPointerException if {@code object}, {@code messageName} or {@code locale} is {@code null}.
176     * @throws ObjectManagementException if getting the message instance fails.
177     */
178    String getMessage( Object object, String messageName, Locale locale, Object... arguments )
179        throws NullPointerException, ObjectManagementException;
180
181    // SECTION-END
182}