001: /*
002: * Copyright 2001-2006 C:1 Financial Services GmbH
003: *
004: * This software is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License Version 2.1, as published by the Free Software Foundation.
007: *
008: * This software is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011: * Lesser General Public License for more details.
012: *
013: * You should have received a copy of the GNU Lesser General Public
014: * License along with this library; if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
016: */
017:
018: package de.finix.contelligent.core;
019:
020: import java.io.IOException;
021: import java.io.Writer;
022: import java.net.URL;
023: import java.util.Map;
024: import java.util.Set;
025:
026: import de.finix.contelligent.Component;
027: import de.finix.contelligent.ComponentManager;
028: import de.finix.contelligent.ComponentPath;
029: import de.finix.contelligent.Type;
030: import de.finix.contelligent.exception.TypeException;
031: import de.finix.contelligent.exception.UnknownTypeException;
032: import de.finix.contelligent.xml.elements.TypeElement;
033:
034: /**
035: * A <code>ComponentFactory</code> acts as a factory for Contelligent
036: * {@link Component components}.
037: */
038: public interface ComponentFactory {
039:
040: /**
041: * Returns true if a type with the given name exists.
042: *
043: * @param typeName
044: * a <code>String</code> value
045: * @return a <code>boolean</code> value
046: */
047: public boolean exists(String typeName);
048:
049: /**
050: * Returns the type with the given name or throws an exception if such a
051: * type does not exist.
052: *
053: * @param typeName
054: * the name of the type to return
055: * @return a <code>Type</code> instance
056: * @exception UnknownTypeException
057: * if no type with the specified name exists
058: */
059: Type getType(String typeName) throws UnknownTypeException;
060:
061: /**
062: * Returns true if <code>maybeSubType</code> is the sub type of type named
063: * <code>maybeSuperTypeName</code>.
064: *
065: * @param maybeSubType
066: * a <code>Type</code> value
067: * @param maybeSuperTypeName
068: * a <code>String</code> value
069: * @return a <code>boolean</code> value
070: */
071: boolean isSubType(Type maybeSubType, String maybeSuperTypeName);
072:
073: /**
074: * Returns an <code>Set</code> containing the names of all currently
075: * registered types.
076: *
077: * @return a <code>Set</code> of <code>String</code> elements
078: */
079: public Set typeNames();
080:
081: /**
082: * Returns an <code>Set</code> containing the names of the subtypes of the
083: * given type.
084: *
085: * @param typeName
086: * @return set of String, empty if the type has no subtypes.
087: */
088: Set getSubTypeNames(String typeName);
089:
090: /**
091: * Returns newly created {@link Component} of the given type and sets all
092: * properties to the type's default values.
093: *
094: * @param type
095: * the type to create an instance of
096: * @return a <code>Component</code> value
097: * @exception TypeException
098: * if an error occurs during instantiation
099: */
100: Component createInstance(Type type) throws TypeException;
101:
102: /**
103: * Returns newly created {@link Component} of the given type and sets all
104: * properties contained in the given map using method
105: * {@link Type#setProperties}. Properties which aren not defined by the
106: * type are ignored. Missing properties get the default value of the type.
107: *
108: * @param type
109: * the type to create an instance of
110: * @param propertyMap
111: * a map with properties to set
112: * @return a <code>Component</code> value
113: * @exception TypeException
114: * if an error occurs during instantiation
115: * @see Type#setProperties
116: */
117: Component createInstance(Type type, Map propertyMap)
118: throws TypeException;
119:
120: /**
121: * Returns newly created {@link Component} of the given type without setting
122: * any properties.
123: *
124: * @param type
125: * the type to create an instance of
126: * @return a <code>Component</code> value
127: * @exception TypeException
128: * if an error occurs during instantiation
129: */
130: Component createRawInstance(Type type) throws TypeException;
131:
132: /**
133: * Creates a new type using the specified {@link TypeElement}.
134: */
135: Type createType(TypeElement typeDefinition) throws TypeException,
136: UnknownTypeException;
137:
138: /**
139: * Writes an XML description of all types starting with the given
140: * <tt>prefix</tt> and which are currently known by this factory to the
141: * specified <code>Writer</code>. If <tt>omitHeader</tt> is true no xml
142: * header is written. If <tt>prefix>/tt> is null all types are written.
143: *
144: * @param writer a <code>Writer</code> value
145: * @param omitHeader a <code>boolean</code> value
146: * @param prefix a <code>String</code> value to match against type-names, maybe null.
147: * @exception IOException if an error occurs
148: */
149: void exportTypes(Writer writer, boolean omitHeader, String prefix)
150: throws IOException;
151:
152: /**
153: * Deletes the specified type.
154: *
155: * @param typeName
156: * a <code>String</code> value
157: * @exception UnknownTypeException
158: * if the type is not known.
159: * @exception TypeException
160: * if the type has any subtypes.
161: */
162: void deleteType(String typeName) throws UnknownTypeException,
163: TypeException;
164:
165: /**
166: * Renames <tt>typeName</tt> into <tt>newtypeName</tt>. If the type has
167: * any subtypes an exception is thrown.d/
168: *
169: * @param typeName
170: * a <code>String</code> value
171: * @param newtypeName
172: * a <code>String</code> value
173: * @exception TypeException
174: * if an error occurs
175: */
176: void renameType(String typeName, String newtypeName)
177: throws TypeException;
178:
179: /**
180: * Describe <code>isBlueprintPath</code> method here.
181: *
182: * @param path
183: * a <code>ComponentPath</code> value
184: * @return a <code>boolean</code> value
185: */
186: boolean isBlueprintPath(ComponentPath path);
187:
188: boolean containsBlueprintPath(ComponentPath path);
189:
190: /**
191: * Describe <code>getBlueprintType</code> method here.
192: *
193: * @param path
194: * a <code>ComponentPath</code> value
195: * @return a <code>Type</code> value
196: */
197: Type getBlueprintType(ComponentPath path);
198:
199: /**
200: * Appends the specified <code>URL</code> to the list of URLs to search
201: * for classes.
202: *
203: * @param url
204: * an <code>URL</code> value
205: */
206: void addURL(URL url);
207:
208: /**
209: * Returns the list of URLs this factory currently uses to search for
210: * classes.
211: *
212: * @return an <code>URL[]</code> value
213: */
214: URL[] getURLs();
215:
216: Class loadClass(String className) throws ClassNotFoundException;
217:
218: void validateBlueprintTypes(ComponentManager componentManager)
219: throws TypeException;
220:
221: /**
222: * Invalidate all types
223: */
224: void invalidateTypes();
225:
226: }
|