Java Code Examples for com.thoughtworks.xstream.converters.UnmarshallingContext#get()

The following examples show how to use com.thoughtworks.xstream.converters.UnmarshallingContext#get() . 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 5 votes vote down vote up
/**
 * Returns the full extracted UID of the specific XML type definition.
 *
 * @param attributes the attributes where to extract the ID information (must not be null)
 * @param context the context where to extract the binding ID information (must not be null)
 *
 * @return the UID of the type definition (neither null, nor empty)
 */
protected String getUID(Map<String, String> attributes, UnmarshallingContext context) {
    String bindingId = (String) context.get("thing-descriptions.bindingId");
    String typeId = getID(attributes);

    String uid = String.format("%s:%s", bindingId, typeId);

    return uid;
}
 
Example 2
Source File: XmlMementoSerializer.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Override
protected Object instantiateNewInstance(HierarchicalStreamReader reader, UnmarshallingContext context) {
    // the super calls getAttribute which requires that we have not yet done moveDown,
    // so we do this earlier and cache it for when we call super.unmarshal.
    // Store this in the UnmarshallingContext. Note that we *must not* use a field of SpecConverter,
    // because that same instance is used by everything calling XmlMementoSerializer (including multiple
    // threads).
    Object instance = context.get("SpecConverter.instance");
    if (instance==null)
        throw new IllegalStateException("Instance should be created and cached");
    return instance;
}
 
Example 3
Source File: AbstractDescriptionTypeConverter.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns the full extracted UID of the specific XML type definition.
 *
 * @param attributes the attributes where to extract the ID information (must not be null)
 * @param context the context where to extract the binding ID information (must not be null)
 *
 * @return the UID of the type definition (neither null, nor empty)
 */
protected String getUID(Map<String, String> attributes, UnmarshallingContext context) {
    String bindingId = (String) context.get("thing-descriptions.bindingId");
    String typeId = getID(attributes);

    String uid = String.format("%s:%s", bindingId, typeId);

    return uid;
}
 
Example 4
Source File: ComponentStyleConverter.java    From weblaf with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 5
Source File: GraphModelReferenceConverter.java    From depan with Apache License 2.0 4 votes vote down vote up
private IFile getProjectSource(UnmarshallingContext context) {
  return (IFile) context.get(GraphModelSource.PROJECT);
}
 
Example 6
Source File: GraphModelReferenceConverter.java    From depan with Apache License 2.0 4 votes vote down vote up
private File getRelativeSource(UnmarshallingContext context) {
  return (File) context.get(GraphModelSource.RELATIVE);
}
 
Example 7
Source File: ReferencedGraphDocumentConverter.java    From depan with Apache License 2.0 4 votes vote down vote up
/** Provide access to the referenced {@code GraphDocument}. */
public GraphDocument getGraphDocument(UnmarshallingContext context) {
  return (GraphDocument) context.get(GraphDocument.class);
}
 
Example 8
Source File: PropertyDocumentReferenceContext.java    From depan with Apache License 2.0 4 votes vote down vote up
public static IContainer getProjectSource(UnmarshallingContext context) {
  return (IContainer) context.get(CONTEXT_KEY.PROJECT);
}
 
Example 9
Source File: PropertyDocumentReferenceContext.java    From depan with Apache License 2.0 4 votes vote down vote up
public static ResourceContainer getResourceRoot(
    UnmarshallingContext context) {
  return (ResourceContainer) context.get(CONTEXT_KEY.RESOURCE_ROOT);
}
 
Example 10
Source File: PainterStyleConverter.java    From weblaf with GNU General Public License v3.0 4 votes vote down vote up
@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 11
Source File: XmlUtils.java    From weblaf with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns {@link Resource} based on the available attributes in the current node.
 *
 * @param reader  {@link HierarchicalStreamReader}
 * @param context {@link UnmarshallingContext}
 * @param mapper  {@link Mapper}
 * @return {@link Resource} based on the available attributes in the current node
 */
@NotNull
public static Resource readResource ( @NotNull final HierarchicalStreamReader reader, @NotNull final UnmarshallingContext context,
                                      @NotNull final Mapper mapper )
{
    final Resource resource;
    final String path = reader.getAttribute ( "path" );
    final String contextBase = ( String ) context.get ( CONTEXT_BASE );
    if ( path != null )
    {
        final String completePath = contextBase != null ? NetUtils.joinUrlPaths ( contextBase, path ) : path;
        final String nearClass = reader.getAttribute ( "nearClass" );
        if ( nearClass != null )
        {
            resource = new ClassResource ( mapper.realClass ( nearClass ), completePath );
        }
        else
        {
            final String contextNearClass = ( String ) context.get ( CONTEXT_NEAR_CLASS );
            if ( contextNearClass != null )
            {
                resource = new ClassResource ( mapper.realClass ( contextNearClass ), completePath );
            }
            else
            {
                resource = new FileResource ( completePath );
            }
        }
    }
    else
    {
        final String url = reader.getAttribute ( "url" );
        if ( url != null )
        {
            final String completeURL = contextBase != null ? NetUtils.joinUrlPaths ( contextBase, url ) : url;
            resource = new UrlResource ( completeURL );
        }
        else
        {
            throw new UtilityException ( "Unable to find any Resource type in node attributes: " + reader.getNodeName () );
        }
    }
    return resource;
}
 
Example 12
Source File: ThingTypeConverter.java    From openhab-core with Eclipse Public License 2.0 3 votes vote down vote up
protected List<String> readSupportedBridgeTypeUIDs(NodeIterator nodeIterator, UnmarshallingContext context) {
    Object nextNode = nodeIterator.next("supported-bridge-type-refs", false);

    if (nextNode != null) {
        String bindingID = (String) context.get("thing-descriptions.bindingId");

        String uidFormat = String.format("%s:%s", bindingID, "%s");

        return ((NodeList) nextNode).getAttributes("bridge-type-ref", "id", uidFormat);
    }

    return null;
}
 
Example 13
Source File: ThingTypeConverter.java    From smarthome with Eclipse Public License 2.0 3 votes vote down vote up
protected List<String> readSupportedBridgeTypeUIDs(NodeIterator nodeIterator, UnmarshallingContext context) {
    Object nextNode = nodeIterator.next("supported-bridge-type-refs", false);

    if (nextNode != null) {
        String bindingID = (String) context.get("thing-descriptions.bindingId");

        String uidFormat = String.format("%s:%s", bindingID, "%s");

        return ((NodeList) nextNode).getAttributes("bridge-type-ref", "id", uidFormat);
    }

    return null;
}