Java 类org.simpleframework.xml.stream.Position 实例源码

项目:simplexml    文件:CompositeArray.java   
/**
 * This <code>read</code> method will read the XML element list from
 * the provided node and deserialize its children as entry types.
 * This ensures each entry type is deserialized as a root type, that 
 * is, its <code>Root</code> annotation must be present and the
 * name of the entry element must match that root element name.
 * 
 * @param node this is the XML element that is to be deserialized
 * @param list this is the array that is to be deserialized
 * 
 * @return this returns the item to attach to the object contact
 */  
public Object read(InputNode node, Object list) throws Exception{
   int length = Array.getLength(list);

   for(int pos = 0; true; pos++) {
      Position line = node.getPosition();
      InputNode next = node.getNext();

      if(next == null) {
         return list;
      }
      if(pos >= length){
          throw new ElementException("Array length missing or incorrect for %s at %s", type, line);
      }
      read(next, list, pos);
   } 
}
项目:simplexml    文件:Composite.java   
/**
 * This <code>readAttribute</code> method is used for deserialization
 * of the provided node object using a delegate converter. This is
 * typically another <code>Composite</code> converter, or if the
 * node is an attribute a <code>Primitive</code> converter. When
 * the delegate converter has completed the deserialized value is
 * assigned to the contact.
 * 
 * @param node this is the node that contains the contact value
 * @param source the type of the object that is being deserialized
 * @param section this is the section to read the attribute from
 * @param map this is the map that contains the label objects
 */
private void readAttribute(InputNode node, Object source, Section section, LabelMap map) throws Exception {
   String name = node.getName();
   String path = section.getAttribute(name);
   Label label = map.getLabel(path);

   if(label == null) {
      Position line = node.getPosition();
      Class expect = context.getType(type, source);

      if(map.isStrict(context) && revision.isEqual()) {              
         throw new AttributeException("Attribute '%s' does not have a match in %s at %s", path, expect, line);
      }            
   } else {
      readInstance(node, source, label);
   }         
}
项目:simplexml    文件:Composite.java   
/**
 * This <code>readElement</code> method is used for deserialization
 * of the provided node object using a delegate converter. This is
 * typically another <code>Composite</code> converter, or if the
 * node is an attribute a <code>Primitive</code> converter. When
 * the delegate converter has completed the deserialized value is
 * assigned to the contact.
 * 
 * @param node this is the node that contains the contact value
 * @param source the type of the object that is being deserialized
 * @param section this is the section to read the element from
 * @param map this is the map that contains the label objects
 */
private void readElement(InputNode node, Object source, Section section, LabelMap map) throws Exception {
   String name = node.getName();
   String path = section.getPath(name); 
   Label label = map.getLabel(path);      

   if(label == null) {
      label = criteria.resolve(path);
   }
   if(label == null) {
      Position line = node.getPosition();
      Class expect = context.getType(type, source);

      if(map.isStrict(context) && revision.isEqual()) {              
         throw new ElementException("Element '%s' does not have a match in %s at %s", path, expect, line);
      } else {
         node.skip();                 
      }
   } else {
      readUnion(node, source, map, label);
   }         
}
项目:simplexml    文件:Composite.java   
/**
 * This <code>read</code> method is used to perform deserialization
 * of the provided node object using a delegate converter. This is
 * typically another <code>Composite</code> converter, or if the
 * node is an attribute a <code>Primitive</code> converter. When
 * the delegate converter has completed the deserialized value is
 * assigned to the contact.
 * 
 * @param node this is the node that contains the contact value
 * @param source the type of the object that is being deserialized
 * @param label this is the label used to create the converter
 */
private Object readInstance(InputNode node, Object source, Label label) throws Exception {    
   Object object = readVariable(node, source, label);

   if(object == null) {     
      Position line = node.getPosition();
      Class expect = context.getType(type, source);

      if(label.isRequired() && revision.isEqual()) {              
         throw new ValueRequiredException("Empty value for %s in %s at %s", label, expect, line);
      }
   } else {
      if(object != label.getEmpty(context)) {  
         criteria.set(label, object);
      }
   }
   return object;
}
项目:simplexml    文件:Composite.java   
/**
 * This method checks to see if there are any <code>Label</code>
 * objects remaining in the provided map that are required. This is
 * used when deserialization is performed to ensure the the XML
 * element deserialized contains sufficient details to satisfy the
 * XML schema class annotations. If there is a required label that
 * remains it is reported within the exception thrown.
 * 
 * @param node this is the node that contains the contact value
 * @param map this is the map to check for remaining labels
 * @param source this is the object that has been deserialized 
 */
