KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > xml > xmlc > metadata > GenerateType


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  *
21  * $Id: GenerateType.java,v 1.1.1.1 2003/03/10 16:36:23 taweili Exp $
22  */

23
24 package org.enhydra.xml.xmlc.metadata;
25
26 /**
27  * Enumerated type indicating the type of class and/or interface XMLC
28  * will generate.
29  */

30 public class GenerateType extends EnumeratedType {
31     /**
32      * Constant indicating a standalone class should be generated.
33      */

34     public static final GenerateType CLASS = new GenerateType("class");
35
36     /**
37      * Constant indicating an interface should be generated.
38      */

39     public static final GenerateType INTERFACE = new GenerateType("interface");
40
41     /**
42      * Constant indicating an implementation should be generated.
43      */

44     public static final GenerateType IMPLEMENTATION = new GenerateType("implementation");
45
46     /**
47      * Constant indicating an interface and implementation should be generated.
48      */

49     public static final GenerateType BOTH = new GenerateType("both");
50
51     /**
52      * Internal constructor. Only a fixed set of types are allowed.
53      */

54     private GenerateType(String JavaDoc name) {
55         super(name);
56     }
57
58     /**
59      * Does this type specify a class being generated?
60      */

61     public boolean generateClass() {
62         return (this == CLASS) || (this == IMPLEMENTATION) || (this == BOTH);
63     }
64
65     /**
66      * Does this type specify an interface being generated?
67      */

68     public boolean generateInterface() {
69         return (this == INTERFACE) || (this == BOTH);
70     }
71
72     /**
73      * Get the object for the specified type. If desiredType is null,
74      * returns null.
75      */

76     public static GenerateType getType(String JavaDoc desiredType) {
77         if (desiredType == null) {
78             return null;
79         } else if (CLASS.fName.equals(desiredType)) {
80             return CLASS;
81         } else if (INTERFACE.fName.equals(desiredType)) {
82             return INTERFACE;
83         } else if (IMPLEMENTATION.fName.equals(desiredType)) {
84             return IMPLEMENTATION;
85         } else if (BOTH.fName.equals(desiredType)) {
86             return BOTH;
87         } else {
88             throw new IllegalArgumentException JavaDoc("Invalid GenerateType: \""
89                                                + desiredType
90                                                + "\", expected one of \""
91                                                + CLASS
92                                                + "\", \", "
93                                                + INTERFACE
94                                                + "\", \""
95                                                + IMPLEMENTATION
96                                                + "\", \""
97                                                + BOTH
98                                                + "\"");
99         }
100     }
101 }
102
Popular Tags