001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019: package org.openharmonise.rm.resources.metadata.properties.ranges;
020:
021: import java.text.*;
022: import java.util.StringTokenizer;
023:
024: import org.openharmonise.rm.metadata.GeneralPropertyInstance;
025:
026: /**
027: * Class which represents a <code>Property</code> range which is
028: * restricted to <code>Boolean</code> values.
029: *
030: * @author Michael Bell
031: * @version $Revision: 1.2 $
032: *
033: */
034: public class BooleanRange extends AbstractRange {
035:
036: /**
037: * Default label for the boolean 'true'
038: */
039: private static final String DEFAULT_TRUE_LABEL = "yes";
040:
041: /**
042: * Default label for the boolean 'false'
043: */
044: private static final String DEFAULT_FALSE_LABEL = "no";
045:
046: /**
047: * Separator character used to separate labels in details field
048: */
049: private static final String SEPARATOR = "|";
050:
051: /**
052: * Current label for the boolean 'true'
053: */
054: private String m_sTrueLabel = DEFAULT_TRUE_LABEL;
055:
056: /**
057: * Current label for the boolean 'false'
058: */
059: private String m_sFalseLabel = DEFAULT_FALSE_LABEL;
060:
061: /**
062: * Boolean range tag name
063: */
064: public final static String TAG_BOOLEAN_RANGE = "BooleanRange";
065:
066: /**
067: * Constructs a new <code>BooleanRange</code>
068: */
069: public BooleanRange() {
070: super (Boolean.class.getName());
071: }
072:
073: /* (non-Javadoc)
074: * @see org.openharmonise.rm.resources.metadata.properties.ranges.Range#isValid(java.lang.Object)
075: */
076: public boolean isValid(Object obj) {
077:
078: return obj instanceof Boolean;
079: }
080:
081: /**
082: * Return the label for the boolean 'true' value.
083: *
084: * @return the label for the boolean 'true' value.
085: */
086: public String getTrueLabel() {
087: return m_sTrueLabel;
088: }
089:
090: /**
091: * Return the label for the boolean 'false' value.
092: *
093: * @return the label for the boolean 'false' value.
094: */
095: public String getFalseLabel() {
096: return m_sFalseLabel;
097: }
098:
099: /**
100: * Sets the label for the boolean 'true' label.
101: *
102: * @param sTrueLabel the label for the boolean 'true' label
103: */
104: public void setTrueLabel(String sTrueLabel) {
105: if (sTrueLabel != null
106: && m_sTrueLabel.equals(sTrueLabel) == false) {
107: isChanged(true);
108: m_sTrueLabel = sTrueLabel;
109: }
110: }
111:
112: /**
113: * Sets the label for the boolean 'false' label.
114: *
115: * @param sTrueLabel the label for the boolean 'false' label
116: */
117: public void setFalseLabel(String sFalseLabel) {
118: if (sFalseLabel != null
119: && 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 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 getPropertyInstanceClass()
142: throws ClassNotFoundException {
143: return GeneralPropertyInstance.class;
144: }
145:
146: /* (non-Javadoc)
147: * @see org.openharmonise.rm.publishing.Publishable#getTagName()
148: */
149: public String getTagName() {
150: return TAG_BOOLEAN_RANGE;
151: }
152:
153: /* (non-Javadoc)
154: * @see org.openharmonise.rm.resources.metadata.properties.ranges.Range#getDetails()
155: */
156: public String getDetails() {
157:
158: if (isChanged()) {
159: StringBuffer strbuf = new StringBuffer();
160:
161: strbuf.append(m_sTrueLabel).append(SEPARATOR).append(
162: 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 sDetails) {
174: if (sDetails != null) {
175: StringTokenizer tokenizer = new StringTokenizer(sDetails,
176: SEPARATOR);
177: SimpleDateFormat formatter = null;
178:
179: int i = 0;
180: int nTmp = 0;
181: while (tokenizer.hasMoreTokens()) {
182: String 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: }
|