private void validate(InputNode node, LabelMap map, Object source) throws Exception {
   Class expect = context.getType(type, source);
   Position line = node.getPosition();

   for(Label label : map) {
      if(label.isRequired() && revision.isEqual()) {
         throw new ValueRequiredException("Unable to satisfy %s for %s at %s", label, expect, line);
      }
      Object value = label.getEmpty(context);

      if(value != null) {
         criteria.set(label, value);
      }
   }      
}
项目:simplexml    文件:Composite.java   
/**
 * This <code>validateAttribute</code> method performs a validation
 * of the provided node object using a delegate converter. This is
 * typically another <code>Composite</code> converter, or if the
 * node is an attribute a <code>Primitive</code> converter. If this
 * fails validation then an exception is thrown to report the issue.
 * 
 * @param node this is the node that contains the contact value
 * @param section this is the section to validate this attribute in
 * @param map this is the map that contains the label objects
 */
private void validateAttribute(InputNode node, Section section, LabelMap map) throws Exception {
   Position line = node.getPosition();
   String name = node.getName();
   String path = section.getAttribute(name);
   Label label = map.getLabel(path);

   if(label == null) {
      Class expect = type.getType();

      if(map.isStrict(context) && revision.isEqual()) {              
         throw new AttributeException("Attribute '%s' does not exist for %s at %s", path, expect, line);
      }            
   } else {
      validate(node, label);
   }         
}
项目:simplexml    文件:Composite.java   
/**
 * This <code>validateElement</code> method performs a validation
 * of the provided node object using a delegate converter. This is
 * typically another <code>Composite</code> converter, or if the
 * node is an attribute a <code>Primitive</code> converter. If this
 * fails validation then an exception is thrown to report the issue.
 * 
 * @param node this is the node that contains the contact value
 * @param section this is the section to validate this element in
 * @param map this is the map that contains the label objects
 */
private void validateElement(InputNode node, Section section, LabelMap map) throws Exception {
   String name = node.getName();
   String path = section.getPath(name);
   Label label = map.getLabel(path);      

   if(label == null) {
      label = criteria.resolve(path);
   }
   if(label == null) {
      Position line = node.getPosition();
      Class expect = type.getType();

      if(map.isStrict(context) && revision.isEqual()) {              
         throw new ElementException("Element '%s' does not exist for %s at %s", path, expect, line);
      } else {
         node.skip();                 
      }
   } else {
      validateUnion(node, map, label);
   }         
}
项目:simplexml    文件:PrimitiveArray.java   
/**
 * This <code>read</code> method will read the XML element list from
 * the provided node and deserialize its children as entry types.
 * This will deserialize each entry type as a primitive value. In
 * order to do this the parent string provided forms the element.
 * 
 * @param node this is the XML element that is to be deserialized
 * @param list this is the array to read the array values in to
 * 
 * @return this returns the item to attach to the object contact
 */ 
public Object read(InputNode node, Object list) throws Exception{
   int length = Array.getLength(list);

   for(int pos = 0; true; pos++) {
      Position line = node.getPosition();
      InputNode next = node.getNext();

      if(next == null) {
         return list;            
      }
      if(pos >= length){
         throw new ElementException("Array length missing or incorrect for %s at %s", type, line);
      }
      Array.set(list, pos, root.read(next));
   } 
}
项目:simple-xml    文件:CompositeArray.java   
/**
 * This <code>read</code> method will read the XML element list from
 * the provided node and deserialize its children as entry types.
 * This ensures each entry type is deserialized as a root type, that 
 * is, its <code>Root</code> annotation must be present and the
 * name of the entry element must match that root element name.
 * 
 * @param node this is the XML element that is to be deserialized
 * @param list this is the array that is to be deserialized
 * 
 * @return this returns the item to attach to the object contact
 */  
