本文整理匯總了Java中com.thoughtworks.xstream.io.HierarchicalStreamWriter.addAttribute方法的典型用法代碼示例。如果您正苦於以下問題:Java HierarchicalStreamWriter.addAttribute方法的具體用法?Java HierarchicalStreamWriter.addAttribute怎麽用?Java HierarchicalStreamWriter.addAttribute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.thoughtworks.xstream.io.HierarchicalStreamWriter
的用法示例。
在下文中一共展示了HierarchicalStreamWriter.addAttribute方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: copy
import com.thoughtworks.xstream.io.HierarchicalStreamWriter; //導入方法依賴的package包/類
public void copy(HierarchicalStreamReader source, HierarchicalStreamWriter destination) {
destination.startNode(source.getNodeName());
int attributeCount = source.getAttributeCount();
for (int i = 0; i < attributeCount; i++) {
destination.addAttribute(source.getAttributeName(i), source.getAttribute(i));
}
String value = source.getValue();
if (value != null && value.length() > 0) {
destination.setValue(value);
}
while (source.hasMoreChildren()) {
source.moveDown();
copy(source, destination);
source.moveUp();
}
destination.endNode();
}
示例2: marshal
import com.thoughtworks.xstream.io.HierarchicalStreamWriter; //導入方法依賴的package包/類
@Override
public void marshal(Object arg0, HierarchicalStreamWriter writer, MarshallingContext arg2)
{
writer.addAttribute("xmlns:oai_dc", "http://www.openarchives.org/OAI/2.0/oai_dc/");
writer.addAttribute("xmlns:dc", "http://purl.org/dc/elements/1.1/");
writer.addAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
writer.addAttribute("xsi:schemaLocation",
"http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd");
DublinCore metadata = (DublinCore) arg0;
startNode(writer, "dc:title", metadata.getTitle());
startNode(writer, "dc:creator", metadata.getCreator());
startNode(writer, "dc:creator", metadata.getTitle());
startNode(writer, "dc:date", metadata.getDate());
startNode(writer, "dc:description", metadata.getDescription());
startNode(writer, "dc:identifier", metadata.getIdentifier());
}
示例3: marshal
import com.thoughtworks.xstream.io.HierarchicalStreamWriter; //導入方法依賴的package包/類
@Override
public void marshal(Object object, HierarchicalStreamWriter writer, MarshallingContext arg2)
{
Request rep = (Request) object;
Map map = rep.getAttributes();
Iterator i = map.keySet().iterator();
while( i.hasNext() )
{
String key = i.next().toString();
String[] value = (String[]) map.get(key);
for( int j = 0; j < value.length; j++ )
{
writer.addAttribute(key, value[j]);
}
}
writer.setValue(rep.getNode());
}
示例4: marshal
import com.thoughtworks.xstream.io.HierarchicalStreamWriter; //導入方法依賴的package包/類
@Override
public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) {
final Properties properties = (Properties)source;
final Map<Object, Object> map = sort ? new TreeMap<Object, Object>(properties) : properties;
for (final Map.Entry<Object, Object> entry : map.entrySet()) {
writer.startNode("property");
writer.addAttribute("name", entry.getKey().toString());
writer.addAttribute("value", entry.getValue().toString());
writer.endNode();
}
if (defaultsField != null) {
final Properties defaults = (Properties)Fields.read(defaultsField, properties);
if (defaults != null) {
writer.startNode("defaults");
marshal(defaults, writer, context);
writer.endNode();
}
}
}
示例5: marshal
import com.thoughtworks.xstream.io.HierarchicalStreamWriter; //導入方法依賴的package包/類
@Override
public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) {
final int length = Array.getLength(source);
for (int i = 0; i < length; ++i) {
final Object item = Array.get(source, i);
final Class<?> itemType = item == null ? Mapper.Null.class : arrayType.getComponentType().isPrimitive()
? Primitives.unbox(item.getClass())
: item.getClass();
ExtendedHierarchicalStreamWriterHelper.startNode(writer, itemName, itemType);
if (!itemType.equals(arrayType.getComponentType())) {
final String attributeName = mapper.aliasForSystemAttribute("class");
if (attributeName != null) {
writer.addAttribute(attributeName, mapper.serializedClass(itemType));
}
}
if (item != null) {
context.convertAnother(item);
}
writer.endNode();
}
}
示例6: writeClass
import com.thoughtworks.xstream.io.HierarchicalStreamWriter; //導入方法依賴的package包/類
@Override
public void writeClass(HierarchicalStreamWriter writer, Object object)
{
if( object.getClass() != clazz )
{
writer.addAttribute(XCLASS, object.getClass().getName());
}
}
示例7: marshallElement
import com.thoughtworks.xstream.io.HierarchicalStreamWriter; //導入方法依賴的package包/類
private void marshallElement(HierarchicalStreamWriter writer, Element element) {
writer.startNode(element.getName());
for (Attribute attribute: (List<Attribute>)element.attributes())
writer.addAttribute(attribute.getName(), attribute.getValue());
if (element.getText().trim().length() != 0)
writer.setValue(element.getText().trim());
for (Element child: (List<Element>)element.elements())
marshallElement(writer, child);
writer.endNode();
}
示例8: 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();
}
}
}
}
示例9: writeClass
import com.thoughtworks.xstream.io.HierarchicalStreamWriter; //導入方法依賴的package包/類
@Override
public void writeClass(HierarchicalStreamWriter writer, Object object)
{
Class<?> clazz = object.getClass();
if( !clazz.equals(defaultClass) )
{
String name = mapping.inverse().get(clazz);
if( name != null )
{
writer.addAttribute(attribute, name);
}
}
}
示例10: setValue
import com.thoughtworks.xstream.io.HierarchicalStreamWriter; //導入方法依賴的package包/類
public void setValue(HierarchicalStreamWriter writer, String string)
{
if( attributeName != null )
{
writer.addAttribute(attributeName, string);
}
else
{
writer.setValue(string);
}
}
示例11: marshal
import com.thoughtworks.xstream.io.HierarchicalStreamWriter; //導入方法依賴的package包/類
@Override
public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) {
final InvocationHandler invocationHandler = Proxy.getInvocationHandler(source);
addInterfacesToXml(source, writer);
writer.startNode("handler");
final String attributeName = mapper.aliasForSystemAttribute("class");
if (attributeName != null) {
writer.addAttribute(attributeName, mapper.serializedClass(invocationHandler.getClass()));
}
context.convertAnother(invocationHandler);
writer.endNode();
}
示例12: marshal
import com.thoughtworks.xstream.io.HierarchicalStreamWriter; //導入方法依賴的package包/類
@Override
public void marshal(Object obj, HierarchicalStreamWriter writer, MarshallingContext context)
{
BaseEntity entity = (BaseEntity) obj;
writer.addAttribute("entityclass", obj.getClass().getName()); //$NON-NLS-1$
String uuid = entity.getUuid();
writer.addAttribute("uuid", uuid); //$NON-NLS-1$
}
示例13: writeItem
import com.thoughtworks.xstream.io.HierarchicalStreamWriter; //導入方法依賴的package包/類
protected void writeItem(final String name, final Class<?> type, final Object item,
final MarshallingContext context, final HierarchicalStreamWriter writer) {
final Class<?> itemType = item == null ? Mapper.Null.class : item.getClass();
ExtendedHierarchicalStreamWriterHelper.startNode(writer, name, itemType);
if (!itemType.equals(type)) {
final String attributeName = mapper().aliasForSystemAttribute("class");
if (attributeName != null) {
writer.addAttribute(attributeName, mapper().serializedClass(itemType));
}
}
if (item != null) {
context.convertAnother(item);
}
writer.endNode();
}
示例14: addAttribute
import com.thoughtworks.xstream.io.HierarchicalStreamWriter; //導入方法依賴的package包/類
protected void addAttribute(HierarchicalStreamWriter writer, String name, String value)
{
if( value != null && value.length() > 0 )
{
writer.addAttribute(name, value);
}
}
示例15: marshal
import com.thoughtworks.xstream.io.HierarchicalStreamWriter; //導入方法依賴的package包/類
@Override
public void marshal(Object object, HierarchicalStreamWriter writer, MarshallingContext arg2)
{
ResumptionToken token = (ResumptionToken) object;
writer.addAttribute(COMPLETELISTSIZE, "" + token.getCompleteListSize());
writer.addAttribute(CURSOR, "" + token.getCursor());
writer.setValue(token.getToken());
}