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

The following examples show how to use com.thoughtworks.xstream.io.HierarchicalStreamReader#getValue() . 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: JavaFieldConverter.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    String methodName = null;
    String declaringClassName = null;
    
    while((methodName == null || declaringClassName == null) && reader.hasMoreChildren()) {
        reader.moveDown();
        
        if (reader.getNodeName().equals("name")) {
            methodName = reader.getValue();
        } else if (reader.getNodeName().equals("clazz")) {
            declaringClassName = reader.getValue();
        }
        reader.moveUp();
    }
    
    Class declaringClass = (Class)javaClassConverter.fromString(declaringClassName);
    try {
        return declaringClass.getDeclaredField(mapper.realMember(declaringClass, methodName));
    } catch (NoSuchFieldException e) {
        throw new ConversionException(e);
    }
}
 
Example 2
Source File: MeasureConverter.java    From pentaho-aggdesigner with GNU General Public License v2.0 6 votes vote down vote up
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
  
  reader.moveDown();
  String label = reader.getValue();
  reader.moveUp();
  reader.moveDown();
  String tableLabel = reader.getValue();
  reader.moveUp();
  Measure foundMeasure = null;
  for (Measure measure : schema.getMeasures()) {
    if (measure.getLabel().equals(label) &&
        measure.getTable().getLabel().equals(tableLabel)) 
    {
          foundMeasure = measure;
          break;
    }
  }
  
  if (foundMeasure == null) {
    throw new RuntimeException("Error: Unable to find measure");
  }
  return foundMeasure;
}
 
Example 3
Source File: HierarchicalStreamCopier.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
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 4
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 5
Source File: EdgeConverter.java    From depan with Apache License 2.0 5 votes vote down vote up
private GraphNode unmarshallGraphNode(
    HierarchicalStreamReader reader,
    UnmarshallingContext context,
    GraphBuilder builder) {
  String nodeId = reader.getValue();
  GraphNode result = builder.findNode(nodeId);
  if (null == result) {
    throw new IllegalStateException(
        "Edge reference to undefined node " + nodeId);
  }
  return result;
}
 
Example 6
Source File: EdgeReferenceConverter.java    From depan with Apache License 2.0 5 votes vote down vote up
private GraphNode unmarshallGraphNode(
    HierarchicalStreamReader reader, UnmarshallingContext context,
    GraphModel graph) {
  String nodeId = reader.getValue();
  GraphNode result = (GraphNode) graph.findNode(nodeId);
  if (null == result) {
    throw new IllegalStateException(
        "Edge reference to undefined node " + nodeId);
  }
  return result;
}
 
Example 7
Source File: Field4RestConverter.java    From gsn with GNU General Public License v3.0 5 votes vote down vote up
public Object unmarshal(HierarchicalStreamReader reader,UnmarshallingContext context) {
	Field4Rest toReturn = null;
	String name = reader.getAttribute("name");
	String type = reader.getAttribute("type");
	Byte typeId;
	if (type.equalsIgnoreCase("numeric"))
		typeId = DataTypes.DOUBLE;
	else if (type.equalsIgnoreCase("string"))
		typeId = DataTypes.VARCHAR;
	else 
		typeId = DataTypes.BINARY;
	
	Boolean isNull = false;
	if (reader.getAttribute("is-null")!=null)
		isNull = Boolean.valueOf(reader.getAttribute("is-null"));

	Serializable value = null;
	if (!isNull) {
		if (type.equalsIgnoreCase("string")) 
			value = reader.getValue();
		else if (type.equalsIgnoreCase("numeric"))
			value = Double.parseDouble(reader.getValue());
		else
			value = (byte[]) base64.decode(reader.getValue());
	}

	toReturn = new Field4Rest(name,typeId,value);
	return toReturn;
}
 
Example 8
Source File: EncodedByteArrayConverter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    String data = reader.getValue(); // needs to be called before hasMoreChildren.
    if (!reader.hasMoreChildren()) {
        return fromString(data);
    } else {
        // backwards compatibility ... try to unmarshal byte arrays that haven't been encoded
        return unmarshalIndividualByteElements(reader, context);
    }
}
 
Example 9
Source File: CharSequenceConverter.java    From Chronicle-Map with Apache License 2.0 5 votes vote down vote up
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    if (context.getRequiredType() == StringBuilder.class) {
        return new StringBuilder(reader.getValue());
    } else {
        return reader.getValue();
    }
}
 
