Java Code Examples for com.thoughtworks.xstream.io.HierarchicalStreamReader#getNodeName()

The following examples show how to use com.thoughtworks.xstream.io.HierarchicalStreamReader#getNodeName() . 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: GitLabSecurityRealm.java    From gitlab-oauth-plugin with MIT License 6 votes vote down vote up
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {

    GitLabSecurityRealm realm = new GitLabSecurityRealm();

    String node;
    String value;

    while (reader.hasMoreChildren()) {
        reader.moveDown();
        node = reader.getNodeName();
        value = reader.getValue();
        setValue(realm, node, value);
        reader.moveUp();
    }

    return realm;
}
 
Example 2
Source File: MapCustomConverter.java    From sdb-mall with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
protected void populateMap(HierarchicalStreamReader reader, UnmarshallingContext context, Map map) {
	while (reader.hasMoreChildren()) {
		reader.moveDown();
		Object key = reader.getNodeName();
		Object value = reader.getValue();
		map.put(key, value);
		reader.moveUp();
	}
}
 
Example 3
Source File: MapEntryConverter.java    From ZenQuery with Apache License 2.0 5 votes vote down vote up
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    Map<String, String> map = new HashMap<String, String>();

    while(reader.hasMoreChildren()) {
        reader.moveDown();

        String key = reader.getNodeName();
        String value = reader.getValue();
        map.put(key, value);

        reader.moveUp();
    }

    return map;
}
 
Example 4
Source File: NodeListConverter.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    Map<String, String> attributes = ConverterAttributeMapValidator.readValidatedAttributes(reader, null);

    String nodeName = reader.getNodeName();
    List<?> values = (List<?>) context.convertAnother(context, List.class);

    return new NodeList(nodeName, attributes, values);
}
 
Example 5
Source File: NodeListConverter.java    From openhab-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    Map<String, String> attributes = ConverterAttributeMapValidator.readValidatedAttributes(reader, null);

    String nodeName = reader.getNodeName();
    List<?> values = (List<?>) context.convertAnother(context, List.class);

    return new NodeList(nodeName, attributes, values);
}
 
Example 6
Source File: NodeAttributesConverter.java    From openhab-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    String nodeName = reader.getNodeName();

    Map<String, String> attributes = ConverterAttributeMapValidator.readValidatedAttributes(reader, null);

    return new NodeAttributes(nodeName, attributes);
}
 
Example 7
Source File: AbstractChronicleMapConverter.java    From Chronicle-Map with Apache License 2.0 5 votes vote down vote up
@Override
public Object unmarshal(HierarchicalStreamReader reader,
                        UnmarshallingContext context) {
    // empty map
    if ("[\"\"]".equals(reader.getValue()))
        return null;
    if (!"cmap".equals(reader.getNodeName()))
        throw new ConversionException("should be under 'cmap' node");
    reader.moveDown();
    while (reader.hasMoreChildren()) {
        reader.moveDown();

        final String nodeName0 = reader.getNodeName();

        if (!nodeName0.equals("entry"))
            throw new ConversionException("unable to convert node named=" + nodeName0);

        final K k;
        final V v;

        reader.moveDown();
        k = deserialize(context, reader);
        reader.moveUp();

        reader.moveDown();
        v = deserialize(context, reader);
        reader.moveUp();

        if (k != null)
            map.put(k, v);

        reader.moveUp();
    }
    reader.moveUp();
    return null;
}
 
Example 8
Source File: AbstractMappingConverter.java    From depan with Apache License 2.0 5 votes vote down vote up
protected Object unmarshalObject(
    HierarchicalStreamReader reader, UnmarshallingContext context) {
  reader.moveDown();
  try {
    String childName = reader.getNodeName();
    Class<?> childClass = mapper.realClass(childName);

    return context.convertAnother(null, childClass);
  } finally {
    reader.moveUp();
  }
}
 
Example 9
Source File: ViewDocumentConverter.java    From depan with Apache License 2.0 5 votes vote down vote up
private boolean isViewNodes(HierarchicalStreamReader reader) {
  String childName = reader.getNodeName();
  if (VIEW_NODES.equals(childName)) {
    return true;
  }
  if (SET_LEGACY.equals(childName)) {
    return true;
  }
  return false;
}
 
