com.thoughtworks.xstream.converters.UnmarshallingContext Java Examples

The following examples show how to use com.thoughtworks.xstream.converters.UnmarshallingContext. 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 Project: gitlab-oauth-plugin   Author: jenkinsci   File: GitLabSecurityRealm.java    License: 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 Project: kogito-runtimes   Author: kiegroup   File: ListenerModelImpl.java    License: Apache License 2.0 6 votes vote down vote up
public Object unmarshal(HierarchicalStreamReader reader, final UnmarshallingContext context) {
    final ListenerModelImpl listener = new ListenerModelImpl();
    listener.setType(reader.getAttribute("type"));
    /* TODO make qualifiers working properly before readd them to the xml
    String qualifierType = reader.getAttribute("qualifier");
    if (qualifierType != null) {
        listener.newQualifierModel(qualifierType);
    }

    readNodes( reader, new AbstractXStreamConverter.NodeReader() {
        public void onNode(HierarchicalStreamReader reader,
                           String name,
                           String value) {
            if ( "qualifier".equals( name ) ) {
                QualifierModelImpl qualifier = readObject(reader, context, QualifierModelImpl.class);
                listener.setQualifierModel(qualifier);
            }
        }
    } );
    */
    return listener;
}
 
Example #3
Source Project: gama   Author: gama-platform   File: ReferenceAgentConverter.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext arg1) {

	// reader.moveDown();
	// final IAgent refAgt = (IAgent) arg1.convertAnother(null, IAgent.class);
	// reader.moveUp();

	// reader.moveDown();
	// final String attrName = reader.getValue();
	// reader.moveUp();

	reader.moveDown();
	final ReferenceToAgent refAttrValue = (ReferenceToAgent) arg1.convertAnother(null, ReferenceToAgent.class);
	reader.moveUp();

	// final ReferenceSavedAgent agtToReturn = new ReferenceSavedAgent(refAgt, attrName, refAttrValue);
	final ReferenceAgent agtToReturn = new ReferenceAgent(null, null, refAttrValue);

	return agtToReturn;
}
 
Example #4
Source Project: weblaf   Author: mgarin   File: TextConverter.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public Object unmarshal ( final HierarchicalStreamReader reader, final UnmarshallingContext context )
{
    // Reading state
    final String state = reader.getAttribute ( STATE );

    // Reading mnemonic
    final String m = reader.getAttribute ( MNEMONIC );
    final int mnemonic = TextUtils.notEmpty ( m ) ? m.charAt ( 0 ) : -1;

    // Reading value
    final String value = reader.getValue ();

    // Creating Text object
    return new Text ( value, state, mnemonic );
}
 
Example #5
Source Project: yes-cart   Author: inspire-software   File: MapConverter.java    License: Apache License 2.0 6 votes vote down vote up
protected void populateMap(HierarchicalStreamReader reader, UnmarshallingContext context, Map map) {
    while (reader.hasMoreChildren()) {
        reader.moveDown();

        reader.moveDown();
        Object key = readItem(reader, context, map);
        reader.moveUp();

        reader.moveDown();
        Object value = readItem(reader, context, map);
        reader.moveUp();

        map.put(key, value);

        reader.moveUp();
    }
}
 
Example #6
Source Project: openhab-core   Author: openhab   File: EventDescriptionConverter.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Override
public final Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    List<EventOption> eventOptions = null;

    NodeList nodes = (NodeList) context.convertAnother(context, NodeList.class);
    NodeIterator nodeIterator = new NodeIterator(nodes.getList());

    NodeList optionNodes = (NodeList) nodeIterator.next();
    if (optionNodes != null) {
        eventOptions = toListOfEventOptions(optionNodes);
    }

    nodeIterator.assertEndOfType();

    EventDescription eventDescription = new EventDescription(eventOptions);

    return eventDescription;
}
 
Example #7
Source Project: lams   Author: lamsfoundation   File: ValueRangeConverter.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
    final boolean oldFormat = "custom".equals(reader.getAttribute(mapper.aliasForSystemAttribute("serialization")));
    if (oldFormat) {
        reader.moveDown();
        reader.moveDown();
    }
    final Map<String, Long> elements = new HashMap<>();
    while (reader.hasMoreChildren()) {
        reader.moveDown();

        final String name = reader.getNodeName();
        elements.put(oldFormat ? name : mapper.realMember(ValueRange.class, name), Long.valueOf(reader.getValue()));
        reader.moveUp();
    }
    if (oldFormat) {
        reader.moveUp();
        reader.moveUp();
    }
    return ValueRange.of(elements.get("minSmallest").longValue(), elements.get("minLargest").longValue(), elements
        .get("maxSmallest")
        .longValue(), elements.get("maxLargest").longValue());
}
 
Example #8
Source Project: openhab-core   Author: openhab   File: ChannelConverter.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    // read attributes
    Map<String, String> attributes = this.attributeMapValidator.readValidatedAttributes(reader);

    // 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 #9
