本文整理汇总了Java中org.simpleframework.xml.stream.OutputNode类的典型用法代码示例。如果您正苦于以下问题:Java OutputNode类的具体用法?Java OutputNode怎么用?Java OutputNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OutputNode类属于org.simpleframework.xml.stream包,在下文中一共展示了OutputNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testAttributeNoKeyString
import org.simpleframework.xml.stream.OutputNode; //导入依赖的package包/类
public void testAttributeNoKeyString() throws Exception
{
Source source = new Source(new TreeStrategy(), new Support(), new Session());
MockElementMap map = new MockElementMap(true, // attribute
false, // data
"entry", // entry
true, // inline
"", // key
String.class, // keyType
"name", // name
true, // required
"value", // value
String.class); // valueType
PrimitiveType type = new PrimitiveType(map);
Contact string = type.getString();
Entry entry = new Entry(string, map);
PrimitiveKey value = new PrimitiveKey(source, entry, new ClassType(String.class));
OutputNode node = NodeBuilder.write(new PrintWriter(System.out));
value.write(node.getChild("attributeNoKeyString"), "example");
node.commit();
}
示例2: testNoAttributeString
import org.simpleframework.xml.stream.OutputNode; //导入依赖的package包/类
public void testNoAttributeString() throws Exception
{
Source source = new Source(new TreeStrategy(), new Support(), new Session());
MockElementMap map = new MockElementMap(false, // attribute
false, // data
"entry", // entry
true, // inline
"", // key
String.class, // keyType
"name", // name
true, // required
"value", // value
String.class); // valueType
PrimitiveType type = new PrimitiveType(map);
Contact string = type.getString();
Entry entry = new Entry(string, map);
CompositeInlineMap value = new CompositeInlineMap(source, entry, new ClassType(Map.class));
OutputNode node = NodeBuilder.write(new PrintWriter(System.out));
Map exampleMap = new HashMap();
exampleMap.put("a", "1");
exampleMap.put("b", "2");
value.write(node.getChild("noAttributeString").getChild("map"), exampleMap);
node.commit();
}
示例3: testAttributeNoKeyString
import org.simpleframework.xml.stream.OutputNode; //导入依赖的package包/类
public void testAttributeNoKeyString() throws Exception
{
Source source = new Source(new TreeStrategy(), new Support(), new Session());
MockElementMap map = new MockElementMap(true, // attribute
false, // data
"entry", // entry
true, // inline
"", // key
String.class, // keyType
"name", // name
true, // required
"value", // value
String.class); // valueType
PrimitiveType type = new PrimitiveType(map);
Contact string = type.getString();
Entry entry = new Entry(string, map);
PrimitiveValue value = new PrimitiveValue(source, entry, new ClassType(String.class));
OutputNode node = NodeBuilder.write(new PrintWriter(System.out));
value.write(node.getChild("attributeNoKeyString"), "example");
node.commit();
}
示例4: testNotInlineString
import org.simpleframework.xml.stream.OutputNode; //导入依赖的package包/类
public void testNotInlineString() throws Exception
{
Source source = new Source(new TreeStrategy(), new Support(), new Session());
MockElementMap map = new MockElementMap(false, // attribute
false, // data
"entry", // entry
true, // inline
"key", // key
String.class, // keyType
"name", // name
true, // required
"value", // value
String.class); // valueType
PrimitiveType type = new PrimitiveType(map);
Contact string = type.getString();
Entry entry = new Entry(string, map);
PrimitiveValue value = new PrimitiveValue(source, entry, new ClassType(String.class));
OutputNode node = NodeBuilder.write(new PrintWriter(System.out));
value.write(node.getChild("notInlineString"), "example");
node.commit();
}
示例5: testNotInlineString
import org.simpleframework.xml.stream.OutputNode; //导入依赖的package包/类
public void testNotInlineString() throws Exception
{
Source source = new Source(new TreeStrategy(), new Support(), new Session());
MockElementMap map = new MockElementMap(false, // attribute
false, // data
"entry", // entry
true, // inline
"key", // key
String.class, // keyType
"name", // name
true, // required
"value", // value
String.class); // valueType
PrimitiveType type = new PrimitiveType(map);
Contact string = type.getString();
Entry entry = new Entry(string, map);
CompositeMap value = new CompositeMap(source, entry, new ClassType(Map.class));
OutputNode node = NodeBuilder.write(new PrintWriter(System.out));
Map exampleMap = new HashMap();
exampleMap.put("a", "1");
exampleMap.put("b", "2");
value.write(node.getChild("notInlineString"), exampleMap);
node.commit();
}
示例6: testInlineString
import org.simpleframework.xml.stream.OutputNode; //导入依赖的package包/类
public void testInlineString() throws Exception
{
Source source = new Source(new TreeStrategy(), new Support(), new Session());
MockElementMap map = new MockElementMap(true, // attribute
false, // data
"entry", // entry
true, // inline
"key", // key
String.class, // keyType
"name", // name
true, // required
"value", // value
String.class); // valueType
PrimitiveType type = new PrimitiveType(map);
Contact string = type.getString();
Entry entry = new Entry(string, map);
PrimitiveKey value = new PrimitiveKey(source, entry, new ClassType(String.class));
OutputNode node = NodeBuilder.write(new PrintWriter(System.out));
value.write(node.getChild("inlineString"), "example");
node.commit();
}
示例7: testNotInlineString
import org.simpleframework.xml.stream.OutputNode; //导入依赖的package包/类
public void testNotInlineString() throws Exception
{
Source source = new Source(new TreeStrategy(), new Support(), new Session());
MockElementMap map = new MockElementMap(false, // attribute
false, // data
"entry", // entry
true, // inline
"key", // key
String.class, // keyType
"name", // name
true, // required
"value", // value
String.class); // valueType
PrimitiveType type = new PrimitiveType(map);
Contact string = type.getString();
Entry entry = new Entry(string, map);
CompositeInlineMap value = new CompositeInlineMap(source, entry, new ClassType(Map.class));
OutputNode node = NodeBuilder.write(new PrintWriter(System.out));
Map exampleMap = new HashMap();
exampleMap.put("a", "1");
exampleMap.put("b", "2");
value.write(node.getChild("notInlineString").getChild("map"), exampleMap);
node.commit();
}
示例8: write
import org.simpleframework.xml.stream.OutputNode; //导入依赖的package包/类
/**
* This <code>write</code> method is used to convert the provided
* object to an XML element. This creates a child node from the
* given <code>OutputNode</code> object. Once this child element
* is created it is populated with the fields of the source object
* in accordance with the XML schema class.
*
* @param source this is the object to be serialized to XML
* @param expect this is the class that is expected to be written
* @param name this is the name of the root annotation used
*
* @throws Exception thrown if there is a problem serializing
*/
public void write(OutputNode node, Object source, Class expect, String name) throws Exception {
OutputNode child = node.getChild(name);
Type type = getType(expect);
if(source != null) {
Class actual = source.getClass();
Decorator decorator = getDecorator(actual);
if(decorator != null) {
decorator.decorate(child);
}
if(!context.setOverride(type, source, child)) {
getComposite(actual).write(child, source);
}
}
child.commit();
}
示例9: testAttributeNoKeyString
import org.simpleframework.xml.stream.OutputNode; //导入依赖的package包/类
public void testAttributeNoKeyString() throws Exception
{
Source source = new Source(new TreeStrategy(), new Support(), new Session());
MockElementMap map = new MockElementMap(true, // attribute
false, // data
"entry", // entry
true, // inline
"", // key
String.class, // keyType
"name", // name
true, // required
"value", // value
String.class); // valueType
PrimitiveType type = new PrimitiveType(map);
Contact string = type.getString();
Entry entry = new Entry(string, map);
CompositeInlineMap value = new CompositeInlineMap(source, entry, new ClassType(Map.class));
OutputNode node = NodeBuilder.write(new PrintWriter(System.out));
Map exampleMap = new HashMap();
exampleMap.put("a", "1");
exampleMap.put("b", "2");
value.write(node.getChild("attributeNoKeyString").getChild("map"), exampleMap);
node.commit();
}
示例10: write
import org.simpleframework.xml.stream.OutputNode; //导入依赖的package包/类
/**
* This <code>write</code> method is used to perform serialization of
* the given source object. Serialization is performed by appending
* elements and attributes from the source object to the provided XML
* element object. How the objects contacts are serialized is
* determined by the XML schema class that the source object is an
* instance of. If a required contact is null an exception is thrown.
*
* @param source this is the source object to be serialized
* @param node the XML element the object is to be serialized to
*/
public void write(OutputNode node, Object source) throws Exception {
Class type = source.getClass();
Schema schema = context.getSchema(type);
Caller caller = schema.getCaller();
try {
if(schema.isPrimitive()) {
primitive.write(node, source);
} else {
caller.persist(source);
write(node, source, schema);
}
} finally {
caller.complete(source);
}
}
示例11: writeElements
import org.simpleframework.xml.stream.OutputNode; //导入依赖的package包/类
/**
* This write method is used to write all the element contacts from
* the provided source object to the XML element. This visits all
* the contacts marked with the <code>Element</code> annotation in
* the source object. All annotated contacts are written as children
* to the XML element. This will throw an exception if a required
* contact within the source object is null.
*
* @param source this is the source object to be serialized
* @param node this is the XML element to write elements to
* @param section this is the section that defines the XML structure
*/
private void writeElements(OutputNode node, Object source, Section section) throws Exception {
for(String name : section) {
Section child = section.getSection(name);
if(child != null) {
OutputNode next = node.getChild(name);
writeSection(next, source, child);
} else {
String path = section.getPath(name);
Label label = section.getElement(path);
Class expect = context.getType(type, source);
Object value = criteria.get(label);
if(value == null) {
if(label == null) {
throw new ElementException("Element '%s' not defined in %s", name, expect);
}
writeUnion(node, source, section, label);
}
}
}
}
示例12: writeUnion
import org.simpleframework.xml.stream.OutputNode; //导入依赖的package包/类
/**
* The <code>writeUnion</code> method is determine the unions
* for a particular label and set the value of that union to
* the same value as the label. This helps the serialization
* process by ensuring once a union is written it is not
* replaced. This is also required when writing inline lists.
*
* @param node this is the XML element to write elements to
* @param source this is the source object to be serialized
* @param section this is the section associated with the label
* @param label this is the label used to define the XML element
*/
private void writeUnion(OutputNode node, Object source, Section section, Label label) throws Exception {
Contact contact = label.getContact();
Object value = contact.get(source);
Class expect = context.getType(type, source);
if(value == null && label.isRequired()) {
throw new ElementException("Value for %s is null in %s", label, expect);
}
Object replace = writeReplace(value);
if(replace != null) {
writeElement(node, replace, label);
}
criteria.set(label, replace);
}
示例13: writeElement
import org.simpleframework.xml.stream.OutputNode; //导入依赖的package包/类
/**
* This write method is used to append the provided object as an
* element to the given XML element object. This will recursively
* write the contacts from the provided object as elements. This is
* done using the <code>Converter</code> acquired from the contact
* label. If the type of the contact value is not of the same
* type as the XML schema class a "class" attribute is appended.
* <p>
* If the element being written is inline, then this will not
* check to see if there is a "class" attribute specifying the
* name of the class. This is because inline elements do not have
* an outer class and thus could never have an override.
*
* @param value this is the value to be set as an element
* @param node this is the XML element to write the element to
* @param label the label that contains the contact details
*/
private void writeElement(OutputNode node, Object value, Label label) throws Exception {
if(value != null) {
Class real = value.getClass();
Label match = label.getLabel(real);
String name = match.getName();
Type type = label.getType(real);
OutputNode next = node.getChild(name);
if(!match.isInline()) {
writeNamespaces(next, type, match);
}
if(match.isInline() || !isOverridden(next, value, type)) {
Converter convert = match.getConverter(context);
boolean data = match.isData();
next.setData(data);
writeElement(next, value, convert);
}
}
}
示例14: testNoAttributeString
import org.simpleframework.xml.stream.OutputNode; //导入依赖的package包/类
public void testNoAttributeString() throws Exception
{
Source source = new Source(new TreeStrategy(), new Support(), new Session());
MockElementMap map = new MockElementMap(false, // attribute
false, // data
"entry", // entry
true, // inline
"", // key
String.class, // keyType
"name", // name
true, // required
"value", // value
String.class); // valueType
PrimitiveType type = new PrimitiveType(map);
Contact string = type.getString();
Entry entry = new Entry(string, map);
PrimitiveKey value = new PrimitiveKey(source, entry, new ClassType(String.class));
OutputNode node = NodeBuilder.write(new PrintWriter(System.out));
value.write(node.getChild("noAttributeString"), "example");
node.commit();
}
示例15: write
import org.simpleframework.xml.stream.OutputNode; //导入依赖的package包/类
public void write(OutputNode node) throws Exception {
OutputNode member = node.getChild(CODE);
OutputNode nameNode = member.getChild(Member.NAME);
nameNode.setValue(name);
OutputNode valueNode = member.getChild(Value.CODE);
value.write(valueNode);
}