KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > rift > coad > lib > configuration > xml > XMLConfigurationType


1 /*
2  * CoadunationLib: The coaduntion implementation library.
3  * Copyright (C) 2006 Rift IT Contracting
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * XMLConfigurationException.java
20  *
21  * XMLConfigurationType.java
22  *
23  * The object wrapping the type information for the XML configuration.
24  */

25
26 package com.rift.coad.lib.configuration.xml;
27
28 /**
29  * The object wrapping the type information for the XML configuration.
30  *
31  * @author Brett Chaldecott
32  */

33 public class XMLConfigurationType {
34     
35     // the classes static variables
36
public final static long STRING_VALUE = 1;
37     public final static String JavaDoc STRING_ID = "string";
38     public final static long LONG_VALUE = 2;
39     public final static String JavaDoc LONG_ID = "long";
40     public final static long BOOLEAN_VALUE = 3;
41     public final static String JavaDoc BOOLEAN_ID = "boolean";
42     
43     // the classes member variables
44
private long type = 0;
45     
46     /**
47      * Creates a new instance of XMLConfigurationType
48      *
49      * @param type The type of xml configurate value.
50      * @exception XMLConfigurationException
51      */

52     public XMLConfigurationType(long type) throws XMLConfigurationException {
53         if ((type != STRING_VALUE) &&(type != LONG_VALUE)) {
54             throw new XMLConfigurationException(
55                     "Invalid type information can either be [STRING] or [LONG]");
56         }
57         this.type = type;
58     }
59     
60     /**
61      * Creates a new instance of XMLConfigurationType
62      *
63      * @param type The type of xml configurate value.
64      * @exception XMLConfigurationException
65      */

66     public XMLConfigurationType(String JavaDoc type) throws XMLConfigurationException {
67         setTypeFromString(type);
68     }
69     
70     
71     /**
72      * The getter method for the type information
73      *
74      * @return The type contained in the long variable.
75      */

76     public long getType() {
77         return type;
78     }
79     
80     
81     /**
82      * The setter method for the type infomration.
83      *
84      * @param type The new type value
85      * @exception XMLConfigurationException
86      */

87     public void setType(long type) throws XMLConfigurationException {
88         if ((type != STRING_VALUE) &&(type != LONG_VALUE) &&
89                 (type != BOOLEAN_VALUE)) {
90             throw new XMLConfigurationException(
91                     "Invalid type information can either be [STRING] or [LONG] " +
92                     "or [BOOLEAN]");
93         }
94         this.type = type;
95     }
96     
97     
98     /**
99      * This method sets the type information using the string value extracted
100      * from the XML configuration file.
101      *
102      * @param type The string to retrieve the type information from.
103      */

104     public void setTypeFromString(String JavaDoc type)
105         throws XMLConfigurationException {
106         if (type.equalsIgnoreCase(STRING_ID)) {
107             this.type = STRING_VALUE;
108         } else if (type.equalsIgnoreCase(LONG_ID)) {
109             this.type = LONG_VALUE;
110         } else if (type.equalsIgnoreCase(BOOLEAN_ID)) {
111             this.type = BOOLEAN_VALUE;
112         } else {
113             throw new XMLConfigurationException("Invalid type [" + type
114                     + "] can either be [string] or [long].");
115         }
116     }
117     
118     /**
119      * The equals method to check if one type equals another type.
120      *
121      * @return TRUE if the values match, FALSE if they do not.
122      * @param ref The reference to the object to compare.
123      */

124     public boolean equals(Object JavaDoc ref) {
125         if (!(ref instanceof XMLConfigurationType)) {
126             return false;
127         } else if (((XMLConfigurationType)ref).getType() == type) {
128             return true;
129         }
130         return false;
131     }
132     
133 }
134
Popular Tags