001: /*
002: * @(#)DefaultAutoDocFactory.java
003: *
004: * Copyright (C) 2002-2003 Matt Albrecht
005: * groboclown@users.sourceforge.net
006: * http://groboutils.sourceforge.net
007: *
008: * Part of the GroboUtils package at:
009: * http://groboutils.sourceforge.net
010: *
011: * Permission is hereby granted, free of charge, to any person obtaining a
012: * copy of this software and associated documentation files (the "Software"),
013: * to deal in the Software without restriction, including without limitation
014: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
015: * and/or sell copies of the Software, and to permit persons to whom the
016: * Software is furnished to do so, subject to the following conditions:
017: *
018: * The above copyright notice and this permission notice shall be included in
019: * all copies or substantial portions of the Software.
020: *
021: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
022: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
023: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
024: * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
025: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
026: * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
027: * DEALINGS IN THE SOFTWARE.
028: */
029: package net.sourceforge.groboutils.autodoc.v1.defimpl;
030:
031: import net.sourceforge.groboutils.util.classes.v1.SPISingletonStore;
032:
033: import net.sourceforge.groboutils.autodoc.v1.spi.AutoDocFactory;
034: import net.sourceforge.groboutils.autodoc.v1.AutoDocLog;
035: import net.sourceforge.groboutils.autodoc.v1.AutoDocIT;
036: import net.sourceforge.groboutils.autodoc.v1.AutoDocTP;
037:
038: import net.sourceforge.groboutils.autodoc.v1.spi.AutoDocLogFactory;
039: import net.sourceforge.groboutils.autodoc.v1.spi.AutoDocITFactory;
040: import net.sourceforge.groboutils.autodoc.v1.spi.AutoDocTPFactory;
041:
042: import java.util.Vector;
043: import java.util.Enumeration;
044:
045: import org.apache.log4j.Logger;
046:
047: /**
048: * An interface which defines the kinds of classes which should be loaded
049: * for the <tt>AutoDoc</tt> entry point.
050: *
051: * @author Matt Albrecht <a href="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
052: * @version $Date: 2003/02/10 22:52:11 $
053: * @since March 16, 2002
054: */
055: public class DefaultAutoDocFactory implements AutoDocFactory {
056: private static final Logger LOG = Logger
057: .getLogger(DefaultAutoDocFactory.class.getName());
058:
059: private static final SPISingletonStore s_lfStore = new SPISingletonStore(
060: AutoDocLogFactory.class,
061: SPISingletonStore.NO_MULTIPLES_SILENT);
062:
063: private static final SPISingletonStore s_itfStore = new SPISingletonStore(
064: AutoDocITFactory.class,
065: SPISingletonStore.NO_MULTIPLES_SILENT);
066:
067: private static final SPISingletonStore s_tpfStore = new SPISingletonStore(
068: AutoDocTPFactory.class,
069: SPISingletonStore.NO_MULTIPLES_SILENT);
070:
071: private Vector lf = null;
072: private Vector itf = null;
073: private Vector tpf = null;
074:
075: /**
076: * Default constructor (required).
077: */
078: public DefaultAutoDocFactory() {
079: // do nothing - delay the loading of the factory until the last
080: // moment.
081: }
082:
083: /**
084: * Creates a new Log for the class owner.
085: *
086: * @param owner the Class owner, as passed to the <tt>AutoDoc</tt> class.
087: * @return the loaded AutoDocLogFactory's created instance.
088: */
089: public AutoDocLog createLog( Class owner )
090: {
091: if (owner == null)
092: {
093: throw new IllegalArgumentException("no null args");
094: }
095:
096: AutoDocLogSet set = new AutoDocLogSet();
097: Enumeration enum = getLogFactories();
098: while (enum.hasMoreElements())
099: {
100: set.addLog( ((AutoDocLogFactory)enum.nextElement()).
101: createLog( owner ) );
102: }
103: return set;
104: }
105:
106: /**
107: * Creates the Issue Tracker entry point.
108: *
109: * @param owner the Class owner, as passed to the <tt>AutoDoc</tt> class.
110: * @return the loaded AutoDocITFactory's created instance.
111: */
112: public AutoDocIT createIT( Class owner )
113: {
114: if (owner == null)
115: {
116: throw new IllegalArgumentException("no null args");
117: }
118:
119: AutoDocITSet set = new AutoDocITSet();
120: Enumeration enum = getITFactories();
121: while (enum.hasMoreElements())
122: {
123: set.addIT( ((AutoDocITFactory)enum.nextElement()).
124: createIT( owner ) );
125: }
126: return set;
127: }
128:
129: /**
130: * Creates a Test Procedure entry point.
131: *
132: * @param owner the Class owner, as passed to the <tt>AutoDoc</tt> class.
133: * @return the loaded AutoDocTPFactory's created instance.
134: */
135: public AutoDocTP createTP( Class owner )
136: {
137: if (owner == null)
138: {
139: throw new IllegalArgumentException("no null args");
140: }
141:
142: AutoDocTPSet set = new AutoDocTPSet();
143: Enumeration enum = getTPFactories();
144: while (enum.hasMoreElements())
145: {
146: set.addTP( ((AutoDocTPFactory)enum.nextElement()).
147: createTP( owner ) );
148: }
149: return set;
150: }
151:
152: /**
153: * Creates the Log factory if it has not yet been created, or the already
154: * created factory.
155: */
156: protected Enumeration getLogFactories() {
157: return getLogFactoryStore().getSingletons();
158: }
159:
160: /**
161: * Creates the IT factory if it has not yet been created, or the already
162: * created factory.
163: */
164: protected Enumeration getITFactories() {
165: return getITFactoryStore().getSingletons();
166: }
167:
168: /**
169: * Creates the TP factory if it has not yet been created, or the already
170: * created factory.
171: */
172: protected Enumeration getTPFactories() {
173: return getTPFactoryStore().getSingletons();
174: }
175:
176: //-------------------------------------------------------------------------
177: // Static methods
178:
179: /**
180: *
181: */
182: public static SPISingletonStore getLogFactoryStore() {
183: return s_lfStore;
184: }
185:
186: /**
187: *
188: */
189: public static SPISingletonStore getITFactoryStore() {
190: return s_itfStore;
191: }
192:
193: /**
194: *
195: */
196: public static SPISingletonStore getTPFactoryStore() {
197: return s_tpfStore;
198: }
199: }
|