public Object read(InputNode node, Object list) throws Exception{
   int length = Array.getLength(list);

   for(int pos = 0; true; pos++) {
      Position line = node.getPosition();
      InputNode next = node.getNext();

      if(next == null) {
         return list;
      }
      if(pos >= length){
          throw new ElementException("Array length missing or incorrect for %s at %s", type, line);
      }
      read(next, list, pos);
   } 
}
项目:simple-xml    文件:Composite.java   
/**
 * This <code>readAttribute</code> method is used for deserialization
 * of the provided node object using a delegate converter. This is
 * typically another <code>Composite</code> converter, or if the
 * node is an attribute a <code>Primitive</code> converter. When
 * the delegate converter has completed the deserialized value is
 * assigned to the contact.
 * 
 * @param node this is the node that contains the contact value
 * @param source the type of the object that is being deserialized
 * @param section this is the section to read the attribute from
 * @param map this is the map that contains the label objects
 */
private void readAttribute(InputNode node, Object source, Section section, LabelMap map) throws Exception {
   String name = node.getName();
   String path = section.getAttribute(name);
   Label label = map.getLabel(path);

   if(label == null) {
      Position line = node.getPosition();
      Class expect = context.getType(type, source);

      if(map.isStrict(context) && revision.isEqual()) {              
         throw new AttributeException("Attribute '%s' does not have a match in %s at %s", path, expect, line);
      }            
   } else {
      readInstance(node, source, label);
   }         
}
项目:simple-xml    文件:Composite.java   
/**
 * This <code>readElement</code> method is used for deserialization
 * of the provided node object using a delegate converter. This is
 * typically another <code>Composite</code> converter, or if the
 * node is an attribute a <code>Primitive</code> converter. When
 * the delegate converter has completed the deserialized value is
 * assigned to the contact.
 * 
 * @param node this is the node that contains the contact value
 * @param source the type of the object that is being deserialized
 * @param section this is the section to read the element from
 * @param map this is the map that contains the label objects
 */
private void readElement(InputNode node, Object source, Section section, LabelMap map) throws Exception {
   String name = node.getName();
   String path = section.getPath(name); 
   Label label = map.getLabel(path);      

   if(label == null) {
      label = criteria.resolve(path);
   }
   if(label == null) {
      Position line = node.getPosition();
      Class expect = context.getType(type, source);

      if(map.isStrict(context) && revision.isEqual()) {              
         throw new ElementException("Element '%s' does not have a match in %s at %s", path, expect, line);
      } else {
         node.skip();                 
      }
   } else {
      readUnion(node, source, map, label);
   }         
}
项目:simple-xml    文件:Composite.java   
/**
 * This <code>read</code> method is used to perform deserialization
 * of the provided node object using a delegate converter. This is
 * typically another <code>Composite</code> converter, or if the
 * node is an attribute a <code>Primitive</code> converter. When
 * the delegate converter has completed the deserialized value is
 * assigned to the contact.
 * 
 * @param node this is the node that contains the contact value
 * @param source the type of the object that is being deserialized
 * @param label this is the label used to create the converter
 */
private Object readInstance(InputNode node, Object source, Label label) throws Exception {    
   Object object = readVariable(node, source, label);

   if(object == null) {     
      Position line = node.getPosition();
      Class expect = context.getType(type, source);

      if(label.isRequired() && revision.isEqual()) {              
         throw new ValueRequiredException("Empty value for %s in %s at %s", label, expect, line);
      }
   } else {
      if(object != label.getEmpty(context)) {  
         criteria.set(label, object);
      }
   }
   return object;
}
项目:simple-xml    文件:Composite.java   
/**
 * This method checks to see if there are any <code>Label</code>
 * objects remaining in the provided map that are required. This is
 * used when deserialization is performed to ensure the the XML
 * element deserialized contains sufficient details to satisfy the
 * XML schema class annotations. If there is a required label that
 * remains it is reported within the exception thrown.
 * 
 * @param node this is the node that contains the contact value
 * @param map this is the map to check for remaining labels
 * @param source this is the object that has been deserialized 
 */
