KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > swixml > Factory


1 /*--
2  $Id: Factory.java,v 1.1 2004/03/01 07:56:05 wolfpaulus Exp $
3
4  Copyright (C) 2003-2004 Wolf Paulus.
5  All rights reserved.
6
7  Redistribution and use in source and binary forms, with or without
8  modification, are permitted provided that the following conditions
9  are met:
10
11  1. Redistributions of source code must retain the above copyright
12  notice, this list of conditions, and the following disclaimer.
13
14  2. Redistributions in binary form must reproduce the above copyright
15  notice, this list of conditions, and the disclaimer that follows
16  these conditions in the documentation and/or other materials provided
17  with the distribution.
18
19  3. The end-user documentation included with the redistribution,
20  if any, must include the following acknowledgment:
21         "This product includes software developed by the
22          SWIXML Project (http://www.swixml.org/)."
23  Alternately, this acknowledgment may appear in the software itself,
24  if and wherever such third-party acknowledgments normally appear.
25
26  4. The name "Swixml" must not be used to endorse or promote products
27  derived from this software without prior written permission. For
28  written permission, please contact <info_AT_swixml_DOT_org>
29
30  5. Products derived from this software may not be called "Swixml",
31  nor may "Swixml" appear in their name, without prior written
32  permission from the Swixml Project Management.
33
34  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
35  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
36  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
37  DISCLAIMED. IN NO EVENT SHALL THE SWIXML PROJECT OR ITS
38  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
41  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
42  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
43  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
44  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
45  SUCH DAMAGE.
46  ====================================================================
47
48  This software consists of voluntary contributions made by many
49  individuals on behalf of the Swixml Project and was originally
50  created by Wolf Paulus <wolf_AT_swixml_DOT_org>. For more information
51  on the Swixml Project, please see <http://www.swixml.org/>.
52 */

53
54 package org.swixml;
55
56 import java.lang.reflect.InvocationTargetException JavaDoc;
57 import java.lang.reflect.Method JavaDoc;
58 import java.util.Collection JavaDoc;
59
60 /**
61  * An interface to represent a generic factory
62  *
63  * @author <a HREF="mailto:wolf@paulus.com">Wolf Paulus</a>
64  * @version $Revision: 1.1 $
65  */

66 public interface Factory {
67   /** Specifies the prefix string for all setter methods */
68   static final String JavaDoc SETTER_ID = "set";
69   static final String JavaDoc ADDER_ID = "add";
70   /**
71    * Create a new component instance
72    *
73    * @return instance <code>Object</code> a new instance of a template class
74    * @throws Exception
75    */

76   Object JavaDoc newInstance() throws Exception JavaDoc;
77
78   /**
79    * Creates a new Object which class is {@link #getTemplate()}
80    * @param parameter <code>Object</code>, parameter used during construction or initialization.
81    * @return instance <code>Object</code> a new instance of a template class
82    * @throws Exception
83    */

84   Object JavaDoc newInstance( Object JavaDoc parameter ) throws Exception JavaDoc;
85
86   /**
87    * Creates a new Object which class is {@link #getTemplate()} and the constructor
88    * parameter are <code>parameter</code>.
89    *
90    * @param parameter <code>Object[]</code> the parameter array to be passed into the constructor
91    * @return <code>Object</object> - the created object, an instance of the template class
92    * @throws InstantiationException if the creation of the object failed
93    * @throws IllegalAccessException if the constructor is either private or protected.
94    * @throws InvocationTargetException if the constructor invoked throws an exception
95    */

96   Object JavaDoc newInstance(Object JavaDoc[] parameter) throws InstantiationException JavaDoc, IllegalAccessException JavaDoc, InvocationTargetException JavaDoc;
97
98   /**
99    * @return class - <code>Class</code> the backing class template
100    */

101   Class JavaDoc getTemplate();
102
103   /**
104    * @return <code>Collection</code> - containing all available setter methods
105    */

106   Collection JavaDoc getSetters();
107
108   /**
109    * Returns a setter method, which accepts a parameter of the given type
110    * @param template <code>Class</code> type of the setter method's parameter
111    * @return <code>Method</code> setter method which maybe invoked on an object of the template class
112    */

113   Method JavaDoc getSetter( Class JavaDoc template );
114
115   /**
116    * Returns a setter method by name<br>
117    * @param name <code>String</code> name of the setter method
118    * @return <code>Method</code> - setter method which can be invoked on an object of the template class
119    * @see #guessSetter
120    * <pre><b>Typical Use:</b>
121    * <p>Method method = factory.getSetter(&quot;set&quot; + Parser.capitalize(attr.getName()));</p>
122    * </pre>
123    */

124   Method JavaDoc getSetter( String JavaDoc name );
125
126   /**
127    * Returns a setter method by a Attribute name.
128    * Differently to the <code>getSetter</code> method, here the attibute name can be used directly and
129    * case doesn't matter.<br>
130    * @param name <code>String</code> name of the setter method
131    * @return <code>Method</code> - setter method which can invoked on an object of the template class
132    * @see #getSetter
133    * <pre><b>Typical Use:</b>
134    * <p>Method method = factory.getSetter( attr.getName() );</p>
135    * </pre>
136    */

137   Method JavaDoc guessSetter(String JavaDoc name);
138
139 }
140
Popular Tags