Source Code Cross Referenced for IntegerRange.java in  » Content-Management-System » harmonise » org » openharmonise » rm » resources » metadata » properties » ranges » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Content Management System » harmonise » org.openharmonise.rm.resources.metadata.properties.ranges 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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.util.StringTokenizer;
022:
023:        import org.openharmonise.rm.PopulateException;
024:        import org.openharmonise.rm.publishing.State;
025:        import org.w3c.dom.Element;
026:
027:        /**
028:         * Class which represents a <code>Property</code> range which is
029:         * restricted to integer values.
030:         * 
031:         * @author Michael Bell
032:         * @version $Revision: 1.2 $
033:         *
034:         */
035:        public class IntegerRange extends NumberRange {
036:
037:            /**
038:             * Integer range tag name
039:             */
040:            public final static String TAG_INTEGER_RANGE = "IntegerRange";
041:
042:            /**
043:             * The maximum limit for this range
044:             */
045:            private int m_nMax = -1;
046:
047:            /**
048:             * The minumum limit for this range
049:             */
050:            private int m_nMin = -1;
051:
052:            /**
053:             * The separator character used to separate range restrictions when compiling
054:             * the <code>String</code> representation for the database details field.
055:             */
056:            static final private String SEPARATOR = ":";
057:
058:            /**
059:             * Constructs a new <code>IntegerRange</code>
060:             */
061:            public IntegerRange() {
062:                super (Integer.class.getName());
063:            }
064:
065:            /* (non-Javadoc)
066:             * @see org.openharmonise.rm.resources.metadata.properties.ranges.Range#isValid(java.lang.Object)
067:             */
068:            public boolean isValid(Object obj) {
069:                boolean bIsValid = false;
070:
071:                if (obj instanceof  Integer) {
072:                    bIsValid = true;
073:                    int nVal = ((Integer) obj).intValue();
074:
075:                    if (hasMin() == true) {
076:                        int nMin = m_nMin;
077:
078:                        if (m_bMinExclusive == true) {
079:                            nMin = nMin + 1;
080:                        }
081:
082:                        if (nVal <= nMin) {
083:                            bIsValid = false;
084:                        }
085:                    }
086:
087:                    if (hasMax() == true && bIsValid == true) {
088:                        int nMax = m_nMax;
089:
090:                        if (m_bMinExclusive == true) {
091:                            nMax = nMax - 1;
092:                        }
093:
094:                        if (nVal >= nMax) {
095:                            bIsValid = false;
096:                        }
097:                    }
098:                }
099:
100:                return bIsValid;
101:            }
102:
103:            /**
104:             * Sets the maximum value for this range and whether it's an exclusive limit.
105:             * 
106:             * @param nMax the maximum integer limit for this range
107:             * @param bIsExclusive <code>true</code> if the maximum limit is exclusive,
108:             * otherwise <code>false</code>
109:             */
110:            public void setMax(int nMax, boolean bIsExclusive) {
111:                m_nMax = nMax;
112:                m_bMaxExclusive = bIsExclusive;
113:                hasMax(true);
114:                isChanged(true);
115:            }
116:
117:            /**
118:             * Sets the minimum value for this range and whether it's an exclusive limit.
119:             * 
120:             * @param nMax the minimum integer value for this range
121:             * @param bIsExclusive <code>true</code> if the minimum limit is exclusive,
122:             * otherwise <code>false</code>
123:             */
124:            public void setMin(int nMin, boolean bIsExclusive) {
125:                m_nMin = nMin;
126:                m_bMinExclusive = bIsExclusive;
127:                hasMin(true);
128:                isChanged(true);
129:            }
130:
131:            /**
132:             * Returns the minimum value this range will allow.
133:             * 
134:             * @return the minimum value this range will allow
135:             */
136:            public int getMin() {
137:                return m_nMin;
138:            }
139:
140:            /**
141:             * Returns the maximum value this range will allow.
142:             * 
143:             * @return the maximum value this range will allow
144:             */
145:            public int getMax() {
146:                return m_nMax;
147:            }
148:
149:            /* (non-Javadoc)
150:             * @see org.openharmonise.rm.resources.metadata.properties.ranges.Range#getDetails()
151:             */
152:            public String getDetails() {
153:
154:                if (isChanged()) {
155:                    StringBuffer strbuf = new StringBuffer();
156:
157:                    if (hasMin() == true) {
158:                        strbuf.append(m_nMin).append(SEPARATOR).append(
159:                                this .m_bMinExclusive);
160:                    } else {
161:                        strbuf.append(SEPARATOR);
162:                    }
163:                    strbuf.append(SEPARATOR);
164:                    if (hasMax() == true) {
165:                        strbuf.append(m_nMax).append(SEPARATOR).append(
166:                                this .m_bMaxExclusive);
167:                    } else {
168:                        strbuf.append(SEPARATOR);
169:                    }
170:                    super .setDetails(strbuf.toString());
171:                }
172:
173:                return super .getDetails();
174:            }
175:
176:            /* (non-Javadoc)
177:             * @see org.openharmonise.rm.resources.metadata.properties.ranges.Range#setDetails(java.lang.String)
178:             */
179:            public void setDetails(String sDetails) {
180:                if (sDetails != null) {
181:                    StringTokenizer tokenizer = new StringTokenizer(sDetails,
182:                            SEPARATOR);
183:
184:                    int i = 0;
185:                    int nTmp = 0;
186:                    while (tokenizer.hasMoreTokens()) {
187:                        String token = tokenizer.nextToken();
188:
189:                        if (token != null && token.length() > 0) {
190:                            if (i == 0 || i == 2) {
191:                                nTmp = Integer.parseInt(token);
192:
193:                                if (i == 0) {
194:                                    m_nMin = nTmp;
195:                                    hasMin(true);
196:
197:                                } else if (i == 2) {
198:                                    m_nMax = nTmp;
199:                                    hasMax(true);
200:                                }
201:                            } else {
202:                                if (i == 1) {
203:                                    m_bMinExclusive = Boolean.getBoolean(token);
204:                                } else if (i == 3) {
205:                                    m_bMaxExclusive = Boolean.getBoolean(token);
206:                                }
207:                            }
208:
209:                        }
210:                        i++;
211:                    }
212:                }
213:
214:                super .setDetails(sDetails);
215:            }
216:
217:            /* (non-Javadoc)
218:             * @see java.lang.Object#equals(java.lang.Object)
219:             */
220:            public boolean equals(Object obj) {
221:                boolean bResult = false;
222:
223:                if (obj instanceof  IntegerRange) {
224:                    if (super .equals(obj) == true) {
225:                        IntegerRange iRange = (IntegerRange) obj;
226:
227:                        if (m_nMin == iRange.getMin()
228:                                && m_nMax == iRange.getMax()) {
229:                            bResult = true;
230:                        }
231:                    }
232:                }
233:
234:                return bResult;
235:            }
236:
237:            /* (non-Javadoc)
238:             * @see org.openharmonise.rm.publishing.Publishable#getTagName()
239:             */
240:            public String getTagName() {
241:                return TAG_INTEGER_RANGE;
242:            }
243:
244:            /* (non-Javadoc)
245:             * @see org.openharmonise.rm.publishing.Publishable#populate(org.w3c.dom.Element, org.openharmonise.rm.publishing.State)
246:             */
247:            public void populate(Element xmlElement, State state)
248:                    throws PopulateException {
249:
250:                String sTagname = xmlElement.getTagName();
251:
252:                if (sTagname.equals(TAG_MAX)) {
253:                    setMax(getChildIntValue(xmlElement),
254:                            isExclusive(xmlElement));
255:                } else if (sTagname.equals(TAG_MIN)) {
256:                    setMin(getChildIntValue(xmlElement),
257:                            isExclusive(xmlElement));
258:                } else {
259:                    super .populate(xmlElement, state);
260:                }
261:
262:            }
263:
264:            /**
265:             * Returns the <code>int</code> value taken from the first child node
266:             * of the specified XML element.
267:             * 
268:             * @param xmlElement the XML element
269:             * @return the <code>int</code> value
270:             */
271:            private int getChildIntValue(Element el) {
272:                int nVal = 0;
273:
274:                String sVal = el.getFirstChild().getNodeValue();
275:
276:                if (sVal != null) {
277:                    nVal = Integer.parseInt(sVal);
278:                }
279:
280:                return nVal;
281:            }
282:        }
w__w__w__.j__a_v_a___2__s.__c__o___m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.