Java Code Examples for com.thoughtworks.xstream.converters.UnmarshallingContext#put()
The following examples show how to use
com.thoughtworks.xstream.converters.UnmarshallingContext#put() .
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: AbstractDescriptionTypeConverter.java From openhab-core with Eclipse Public License 2.0 | 6 votes |
@Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { // read attributes Map<String, String> attributes = this.attributeMapValidator.readValidatedAttributes(reader); // set automatically extracted URI for a possible 'config-description' section context.put("config-description.uri", this.type + ":" + getUID(attributes, context)); // read values List<?> nodes = (List<?>) context.convertAnother(context, List.class); NodeIterator nodeIterator = new NodeIterator(nodes); // create object Object object = unmarshalType(reader, context, attributes, nodeIterator); nodeIterator.assertEndOfType(); return object; }
Example 2
Source File: ViewDocumentConverter.java From depan with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} * <p> * This implementation temporarily injects the current {@code GraphModel} * instance into the {@code UnmarshallingContext} with the key * {@code GraphModel.class}. This allows the {@link EdgeReferenceConverter} to * translate node ids directly into node references. * * @see EdgeConverter#unmarshal(HierarchicalStreamReader, UnmarshallingContext) */ @Override public Object unmarshal( HierarchicalStreamReader reader, UnmarshallingContext context) { // There should not be two graphs in the same serialization, // but just in case .... GraphDocument prior = getGraphDocument(context); setupReferenceDocuments(context); try { GraphModelReference viewInfo = unmarshalGraphModelReference(reader, context); context.put(GraphModel.class, viewInfo.getGraph()); Collection<GraphNode> viewNodes = unmarshalNodes(reader, context); // TODO: Converter for ViewPreferences ViewPreferences viewPrefs = (ViewPreferences) unmarshalObject(reader, context); viewPrefs.afterUnmarshall(); viewPrefs.initTransients(); return new ViewDocument(viewInfo, viewNodes, viewPrefs); } finally { putGraphDocument(context, prior); } }
Example 3
Source File: AbstractDescriptionTypeConverter.java From smarthome with Eclipse Public License 2.0 | 6 votes |
@Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { // read attributes Map<String, String> attributes = this.attributeMapValidator.readValidatedAttributes(reader); // set automatically extracted URI for a possible 'config-description' section context.put("config-description.uri", this.type + ":" + getUID(attributes, context)); // read values List<?> nodes = (List<?>) context.convertAnother(context, List.class); NodeIterator nodeIterator = new NodeIterator(nodes); // create object Object object = unmarshalType(reader, context, attributes, nodeIterator); nodeIterator.assertEndOfType(); return object; }
Example 4
Source File: BindingInfoConverter.java From openhab-core with Eclipse Public License 2.0 | 5 votes |
@Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { BindingInfoXmlResult bindingInfoXmlResult = null; BindingInfo bindingInfo = null; // read attributes Map<String, String> attributes = this.attributeMapValidator.readValidatedAttributes(reader); String id = attributes.get("id"); // set automatically extracted URI for a possible 'config-description' section context.put("config-description.uri", "binding:" + id); // read values List<?> nodes = (List<?>) context.convertAnother(context, List.class); NodeIterator nodeIterator = new NodeIterator(nodes); String name = (String) nodeIterator.nextValue("name", true); String description = (String) nodeIterator.nextValue("description", false); String author = (String) nodeIterator.nextValue("author", false); String serviceId = (String) nodeIterator.nextValue("service-id", false); URI configDescriptionURI = readConfigDescriptionURI(nodeIterator); ConfigDescription configDescription = null; if (configDescriptionURI == null) { configDescription = readConfigDescription(nodeIterator); if (configDescription != null) { configDescriptionURI = configDescription.getUID(); } } nodeIterator.assertEndOfType(); // create object bindingInfo = new BindingInfo(id, name, description, author, serviceId, configDescriptionURI); bindingInfoXmlResult = new BindingInfoXmlResult(bindingInfo, configDescription); return bindingInfoXmlResult; }
Example 5
Source File: ThingDescriptionConverter.java From openhab-core with Eclipse Public License 2.0 | 5 votes |
@Override public final Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { // read attributes Map<String, String> attributes = this.attributeMapValidator.readValidatedAttributes(reader); String bindingId = attributes.get("bindingId"); context.put("thing-descriptions.bindingId", bindingId); List<?> typeList = (List<?>) context.convertAnother(context, List.class); return new ThingDescriptionList(typeList); }
Example 6
Source File: ComponentStyleConverter.java From weblaf with GNU General Public License v3.0 | 5 votes |
/** * Reads {@link PainterStyle} for the specified {@link ComponentStyle}. * * @param style {@link ComponentStyle} to read {@link PainterStyle} for * @param descriptor {@link ComponentDescriptor} * @param reader {@link HierarchicalStreamReader} * @param context {@link UnmarshallingContext} */ private void readPainterStyle ( @NotNull final ComponentStyle style, @NotNull final ComponentDescriptor descriptor, @NotNull final HierarchicalStreamReader reader, @NotNull final UnmarshallingContext context ) { // Retrieving overwrite policy final String ow = reader.getAttribute ( OVERWRITE_ATTRIBUTE ); final Boolean overwrite = ow != null ? Boolean.parseBoolean ( ow ) : null; // Retrieving default painter class from component descriptor final Class<? extends Painter> defaultPainter = descriptor.getPainterClass (); // Unmarshalling painter class final Class<? extends Painter> painterClass = PainterStyleConverter.unmarshalPainterClass ( reader, context, mapper, defaultPainter, style.getId () ); // Providing painter class to subsequent converters final Object opc = context.get ( CONTEXT_PAINTER_CLASS ); context.put ( CONTEXT_PAINTER_CLASS, painterClass ); // Creating painter style final PainterStyle painterStyle = new PainterStyle (); painterStyle.setOverwrite ( overwrite ); painterStyle.setPainterClass ( painterClass.getCanonicalName () ); // Reading painter style properties // Using LinkedHashMap to keep properties order final LinkedHashMap<String, Object> painterProperties = new LinkedHashMap<String, Object> (); StyleConverterUtils.readProperties ( reader, context, mapper, painterProperties, painterClass, style.getId () ); painterStyle.setProperties ( painterProperties ); // Saving painter style style.setPainterStyle ( painterStyle ); // Cleaning up context context.put ( CONTEXT_PAINTER_CLASS, opc ); }
Example 7
Source File: ThingDescriptionConverter.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Override public final Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { // read attributes Map<String, String> attributes = this.attributeMapValidator.readValidatedAttributes(reader); String bindingId = attributes.get("bindingId"); context.put("thing-descriptions.bindingId", bindingId); List<?> typeList = (List<?>) context.convertAnother(context, List.class); return new ThingDescriptionList(typeList); }
Example 8
Source File: BindingInfoConverter.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { BindingInfoXmlResult bindingInfoXmlResult = null; BindingInfo bindingInfo = null; // read attributes Map<String, String> attributes = this.attributeMapValidator.readValidatedAttributes(reader); String id = attributes.get("id"); // set automatically extracted URI for a possible 'config-description' section context.put("config-description.uri", "binding:" + id); // read values List<?> nodes = (List<?>) context.convertAnother(context, List.class); NodeIterator nodeIterator = new NodeIterator(nodes); String name = (String) nodeIterator.nextValue("name", true); String description = (String) nodeIterator.nextValue("description", false); String author = (String) nodeIterator.nextValue("author", false); String serviceId = (String) nodeIterator.nextValue("service-id", false); URI configDescriptionURI = readConfigDescriptionURI(nodeIterator); ConfigDescription configDescription = null; if (configDescriptionURI == null) { configDescription = readConfigDescription(nodeIterator); if (configDescription != null) { configDescriptionURI = configDescription.getUID(); } } nodeIterator.assertEndOfType(); // create object bindingInfo = new BindingInfo(id, name, description, author, serviceId, configDescriptionURI); bindingInfoXmlResult = new BindingInfoXmlResult(bindingInfo, configDescription); return bindingInfoXmlResult; }
Example 9
Source File: PainterStyleConverter.java From weblaf with GNU General Public License v3.0 | 4 votes |
@NotNull @Override public Object unmarshal ( @NotNull final HierarchicalStreamReader reader, @NotNull final UnmarshallingContext context ) { // Retrieving style identifier from context // It must be there at all times, whether this painter is read from style or another painter final String styleId = ( String ) context.get ( ComponentStyleConverter.CONTEXT_STYLE_ID ); if ( styleId == null ) { throw new StyleException ( "Context style identifier must be specified" ); } // Retrieving overwrite policy final String ow = reader.getAttribute ( ComponentStyleConverter.OVERWRITE_ATTRIBUTE ); final Boolean overwrite = ow != null ? Boolean.parseBoolean ( ow ) : null; // Retrieving default painter class based on parent painter and this node name // Basically we are reading this painter as a field of another painter here final Class<? extends Painter> parent = ( Class<? extends Painter> ) context.get ( ComponentStyleConverter.CONTEXT_PAINTER_CLASS ); final Class<? extends Painter> defaultPainter = getDefaultPainter ( parent, reader.getNodeName () ); // Unmarshalling painter class final Class<? extends Painter> painterClass = PainterStyleConverter.unmarshalPainterClass ( reader, context, mapper, defaultPainter, styleId ); // Providing painter class to subsequent converters context.put ( ComponentStyleConverter.CONTEXT_PAINTER_CLASS, painterClass ); // Reading painter style properties // Using LinkedHashMap to keep properties order final LinkedHashMap<String, Object> painterProperties = new LinkedHashMap<String, Object> (); StyleConverterUtils.readProperties ( reader, context, mapper, painterProperties, painterClass, styleId ); // Creating painter style final PainterStyle painterStyle = new PainterStyle (); painterStyle.setOverwrite ( overwrite ); painterStyle.setPainterClass ( painterClass.getCanonicalName () ); painterStyle.setProperties ( painterProperties ); // Cleaning up context context.put ( ComponentStyleConverter.CONTEXT_PAINTER_CLASS, parent ); return painterStyle; }
Example 10
Source File: XmlIconSetConverter.java From weblaf with GNU General Public License v3.0 | 4 votes |
@NotNull @Override public Object unmarshal ( @NotNull final HierarchicalStreamReader reader, @NotNull final UnmarshallingContext context ) { try { final XmlIconSet iconSetData = ( XmlIconSet ) context.currentObject (); // Forcefully updating XmlIconSet final identifier ReflectUtils.setFieldValue ( iconSetData, "id", reader.getAttribute ( ID_ATTRIBUTE ) ); // Configuring context with XmlIconSet resource settings context.put ( XmlUtils.CONTEXT_NEAR_CLASS, reader.getAttribute ( XmlUtils.NEAR_CLASS_ATTRIBUTE ) ); context.put ( XmlUtils.CONTEXT_BASE, reader.getAttribute ( XmlUtils.BASE_ATTRIBUTE ) ); // Reading icons specified in the XmlIconSet while ( reader.hasMoreChildren () ) { reader.moveDown (); final String nodeName = reader.getNodeName (); final Class<?> iconSourceClass = mapper.realClass ( nodeName ); if ( IconSource.class.isAssignableFrom ( iconSourceClass ) ) { iconSetData.addIcon ( ( IconSource ) context.convertAnother ( iconSetData, iconSourceClass ) ); } reader.moveUp (); } // Removing XmlIconSet resource settings from context context.put ( XmlUtils.CONTEXT_BASE, null ); context.put ( XmlUtils.CONTEXT_NEAR_CLASS, null ); return iconSetData; } catch ( final Exception e ) { throw new IconException ( "Unable to load XmlIconSet", e ); } }
Example 11
Source File: XmlMementoSerializer.java From brooklyn-server with Apache License 2.0 | 4 votes |
protected void instantiateNewInstanceSettingCache(HierarchicalStreamReader reader, UnmarshallingContext context) { Object instance = super.instantiateNewInstance(reader, context); context.put("SpecConverter.instance", instance); }
Example 12
Source File: XmlMementoSerializer.java From brooklyn-server with Apache License 2.0 | 4 votes |
@Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { String catalogItemId = null; instantiateNewInstanceSettingCache(reader, context); if (reader instanceof PathTrackingReader) { // have to assume this is first; there is no mark/reset support on these readers // (if there were then it would be easier, we could just look for that child anywhere, // and not need a custom writer!) if ("catalogItemId".equals( ((PathTrackingReader)reader).peekNextChild() )) { // cache the instance reader.moveDown(); catalogItemId = reader.getValue(); reader.moveUp(); } } boolean customLoaderSet = false; try { if (Strings.isNonBlank(catalogItemId)) { if (lookupContext==null) throw new NullPointerException("lookupContext required to load catalog item "+catalogItemId); RegisteredType cat = lookupContext.lookupManagementContext().getTypeRegistry().get(catalogItemId); if (cat==null) { String upgradedItemId = CatalogUpgrades.getTypeUpgradedIfNecessary(lookupContext.lookupManagementContext(), catalogItemId); if (!Objects.equal(catalogItemId, upgradedItemId)) { LOG.warn("Upgrading spec catalog item id from "+catalogItemId+" to "+upgradedItemId+" on rebind "+getContextDescription(context)); cat = lookupContext.lookupManagementContext().getTypeRegistry().get(upgradedItemId); catalogItemId = upgradedItemId; } } if (cat==null) throw new NoSuchElementException("catalog item: "+catalogItemId); BrooklynClassLoadingContext clcNew = CatalogUtils.newClassLoadingContext(lookupContext.lookupManagementContext(), cat); delegatingClassLoader.pushClassLoadingContext(clcNew); customLoaderSet = true; CatalogUpgrades.markerForCodeThatLoadsJavaTypesButShouldLoadRegisteredType(); } AbstractBrooklynObjectSpec<?, ?> result = (AbstractBrooklynObjectSpec<?, ?>) super.unmarshal(reader, context); // we wrote it twice so this shouldn't be necessary; but if we fix it so we only write once, we'd need this result.catalogItemId(catalogItemId); return result; } finally { context.put("SpecConverter.instance", null); if (customLoaderSet) { delegatingClassLoader.popClassLoadingContext(); } } }
Example 13
Source File: PropertyDocumentReferenceContext.java From depan with Apache License 2.0 | 4 votes |
public static void setResourceRoot( UnmarshallingContext context, ResourceContainer proj) { context.put(CONTEXT_KEY.RESOURCE_ROOT, proj); }
Example 14
Source File: PropertyDocumentReferenceContext.java From depan with Apache License 2.0 | 4 votes |
public static void setProjectSource( UnmarshallingContext context, IContainer proj) { context.put(CONTEXT_KEY.PROJECT, proj); }
Example 15
Source File: GraphModelConverter.java From depan with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} * <p> * This implementation injects a newly synthesized {@code GraphBuilder} * instance into the {@code UnmarshallingContext} with the key * {@code GraphBuilder.class}. This allows the {@link EdgeConverter} to * translate node ids directly into node references. * * @see EdgeConverter#unmarshal(HierarchicalStreamReader, UnmarshallingContext) */ @Override public Object unmarshal( HierarchicalStreamReader reader, UnmarshallingContext context) { // There should not be two graphs in the same serialization, // but just in case .... GraphBuilder prior = contextGraphBuilder(context); try { GraphBuilder builder = GraphBuilders.createGraphModelBuilder(); context.put(GraphBuilder.class, builder); while (reader.hasMoreChildren()) { reader.moveDown(); String childName = reader.getNodeName(); Class<?> childClass = mapper.realClass(childName); if (GraphNode.class.isAssignableFrom(childClass)) { GraphNode node = (GraphNode) context.convertAnother(null, childClass); builder.newNode(node); } else if (GraphEdge.class.isAssignableFrom(childClass)) { GraphEdge edge = (GraphEdge) context.convertAnother(null, childClass); builder.addEdge(edge); } else { LOG.info("Skipped object with tag {}", childName); } reader.moveUp(); } return builder.createGraphModel(); } catch (RuntimeException err) { // TODO Auto-generated catch block err.printStackTrace(); throw err; } finally { context.put(GraphBuilder.class, prior); } }
Example 16
Source File: ReferencedGraphDocumentConverter.java From depan with Apache License 2.0 | 4 votes |
/** Save a reference to the referenced {@code GraphDocument}. */ public void putGraphDocument( UnmarshallingContext context, GraphDocument graphDoc) { context.put(GraphDocument.class, graphDoc); }
Example 17
Source File: GraphModelReferenceConverter.java From depan with Apache License 2.0 | 2 votes |
/** * Store the file-system path for the XML source in the supplied * {@link UnmarshallingContext}. */ public static void setRelativeSource(UnmarshallingContext context, File source) { context.put(GraphModelSource.RELATIVE, source); }
Example 18
Source File: GraphModelReferenceConverter.java From depan with Apache License 2.0 | 2 votes |
/** * Store the project-based path for the XML source in the supplied * {@link UnmarshallingContext}. */ public static void setProjectSource(UnmarshallingContext context, IFile source) { context.put(GraphModelSource.PROJECT, source); }