Clover coverage report - JBind Project
Coverage timestamp: Fr Mai 28 2004 11:17:36 CEST
file stats: LOC: 154   Methods: 12
NCLOC: 109   Classes: 1
This license of Clover is provided to support the development of JBind only. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover.
 
 Source file Conditionals Statements Methods TOTAL
AbstractSimpleData.java 64,3% 71,4% 83,3% 72%
 1   
 /*
 2   
  * JBind
 3   
  *
 4   
  * Copyright (c) by Stefan Wachter. All rights reserved.
 5   
  *
 6   
  * Usage, modification, and redistribution is subject to license terms that are
 7   
  * available at 'http://www.jbind.org'. The JBind license is like the
 8   
  * 'Apache Software License V 1.1'.
 9   
  */
 10   
 package org.jbind.xml.instance.data;
 11   
 
 12   
 import org.jbind.util.reflect.ReflectUtil;
 13   
 import org.jbind.xml.base.WhiteSpaceProcessing;
 14   
 import org.jbind.xml.core.base.ITextContentMemento;
 15   
 import org.jbind.xml.core.data.IAnySimpleTypeData;
 16   
 import org.jbind.xml.core.data.IDataVisitor;
 17   
 import org.jbind.xml.core.type.ISimpleType;
 18   
 import org.jbind.xml.msg.IConstraintViolations;
 19   
 import org.jbind.xml.msg.XmlException;
 20   
 import org.jbind.xml.msg.XmlMessages;
 21   
 import org.jbind.xml.schema.constraint.LocalCheckContext;
 22   
 
 23   
 public abstract class AbstractSimpleData extends AbstractData implements IAnySimpleTypeData {
 24   
 
 25   
   /**
 26   
    * <i>(optional)</i>. If the normalized value is not set then it is calculated
 27   
    * from the simple storage object of the data by calling the {@link
 28   
    * #getCanonicalForm_ getCanonicalForm_} method.
 29   
    */
 30   
   private String myNormalizedValue = null;
 31   
 
 32  650
   public final String getLexicalValue_() {
 33  650
     return getImpl_().getTextContent();
 34   
   }
 35   
 
 36  321
   public final String getNormalizedValue_() {
 37  321
     String res = null;
 38  321
     if (null != myNormalizedValue) {
 39  321
       res = myNormalizedValue;
 40   
     } else {
 41  0
       res = getCanonicalForm_();
 42   
     }
 43  321
     return res;
 44   
   }
 45   
 
 46  650
   public final String toString() {
 47  650
     return getLexicalValue_();
 48   
   }
 49   
 
 50  1
   public final void setLexicalValue_(String aValue) throws XmlException {
 51  1
     String saveNormalizedValue = myNormalizedValue;
 52  1
     ITextContentMemento saveTextContent = getImpl_().saveTextContent();
 53  1
     Object simpleStorageObject = getSimpleStorageObject();
 54   
 
 55  1
     getImpl_().setTextContent(aValue);
 56  1
     try {
 57  1
       acceptImpl_();
 58  1
       IConstraintViolations violations = XmlMessages.constraintViolations();
 59  1
       LocalCheckContext context = new LocalCheckContext(this, violations);
 60  1
       getType_().checkConstraints(context);
 61  1
       if (!violations.isEmpty()) {
 62  0
         throw new XmlException(violations);
 63   
       }
 64   
     } catch (XmlException e) {
 65   
       // rollback
 66  0
       myNormalizedValue = saveNormalizedValue;
 67  0
       getImpl_().restoreTextContent(saveTextContent);
 68  0
       setSimpleStorageObject(simpleStorageObject);
 69  0
       throw e;
 70   
     }
 71   
   }
 72   
 
 73  2542
   public final void acceptImpl_() throws XmlException {
 74  2542
     String tc = getImpl_().getTextContent();
 75  2542
     if (null != tc) {
 76  2542
       WhiteSpaceProcessing wsp = getType_().getConstraints().getWhiteSpaceProcessing();
 77  2542
       String normalizedValue = (null != wsp) ? wsp.process(tc) : tc;
 78  2542
       doAccept(normalizedValue);
 79   
     } else {
 80  0
       throw new XmlException(XmlMessages.missingSimpleData(getImpl_()));
 81   
     }
 82   
   }
 83   
 
 84   
   /**
 85   
    * Hook method that accepts the normalized value and converts it into a
 86   
    * corresponging internal representation (the so called simple storage object).
 87   
    * <p>
 88   
    * If an exception is raised during execution of the method then this data object
 89   
    * may be inconsistent. It is in the responsibility of the caller either to
 90   
    * rollback the changes or to discard this data object.
 91   
    *
 92   
    * @param aNormalizedValue <i>(required)</i>.
 93   
    * @throws XmlException Raised iff the string can not be converted
 94   
    * into the internal representation.
 95   
    */
 96  2542
   protected void doAccept(String aNormalizedValue) throws XmlException {
 97  2542
     myNormalizedValue = aNormalizedValue;
 98   
   }
 99   
 
 100   
   protected abstract void setSimpleStorageObject(Object anObject);
 101   
 
 102  13
   protected final IConstraintViolations completeSimpleStorageAssignment_() {
 103  13
     IConstraintViolations violations = XmlMessages.constraintViolations();
 104  13
     if (null == getSimpleStorageObject()) {
 105  1
       violations.add(XmlMessages.triedToAssignNull(null));
 106   
     } else {
 107  12
       String saveNormalizedValue = myNormalizedValue;
 108  12
       ITextContentMemento saveTextContent = getImpl_().saveTextContent();
 109  12
       myNormalizedValue = null;
 110  12
       getImpl_().setTextContent(this);
 111  12
       LocalCheckContext context = new LocalCheckContext(this, violations);
 112  12
       getType_().checkConstraints(context);
 113  12
       if (violations.isEmpty() && (null != getFixed_()) && !getFixed_().simpleStorageValueEquals(this)) {
 114  2
         violations.add(XmlMessages.triedToChangeFixed(getFixed_(), getCanonicalForm_(), null));
 115   
       }
 116  12
       if (!violations.isEmpty()) {
 117   
         // rollback the assignment
 118  2
         myNormalizedValue = saveNormalizedValue;
 119  2
         getImpl_().restoreTextContent(saveTextContent);
 120   
       }
 121   
     }
 122  13
     return violations;
 123   
   }
 124   
 
 125  155
   public String getTextContent_() {
 126  155
     return getCanonicalForm_();
 127   
   }
 128   
 
 129  0
   public final Object getObject() {
 130  0
     return getSimpleStorageObject();
 131   
   }
 132   
 
 133  0
   public final void setObject(Object aNewValue) throws XmlException {
 134  0
     Object oldValue = getSimpleStorageObject();
 135  0
     try {
 136  0
       setSimpleStorageObject(aNewValue);
 137   
     } catch (ClassCastException e) {
 138  0
       throw new XmlException(XmlMessages.invalidSimpleStorageType(aNewValue.getClass().getName(), ReflectUtil.getWrapperClass(((ISimpleType)getType_()).getSimpleStorageType()).getName(), null));
 139   
     }
 140  0
     IConstraintViolations violations = completeSimpleStorageAssignment_();
 141  0
     if (!violations.isEmpty()) {
 142  0
       setSimpleStorageObject(oldValue);
 143  0
       throw new XmlException(violations);
 144   
     }
 145   
   }
 146   
 
 147  250
   protected void doAcceptStarts_(IDataVisitor aVisitor) {
 148  250
     aVisitor.visitAnySimpleDataStarts(this);
 149   
   }
 150  250
   protected void doAcceptEnds_(IDataVisitor aVisitor) {
 151  250
     aVisitor.visitAnySimpleDataEnds(this);
 152   
   }
 153   
 }
 154