private void validate(InputNode node, LabelMap map, Object source) throws Exception {
   Class expect = context.getType(type, source);
   Position line = node.getPosition();

   for(Label label : map) {
      if(label.isRequired() && revision.isEqual()) {
         throw new ValueRequiredException("Unable to satisfy %s for %s at %s", label, expect, line);
      }
      Object value = label.getEmpty(context);

      if(value != null) {
         criteria.set(label, value);
      }
   }      
}
项目:simple-xml    文件:Composite.java   
/**
 * This <code>validateAttribute</code> method performs a validation
 * of the provided node object using a delegate converter. This is
 * typically another <code>Composite</code> converter, or if the
 * node is an attribute a <code>Primitive</code> converter. If this
 * fails validation then an exception is thrown to report the issue.
 * 
 * @param node this is the node that contains the contact value
 * @param section this is the section to validate this attribute in
 * @param map this is the map that contains the label objects
 */
private void validateAttribute(InputNode node, Section section, LabelMap map) throws Exception {
   Position line = node.getPosition();
   String name = node.getName();
   String path = section.getAttribute(name);
   Label label = map.getLabel(path);

   if(label == null) {
      Class expect = type.getType();

      if(map.isStrict(context) && revision.isEqual()) {              
         throw new AttributeException("Attribute '%s' does not exist for %s at %s", path, expect, line);
      }            
   } else {
      validate(node, label);
   }         
}
项目:simple-xml    文件:Composite.java   
/**
 * This <code>validateElement</code> method performs a validation
 * of the provided node object using a delegate converter. This is
 * typically another <code>Composite</code> converter, or if the
 * node is an attribute a <code>Primitive</code> converter. If this
 * fails validation then an exception is thrown to report the issue.
 * 
 * @param node this is the node that contains the contact value
 * @param section this is the section to validate this element in
 * @param map this is the map that contains the label objects
 */
private void validateElement(InputNode node, Section section, LabelMap map) throws Exception {
   String name = node.getName();
   String path = section.getPath(name);
   Label label = map.getLabel(path);      

   if(label == null) {
      label = criteria.resolve(path);
   }
   if(label == null) {
      Position line = node.getPosition();
      Class expect = type.getType();

      if(map.isStrict(context) && revision.isEqual()) {              
         throw new ElementException("Element '%s' does not exist for %s at %s", path, expect, line);
      } else {
         node.skip();                 
      }
   } else {
      validateUnion(node, map, label);
   }         
}
项目:simple-xml    文件:PrimitiveArray.java   
/**
 * This <code>read</code> method will read the XML element list from
 * the provided node and deserialize its children as entry types.
 * This will deserialize each entry type as a primitive value. In
 * order to do this the parent string provided forms the element.
 * 
 * @param node this is the XML element that is to be deserialized
 * @param list this is the array to read the array values in to
 * 
 * @return this returns the item to attach to the object contact
 */ 
public Object read(InputNode node, Object list) throws Exception{
   int length = Array.getLength(list);

   for(int pos = 0; true; pos++) {
      Position line = node.getPosition();
      InputNode next = node.getNext();

      if(next == null) {
         return list;            
      }
      if(pos >= length){
         throw new ElementException("Array length missing or incorrect for %s at %s", type, line);
      }
      Array.set(list, pos, root.read(next));
   } 
}
项目:simplexml    文件:Factory.java   
/**
 * This is used to get a possible override from the provided node.
 * If the node provided is an element then this checks for a  
 * specific class override using the <code>Strategy</code> object.
 * If the strategy cannot resolve a class then this will return 
 * null. If the resolved <code>Value</code> is not assignable to 
 * the field then this will thrown an exception.
 * 
 * @param node this is the node used to search for the override
 * 
 * @return this returns null if no override type can be found
 * 
 * @throws Exception if the override type is not compatible
 */
protected Value getOverride(InputNode node) throws Exception {
   Value value = getConversion(node);      

   if(value != null) {
      Position line = node.getPosition();
      Class proposed = value.getType();
      Class expect = getType();

      if(!isCompatible(expect, proposed)) {
         throw new InstantiationException("Incompatible %s for %s at %s", proposed, type, line);              
      }
   }         
   return value; 
}
项目:simplexml    文件:CompositeKey.java   
/**
 * This method is used to read the key value from the node. The 
 * value read from the node is resolved using the template filter.
 * If the key value can not be found according to the annotation
 * attributes then null is assumed and returned.
 * 
 * @param node this is the node to read the key value from
 * 
 * @return this returns the value deserialized from the node
 */ 