Source Project: lams   Author: lamsfoundation   File: EnumSetConverter.java    License: GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    String attributeName = mapper.aliasForSystemAttribute("enum-type");
    if (attributeName == null) {
        throw new ConversionException("No EnumType specified for EnumSet");
    }
    Class enumTypeForSet = mapper.realClass(reader.getAttribute(attributeName));
    EnumSet set = EnumSet.noneOf(enumTypeForSet);
    String[] enumValues = reader.getValue().split(",");
    for (int i = 0; i < enumValues.length; i++) {
        String enumValue = enumValues[i];
        if(enumValue.length() > 0) {
            set.add(Enum.valueOf(enumTypeForSet, enumValue));
        }
    }
    return set;
}
 
Example #10
Source Project: lams   Author: lamsfoundation   File: JavaFieldConverter.java    License: 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 #11
Source Project: lams   Author: lamsfoundation   File: EncodedByteArrayConverter.java    License: GNU General Public License v2.0 6 votes vote down vote up
private Object unmarshalIndividualByteElements(HierarchicalStreamReader reader, UnmarshallingContext context) {
    List bytes = new ArrayList(); // have to create a temporary list because don't know the size of the array
    boolean firstIteration = true;
    while (firstIteration || reader.hasMoreChildren()) { // hangover from previous hasMoreChildren
        reader.moveDown();
        bytes.add(byteConverter.fromString(reader.getValue()));
        reader.moveUp();
        firstIteration = false;
    }
    // copy into real array
    byte[] result = new byte[bytes.size()];
    int i = 0;
    for (Iterator iterator = bytes.iterator(); iterator.hasNext();) {
        Byte b = (Byte) iterator.next();
        result[i] = b.byteValue();
        i++;
    }
    return result;
}
 
Example #12
Source Project: weblaf   Author: mgarin   File: AbstractIconSourceConverter.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns {@link List} of {@link IconAdjustment}s specified in XML.
 *
 * @param reader  {@link HierarchicalStreamReader}
 * @param context {@link UnmarshallingContext}
 * @return {@link List} of {@link IconAdjustment}s specified in XML
 */
@NotNull
protected List<IconAdjustment<I>> readAdjustments ( @NotNull final HierarchicalStreamReader reader,
                                                    @NotNull final UnmarshallingContext context )
{
    final List<IconAdjustment<I>> adjustments = new ArrayList<IconAdjustment<I>> ();
    while ( reader.hasMoreChildren () )
    {
        reader.moveDown ();

        final String nodeName = reader.getNodeName ();
        final Class<?> iconSourceClass = mapper.realClass ( nodeName );
        if ( IconAdjustment.class.isAssignableFrom ( iconSourceClass ) )
        {
            adjustments.add ( ( IconAdjustment ) context.convertAnother ( adjustments, iconSourceClass ) );
        }

        reader.moveUp ();
    }
    return adjustments;
}
 
Example #13
Source Project: brooklyn-server   Author: apache   File: ObjectWithDefaultStringImplConverter.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    String clazzName = reader.getAttribute("class");
    Class<?> clazz;
    if (clazzName == null) {
        clazz = defaultImpl;
    } else if (clazzName.equals("string")) {
        clazz = String.class;
    } else if (Boxing.getPrimitiveType(clazzName).isPresent()) {
        clazz = Boxing.getPrimitiveType(clazzName).get();
    } else {
        try {
            clazz = loader.getReference().loadClass(clazzName);
        } catch (ClassNotFoundException e) {
            throw Exceptions.propagate(e);
        }
    }
    Converter converter = lookup.lookupConverterForType(clazz);
    return converter.unmarshal(reader, context);
}
 
Example #14
Source Project: smarthome   Author: eclipse-archived   File: AbstractDescriptionTypeConverter.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@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 #15
Source Project: gatf   Author: sumeetchhetri   File: MapKeyValueCustomXstreamConverter.java    License: Apache License 2.0 5 votes vote down vote up
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context)
{
    final AbstractMap<String, String> map = new HashMap<String, String>();
    while (reader.hasMoreChildren())
    {
        reader.moveDown();
        map.put(reader.getNodeName(), reader.getValue());
        reader.moveUp();
    }
    return map;
}
 
Example #16
Source Project: smarthome   Author: eclipse-archived   File: NodeAttributesConverter.java    License: 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 #17
Source Project: Shop-for-JavaWeb   Author: EleTeam   File: DateTimeConverter.java    License: MIT License 5 votes vote down vote up
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
	try{
		Date date = DateUtils.parseDate(reader.getValue());
		return date;
	}catch (Exception e) {
		return null;
	}
}
 
Example #18
Source Project: warnings-ng-plugin   Author: jenkinsci   File: ReportXmlStream.java    License: MIT License 5 votes vote down vote up
@SuppressWarnings("CastToConcreteClass")
@Override
protected void populateCollection(final HierarchicalStreamReader reader,
        final UnmarshallingContext context, final Collection collection) {
    super.populateCollection(reader, context, collection);
    Ensure.that(collection).isInstanceOf(LineRangeList.class);
    ((LineRangeList) collection).trim();
}
 
