本文整理匯總了Java中com.thoughtworks.xstream.io.HierarchicalStreamWriter.startNode方法的典型用法代碼示例。如果您正苦於以下問題:Java HierarchicalStreamWriter.startNode方法的具體用法?Java HierarchicalStreamWriter.startNode怎麽用?Java HierarchicalStreamWriter.startNode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.thoughtworks.xstream.io.HierarchicalStreamWriter
的用法示例。
在下文中一共展示了HierarchicalStreamWriter.startNode方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: marshal
import com.thoughtworks.xstream.io.HierarchicalStreamWriter; //導入方法依賴的package包/類
/**
* writes the argument <code>value</code> to the XML file specified through
* <code>writer</code>
*
* @pre <code>value</code> is a valid <code>SpotFieldNode</code>, <code>
* writer</code> is a valid <code>HierarchicalStreamWriter</code>, and
* <code>context</code> is a valid <code>MarshallingContext</code>
* @post <code>value</code> is written to the XML file specified via
* <code>writer</code>
* @param value <code>SpotFieldNode</code> that you wish to write to a
* file
* @param writer stream to write through
* @param context <code>MarshallingContext</code> used to store generic data
*/
@Override
public void marshal(Object value, HierarchicalStreamWriter writer,
MarshallingContext context) {
SpotFieldNode spotFieldNode = (SpotFieldNode) value;
writer.startNode("isotopeName");
writer.setValue(spotFieldNode.getName());
writer.endNode();
writer.startNode("methodNameForShrimpFraction");
writer.setValue(spotFieldNode.getMethodNameForShrimpFraction());
writer.endNode();
}
示例2: marshal
import com.thoughtworks.xstream.io.HierarchicalStreamWriter; //導入方法依賴的package包/類
/**
* writes the argument <code>value</code> to the XML file specified through
* <code>writer</code>
*
* @pre <code>value</code> is a valid <code>Task</code>, <code>
* writer</code> is a valid <code>HierarchicalStreamWriter</code>, and
* <code>context</code> is a valid <code>MarshallingContext</code>
* @post <code>value</code> is written to the XML file specified via
* <code>writer</code>
* @param value <code>Task</code> that you wish to write to a file
* @param writer stream to write through
* @param context <code>MarshallingContext</code> used to store generic data
*/
@Override
public void marshal(Object value, HierarchicalStreamWriter writer,
MarshallingContext context) {
TaskInterface task = (Task) value;
writer.startNode("name");
writer.setValue(task.getName());
writer.endNode();
writer.startNode("taskExpressionsOrdered");
context.convertAnother(task.getTaskExpressionTreesOrdered());
writer.endNode();
}
示例3: marshal
import com.thoughtworks.xstream.io.HierarchicalStreamWriter; //導入方法依賴的package包/類
@Override
public void marshal(Object original, HierarchicalStreamWriter writer, MarshallingContext context) {
super.marshal(original, writer, context);
WxPayOrderNotifyResult obj = (WxPayOrderNotifyResult) original;
List<WxPayOrderNotifyCoupon> list = obj.getCouponList();
if (list == null || list.size() == 0) {
return;
}
for (int i = 0; i < list.size(); i++) {
WxPayOrderNotifyCoupon coupon = list.get(i);
writer.startNode("coupon_id_" + i);
writer.setValue(coupon.getCouponId());
writer.endNode();
writer.startNode("coupon_type_" + i);
writer.setValue(coupon.getCouponType());
writer.endNode();
writer.startNode("coupon_fee_" + i);
writer.setValue(coupon.getCouponFee() + "");
writer.endNode();
}
}
示例4: marshal
import com.thoughtworks.xstream.io.HierarchicalStreamWriter; //導入方法依賴的package包/類
@Override
public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) {
final Font font = (Font)source;
final Map<TextAttribute, ?> attributes = font.getAttributes();
if (mapper != null) {
final String classAlias = mapper.aliasForSystemAttribute("class");
for (final Map.Entry<TextAttribute, ?> entry : attributes.entrySet()) {
final String name = textAttributeConverter.toString(entry.getKey());
final Object value = entry.getValue();
final Class<?> type = value != null ? value.getClass() : Mapper.Null.class;
ExtendedHierarchicalStreamWriterHelper.startNode(writer, name, type);
writer.addAttribute(classAlias, mapper.serializedClass(type));
if (value != null) {
context.convertAnother(value);
}
writer.endNode();
}
} else {
writer.startNode("attributes"); // <attributes>
context.convertAnother(attributes);
writer.endNode(); // </attributes>
}
}
示例5: marshal
import com.thoughtworks.xstream.io.HierarchicalStreamWriter; //導入方法依賴的package包/類
@Override
public void marshal(Object object, HierarchicalStreamWriter writer, MarshallingContext arg2)
{
Header header = (Header) object;
addAttribute(writer, "status", header.getStatus());
writer.startNode("identifier");
writer.setValue(header.getIdentifier());
writer.endNode();
writer.startNode("datestamp");
writer.setValue(header.getDatestamp());
writer.endNode();
Iterator i = header.getSpecs().iterator();
while( i.hasNext() )
{
writer.startNode("setSpec");
writer.setValue(i.next().toString());
writer.endNode();
}
}
示例6: marshal
import com.thoughtworks.xstream.io.HierarchicalStreamWriter; //導入方法依賴的package包/類
/**
* The marshal method for EnumTypeConverter has been implemented to aid
* testing.
*/
@Override
public void marshal(final Object value, final HierarchicalStreamWriter writer, final MarshallingContext context) {
final Definition def = (Definition) value;
writer.startNode("ID");
writer.setValue(def.getId());
writer.endNode();
writer.startNode("Name");
writer.setValue(def.getId());
writer.endNode();
}
示例7: marshalPrincipals
import com.thoughtworks.xstream.io.HierarchicalStreamWriter; //導入方法依賴的package包/類
protected void marshalPrincipals(final Set<Principal> principals, final HierarchicalStreamWriter writer,
final MarshallingContext context) {
writer.startNode("principals");
for (final Principal principal : principals) {
writeItem(principal, context, writer);
}
writer.endNode();
}
示例8: marshal
import com.thoughtworks.xstream.io.HierarchicalStreamWriter; //導入方法依賴的package包/類
public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) {
AbstractMap map = (AbstractMap) value;
for (Object obj : map.entrySet()) {
Map.Entry entry = (Map.Entry) obj;
writer.startNode(entry.getKey().toString());
Object val = entry.getValue();
if (null != val) {
writer.setValue(val.toString());
}
writer.endNode();
}
}
示例9: addInterfacesToXml
import com.thoughtworks.xstream.io.HierarchicalStreamWriter; //導入方法依賴的package包/類
private void addInterfacesToXml(final Object source, final HierarchicalStreamWriter writer) {
final Class<?>[] interfaces = source.getClass().getInterfaces();
for (final Class<?> currentInterface : interfaces) {
writer.startNode("interface");
writer.setValue(mapper.serializedClass(currentInterface));
writer.endNode();
}
}
示例10: marshal
import com.thoughtworks.xstream.io.HierarchicalStreamWriter; //導入方法依賴的package包/類
@Override
public void marshal(Object obj, HierarchicalStreamWriter writer, MarshallingContext context)
{
writer.startNode("id");
writer.setValue(Long.toString(((IdCloneable) obj).getId()));
writer.endNode();
}
示例11: rmarshalNode
import com.thoughtworks.xstream.io.HierarchicalStreamWriter; //導入方法依賴的package包/類
private void rmarshalNode(HierarchicalStreamWriter writer, MarshallingContext context, Node node)
{
NamedNodeMap map = node.getAttributes();
int count;
if( map != null )
{
count = map.getLength();
for( int i = 0; i < count; i++ )
{
Node attribute = map.item(i);
writer.addAttribute(attribute.getNodeName(), attribute.getNodeValue());
}
}
NodeList list = node.getChildNodes();
if( list != null )
{
count = list.getLength();
for( int i = 0; i < count; i++ )
{
Node child = list.item(i);
if( child.getNodeType() == Node.TEXT_NODE )
{
String value = child.getNodeValue();
if( value != null && value.length() > 0 )
{
writer.setValue(value);
}
}
else
{
writer.startNode(child.getNodeName());
rmarshalNode(writer, context, child);
writer.endNode();
}
}
}
}
示例12: startNode
import com.thoughtworks.xstream.io.HierarchicalStreamWriter; //導入方法依賴的package包/類
public void startNode(HierarchicalStreamWriter writer, String node, Object value)
{
if( value != null )
{
writer.startNode(node);
xstream.marshal(value, writer);
writer.endNode();
}
}
示例13: marshal
import com.thoughtworks.xstream.io.HierarchicalStreamWriter; //導入方法依賴的package包/類
@Override
public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) {
final Field field = (Field)source;
final Class<?> type = field.getDeclaringClass();
writer.startNode("name");
writer.setValue(mapper.serializedMember(type, field.getName()));
writer.endNode();
writer.startNode("clazz");
writer.setValue(javaClassConverter.toString(type));
writer.endNode();
}
示例14: marshallField
import com.thoughtworks.xstream.io.HierarchicalStreamWriter; //導入方法依賴的package包/類
@Override
protected void marshallField(MarshallingContext context, Object newObj, Field field) {
HierarchicalStreamWriter writer = writerStack.get().peek();
if (field.getAnnotation(ManyToOne.class) != null) {
super.marshallField(context, ((AbstractEntity) newObj).getId(), field);
} else if (newObj instanceof HibernateProxy) {
newObj = ((HibernateProxy)newObj).getHibernateLazyInitializer().getImplementation();
super.marshallField(context, newObj, field);
} else if (newObj instanceof VersionedDocument) {
marshallElement(writer, ((VersionedDocument)newObj).getRootElement());
} else if (Collection.class.isAssignableFrom(field.getType())
&& ReflectionUtils.getCollectionElementType(field.getGenericType()) == VersionedDocument.class) {
for (VersionedDocument vdom: (List<VersionedDocument>)newObj) {
if (vdom != null) {
marshallElement(writer, vdom.getRootElement());
} else {
writer.startNode(mapper.serializedClass(null));
writer.endNode();
}
}
} else if (Map.class.isAssignableFrom(field.getType())
&& ReflectionUtils.getMapValueType(field.getGenericType()) == VersionedDocument.class) {
for (Map.Entry<Object, VersionedDocument> entry:
((Map<Object, VersionedDocument>)newObj).entrySet()) {
writer.startNode(mapper.serializedClass(Map.Entry.class));
if (entry.getKey() != null) {
writer.startNode(mapper.serializedClass(entry.getKey().getClass()));
context.convertAnother(entry.getKey());
writer.endNode();
} else {
writer.startNode(mapper.serializedClass(null));
writer.endNode();
}
if (entry.getValue() != null) {
marshallElement(writer, entry.getValue().getRootElement());
} else {
writer.startNode(mapper.serializedClass(null));
writer.endNode();
}
writer.endNode();
}
} else if (field.getType().isEnum()) {
writer.setValue(((Enum)newObj).name());
} else if (field.getType() == String.class) {
String stringValue = (String) newObj;
if (stringValue.indexOf('\0') != -1)
writer.setValue(StringUtils.replace(stringValue, "\0", ""));
else
writer.setValue(stringValue);
} else {
super.marshallField(context, newObj, field);
}
}
示例15: marshal
import com.thoughtworks.xstream.io.HierarchicalStreamWriter; //導入方法依賴的package包/類
@Override
public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) {
try {
final Externalizable externalizable = (Externalizable)source;
final CustomObjectOutputStream.StreamCallback callback = new CustomObjectOutputStream.StreamCallback() {
@Override
public void writeToStream(final Object object) {
if (object == null) {
writer.startNode("null");
writer.endNode();
} else {
ExtendedHierarchicalStreamWriterHelper.startNode(writer, mapper.serializedClass(object
.getClass()), object.getClass());
context.convertAnother(object);
writer.endNode();
}
}
@Override
public void writeFieldsToStream(final Map<String, Object> fields) {
throw new UnsupportedOperationException();
}
@Override
public void defaultWriteObject() {
throw new UnsupportedOperationException();
}
@Override
public void flush() {
writer.flush();
}
@Override
public void close() {
throw new UnsupportedOperationException(
"Objects are not allowed to call ObjectOutput.close() from writeExternal()");
}
};
@SuppressWarnings("resource")
final CustomObjectOutputStream objectOutput = CustomObjectOutputStream.getInstance(context, callback);
externalizable.writeExternal(objectOutput);
objectOutput.popCallback();
} catch (final IOException e) {
throw new ConversionException("Cannot serialize " + source.getClass().getName() + " using Externalization",
e);
}
}