Java Code Examples for com.thoughtworks.xstream.io.HierarchicalStreamWriter#addAttribute()
The following examples show how to use
com.thoughtworks.xstream.io.HierarchicalStreamWriter#addAttribute() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ModelSerializer.java From mql-editor with GNU Lesser General Public License v2.1 | 6 votes |
public void marshal( Object value, HierarchicalStreamWriter writer, MarshallingContext context ) { Condition condition = (Condition) value; writer.startNode( "condition" ); writer.addAttribute( "combinationType", condition.getCombinationType() != null ? condition.getCombinationType() .toString() : "" ); writer.addAttribute( "defaultValue", condition.getDefaultValue() ); writer.addAttribute( "operator", condition.getOperator().toString() ); writer.addAttribute( "selectedAggType", condition.getSelectedAggType() != null ? condition.getSelectedAggType() .toString() : "" ); writer.addAttribute( "value", condition.getValue() ); writer.startNode( "column" ); context.convertAnother( condition.getColumn() ); writer.endNode(); writer.endNode(); }
Example 2
Source File: HierarchicalStreamCopier.java From lams with GNU General Public License v2.0 | 6 votes |
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(); }
Example 3
Source File: PropertiesConverter.java From lams with GNU General Public License v2.0 | 6 votes |
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { final Properties properties = (Properties) source; Map map = sort ? (Map)new TreeMap(properties) : (Map)properties; for (Iterator iterator = map.entrySet().iterator(); iterator.hasNext();) { Map.Entry entry = (Map.Entry) iterator.next(); writer.startNode("property"); writer.addAttribute("name", entry.getKey().toString()); writer.addAttribute("value", entry.getValue().toString()); writer.endNode(); } if (defaultsField != null) { Properties defaults = (Properties)Fields.read(defaultsField, properties); if (defaults != null) { writer.startNode("defaults"); marshal(defaults, writer, context); writer.endNode(); } } }
Example 4
Source File: AbstractReflectionConverter.java From lams with GNU General Public License v2.0 | 6 votes |
public void marshal(Object original, final HierarchicalStreamWriter writer, final MarshallingContext context) { final Object source = serializationMembers.callWriteReplace(original); if (source != original && context instanceof ReferencingMarshallingContext) { ((ReferencingMarshallingContext)context).replace(original, source); } if (source.getClass() != original.getClass()) { String attributeName = mapper.aliasForSystemAttribute("resolves-to"); if (attributeName != null) { writer.addAttribute(attributeName, mapper.serializedClass(source.getClass())); } context.convertAnother(source); } else { doMarshal(source, writer, context); } }
Example 5
Source File: StringKeyMapConverter.java From brooklyn-server with Apache License 2.0 | 6 votes |
protected void marshalStringKey(HierarchicalStreamWriter writer, MarshallingContext context, Entry entry) { String key = (String)entry.getKey(); String entryNodeName = getEntryNodeName(); boolean useKeyAsNodeName = (!key.equals(entryNodeName) && isKeyValidForNodeName(key)); if (useKeyAsNodeName) entryNodeName = key; ExtendedHierarchicalStreamWriterHelper.startNode(writer, entryNodeName, Map.Entry.class); if (!useKeyAsNodeName) writer.addAttribute("key", key); Object value = entry.getValue(); if (entry.getValue()!=null && isInlineableType(value.getClass())) { if (!(value instanceof String)) writer.addAttribute("type", mapper().serializedClass(entry.getValue().getClass())); if (entry.getValue().getClass().isEnum()) writer.setValue(((Enum)entry.getValue()).name()); else writer.setValue(""+entry.getValue()); } else { writeItem(entry.getValue(), context, writer); } writer.endNode(); }
Example 6
Source File: FileDocumentReferenceConverter.java From depan with Apache License 2.0 | 5 votes |
/** * Simply output the workspace relative name for the referenced GraphModel. */ @Override public void marshal( Object source, HierarchicalStreamWriter writer, MarshallingContext context) { FileDocumentReference<?> docRef = (FileDocumentReference<?>) source; String location = PlatformTools.fromPath(docRef.getLocation().getFullPath()); writer.startNode(FILE_DOC_REF_TAG); writer.addAttribute(DOC_PATH_ATTR, location); writer.endNode(); }
Example 7
Source File: ResourceDocumentReferenceConverter.java From depan with Apache License 2.0 | 5 votes |
/** * Simply output the workspace relative name for the referenced GraphModel. */ @Override public void marshal( Object source, HierarchicalStreamWriter writer, MarshallingContext context) { ResourceDocumentReference<?> docRef = (ResourceDocumentReference<?>) source; ResourceContainer container = docRef.getResourceContainer(); String docPath = PlatformTools.fromPath(container.getPath()); String docName = docRef.getDocument().getName(); writer.startNode(RSRC_DOC_REF_TAG); writer.addAttribute(DOC_PATH_ATTR, docPath); writer.addAttribute(DOC_NAME_ATTR, docName); writer.endNode(); }
Example 8
Source File: VersionedXmlDoc.java From onedev with MIT License | 5 votes |
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(); }
Example 9
Source File: UserXmlUtil.java From auction-website with MIT License | 5 votes |
@Override public void marshal(Object o, HierarchicalStreamWriter writer, MarshallingContext marshallingContext) { UserEntity seller = (UserEntity) o; writer.addAttribute("UserID", seller.getUsername()); // this will compute the sum of ratings of a user as seller seller.setRatingAs("seller"); writer.addAttribute("Rating", String.valueOf(seller.getRatingAsSeller())); }
Example 10
Source File: ResourceTransportWrapperConverter.java From saros with GNU General Public License v2.0 | 5 votes |
@Override public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) { ResourceTransportWrapper<?> wrapper = (ResourceTransportWrapper<?>) value; IResource resource = wrapper.getResource(); String i = session.getReferencePointId(resource.getReferencePoint()); if (i == null) { log.error( "Could not retrieve reference point id for reference point '" + resource.getReferencePoint().getName() + "' of resource " + resource + ". Make sure you don't create activities for non-shared resources"); return; } // TODO use IPath.toPortableString() instead? String p = URLCodec.encode(pathFactory.fromPath(resource.getReferencePointRelativePath())); Type type = resource.getType(); if (type != Type.FILE && type != Type.FOLDER) { throw new IllegalStateException( "Illegal resource type " + type + " for resource " + resource); } String t = type.name(); writer.addAttribute(REFERENCE_POINT_ID, i); writer.addAttribute(PATH, p); writer.addAttribute(TYPE, t); }
Example 11
Source File: Field4RestConverter.java From gsn with GNU General Public License v3.0 | 5 votes |
public void marshal(Object in, HierarchicalStreamWriter writer, MarshallingContext context) { Field4Rest input = (Field4Rest) in; writer.addAttribute("name", input.getName()); if(input.getValue()==null) writer.addAttribute("is-null", "true"); String type = "not-detected"; String value = null; switch (input.getType()) { case DataTypes.BIGINT: case DataTypes.SMALLINT: case DataTypes.INTEGER: case DataTypes.DOUBLE: case DataTypes.TINYINT: case DataTypes.FLOAT: type="numeric"; if (input.getValue() !=null) value = Double.toString(((Number)input.getValue()).doubleValue()); break; case DataTypes.CHAR: case DataTypes.VARCHAR: type="string"; if (input.getValue() !=null) value = (String)input.getValue(); break; default: type="binary"; if (input.getValue() !=null) value =base64.encode((byte[]) input.getValue()); } writer.addAttribute("type", type); if (value!=null) writer.setValue(value); }
Example 12
Source File: EnumMapConverter.java From lams with GNU General Public License v2.0 | 5 votes |
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { Class type = (Class) Fields.read(typeField, source); String attributeName = mapper().aliasForSystemAttribute("enum-type"); if (attributeName != null) { writer.addAttribute(attributeName, mapper().serializedClass(type)); } super.marshal(source, writer, context); }
Example 13
Source File: ChannelModelImpl.java From kogito-runtimes with Apache License 2.0 | 5 votes |
public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) { ChannelModelImpl channel = (ChannelModelImpl) value; writer.addAttribute("name", channel.getName()); writer.addAttribute("type", channel.getType()); /* TODO make qualifiers working properly before readd them to the xml QualifierModelImpl qualifier = (QualifierModelImpl)channel.getQualifierModel(); if (qualifier != null) { if (qualifier.isSimple()) { writer.addAttribute("qualifier", qualifier.getType()); } else { writeObject(writer, context, "qualifier", qualifier); } } */ }
Example 14
Source File: RssImageEntryConverter.java From mamute with Apache License 2.0 | 5 votes |
@Override public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) { final RssImageEntry entry = (RssImageEntry) value; writer.addAttribute("url", entry.getUrl()); writer.addAttribute("type", "image/*"); writer.addAttribute("length", "0"); }
Example 15
Source File: BeanDefinitionWriterServiceImpl.java From geomajas-project-server with GNU Affero General Public License v3.0 | 4 votes |
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { RuntimeBeanReference value = (RuntimeBeanReference) source; writer.addAttribute("bean", value.getBeanName()); }
Example 16
Source File: ModelSerializer.java From mql-editor with GNU Lesser General Public License v2.1 | 4 votes |
public void marshal( Object value, HierarchicalStreamWriter writer, MarshallingContext context ) { Domain domain = (Domain) value; writer.addAttribute( "id", domain.getId() ); writer.addAttribute( "name", domain.getName() ); }
Example 17
Source File: ExternalizableConverter.java From lams with GNU General Public License v2.0 | 4 votes |
public void marshal(final Object original, final HierarchicalStreamWriter writer, final MarshallingContext context) { final Object source = serializationMembers.callWriteReplace(original); if (source != original && context instanceof ReferencingMarshallingContext) { ((ReferencingMarshallingContext)context).replace(original, source); } if (source.getClass() != original.getClass()) { final String attributeName = mapper.aliasForSystemAttribute("resolves-to"); if (attributeName != null) { writer.addAttribute(attributeName, mapper.serializedClass(source.getClass())); } context.convertAnother(source); } else { try { Externalizable externalizable = (Externalizable)source; CustomObjectOutputStream.StreamCallback callback = new CustomObjectOutputStream.StreamCallback() { 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(); } } public void writeFieldsToStream(final Map fields) { throw new UnsupportedOperationException(); } public void defaultWriteObject() { throw new UnsupportedOperationException(); } public void flush() { writer.flush(); } public void close() { throw new UnsupportedOperationException("Objects are not allowed to call ObjectOutput.close() from writeExternal()"); } }; final CustomObjectOutputStream objectOutput = CustomObjectOutputStream.getInstance(context, callback); externalizable.writeExternal(objectOutput); objectOutput.popCallback(); } catch (IOException e) { throw new StreamException("Cannot serialize " + source.getClass().getName() + " using Externalization", e); } } }
Example 18
Source File: VersionedExternalizable.java From sakai with Educational Community License v2.0 | 4 votes |
@Override public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { writer.addAttribute(VERSION_ATTRIBUTE, ((VersionedExternalizable) source).getExternalizableVersion()); super.marshal(source, writer, context); }
Example 19
Source File: XMLConfigurer.java From oval with Eclipse Public License 2.0 | 4 votes |
@Override public void marshal(final Object value, final HierarchicalStreamWriter writer, final MarshallingContext context) { final Pattern pattern = (Pattern) value; writer.addAttribute("pattern", pattern.pattern()); writer.addAttribute("flags", Integer.toString(pattern.flags())); }
Example 20
Source File: SettingsConverter.java From weblaf with GNU General Public License v3.0 | 4 votes |
@Override public void marshal ( final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context ) { final SettingsGroup settingsGroup = ( SettingsGroup ) source; // Converting group information writer.addAttribute ( "id", settingsGroup.getId () ); writer.addAttribute ( "name", settingsGroup.getName () ); // Converting settings for ( final Map.Entry<String, Object> entry : settingsGroup.settings ().entrySet () ) { // If key text is proper for node name it will be used, otherwise it will be separated final String key = entry.getKey (); final Object value = entry.getValue (); // Starting entry node final String nodeName; if ( XMLChar.isValidName ( key ) ) { nodeName = key; writer.startNode ( nodeName ); } else { nodeName = "entry"; writer.startNode ( nodeName ); writer.addAttribute ( "key", key ); } if ( value == null ) { // Adding special null value type writer.addAttribute ( "type", NULL_TYPE ); } else { // Adding type reference if it is not the same as node name // This condition added to remove redundant type duplications final String serializedType = mapper.serializedClass ( value.getClass () ); if ( !nodeName.equals ( serializedType ) ) { writer.addAttribute ( "type", serializedType ); } // Converting value context.convertAnother ( value ); } // Closing entry node writer.endNode (); } }