• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java NodeMap类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.simpleframework.xml.stream.NodeMap的典型用法代码示例。如果您正苦于以下问题:Java NodeMap类的具体用法?Java NodeMap怎么用?Java NodeMap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



NodeMap类属于org.simpleframework.xml.stream包,在下文中一共展示了NodeMap类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getParameters_withTwoAttributes_expectMapWithTwoProperties

import org.simpleframework.xml.stream.NodeMap; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void getParameters_withTwoAttributes_expectMapWithTwoProperties() throws Exception {
  NodeMap<InputNode> emptyNodeMap = Mockito.mock(NodeMap.class);
  when(inputNode.getAttributes()).thenReturn(emptyNodeMap);
  when(emptyNodeMap.iterator())
      .thenReturn(Arrays.asList("attribute1_key", "attribute2_key").iterator());
  InputNode inputValue1 = Mockito.mock(InputNode.class);
  when(inputValue1.getValue()).thenReturn("attribute1_value");
  InputNode inputValue2 = Mockito.mock(InputNode.class);
  when(inputValue2.getValue()).thenReturn("attribute2_value");
  when(inputNode.getAttribute("attribute1_key")).thenReturn(inputValue1);
  when(inputNode.getAttribute("attribute2_key")).thenReturn(inputValue2);
  Map<String, String> parameters = BasicPhaseConverter.getParameters(inputNode);
  assertThat(parameters.size(), is(2));
  assertThat(parameters.get("attribute1_key"), is("attribute1_value"));
  assertThat(parameters.get("attribute2_key"), is("attribute2_value"));
}
 
开发者ID:Cognifide,项目名称:aet,代码行数:19,代码来源:BasicPhaseConverterTest.java


示例2: read

import org.simpleframework.xml.stream.NodeMap; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:ngallagher,项目名称:simplexml,代码行数:29,代码来源:RegistryStrategy.java


示例3: read

import org.simpleframework.xml.stream.NodeMap; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:ngallagher,项目名称:simplexml,代码行数:29,代码来源:AnnotationStrategy.java


示例4: writeReference

import org.simpleframework.xml.stream.NodeMap; //导入依赖的package包/类
/**
 * This is used to write the XML element attributes representing
 * the serialized object instance. If the object has already been
 * serialized to the XML document then a reference attribute is
 * inserted and this returns true, if not, then this will write
 * a unique identity marker attribute and return false.
 *
 * @param value this is the instance that is to be serialized    
 * @param node this is the node that contains the attributes
 * 
 * @return returns true if the element has been fully written
 */   
private boolean writeReference(Object value, NodeMap node) {
   String name = get(value);
   int size = size();
   
   if(name != null) {
      node.put(refer, name);
      return true;
   } 
   String unique = String.valueOf(size);
   
   node.put(mark, unique);
   put(value, unique);
   
   return false;   
}
 
开发者ID:ngallagher,项目名称:simplexml,代码行数:28,代码来源:WriteGraph.java


示例5: readVersion

import org.simpleframework.xml.stream.NodeMap; //导入依赖的package包/类
/**
 * This method is used to read the version from the provided input
 * node. Once the version has been read it is used to determine how
 * to deserialize the object. If the version is not the initial
 * version then it is read in a manner that ignores excessive XML
 * elements and attributes. Also none of the annotated fields or
 * methods are required if the version is not the initial version.
 * 
 * @param node the XML element contact values are deserialized from
 * @param source this object whose contacts are to be deserialized
 * @param schema this object visits the objects contacts
 */
private void readVersion(InputNode node, Object source, Schema schema) throws Exception {
   Label label = schema.getVersion();
   Class expect = type.getType();
   
   if(label != null) {
      String name = label.getName();
      NodeMap<InputNode> map = node.getAttributes();
      InputNode value = map.remove(name);
      
      if(value != null) {
         readVersion(value, source, label);
      } else {
         Version version = context.getVersion(expect);
         Double start = revision.getDefault();
         Double expected = version.revision();
         
         criteria.set(label, start);
         revision.compare(expected, start);
      }
   }
}
 
