本文整理汇总了Java中org.simpleframework.xml.stream.NodeMap类的典型用法代码示例。如果您正苦于以下问题:Java NodeMap类的具体用法?Java NodeMap怎么用?Java NodeMap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NodeMap类属于org.simpleframework.xml.stream包,在下文中一共展示了NodeMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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"));
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
}
示例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;
}
示例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);
}
示例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());
}
示例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;
}
示例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;
}
示例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);
}
示例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());
}
}
示例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());
}
}
示例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());
}
示例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);
}