| 1 19 package org.openharmonise.vfs.metadata.range; 20 21 import org.openharmonise.commons.xml.*; 22 import org.openharmonise.vfs.metadata.*; 23 import org.openharmonise.vfs.metadata.value.*; 24 import org.w3c.dom.Element ; 25 import org.w3c.dom.Node ; 26 import org.w3c.dom.NodeList ; 27 import org.w3c.dom.Text ; 28 29 30 37 public class IntegerRange extends AbstractRange implements Range { 38 39 42 private Integer m_nMinInclusive = null; 43 44 47 private Integer m_nMaxInclusive = null; 48 49 52 private Integer m_nMinExclusive = null; 53 54 57 private Integer m_nMaxExclusive = null; 58 59 62 public IntegerRange() { 63 super(); 64 } 65 66 67 73 public Integer getMinimum() { 74 if( this.m_nMinInclusive!=null ) { 75 return this.m_nMinInclusive; 76 } else { 77 return this.m_nMinExclusive; 78 } 79 } 80 81 87 public Integer getMaximum() { 88 if( this.m_nMaxInclusive!=null ) { 89 return this.m_nMaxInclusive; 90 } else { 91 return this.m_nMaxExclusive; 92 } 93 } 94 95 100 public void setMinimum(Integer nVal) { 101 this.m_nMinInclusive = nVal; 102 } 103 104 109 public void setMinimum(int nVal) { 110 this.m_nMinInclusive = new Integer (nVal); 111 } 112 113 118 public void setMaximum(Integer nVal) { 119 this.m_nMaxInclusive = nVal; 120 } 121 122 127 public void setMaximum(int nVal) { 128 this.m_nMaxInclusive = new Integer (nVal); 129 } 130 131 134 public ValidationResult validate(ValueInstance value) { 135 int nVal = ((IntegerValue)value).getValue(); 136 boolean bIsValid = true; 137 138 if(m_nMinInclusive != null) { 139 bIsValid = m_nMinInclusive.intValue() <= nVal; 140 } else if(m_nMinExclusive != null) { 141 bIsValid = m_nMinExclusive.intValue() < nVal; 142 } 143 144 if(bIsValid == true) { 145 if(m_nMaxInclusive != null) { 146 bIsValid = m_nMaxInclusive.intValue() >= nVal; 147 } else if(m_nMaxExclusive != null) { 148 bIsValid = m_nMaxExclusive.intValue() > nVal; 149 } 150 } 151 152 return new ValidationResult(bIsValid,""); 153 } 154 155 158 public void instantiate(Element elRange) { 159 Element elRestriction = XMLUtils.getFirstElementChild(elRange); 160 NodeList nl = elRestriction.getChildNodes(); 161 for(int i=0; i<nl.getLength();i++) { 162 Node node = nl.item(i); 163 if(node.getNodeType()==Node.ELEMENT_NODE) { 164 Element element = (Element )node; 165 if(element.getLocalName().equalsIgnoreCase("minInclusive")) { 166 Node node2 = element.getFirstChild(); 167 if( node2.getNodeType()==Node.TEXT_NODE) { 168 this.m_nMinInclusive = Integer.valueOf( ((Text )node2).getNodeValue() ); 169 } 170 } else if(element.getLocalName().equalsIgnoreCase("maxInclusive")) { 171 Node node2 = element.getFirstChild(); 172 if( node2.getNodeType()==Node.TEXT_NODE) { 173 this.m_nMaxInclusive = Integer.valueOf( ((Text )node2).getNodeValue() ); 174 } 175 } else if(element.getLocalName().equalsIgnoreCase("minExclusive")) { 176 Node node2 = element.getFirstChild(); 177 if( node2.getNodeType()==Node.TEXT_NODE) { 178 this.m_nMinExclusive = Integer.valueOf( ((Text )node2).getNodeValue() ); 179 } 180 } else if(element.getLocalName().equalsIgnoreCase("maxExclusive")) { 181 Node node2 = element.getFirstChild(); 182 if( node2.getNodeType()==Node.TEXT_NODE) { 183 this.m_nMaxExclusive = Integer.valueOf( ((Text )node2).getNodeValue() ); 184 } 185 } 186 } 187 } 188 } 189 190 public String toString() { 191 StringBuffer sBuff = new StringBuffer (); 192 193 sBuff.append("IntegerRange:\n"); 194 if(this.m_nMinInclusive!=null) { 195 sBuff.append("minInclusive: ").append(this.m_nMinInclusive).append("\n"); 196 } 197 if(this.m_nMaxInclusive!=null) { 198 sBuff.append("maxInclusive: ").append(this.m_nMaxInclusive).append("\n"); 199 } 200 if(this.m_nMinExclusive!=null) { 201 sBuff.append("minExclusive: ").append(this.m_nMinExclusive).append("\n"); 202 } 203 if(this.m_nMaxExclusive!=null) { 204 sBuff.append("maxExclusive: ").append(this.m_nMaxExclusive).append("\n"); 205 } 206 207 return sBuff.toString(); 208 } 209 210 } 211 | Popular Tags |