Example 10
Source File: AbstractCollectionConverter.java    From depan with Apache License 2.0 5 votes vote down vote up
/**
 * Utility method to read a single child object from the input stream.
 */
@SuppressWarnings("unchecked")
protected T unmarshalChild(HierarchicalStreamReader reader,
    UnmarshallingContext context) {
  String childName = reader.getNodeName();
  Class<?> childClass = mapper.realClass(childName);
  if (elementType.isAssignableFrom(childClass)) {
    return (T) context.convertAnother(null, childClass);
  }
  return null;
}
 
Example 11
Source File: NodeListDocumentConverter.java    From depan with Apache License 2.0 5 votes vote down vote up
private boolean isNodeList(HierarchicalStreamReader reader) {
  String childName = reader.getNodeName();
  if (NODE_LIST.equals(childName)) {
    return true;
  }
  return false;
}
 
Example 12
Source File: NodeValueConverter.java    From smarthome with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    Map<String, String> attributes = ConverterAttributeMapValidator.readValidatedAttributes(reader, null);

    return new NodeValue(reader.getNodeName(), attributes, reader.getValue());
}
 
Example 13
Source File: WSRequestCodec.java    From SI with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {

            Map<String, String> map = new HashMap<String, String>();

            while(reader.hasMoreChildren()) {
                reader.moveDown();

                String key = reader.getNodeName(); // nodeName aka element's name
                String value = reader.getValue();
                map.put(key, value);

                reader.moveUp();
            }

            return map;
        }
 
Example 14
Source File: GraphModelConverter.java    From depan with Apache License 2.0 4 votes vote down vote up
/**
 * {@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 15
Source File: AbstractChronicleMapConverter.java    From Chronicle-Map with Apache License 2.0 4 votes vote down vote up
private static <E> E deserialize(@NotNull UnmarshallingContext unmarshallingContext,
                                 @NotNull HierarchicalStreamReader reader) {

    switch (reader.getNodeName()) {

        case "java.util.Collections$EmptySet":
            return (E) Collections.emptySet();

        case "java.util.Collections$EmptyList":
            return (E) Collections.emptyList();

        case "java.util.Collections$EmptyMap":
        case "java.util.Collections.EmptyMap":
            return (E) Collections.emptyMap();

    }

    return (E) unmarshallingContext.convertAnother(null, forName(reader.getNodeName()));
}
 
Example 16
Source File: NodeValueConverter.java    From openhab-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    Map<String, String> attributes = ConverterAttributeMapValidator.readValidatedAttributes(reader, null);

    return new NodeValue(reader.getNodeName(), attributes, reader.getValue());
}
 
Example 17
Source File: OlapUtils.java    From bamboobsc with Apache License 2.0 4 votes vote down vote up
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
	
    Map<String, String> map = new HashMap<String, String>();
    
    while(reader.hasMoreChildren()) {
        reader.moveDown();

        String key = reader.getNodeName(); // nodeName aka element's name
        String value = reader.getValue();
        map.put(key, value);

        reader.moveUp();
    }

    return map;
}
 
Example 18
Source File: WSRequestCodec.java    From SI with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {

            Map<String, String> map = new HashMap<String, String>();

            while(reader.hasMoreChildren()) {
                reader.moveDown();

                String key = reader.getNodeName(); // nodeName aka element's name
                String value = reader.getValue();
                map.put(key, value);

                reader.moveUp();
            }

            return map;
        }
 
Example 19
Source File: XmlIconSetConverter.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 )
{
    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 20
Source File: ConverterAssertion.java    From openhab-core with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Asserts that the current node associated with the specified reader does <i>not</i> contain
 * any attributes.
 *
 * @param reader the reader to be used for validation (must not be null)
 * @throws ConversionException if the condition does not fit
 */
public static void assertNoAttribute(HierarchicalStreamReader reader) throws ConversionException {
    if (reader.getAttributeCount() > 0) {
        throw new ConversionException("The parameter '" + reader.getNodeName() + "' uses unknown attributes!");
    }
}