public Object read(InputNode node) throws Exception { 
   Position line = node.getPosition();
   Class expect = type.getType();
   String name = entry.getKey();

   if(name == null) {
      name = context.getName(expect);
   }
   if(entry.isAttribute()) {
      throw new AttributeException("Can not have %s as an attribute for %s at %s", expect, entry, line);
   }
   return read(node, name);
}
项目:simplexml    文件:CompositeKey.java   
/**
 * This method is used to read the key value from the node. The 
 * value read from the node is resolved using the template filter.
 * If the key value can not be found according to the annotation
 * attributes then null is assumed and the node is valid.
 * 
 * @param node this is the node to read the key value from
 * 
 * @return this returns the value deserialized from the node
 */ 
public boolean validate(InputNode node) throws Exception { 
   Position line = node.getPosition();
   Class expect = type.getType();
   String name = entry.getKey();

   if(name == null) {
      name = context.getName(expect);
   }
   if(entry.isAttribute()) {
      throw new ElementException("Can not have %s as an attribute for %s at %s", expect, entry, line);
   }
   return validate(node, name);
}
项目:simplexml    文件:Variable.java   
/**
 * This <code>read</code> method will perform a read using the
 * provided object with the repeater. Reading with this method
 * ensures that any additional XML elements within the source
 * will be added to the value.
 * 
 *  @param node this is the node that contains the extra data
 *  
 *  @return this will return the original deserialized object
 */
public Object read(InputNode node, Object value) throws Exception {
   Position line = node.getPosition();
   String name = node.getName();         

   if(reader instanceof Repeater) {
      Repeater repeat = (Repeater) reader;

      return repeat.read(node, value);
   }
   throw new PersistenceException("Element '%s' is already used with %s at %s", name, label, line);
}
项目:simplexml    文件:Variable.java   
/**
 * This <code>read</code> method will perform a read using the
 * provided object with the repeater. Reading with this method
 * ensures that any additional XML elements within the source
 * will be added to the value.
 * 
 *  @param node this is the node that contains the extra data
 *  
 *  @return this will return the original deserialized object
 */
public boolean validate(InputNode node) throws Exception {
   Position line = node.getPosition();
   String name = node.getName();         

   if(reader instanceof Repeater) {
      Repeater repeat = (Repeater) reader;

      return repeat.validate(node);
   }
   throw new PersistenceException("Element '%s' declared twice at %s", name, line);
}
项目:simplexml    文件:Composite.java   
/**
 * The <code>readResolve</code> method is used to determine if there 
 * is a resolution method which can be used to substitute the object
 * deserialized. The resolve method is used when an object wishes 
 * to provide a substitute within the deserialized object graph.
 * This acts as an equivalent to the Java Object Serialization
 * <code>readResolve</code> method for the object deserialization.
 * 
 * @param node the XML element object provided as a replacement
 * @param source the type of the object that is being deserialized
 * @param caller this is used to invoke the callback methods
 * 
 * @return this returns a replacement for the deserialized object
 */
private Object readResolve(InputNode node, Object source, Caller caller) throws Exception {
   if(source != null) {
      Position line = node.getPosition();
      Object value = caller.resolve(source);
      Class expect = type.getType();
      Class real = value.getClass();

      if(!expect.isAssignableFrom(real)) {
         throw new ElementException("Type %s does not match %s at %s", real, expect, line);              
      }
      return value;
   }
   return source;
}
项目:simplexml    文件:Composite.java   
/**
 * This <code>validate</code> method is used to perform validation
 * of the provided node object using a delegate converter. This is
 * typically another <code>Composite</code> converter, or if the
 * node is an attribute a <code>Primitive</code> converter. If this
 * fails validation then an exception is thrown to report the issue.
 * 
 * @param node this is the node that contains the contact value
 * @param label this is the label used to create the converter
 */
private void validate(InputNode node, Label label) throws Exception {    
   Converter reader = label.getConverter(context);      
   Position line = node.getPosition();
   Class expect = type.getType();
   boolean valid = reader.validate(node);

   if(valid == false) {     
     throw new PersistenceException("Invalid value for %s in %s at %s", label, expect, line);
   }
   criteria.set(label, null);
}
项目:simplexml    文件:Composite.java   
/**
 * This method checks to see if there are any <code>Label</code>
 * objects remaining in the provided map that are required. This is
 * used when validation is performed to ensure the the XML element 
 * validated contains sufficient details to satisfy the XML schema 
 * class annotations. If there is a required label that remains it 
 * is reported within the exception thrown.
 * 
 * @param node this is the node that contains the composite data
 * @param map this contains the converters to perform validation
 */