Example #19
Source Project: openhab-core   Author: openhab   File: NodeAttributesConverter.java    License: 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 #20
Source Project: openhab-core   Author: openhab   File: BindingInfoConverter.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@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 #21
Source Project: depan   Author: google   File: EdgeConverter.java    License: 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 #22
Source Project: onedev   Author: theonedev   File: ReflectionConverter.java    License: MIT License 5 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
protected Object unmarshallField(UnmarshallingContext context, Object result, Class type, Field field) {
	if (field.getAnnotation(ManyToOne.class) != null) {
		Long entityId = (Long) context.convertAnother(context.currentObject(), Long.class);
		return AppLoader.getInstance(Dao.class).load((Class<? extends AbstractEntity>) field.getType(), entityId);
	} else {
		return super.unmarshallField(context, result, type, field);
	}
}
 
Example #23
Source Project: smarthome   Author: eclipse-archived   File: ChannelConverter.java    License: Eclipse Public License 2.0 5 votes vote down vote up
protected ChannelXmlResult unmarshalType(HierarchicalStreamReader reader, UnmarshallingContext context,
        Map<String, String> attributes, NodeIterator nodeIterator) throws ConversionException {
    String id = attributes.get("id");
    String typeId = attributes.get("typeId");
    String label = (String) nodeIterator.nextValue("label", false);
    String description = (String) nodeIterator.nextValue("description", false);
    List<NodeValue> properties = getProperties(nodeIterator);
    AutoUpdatePolicy autoUpdatePolicy = readAutoUpdatePolicy(nodeIterator);

    ChannelXmlResult channelXmlResult = new ChannelXmlResult(id, typeId, label, description, properties,
            autoUpdatePolicy);

    return channelXmlResult;
}
 
Example #24
Source Project: sdb-mall   Author: yjjdick   File: MapCustomConverter.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
	Map map = (Map) createCollection(context.getRequiredType());
	populateMap(reader, context, map);
	return map;

}
 
Example #25
Source Project: saros   Author: saros-project   File: ReplaceableConverter.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public synchronized Object unmarshal(
    HierarchicalStreamReader reader, UnmarshallingContext context) {

  if (isReset()) {
    log.debug("Tried to unmarshal with inactive converter " + delegate);
    return null;
  }

  return delegate.unmarshal(reader, context);
}
 
Example #26
Source Project: lams   Author: lamsfoundation   File: CGLIBEnhancedConverter.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void readCallback(HierarchicalStreamReader reader, UnmarshallingContext context,
    List callbacksToEnhance, List callbacks) {
    Callback callback = (Callback)context.convertAnother(null, mapper.realClass(reader
        .getNodeName()));
    callbacks.add(callback);
    if (callback == null) {
        callbacksToEnhance.add(NoOp.INSTANCE);
    } else {
        callbacksToEnhance.add(callback);
    }
}
 
Example #27
Source Project: brooklyn-server   Author: apache   File: CatalogItemLibrariesConverter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    Object obj = context.convertAnother(context.currentObject(), context.getRequiredType());
    if (CatalogItemLibraries.class.isAssignableFrom(context.getRequiredType())) {
        CatalogItemLibraries libs = (CatalogItemLibraries)obj;
        Collection<String> bundles = libs.getBundles();
        Collection<CatalogBundle> libraries = new ArrayList<CatalogBundle>(bundles.size());
        for (String url : bundles) {
            libraries.add(new CatalogBundleDto(null, null, url));
        }
        return libraries;
    } else {
        return obj;
    }
}
 
Example #28
Source Project: lams   Author: lamsfoundation   File: JavaBeanConverter.java    License: GNU General Public License v2.0 5 votes vote down vote up
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
    final Object result = instantiateNewInstance(context);
    final Set seenProperties = new HashSet() {
        public boolean add(Object e) {
            if (!super.add(e)) {
                throw new DuplicatePropertyException(((FastField)e).getName());
            }
            return true;
        }
    };

    Class resultType = result.getClass();
    while (reader.hasMoreChildren()) {
        reader.moveDown();

        String propertyName = mapper.realMember(resultType, reader.getNodeName());

        if (mapper.shouldSerializeMember(resultType, propertyName)) {
            boolean propertyExistsInClass = beanProvider.propertyDefinedInClass(propertyName, resultType);

            if (propertyExistsInClass) {
                Class type = determineType(reader, result, propertyName);
                Object value = context.convertAnother(result, type);
                beanProvider.writeProperty(result, propertyName, value);
                seenProperties.add(new FastField(resultType, propertyName));
            } else if (!mapper.isIgnoredElement(propertyName)) {
                throw new MissingFieldException(resultType.getName(), propertyName);
            }
        }
        reader.moveUp();
    }

    return result;
}
 
Example #29
Source Project: lams   Author: lamsfoundation   File: JavaBeanConverter.java    License: GNU General Public License v2.0 5 votes vote down vote up
private Object instantiateNewInstance(UnmarshallingContext context) {
    Object result = context.currentObject();
    if (result == null) {
        result = beanProvider.newInstance(context.getRequiredType());
    }
    return result;
}
 
Example #30
Source Project: depan   Author: google   File: AbstractCollectionConverter.java    License: 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;
}