KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > rm > resources > metadata > properties > ranges > BooleanRange


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.rm.resources.metadata.properties.ranges;
20
21 import java.text.*;
22 import java.util.StringTokenizer JavaDoc;
23
24 import org.openharmonise.rm.metadata.GeneralPropertyInstance;
25
26
27 /**
28  * Class which represents a <code>Property</code> range which is
29  * restricted to <code>Boolean</code> values.
30  *
31  * @author Michael Bell
32  * @version $Revision: 1.2 $
33  *
34  */

35 public class BooleanRange extends AbstractRange {
36     
37     /**
38      * Default label for the boolean 'true'
39      */

40     private static final String JavaDoc DEFAULT_TRUE_LABEL = "yes";
41     
42     /**
43      * Default label for the boolean 'false'
44      */

45     private static final String JavaDoc DEFAULT_FALSE_LABEL = "no";
46     
47     /**
48      * Separator character used to separate labels in details field
49      */

50     private static final String JavaDoc SEPARATOR = "|";
51     
52     /**
53      * Current label for the boolean 'true'
54      */

55     private String JavaDoc m_sTrueLabel = DEFAULT_TRUE_LABEL;
56     
57     /**
58      * Current label for the boolean 'false'
59      */

60     private String JavaDoc m_sFalseLabel = DEFAULT_FALSE_LABEL;
61     
62     /**
63      * Boolean range tag name
64      */

65     public final static String JavaDoc TAG_BOOLEAN_RANGE = "BooleanRange";
66
67     /**
68      * Constructs a new <code>BooleanRange</code>
69      */

70     public BooleanRange() {
71         super(Boolean JavaDoc.class.getName());
72     }
73
74
75     /* (non-Javadoc)
76      * @see org.openharmonise.rm.resources.metadata.properties.ranges.Range#isValid(java.lang.Object)
77      */

78     public boolean isValid(Object JavaDoc obj) {
79         
80         return obj instanceof Boolean JavaDoc;
81     }
82     
83     /**
84      * Return the label for the boolean 'true' value.
85      *
86      * @return the label for the boolean 'true' value.
87      */

88     public String JavaDoc getTrueLabel() {
89         return m_sTrueLabel;
90     }
91     
92     /**
93      * Return the label for the boolean 'false' value.
94      *
95      * @return the label for the boolean 'false' value.
96      */

97     public String JavaDoc getFalseLabel() {
98         return m_sFalseLabel;
99     }
100     
101     /**
102      * Sets the label for the boolean 'true' label.
103      *
104      * @param sTrueLabel the label for the boolean 'true' label
105      */

106     public void setTrueLabel(String JavaDoc sTrueLabel) {
107         if(sTrueLabel != null && m_sTrueLabel.equals(sTrueLabel) == false) {
108             isChanged(true);
109             m_sTrueLabel = sTrueLabel;
110         }
111     }
112     
113     /**
114      * Sets the label for the boolean 'false' label.
115      *
116      * @param sTrueLabel the label for the boolean 'false' label
117      */

118     public void setFalseLabel(String JavaDoc sFalseLabel) {
119         if(sFalseLabel != null && m_sTrueLabel.equals(sFalseLabel) == false) {
120             isChanged(true);
121             m_sFalseLabel = sFalseLabel;
122         }
123     }
124
125     /* (non-Javadoc)
126      * @see java.lang.Object#equals(java.lang.Object)
127      */

128     public boolean equals(Object JavaDoc obj) {
129         boolean bResult = false;
130
131         if (obj instanceof BooleanRange) {
132             bResult = super.equals(obj);
133         }
134
135         return bResult;
136     }
137
138     /* (non-Javadoc)
139      * @see org.openharmonise.rm.resources.metadata.properties.ranges.Range#getPropertyInstanceClass()
140      */

141     public Class JavaDoc getPropertyInstanceClass() throws ClassNotFoundException JavaDoc {
142         return GeneralPropertyInstance.class;
143     }
144     
145     /* (non-Javadoc)
146      * @see org.openharmonise.rm.publishing.Publishable#getTagName()
147      */

148     public String JavaDoc getTagName() {
149         return TAG_BOOLEAN_RANGE;
150     }
151     
152     /* (non-Javadoc)
153      * @see org.openharmonise.rm.resources.metadata.properties.ranges.Range#getDetails()
154      */

155     public String JavaDoc getDetails() {
156
157         if (isChanged()) {
158             StringBuffer JavaDoc strbuf = new StringBuffer JavaDoc();
159             
160             strbuf.append(m_sTrueLabel)
161                 .append(SEPARATOR)
162                 .append(m_sFalseLabel);
163             
164             super.setDetails(strbuf.toString());
165         }
166
167         return super.getDetails();
168     }
169     
170     /* (non-Javadoc)
171      * @see org.openharmonise.rm.resources.metadata.properties.ranges.Range#setDetails(java.lang.String)
172      */

173     public void setDetails(String JavaDoc sDetails) {
174         if (sDetails != null) {
175             StringTokenizer JavaDoc tokenizer =
176                 new StringTokenizer JavaDoc(sDetails, SEPARATOR);
177             SimpleDateFormat formatter = null;
178
179             int i = 0;
180             int nTmp = 0;
181             while (tokenizer.hasMoreTokens()) {
182                 String JavaDoc token = tokenizer.nextToken();
183
184                 if (token != null && token.length() > 0) {
185                     
186                     if(i == 0) {
187                         m_sTrueLabel = token;
188                     } else {
189                         m_sFalseLabel = token;
190                     }
191                 }
192                 i++;
193             }
194         }
195
196         super.setDetails(sDetails);
197     }
198 }
199
Popular Tags