开发者ID:ngallagher,项目名称:simplexml,代码行数:34,代码来源:Composite.java


示例6: read

import org.simpleframework.xml.stream.NodeMap; //导入依赖的package包/类
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;
}
 
开发者ID:ngallagher,项目名称:simplexml,代码行数:19,代码来源:AnnotationConverterTest.java


示例7: write

import org.simpleframework.xml.stream.NodeMap; //导入依赖的package包/类
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);
}
 
开发者ID:ngallagher,项目名称:simplexml,代码行数:18,代码来源:AnnotationConverterTest.java


示例8: testReference

import org.simpleframework.xml.stream.NodeMap; //导入依赖的package包/类
public void testReference() throws Exception {
   StringReader reader = new StringReader(REFERENCE);
   Contract contract = new Contract("id", "reference", "class", "length");
   ReadGraph graph = new ReadGraph(contract, new Loader());
   InputNode event = NodeBuilder.read(reader);
   NodeMap attributes = event.getAttributes();
   
   graph.put("1", "first text");
   graph.put("2", "second text");
   graph.put("3", "third text");
   
   Value value = graph.read(new Entry(String.class), attributes);
   
   assertEquals(0, value.getLength());
   assertEquals("first text", value.getValue());
   assertEquals(String.class, value.getType());
   assertEquals(true, value.isReference());     
}
 
开发者ID:ngallagher,项目名称:simplexml,代码行数:19,代码来源:CycleStrategyTest.java


示例9: write

import org.simpleframework.xml.stream.NodeMap; //导入依赖的package包/类
public boolean write(Type field, Object value, NodeMap<OutputNode> node, Map map) throws Exception {
    boolean done = strategy.write(field, value, node, map);
    Node entry = node.remove("class");
    
    if(entry != null) {
        String className = entry.getValue();
        Class type = Class.forName(className);
        String name = forward.get(type);

        if(name == null) {
            throw new PersistenceException("Could not find alias for class %s", className);
        }
        node.put("type", name);
    }
    return done;
}
 
开发者ID:ngallagher,项目名称:simplexml,代码行数:17,代码来源:AliasTest.java


示例10: readValue

import org.simpleframework.xml.stream.NodeMap; //导入依赖的package包/类
/**
 * This is used to resolve and load a class for the given element.
 * Resolution of the class to used is done by inspecting the
 * XML element provided. If there is a "class" attribute on the
 * element then its value is used to resolve the class to use.
 * If no such attribute exists the specified field is returned,
 * or if the field type is an array then the component type.
 * 
 * @param type this is the type of the XML element expected
 * @param node this is the element used to resolve an override
 * 
 * @return returns the class that should be used for the object
 * 
 * @throws Exception thrown if the class cannot be resolved
 */   
private Class readValue(Type type, NodeMap node) throws Exception {      
   Node entry = node.remove(label);      
   Class expect = type.getType();
   
   if(entry != null) {
      String name = entry.getValue();
      Class actual = loader.load(name);
      // Arrays are annotated with the type of the element.
      if (expect.isArray()) {
         if (actual == expect.getComponentType())
            actual = expect;
         else
            actual = Array.newInstance(actual, 0).getClass();
      }
      expect = actual;
   }    
   return expect;
}
 
开发者ID:shevek,项目名称:simple-xml,代码行数:34,代码来源:TreeStrategy.java


示例11: read

import org.simpleframework.xml.stream.NodeMap; //导入依赖的package包/类
/**
 * This is used to recover the object references from the document
 * using the special attributes specified. This allows the element
 * specified by the <code>NodeMap</code> to be used to discover
 * exactly which node in the object graph the element represents.
 * 
 * @param type the type of the field or method in the instance
 * @param node this is the XML element to be deserialized
 * 
 * @return this is used to return the type to acquire the value
 */