private void validate(InputNode node, LabelMap map) throws Exception {     
   Position line = node.getPosition();

   for(Label label : map) {
      Class expect = type.getType();

      if(label.isRequired() && revision.isEqual()) {
         throw new ValueRequiredException("Unable to satisfy %s for %s at %s", label, expect, line);
      }
   }      
}
项目:simple-xml    文件:Factory.java   
/**
 * This is used to get a possible override from the provided node.
 * If the node provided is an element then this checks for a  
 * specific class override using the <code>Strategy</code> object.
 * If the strategy cannot resolve a class then this will return 
 * null. If the resolved <code>Value</code> is not assignable to 
 * the field then this will thrown an exception.
 * 
 * @param node this is the node used to search for the override
 * 
 * @return this returns null if no override type can be found
 * 
 * @throws Exception if the override type is not compatible
 */
protected Value getOverride(InputNode node) throws Exception {
   Value value = getConversion(node);      

   if(value != null) {
      Position line = node.getPosition();
      Class proposed = value.getType();
      Class expect = getType();

      if(!isCompatible(expect, proposed)) {
         throw new InstantiationException("Incompatible %s for %s at %s", proposed, type, line);              
      }
   }         
   return value; 
}
项目:simple-xml    文件:CompositeKey.java   
/**
 * This method is used to read the key value from the node. The 
 * value read from the node is resolved using the template filter.
 * If the key value can not be found according to the annotation
 * attributes then null is assumed and returned.
 * 
 * @param node this is the node to read the key value from
 * 
 * @return this returns the value deserialized from the node
 */ 
public Object read(InputNode node) throws Exception { 
   Position line = node.getPosition();
   Class expect = type.getType();
   String name = entry.getKey();

   if(name == null) {
      name = context.getName(expect);
   }
   if(entry.isAttribute()) {
      throw new AttributeException("Can not have %s as an attribute for %s at %s", expect, entry, line);
   }
   return read(node, name);
}
项目:simple-xml    文件:CompositeKey.java   
/**
 * This method is used to read the key value from the node. The 
 * value read from the node is resolved using the template filter.
 * If the key value can not be found according to the annotation
 * attributes then null is assumed and the node is valid.
 * 
 * @param node this is the node to read the key value from
 * 
 * @return this returns the value deserialized from the node
 */ 
public boolean validate(InputNode node) throws Exception { 
   Position line = node.getPosition();
   Class expect = type.getType();
   String name = entry.getKey();

   if(name == null) {
      name = context.getName(expect);
   }
   if(entry.isAttribute()) {
      throw new ElementException("Can not have %s as an attribute for %s at %s", expect, entry, line);
   }
   return validate(node, name);
}
项目:simple-xml    文件:Variable.java   
/**
 * This <code>read</code> method will perform a read using the
 * provided object with the repeater. Reading with this method
 * ensures that any additional XML elements within the source
 * will be added to the value.
 * 
 *  @param node this is the node that contains the extra data
 *  
 *  @return this will return the original deserialized object
 */
public Object read(InputNode node, Object value) throws Exception {
   Position line = node.getPosition();
   String name = node.getName();         

   if(reader instanceof Repeater) {
      Repeater repeat = (Repeater) reader;

      return repeat.read(node, value);
   }
   throw new PersistenceException("Element '%s' is already used with %s at %s", name, label, line);
}
项目:simple-xml    文件:Variable.java   
/**
 * This <code>read</code> method will perform a read using the
 * provided object with the repeater. Reading with this method
 * ensures that any additional XML elements within the source
 * will be added to the value.
 * 
 *  @param node this is the node that contains the extra data
 *  
 *  @return this will return the original deserialized object
 */
