Java Code Examples for org.simpleframework.xml.stream.NodeMap#getNode()

The following examples show how to use org.simpleframework.xml.stream.NodeMap#getNode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RegistryStrategy.java    From simplexml with Apache License 2.0 6 votes vote down vote up
/**
 * This is used to read the <code>Value</code> which will be used 
 * to represent the deserialized object. If there is an binding
 * present then the value will contain an object instance. If it
 * does not then it is up to the internal strategy to determine 
 * what the returned value contains.
 * 
 * @param type this is the type that represents a method or field
 * @param node this is the node representing the XML element
 * @param value this is the value from the internal strategy
 * 
 * @return the value representing the deserialized value
 */   
private Value read(Type type, NodeMap<InputNode> node, Value value) throws Exception {
   Converter converter = lookup(type, value);
   InputNode source = node.getNode();
   
   if(converter != null) {
      Object data = converter.read(source);
      Class actual = type.getType();
   
      if(value != null) {
         value.setValue(data);
      }
      return new Reference(value, data, actual);
   }
   return value;
}
 
Example 2
Source File: AnnotationStrategy.java    From simplexml with Apache License 2.0 6 votes vote down vote up
/**
 * This is used to read the <code>Value</code> which will be used 
 * to represent the deserialized object. If there is an annotation
 * present then the value will contain an object instance. If it
 * does not then it is up to the internal strategy to determine 
 * what the returned value contains.
 * 
 * @param type this is the type that represents a method or field
 * @param node this is the node representing the XML element
 * @param value this is the value from the internal strategy
 * 
 * @return the value representing the deserialized value
 */
private Value read(Type type, NodeMap<InputNode> node, Value value) throws Exception {
   Converter converter = scanner.getConverter(type, value);
   InputNode parent = node.getNode();
   
   if(converter != null) {
      Object data = converter.read(parent);
      Class actual = type.getType();
      
      if(value != null) {
         value.setValue(data);
      }
      return new Reference(value, data, actual);
   }
   return value;
}
 
Example 3
Source File: AnnotationConverterTest.java    From simplexml with Apache License 2.0 6 votes vote down vote up
public Value read(Type type, NodeMap<InputNode> node, Map map) throws Exception {
   Value value = strategy.read(type, node, map);
   Convert convert = type.getAnnotation(Convert.class);
   InputNode parent = node.getNode();
   
   if(convert != null) {
      Class<? extends Converter> converterClass = convert.value();
      Constructor<? extends Converter> converterConstructor = converterClass.getDeclaredConstructor();
      
      if(!converterConstructor.isAccessible()) {
         converterConstructor.setAccessible(true);
      }
      Converter converter = converterConstructor.newInstance();
      Object result = converter.read(parent);
      return new Wrapper(result);
   }
   return value;
}
 
Example 4
Source File: AnnotationConverterTest.java    From simplexml with Apache License 2.0 6 votes vote down vote up
public boolean write(Type type, Object value, NodeMap<OutputNode> node, Map map) throws Exception {
   Convert convert = type.getAnnotation(Convert.class);
   OutputNode parent = node.getNode();
   
   if(convert != null) {
      Class<? extends Converter> converterClass = convert.value();
      Constructor<? extends Converter> converterConstructor = converterClass.getDeclaredConstructor();
      
      if(!converterConstructor.isAccessible()) {
         converterConstructor.setAccessible(true);
      }
      Converter converter = converterConstructor.newInstance();
      converter.write(parent, value);
      return true;
   }
   return strategy.write(type, value, node, map);
}
 
Example 5
Source File: ValidationTestCase.java    From simplexml with Apache License 2.0 5 votes vote down vote up
public void read(Type type, NodeMap<InputNode> node){
   InputNode element = node.getNode();
   if(element.isRoot()) {
      Object source = element.getSource();
      Class sourceType = source.getClass();
      Class itemType = type.getType();
      System.out.printf(">>>>> ELEMENT=[%s]%n>>>>> TYPE=[%s]%n>>>>> SOURCE=[%s]%n", element, itemType, sourceType);
   }
}
 
Example 6
Source File: ConversionTest.java    From simplexml with Apache License 2.0 5 votes vote down vote up
public Value read(Type field, NodeMap<InputNode> node, Map map) throws Exception {
   Value value = strategy.read(field, node, map);
   Class type = value == null ? field.getType() : value.getType();
   Converter converter = registry.resolve(type);
   if(converter != null) {
      InputNode source = node.getNode();
      Object data = converter.read(source);
      return new Wrapper(value, data);
   }
   return value;
}
 
Example 7
Source File: ConversionTest.java    From simplexml with Apache License 2.0 5 votes vote down vote up
public boolean write(Type field, Object value, NodeMap<OutputNode> node, Map map) throws Exception {
   boolean reference = strategy.write(field, value, node, map);
   if(!reference) {
      Class type = value.getClass();
      Converter converter = registry.resolve(type);
      OutputNode source = node.getNode();
      if(converter != null) {
         converter.write(source, value);
         return true;
      }
      return false;
   }
   return reference;
}
 
Example 8
Source File: UARTActivity.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void write(final Type type, final NodeMap<OutputNode> node) {
	if (type.getType().equals(Command[].class)) {
		final OutputNode element = node.getNode();

		final StringBuilder builder = new StringBuilder("A configuration must have 9 commands, one for each button.\n        Possible icons are:");
		for (Command.Icon icon : Command.Icon.values())
			builder.append("\n          - ").append(icon.toString());
		element.setComment(builder.toString());
	}
}
 
Example 9
Source File: VisitorSetNodeNameTest.java    From simplexml with Apache License 2.0 4 votes vote down vote up
public void write(Type type, NodeMap<OutputNode> node) throws Exception {        
   OutputNode parent = node.getNode();
   String name = parent.getName();
   name = name.toUpperCase();
   parent.setName(name);
}
 
Example 10
Source File: RegistryStrategy.java    From simplexml with Apache License 2.0 3 votes vote down vote up
/**
 * This is used to serialize a representation of the object value
 * provided. If there is a <code>Registry</code> binding present
 * for the provided type then this will use the converter specified
 * to serialize a representation of the object. If however there
 * is no binding present then this will delegate to the internal 
 * strategy. This returns true if the serialization has completed.
 * 
 * @param type this is the type that represents the field or method
 * @param value this is the object instance to be serialized
 * @param node this is the XML element to be serialized to
 * 
 * @return this returns true if it was serialized, false otherwise
 */
private boolean write(Type type, Object value, NodeMap<OutputNode> node) throws Exception {
   Converter converter = lookup(type, value);
   OutputNode source = node.getNode();
   
   if(converter != null) {
      converter.write(source, value);
      return true;
   }
   return false;  
}
 
Example 11
Source File: AnnotationStrategy.java    From simplexml with Apache License 2.0 3 votes vote down vote up
/**
 * This is used to serialize a representation of the object value
 * provided. If there is a <code>Convert</code> annotation present
 * on the provided type then this will use the converter specified
 * to serialize a representation of the object. If however there
 * is no annotation then this will delegate to the internal 
 * strategy. This returns true if the serialization has completed.
 * 
 * @param type this is the type that represents the field or method
 * @param value this is the object instance to be serialized
 * @param node this is the XML element to be serialized to
 * 
 * @return this returns true if it was serialized, false otherwise
 */
private boolean write(Type type, Object value, NodeMap<OutputNode> node) throws Exception {
   Converter converter = scanner.getConverter(type, value);
   OutputNode parent = node.getNode();
   
   if(converter != null) {
      converter.write(parent, value);
      return true;
   }
   return false;
}