KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.openharmonise.rm.metadata.GeneralPropertyInstance;
22 import org.openharmonise.rm.publishing.Publishable;
23 import org.w3c.dom.Element JavaDoc;
24
25
26 /**
27  *
28  * Abstract class which represents a <code>Property</code> range which is
29  * restricted to <code>Number</code> values.
30  *
31  * @author Michael Bell
32  * @version $Revision: 1.2 $
33  *
34  */

35 public abstract class NumberRange extends AbstractRange implements Range, Publishable {
36
37     public static final String JavaDoc TAG_MAX = "Max";
38     public static final String JavaDoc TAG_MIN = "Min";
39     public static final String JavaDoc ATTRIB_EXCLUSIVE = "exclusive";
40
41     /**
42      * A <code>boolean</code> to indicate whether this range has a maximum
43      * value.
44      */

45     protected boolean m_bHasMax = false;
46     
47     /**
48      * A <code>boolean</code> to indicate whether this range has a minimum
49      * value.
50      */

51     protected boolean m_bHasMin = false;
52     
53     /**
54      * A <code>boolean</code> to indicate whether the minimum limit is
55      * exclusive. <code>true</code> if the value is exclusive, <code>false</code>
56      * otherwise.
57      */

58     protected boolean m_bMinExclusive = false;
59     
60     /**
61      * A <code>boolean</code> to indicate whether the maximum limit is
62      * exclusive. <code>true</code> if the value is exclusive, <code>false</code>
63      * otherwise.
64      */

65     protected boolean m_bMaxExclusive = false;
66
67     /**
68      * Constructs a new <code>NumberRange</code>
69      *
70      */

71     public NumberRange() {
72         super(Number JavaDoc.class.getName());
73     }
74
75     /**
76      * Constructs a <code>NumberRange</code> with the specified class restriction.
77      *
78      * @param sObjClassName the class name of objects within this range
79      */

80     public NumberRange(String JavaDoc sObjClassName) {
81         super(sObjClassName);
82     }
83
84     /**
85      * Constructs a <code>NumberRange</code> with the specified class restriction.
86      *
87      * @param sObjClassName the class name of objects within this range
88      * @param sDetails a <code>String</code> representation of the non class
89      * type restrictions
90      */

91     public NumberRange(String JavaDoc sObjClassName, String JavaDoc sDetails) {
92         super(sObjClassName, sDetails);
93     }
94
95     /* (non-Javadoc)
96      * @see org.openharmonise.rm.resources.metadata.properties.ranges.Range#isValid(java.lang.Object)
97      */

98     public boolean isValid(Object JavaDoc obj) {
99         return (obj instanceof Number JavaDoc);
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     /**
142      * Return the minimum value this range will allow.
143      *
144      * @return the minimum value this range will allow
145      */

146     public boolean isMinExclusive() {
147         return m_bMinExclusive;
148     }
149
150     /**
151      * Returns <code>true</code> if max limit is exclusive.
152      *
153      * @return <code>true</code> if max limit is exclusive
154      */

155     public boolean isMaxExclusive() {
156         return m_bMaxExclusive;
157     }
158
159     /* (non-Javadoc)
160      * @see java.lang.Object#equals(java.lang.Object)
161      */

162     public boolean equals(Object JavaDoc obj) {
163         boolean bResult = false;
164
165         if (obj instanceof NumberRange) {
166             if (super.equals(obj) == true) {
167                 NumberRange nRange = (NumberRange) obj;
168
169                 if (hasMin() == nRange.hasMin()
170                     && hasMax() == nRange.hasMax()) {
171                     bResult = true;
172                 }
173             }
174         }
175
176         return bResult;
177     }
178
179     /* (non-Javadoc)
180      * @see org.openharmonise.rm.resources.metadata.properties.ranges.Range#getPropertyInstanceClass()
181      */

182     public Class JavaDoc getPropertyInstanceClass() throws ClassNotFoundException JavaDoc {
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 JavaDoc el) {
196         boolean bExcl = false;
197         String JavaDoc sExcl = el.getAttribute(ATTRIB_EXCLUSIVE);
198                     
199         if(sExcl != null) {
200             bExcl = Boolean.getBoolean(sExcl);
201         }
202         
203         return bExcl;
204     }
205 }
206
Popular Tags