public Value read(Type type, NodeMap node) throws Exception {
   Node entry = node.remove(label);
   Class expect = type.getType();
   
   if(entry != null) {      
      String name = entry.getValue();
      Class actual = loader.load(name);
      // Arrays are annotated with the type of the element.
      if (expect.isArray()) {
         if (actual == expect.getComponentType())
            actual = expect;
         else
            actual = Array.newInstance(actual, 0).getClass();
      }
      expect = actual;
   }  
   return readInstance(type, expect, node); 
}
 
开发者ID:shevek,项目名称:simple-xml,代码行数:30,代码来源:ReadGraph.java


示例12: write

import org.simpleframework.xml.stream.NodeMap; //导入依赖的package包/类
@Override
public void write(final Type type, final NodeMap<OutputNode> node) throws Exception {
	if (type.getType().equals(Command[].class)) {
		OutputNode element = node.getNode();

		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());
	}
}
 
开发者ID:runtimeco,项目名称:Android-DFU-App,代码行数:12,代码来源:UARTActivity.java


示例13: write

import org.simpleframework.xml.stream.NodeMap; //导入依赖的package包/类
@Override
public void write(Type type, NodeMap<OutputNode> node) throws Exception {
    OutputNode outputNode = node.getNode();
    if ("DdsRequestObject".equals(outputNode.getName())) {
        OutputNode operationNameAtribute = outputNode.getParent().getAttributes().get("DdsOperationName");
        outputNode.setName(operationNameAtribute.getValue());
    }
}
 
开发者ID:open-eid,项目名称:MOPP-Android,代码行数:9,代码来源:RequestObjectInterceptor.java


示例14: getParameters_withNoAttributes_expectEmptyMap

import org.simpleframework.xml.stream.NodeMap; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void getParameters_withNoAttributes_expectEmptyMap() throws Exception {
  NodeMap<InputNode> emptyNodeMap = Mockito.mock(NodeMap.class);
  when(emptyNodeMap.iterator()).thenReturn(Iterators.<String>emptyIterator());
  when(inputNode.getAttributes()).thenReturn(emptyNodeMap);
  Map<String, String> parameters = BasicPhaseConverter.getParameters(inputNode);
  assertTrue(parameters.isEmpty());
}
 
开发者ID:Cognifide,项目名称:aet,代码行数:10,代码来源:BasicPhaseConverterTest.java


示例15: write

import org.simpleframework.xml.stream.NodeMap; //导入依赖的package包/类
/**
 * This is used to write the XML element attributes representing
 * the serialized object instance. If the object has already been
 * serialized to the XML document then a reference attribute is
 * inserted and this returns true, if not, then this will write
 * a unique identity marker attribute and return false.
 * 
 * @param type this is the type of the object to be serialized
 * @param value this is the instance that is to be serialized    
 * @param node this is the node that contains the attributes
 * 
 * @return returns true if the element has been fully written
 */
public boolean write(Type type, Object value, NodeMap node){
   Class actual = value.getClass();
   Class expect = type.getType();
   Class real = actual;
   
   if(actual.isArray()) {
      real = writeArray(actual, value, node);
   }
   if(actual != expect) {
      node.put(label, real.getName());
   }       
   return writeReference(value, node);
}
 
开发者ID:ngallagher,项目名称:simplexml,代码行数:27,代码来源:WriteGraph.java


示例16: read

import org.simpleframework.xml.stream.NodeMap; //导入依赖的package包/类
/**
 * This is used to recover the object references from the document
 * using the special attributes specified. This allows the element
 * specified by the <code>NodeMap</code> to be used to discover
 * exactly which node in the object graph the element represents.
 * 
 * @param type the type of the field or method in the instance
 * @param node this is the XML element to be deserialized
 * 
 * @return this is used to return the type to acquire the value
 */
public Value read(Type type, NodeMap node) throws Exception {
   Node entry = node.remove(label);
   Class expect = type.getType();
   
   if(expect.isArray()) {
      expect = expect.getComponentType();
   }
   if(entry != null) {      
      String name = entry.getValue();
      expect = loader.load(name);
   }  
   return readInstance(type, expect, node); 
}
 
