1 19 package org.openharmonise.rm.resources.metadata.properties.ranges; 20 21 import java.util.Vector ; 22 23 import org.openharmonise.rm.*; 24 import org.openharmonise.rm.factory.*; 25 import org.openharmonise.rm.publishing.*; 26 import org.openharmonise.rm.resources.publishing.Template; 27 import org.w3c.dom.*; 28 29 30 40 public abstract class AbstractRange implements Range, Publishable, Cloneable { 41 42 46 public static final String TAG_RANGE = "Range"; 47 48 51 public static final String TAG_RANGE_DETAILS = "RangeDetails"; 52 53 56 public static final String TAG_RANGE_OBJECT = "RangeObject"; 57 58 62 protected String m_sDetails = null; 63 64 67 protected String m_sObjectClassName = null; 68 69 73 private boolean m_bIsChanged = false; 74 75 78 public AbstractRange() { 79 } 80 81 86 public AbstractRange(String sObjectClassName) { 87 this(sObjectClassName, null); 88 } 89 90 97 public AbstractRange(String sObjectClassName, String sDetails) { 98 m_sObjectClassName = sObjectClassName; 99 m_sDetails = sDetails; 100 } 101 102 109 public boolean hasDetails() { 110 return m_sDetails != null; 111 } 112 113 116 public String getDetails() { 117 118 return m_sDetails; 119 } 120 121 124 public String getObject() { 125 126 return m_sObjectClassName; 127 } 128 129 132 abstract public boolean isValid(Object obj); 133 134 137 public void setDetails(String sDetails) { 138 m_sDetails = sDetails; 139 140 } 141 142 145 public Object clone() { 146 try { 147 return super.clone(); 148 } catch (CloneNotSupportedException e) { 149 return null; 150 } 151 } 152 153 156 public String getTagName() { 157 return TAG_RANGE; 158 } 159 160 163 public void populate(Element xmlElement, State state) 164 throws PopulateException { 165 String sTagName = xmlElement.getTagName(); 166 Text txt = null; 167 String sTemp = null; 168 169 if (sTagName.equals(getTagName()) == true || sTagName.equals(TAG_RANGE) == true) { 170 NodeList nodes = xmlElement.getChildNodes(); 171 172 for (int i = 0; i < nodes.getLength(); i++) { 173 if (nodes.item(i).getNodeType() != Node.ELEMENT_NODE) { 174 continue; 175 } 176 177 Element el = (Element) nodes.item(i); 178 populate(el, state); 179 } 180 } else if (sTagName.equals(TAG_RANGE_OBJECT)) { 181 NodeList nodes = xmlElement.getChildNodes(); 182 183 for(int i=0;i<nodes.getLength();i++) { 185 Node node = nodes.item(i); 186 187 if(node.getNodeType() == Node.TEXT_NODE) { 188 txt = (Text) node; 189 String sVal = txt.getNodeValue().trim(); 190 if(sVal.length() > 0) { 191 this.m_sObjectClassName = sVal; 192 break; 193 } 194 } else if(node.getNodeType() == Node.ELEMENT_NODE) { 195 try { 196 String sClassname = HarmoniseObjectFactory.getClassName((Element)node); 197 this.m_sObjectClassName = sClassname; 198 break; 199 } catch (HarmoniseFactoryException e) { 200 throw new PopulateException(e); 201 } 202 } 203 } 204 205 206 } else if (sTagName.equals(TAG_RANGE_DETAILS)) { 207 txt = (Text) xmlElement.getFirstChild(); 208 setDetails(txt.getNodeValue()); 209 } 210 211 } 212 213 216 public Element publish(Element topEl, HarmoniseOutput output, State state) 217 throws PublishException { 218 Element docEl = null; 219 NodeList nodes = null; 220 Text txt = null; 221 String sTagName = topEl.getTagName(); 222 223 try { 224 225 if (sTagName.equals(getTagName()) || sTagName.equals(TAG_RANGE)) { 226 docEl = output.createElement(getTagName()); 227 228 nodes = topEl.getChildNodes(); 229 } else if (sTagName.equals(TAG_RANGE_OBJECT)) { 230 docEl = output.createElement(sTagName); 231 txt = output.createTextNode(getObject()); 232 docEl.appendChild(txt); 233 output.copyChildren(docEl, topEl, new Vector ()); 234 } else if (sTagName.equals(TAG_RANGE_DETAILS)) { 235 docEl = output.createElement(sTagName); 236 txt = output.createTextNode(getDetails()); 237 docEl.appendChild(txt); 238 output.copyChildren(docEl, topEl, new Vector ()); 239 } 240 241 Element formEl; 243 Element el; 244 245 if (nodes != null) { 246 for (int i = 0; i < nodes.getLength(); i++) { 247 if (nodes.item(i).getNodeType() != Node.ELEMENT_NODE) { 248 continue; 249 } 250 251 formEl = (Element) nodes.item(i); 252 el = publish(formEl, output, state); 253 254 if (el != null) { 255 docEl.appendChild(el); 256 } 257 } 258 } 259 260 } catch (Exception ex) { 261 throw new PublishException(ex.getLocalizedMessage()); 262 } 263 264 return docEl; 265 } 266 267 270 public Element publish(Template template, HarmoniseOutput output, State state) 271 throws PublishException { 272 Element resultEl = null; 273 274 try { 275 276 resultEl = 277 publish(template.getTemplateRootElement(), output, state); 278 } catch (DataAccessException e) { 279 throw new PublishException(e); 280 } 281 282 return resultEl; 283 } 284 285 291 public void isChanged(boolean bIsChanged) { 292 m_bIsChanged = bIsChanged; 293 } 294 295 300 public boolean isChanged() { 301 return m_bIsChanged; 302 } 303 304 307 public boolean equals(Object obj) { 308 boolean bResult = false; 309 310 if (obj instanceof AbstractRange) { 311 AbstractRange range = (AbstractRange) obj; 312 313 if (this == range) { 314 bResult = true; 315 } else { 316 bResult = true; 317 318 bResult = m_sObjectClassName.equals(range.getObject()); 319 320 if (bResult == true) { 321 322 String sDetails = getDetails(); 323 String sOtherDetails = range.getDetails(); 324 325 if ((sDetails == null && sOtherDetails != null) 326 || (sOtherDetails == null && sDetails != null) 327 || (sDetails != null && sDetails.equals(sOtherDetails) == false)) { 328 bResult = false; 329 } 330 } 331 332 } 333 } 334 335 return bResult; 336 } 337 338 341 public String toString() { 342 StringBuffer strbuf = new StringBuffer (); 343 344 strbuf.append("range [obj - ").append(m_sObjectClassName).append("]"); 345 strbuf.append("[ details - ").append(m_sDetails).append("]"); 346 347 return strbuf.toString(); 348 } 349 350 351 354 abstract public Class getPropertyInstanceClass() throws ClassNotFoundException ; 355 356 } 357 | Popular Tags |