public boolean validate(InputNode node) throws Exception {
   Position line = node.getPosition();
   String name = node.getName();         

   if(reader instanceof Repeater) {
      Repeater repeat = (Repeater) reader;

      return repeat.validate(node);
   }
   throw new PersistenceException("Element '%s' declared twice at %s", name, line);
}
项目:simple-xml    文件:Composite.java   
/**
 * The <code>readResolve</code> method is used to determine if there 
 * is a resolution method which can be used to substitute the object
 * deserialized. The resolve method is used when an object wishes 
 * to provide a substitute within the deserialized object graph.
 * This acts as an equivalent to the Java Object Serialization
 * <code>readResolve</code> method for the object deserialization.
 * 
 * @param node the XML element object provided as a replacement
 * @param source the type of the object that is being deserialized
 * @param caller this is used to invoke the callback methods
 * 
 * @return this returns a replacement for the deserialized object
 */
private Object readResolve(InputNode node, Object source, Caller caller) throws Exception {
   if(source != null) {
      Position line = node.getPosition();
      Object value = caller.resolve(source);
      Class expect = type.getType();
      Class real = value.getClass();

      if(!expect.isAssignableFrom(real)) {
         throw new ElementException("Type %s does not match %s at %s", real, expect, line);              
      }
      return value;
   }
   return source;
}
项目:simple-xml    文件:Composite.java   
/**
 * This <code>validate</code> method is used to perform validation
 * of the provided node object using a delegate converter. This is
 * typically another <code>Composite</code> converter, or if the
 * node is an attribute a <code>Primitive</code> converter. If this
 * fails validation then an exception is thrown to report the issue.
 * 
 * @param node this is the node that contains the contact value
 * @param label this is the label used to create the converter
 */
private void validate(InputNode node, Label label) throws Exception {    
   Converter reader = label.getConverter(context);      
   Position line = node.getPosition();
   Class expect = type.getType();
   boolean valid = reader.validate(node);

   if(valid == false) {     
     throw new PersistenceException("Invalid value for %s in %s at %s", label, expect, line);
   }
   criteria.set(label, null);
}
项目:simple-xml    文件:Composite.java   
/**
 * This method checks to see if there are any <code>Label</code>
 * objects remaining in the provided map that are required. This is
 * used when validation is performed to ensure the the XML element 
 * validated contains sufficient details to satisfy the XML schema 
 * class annotations. If there is a required label that remains it 
 * is reported within the exception thrown.
 * 
 * @param node this is the node that contains the composite data
 * @param map this contains the converters to perform validation
 */
private void validate(InputNode node, LabelMap map) throws Exception {     
   Position line = node.getPosition();

   for(Label label : map) {
      Class expect = type.getType();

      if(label.isRequired() && revision.isEqual()) {
         throw new ValueRequiredException("Unable to satisfy %s for %s at %s", label, expect, line);
      }
   }      
}
项目:nfce    文件:StringNullConverterTest.java   
@Override
public Position getPosition() {
    return null;
}
项目:nfe    文件:StringNullConverterTest.java   
@Override
public Position getPosition() {
    return null;
}
项目:simplexml    文件:CompositeKey.java   
/**
 * This method is used to read the key value from the node. The 
 * value read from the node is resolved using the template filter.
 * If the key value can not be found according to the annotation
 * attributes then null is assumed and returned.
 * 
 * @param node this is the node to read the key value from
 * @param value this is the value to deserialize in to
 * 
 * @return this returns the value deserialized from the node
 * 
 * @throws Exception if value is not null an exception is thrown
 */ 
public Object read(InputNode node, Object value) throws Exception {
   Position line = node.getPosition();
   Class expect = type.getType();

   if(value != null) {
      throw new PersistenceException("Can not read key of %s for %s at %s", expect, entry, line);
   }
   return read(node);
}
项目:simple-xml    文件:CompositeKey.java   
/**
 * This method is used to read the key value from the node. The 
 * value read from the node is resolved using the template filter.
 * If the key value can not be found according to the annotation
 * attributes then null is assumed and returned.
 * 
 * @param node this is the node to read the key value from
 * @param value this is the value to deserialize in to
 * 
 * @return this returns the value deserialized from the node
 * 
 * @throws Exception if value is not null an exception is thrown
 */ 
public Object read(InputNode node, Object value) throws Exception {
   Position line = node.getPosition();
   Class expect = type.getType();

   if(value != null) {
      throw new PersistenceException("Can not read key of %s for %s at %s", expect, entry, line);
   }
   return read(node);
}