开发者ID:ngallagher,项目名称:simplexml,代码行数:25,代码来源:ReadGraph.java


示例17: readInstance

import org.simpleframework.xml.stream.NodeMap; //导入依赖的package包/类
/**
 * This is used to recover the object references from the document
 * using the special attributes specified. This allows the element
 * specified by the <code>NodeMap</code> to be used to discover
 * exactly which node in the object graph the element represents.
 * 
 * @param type the type of the field or method in the instance
 * @param real this is the overridden type from the XML element
 * @param node this is the XML element to be deserialized
 * 
 * @return this is used to return the type to acquire the value
 */
private Value readInstance(Type type, Class real, NodeMap node) throws Exception {      
   Node entry = node.remove(mark);
   
   if(entry == null) {
      return readReference(type, real, node);
   }      
   String key = entry.getValue();
   
   if(containsKey(key)) {
      throw new CycleException("Element '%s' already exists", key);
   }
   return readValue(type, real, node, key);
}
 
开发者ID:ngallagher,项目名称:simplexml,代码行数:26,代码来源:ReadGraph.java


示例18: readReference

import org.simpleframework.xml.stream.NodeMap; //导入依赖的package包/类
/**
 * This is used to recover the object references from the document
 * using the special attributes specified. This allows the element
 * specified by the <code>NodeMap</code> to be used to discover
 * exactly which node in the object graph the element represents.
 * 
 * @param type the type of the field or method in the instance
 * @param real this is the overridden type from the XML element
 * @param node this is the XML element to be deserialized    
 * 
 * @return this is used to return the type to acquire the value
 */ 
private Value readReference(Type type, Class real, NodeMap node) throws Exception {
   Node entry = node.remove(refer);
   
   if(entry == null) {
      return readValue(type, real, node);
   }
   String key = entry.getValue();
   Object value = get(key); 
      
   if(!containsKey(key)) {        
      throw new CycleException("Invalid reference '%s' found", key);
   }
   return new Reference(value, real);
}
 
开发者ID:ngallagher,项目名称:simplexml,代码行数:27,代码来源:ReadGraph.java


示例19: testSmallSource

import org.simpleframework.xml.stream.NodeMap; //导入依赖的package包/类
public void testSmallSource() throws Exception {
   InputNode event = NodeBuilder.read(new StringReader(SMALL_SOURCE));

   assertTrue(event.isRoot());
   assertEquals("override", event.getName());         
   assertEquals("12", event.getAttribute("id").getValue());
   assertEquals("true", event.getAttribute("flag").getValue());

   NodeMap list = event.getAttributes();

   assertEquals("12", list.get("id").getValue());
   assertEquals("true", list.get("flag").getValue());

   InputNode text = event.getNext();
   
   assertFalse(text.isRoot());
   assertTrue(event.isRoot());
   assertEquals("text", text.getName());
   assertEquals("entry text", text.getValue());
   assertEquals(null, text.getNext());
   
   InputNode name = event.getNext();
   
   assertFalse(name.isRoot());
   assertEquals("name", name.getName());
   assertEquals("some name", name.getValue());
   assertEquals(null, name.getNext());
   assertEquals(null, text.getNext());
   
   InputNode third = event.getNext();
   
   assertTrue(event.isRoot());
   assertFalse(third.isRoot());
   assertEquals("third", third.getName());
   assertEquals("text", text.getName());
   assertEquals(null, text.getNext());
   assertEquals("added to schema", third.getValue());
   assertEquals(null, event.getNext());
}
 
开发者ID:ngallagher,项目名称:simplexml,代码行数:40,代码来源:NodeReaderTest.java


示例20: read

import org.simpleframework.xml.stream.NodeMap; //导入依赖的package包/类
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);
   }
}
 
开发者ID:ngallagher,项目名称:simplexml,代码行数:10,代码来源:ValidationTestCase.java



注:本文中的org.simpleframework.xml.stream.NodeMap类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Response类代码示例发布时间:2022-05-22
下一篇:
Java ArrayFactory类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap