KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > meta > info > builder > tags > TypeTag


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

49
50 package org.apache.avalon.meta.info.builder.tags;
51
52 import java.util.Properties JavaDoc;
53
54 import org.apache.avalon.framework.Version;
55 import org.apache.avalon.meta.info.ContextDescriptor;
56 import org.apache.avalon.meta.info.DependencyDescriptor;
57 import org.apache.avalon.meta.info.ExtensionDescriptor;
58 import org.apache.avalon.meta.info.InfoDescriptor;
59 import org.apache.avalon.meta.info.CategoryDescriptor;
60 import org.apache.avalon.meta.info.ServiceDescriptor;
61 import org.apache.avalon.meta.info.StageDescriptor;
62 import org.apache.avalon.meta.info.Type;
63
64 import com.thoughtworks.qdox.model.DocletTag;
65 import com.thoughtworks.qdox.model.JavaClass;
66
67 /**
68  * <p>A doclet tag the declares a a {@link Type} descriptor using the
69  * <code>&amp;avalon.type</code> or <code>&amp;avalon.component</code>
70  * javadoc tag. The &amp;avalon.component is senonomouse with &amp;avalon.type.
71  * The &amp;avalon.type tag recognizes the following attributes:<p>
72  *
73  * <table border="1" cellpadding="3" cellspacing="0" width="100%">
74  * <tr bgcolor="#CCCCFF" class="TableHeadingColor">
75  * <td colspan="3"><p><b>Tag Attributes</b></p></td>
76  * </tr>
77  * <tr bgcolor="white" class="TableRowColor">
78  * <td>name</td><td>required</td>
79  * <td>The name of the component type.</td></tr>
80  * <tr bgcolor="white" class="TableRowColor">
81  * <td>version</td><td>optional</td>
82  * <td>A version identifier in the format [major].[minor].[micro].
83  * If not supplied the version 1.0.0 will be assumed.</td></tr>
84  * <tr bgcolor="white" class="TableRowColor">
85  * <td>lifestyle</td><td>optional</td>
86  * <td>The component implementation lifestyle - one of "singleton",
87  * "thread", "pooled", or "transient". If not supplied "transient"
88  * is assumed.</td></tr>
89  * </table>
90  *
91  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
92  * @version $Revision: 1.7 $ $Date: 2003/07/24 12:12:02 $
93  */

94 public class TypeTag extends AbstractTag
95 {
96    /**
97     * Javadoc tag key for the type tag.
98     */

99     public static final String JavaDoc KEY = "component";
100
101    /**
102     * The name parameter
103     */

104     public static final String JavaDoc NAME_PARAM = "name";
105
106    /**
107     * The version parameter
108     */

109     public static final String JavaDoc VERSION_PARAM = "version";
110
111    /**
112     * The version parameter
113     */

114     public static final String JavaDoc LIFESTYLE_PARAM = "lifestyle";
115
116    /**
117     * Type tag constructor.
118     * @param clazz the javadoc class descriptor
119     */

120     public TypeTag( final JavaClass clazz )
121     {
122         super( clazz );
123     }
124
125    /**
126     * Return the value of the Avalon 'component' tag.
127     * @return the name of the component type
128     * @exception IllegalArgumentException if the name tag does not contain a value
129     */

130     public Type getType()
131     {
132         DocletTag tag = getJavaClass().getTagByName( getNS() + Tags.DELIMITER + KEY );
133         if( null == tag )
134         {
135             return null;
136         }
137
138         final String JavaDoc name = getName( tag );
139         final Version version = getVersion( tag );
140         final String JavaDoc lifestyle = getLifestyle( tag );
141         final String JavaDoc type = getJavaClass().getFullyQualifiedName();
142         final Properties JavaDoc properties = new AttributeTag( getJavaClass() ).getProperties();
143         final String JavaDoc schema = new SchemaTag( getJavaClass() ).getConfigurationSchema();
144         final InfoDescriptor info = new InfoDescriptor( name, type, version, lifestyle, schema, properties );
145         final ServiceDescriptor[] services = new ServicesTag( getJavaClass() ).getServices();
146         final CategoryDescriptor[] loggers = new LoggerTag( getJavaClass() ).getCategories();
147         final DependencyDescriptor[] dependencies =
148           new DependencyTag( getJavaClass() ).getDependencies();
149         final StageDescriptor[] stages = new StageTag( getJavaClass() ).getStages();
150         final ExtensionDescriptor[] extensions = new ExtensionTag( getJavaClass() ).getExtensions();
151         final ContextDescriptor context = new ContextTag( getJavaClass() ).getContext();
152
153         return new Type( info, loggers, context, services, dependencies, stages, extensions, null );
154     }
155
156     private String JavaDoc getName(DocletTag tag)
157     {
158         return getNamedParameter( tag, NAME_PARAM );
159     }
160
161     private String JavaDoc getLifestyle(DocletTag tag)
162     {
163         return getNamedParameter( tag, LIFESTYLE_PARAM, null );
164     }
165
166     private Version getVersion(DocletTag tag)
167     {
168         return Version.getVersion( getNamedParameter( tag, VERSION_PARAM, "" ) );
169     }
170 }
171
Popular Tags