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 org.openharmonise.rm.metadata.GeneralPropertyInstance;
022: import org.openharmonise.rm.publishing.Publishable;
023: import org.w3c.dom.Element;
024:
025: /**
026: *
027: * Abstract class which represents a <code>Property</code> range which is
028: * restricted to <code>Number</code> values.
029: *
030: * @author Michael Bell
031: * @version $Revision: 1.2 $
032: *
033: */
034: public abstract class NumberRange extends AbstractRange implements
035: Range, Publishable {
036:
037: public static final String TAG_MAX = "Max";
038: public static final String TAG_MIN = "Min";
039: public static final String ATTRIB_EXCLUSIVE = "exclusive";
040:
041: /**
042: * A <code>boolean</code> to indicate whether this range has a maximum
043: * value.
044: */
045: protected boolean m_bHasMax = false;
046:
047: /**
048: * A <code>boolean</code> to indicate whether this range has a minimum
049: * value.
050: */
051: protected boolean m_bHasMin = false;
052:
053: /**
054: * A <code>boolean</code> to indicate whether the minimum limit is
055: * exclusive. <code>true</code> if the value is exclusive, <code>false</code>
056: * otherwise.
057: */
058: protected boolean m_bMinExclusive = false;
059:
060: /**
061: * A <code>boolean</code> to indicate whether the maximum limit is
062: * exclusive. <code>true</code> if the value is exclusive, <code>false</code>
063: * otherwise.
064: */
065: protected boolean m_bMaxExclusive = false;
066:
067: /**
068: * Constructs a new <code>NumberRange</code>
069: *
070: */
071: public NumberRange() {
072: super (Number.class.getName());
073: }
074:
075: /**
076: * Constructs a <code>NumberRange</code> with the specified class restriction.
077: *
078: * @param sObjClassName the class name of objects within this range
079: */
080: public NumberRange(String sObjClassName) {
081: super (sObjClassName);
082: }
083:
084: /**
085: * Constructs a <code>NumberRange</code> with the specified class restriction.
086: *
087: * @param sObjClassName the class name of objects within this range
088: * @param sDetails a <code>String</code> representation of the non class
089: * type restrictions
090: */
091: public NumberRange(String sObjClassName, String sDetails) {
092: super (sObjClassName, sDetails);
093: }
094:
095: /* (non-Javadoc)
096: * @see org.openharmonise.rm.resources.metadata.properties.ranges.Range#isValid(java.lang.Object)
097: */
098: public boolean isValid(Object obj) {
099: return (obj instanceof Number);
100: }
101:
102: /**
103: * Returns <code>true</code> if this range has a minimum limit.
104: *
105: * @return <code>true</code> if this range has a minimum limit
106: */
107: public boolean hasMin() {
108: return m_bHasMin;
109: }
110:
111: /**
112: * Sets whether this range has a minimum limit.
113: *
114: * @param bHasMin <code>true</code> if this range has a minimum limit, otherwise
115: * <code>false</code>
116: */
117: public void hasMin(boolean bHasMin) {
118: m_bHasMin = bHasMin;
119: }
120:
121: /**
122: * Returns <code>true</code> if this range has a maximum limit.
123: *
124: * @return <code>true</code> if this range has a maximum limit
125: */
126: public boolean hasMax() {
127: return m_bHasMax;
128: }
129:
130: /**
131: * Sets whether this range has a maximum limit.
132: *
133: * @param bHasMin <code>true</code> if this range has a maximum limit, otherwise
134: * <code>false</code>
135: */
136: public void hasMax(boolean bHasMax) {
137: m_bHasMax = bHasMax;
138: }
139:
140: /**
141: * Return the minimum value this range will allow.
142: *
143: * @return the minimum value this range will allow
144: */
145: public boolean isMinExclusive() {
146: return m_bMinExclusive;
147: }
148:
149: /**
150: * Returns <code>true</code> if max limit is exclusive.
151: *
152: * @return <code>true</code> if max limit is exclusive
153: */
154: public boolean isMaxExclusive() {
155: return m_bMaxExclusive;
156: }
157:
158: /* (non-Javadoc)
159: * @see java.lang.Object#equals(java.lang.Object)
160: */
161: public boolean equals(Object obj) {
162: boolean bResult = false;
163:
164: if (obj instanceof NumberRange) {
165: if (super .equals(obj) == true) {
166: NumberRange nRange = (NumberRange) obj;
167:
168: if (hasMin() == nRange.hasMin()
169: && hasMax() == nRange.hasMax()) {
170: bResult = true;
171: }
172: }
173: }
174:
175: return bResult;
176: }
177:
178: /* (non-Javadoc)
179: * @see org.openharmonise.rm.resources.metadata.properties.ranges.Range#getPropertyInstanceClass()
180: */
181: public Class getPropertyInstanceClass()
182: throws ClassNotFoundException {
183: return GeneralPropertyInstance.class;
184: }
185:
186: /**
187: * Returns <code>true</code> if the specified XML element has an
188: * attribute which matches <code>ATTRIB_EXCLUSIVE</code> and
189: * had a 'true' value.
190: *
191: * @param el the XML element
192: * @return returns the <code>boolean</code> value of the
193: * <code>ATTRIB_EXCLUSIVE</code> attribute
194: */
195: protected boolean isExclusive(Element el) {
196: boolean bExcl = false;
197: String sExcl = el.getAttribute(ATTRIB_EXCLUSIVE);
198:
199: if (sExcl != null) {
200: bExcl = Boolean.getBoolean(sExcl);
201: }
202:
203: return bExcl;
204: }
205: }
|