Example 10
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 11
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 12
Source File: ValueConverter.java    From weblaf with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Object unmarshal ( final HierarchicalStreamReader reader, final UnmarshallingContext context )
{
    final Value value = new Value ();

    // Reading language
    final String locale = reader.getAttribute ( LANGUAGE );
    value.setLocale ( LanguageUtils.fromString ( locale ) );

    // Reading possible single-value case attributes
    final String state = reader.getAttribute ( STATE );
    final String character = reader.getAttribute ( MNEMONIC );
    final int mnemonic = character != null ? character.charAt ( 0 ) : -1;

    // Reading texts and tooltips
    final String text = reader.getValue ();
    final List<Text> texts = new ArrayList<Text> ();
    while ( reader.hasMoreChildren () )
    {
        reader.moveDown ();
        texts.add ( ( Text ) context.convertAnother ( value, Text.class ) );
        reader.moveUp ();
    }

    // Determining what should we save
    if ( texts.size () == 0 )
    {
        // Saving single text
        value.addText ( new Text ( text, state, mnemonic ) );
    }
    else
    {
        // Saving multiple texts
        value.setTexts ( texts );
    }

    return value;
}
 
Example 13
Source File: HexToIntegerConverter.java    From openhab1-addons with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    String value = reader.getValue();
    long lVal;
    if (value.startsWith("0x")) {
        lVal = Long.decode(value);
    } else {
        lVal = Long.parseLong(value, 16);
    }

    return (int) lVal;
}
 
Example 14
Source File: GamaScopeConverter.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext arg1) {
	reader.moveDown();
	final String res = reader.getValue();
	reader.moveUp();

	return res;
}
 
Example 15
Source File: FilterCriteriaConverter.java    From smarthome with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    String name = reader.getAttribute("name");
    String criteria = reader.getValue();
    return new FilterCriteria(name, criteria);
}
 
Example 16
Source File: StringBuilderConverter.java    From Chronicle-Map with Apache License 2.0 4 votes vote down vote up
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    return new StringBuilder(reader.getValue());
}
 
Example 17
Source File: JodaDateMidnightConverter.java    From projectforge-webapp with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context)
{
  final String data = reader.getValue();
  return parse(data);
}
 
Example 18
Source File: JodaDateTimeConverter.java    From projectforge-webapp with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context)
{
  final String data = reader.getValue();
  return parse(data);
}
 
Example 19
Source File: SimpleArrayConverter.java    From weblaf with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Object unmarshal ( final HierarchicalStreamReader reader, final UnmarshallingContext context )
{
    final String object = reader.getValue ();
    if ( object != null )
    {
        final List<String> values = TextUtils.stringToList ( object, separator );
        final Class componentType = context.getRequiredType ().getComponentType ();
        final Object array = Array.newInstance ( componentType, values.size () );
        for ( int i = 0; i < values.size (); i++ )
        {
            final String v = values.get ( i );
            if ( componentType == Integer.class || componentType == int.class )
            {
                Array.set ( array, i, Integer.valueOf ( v ) );
            }
            else if ( componentType == Character.class || componentType == char.class )
            {
                Array.set ( array, i, v.charAt ( 0 ) );
            }
            else if ( componentType == Byte.class || componentType == byte.class )
            {
                Array.set ( array, i, Byte.valueOf ( v ) );
            }
            else if ( componentType == Short.class || componentType == short.class )
            {
                Array.set ( array, i, Short.valueOf ( v ) );
            }
            else if ( componentType == Long.class || componentType == long.class )
            {
                Array.set ( array, i, Long.valueOf ( v ) );
            }
            else if ( componentType == Float.class || componentType == float.class )
            {
                Array.set ( array, i, Float.valueOf ( v ) );
            }
            else if ( componentType == Double.class || componentType == double.class )
            {
                Array.set ( array, i, Double.valueOf ( v ) );
            }
            else if ( componentType == Color.class )
            {
                Array.set ( array, i, ColorConverter.colorFromString ( v ) );
            }
            else if ( componentType == Insets.class )
            {
                Array.set ( array, i, InsetsConverter.insetsFromString ( v ) );
            }
            else
            {
                throw new IllegalArgumentException ( "Unable to unmarshal array of type: " + componentType );
            }
        }
        return array;
    }
    else
    {
        return null;
    }
}
 
Example 20
Source File: XmlMementoSerializer.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
@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();
        }
    }
}