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 File: GitLabSecurityRealm.java From gitlab-oauth-plugin with MIT License | 6 votes |
@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: EnumSetConverter.java From lams with GNU General Public License v2.0 | 6 votes |
@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 #3
Source File: JavaFieldConverter.java From lams with GNU General Public License v2.0 | 6 votes |
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 #4
Source File: EncodedByteArrayConverter.java From lams with GNU General Public License v2.0 | 6 votes |
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 #5
Source File: MapConverter.java From yes-cart with Apache License 2.0 | 6 votes |
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 File: TextConverter.java From weblaf with GNU General Public License v3.0 | 6 votes |
@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 #7
Source File: EventDescriptionConverter.java From openhab-core with Eclipse Public License 2.0 | 6 votes |
@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 #8
Source File: ReferenceAgentConverter.java From gama with GNU General Public License v3.0 | 6 votes |
@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 #9
Source File: ValueRangeConverter.java From lams with GNU General Public License v2.0 | 6 votes |
@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 #10
Source File: AbstractIconSourceConverter.java From weblaf with GNU General Public License v3.0 | 6 votes |
/** * 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 #11
Source File: ObjectWithDefaultStringImplConverter.java From brooklyn-server with Apache License 2.0 | 6 votes |
@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 #12
Source File: ListenerModelImpl.java From kogito-runtimes with Apache License 2.0 | 6 votes |
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 #13
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 #14
Source File: ChannelConverter.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); // 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 File: MapConverter.java From lams with GNU General Public License v2.0 | 5 votes |
protected void populateMap(HierarchicalStreamReader reader, UnmarshallingContext context, Map map, Map target) { while (reader.hasMoreChildren()) { reader.moveDown(); putCurrentEntryIntoMap(reader, context, map, target); reader.moveUp(); } }
Example #16
Source File: ViewExtensionConverter.java From depan with Apache License 2.0 | 5 votes |
@Override public Object unmarshal( HierarchicalStreamReader reader, UnmarshallingContext context) { String extId = getExtensionId(reader); try { ViewExtension result = ViewExtensionRegistry.getRegistryExtension(extId); return result; } catch (RuntimeException err) { ViewDocLogger.LOG.error( "Unable to locate extension {}.", extId, err); throw err; } }
Example #17
Source File: GraphModelReferenceConverter.java From depan with Apache License 2.0 | 5 votes |
private GraphModelReference unmarshalProjectGraphFile( String graphPath, UnmarshallingContext context) { IFile graphRsrc = GraphModelReference.getLocation(graphPath); if (null == graphRsrc) { throw new RuntimeException( "Can't locate resource " + graphPath + " for dependency information"); } if (!(graphRsrc instanceof IFile)) { throw new RuntimeException("Resource " + graphPath + " is not a file"); } GraphDocument graph = ResourceCache.fetchGraphDocument((IFile) graphRsrc); return new GraphModelReference(graphRsrc, graph); }
Example #18
Source File: GamaMapConverter.java From gama with GNU General Public License v3.0 | 5 votes |
@Override public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext arg1) { // reader.moveDown(); final GamaMapReducer rmt = (GamaMapReducer) arg1.convertAnother(null, GamaMapReducer.class); // reader.moveUp(); return rmt.constructObject(convertScope.getScope()); }
Example #19
Source File: XMLConfigurer.java From oval with Eclipse Public License 2.0 | 5 votes |
@Override public Pattern unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { final String pattern = reader.getAttribute("pattern"); final String flags = reader.getAttribute("flags"); if (flags == null || flags.trim().length() == 0) return Pattern.compile(pattern); return Pattern.compile(pattern, Integer.parseInt(flags)); }
Example #20
Source File: RegexPatternConverter.java From lams with GNU General Public License v2.0 | 5 votes |
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { reader.moveDown(); String pattern = reader.getValue(); reader.moveUp(); reader.moveDown(); int flags = Integer.parseInt(reader.getValue()); reader.moveUp(); return Pattern.compile(pattern, flags); }
Example #21
Source File: Point2DConverter.java From depan with Apache License 2.0 | 5 votes |
@Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { try { String textX = reader.getAttribute("x"); String textY = reader.getAttribute("y"); Double posX = Double.valueOf(textX); Double posY = Double.valueOf(textY); return new Point2D.Double(posX, posY); } catch (RuntimeException err) { // TODO Auto-generated catch block err.printStackTrace(); throw err; } }
Example #22
Source File: PolygonConverter.java From Digital with GNU General Public License v3.0 | 5 votes |
@Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext unmarshallingContext) { String path = reader.getAttribute("path"); boolean evenOdd = Boolean.parseBoolean(reader.getAttribute("evenOdd")); final Polygon polygon = Polygon.createFromPath(path); if (polygon != null) polygon.setEvenOdd(evenOdd); return polygon; }
Example #23
Source File: DateTimeConverter.java From jenkins-deployment-dashboard-plugin with MIT License | 5 votes |
@Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext uc) { DateTime dateTime = DateTime.now(); try { dateTime = DateTime.parse(reader.getValue()); } catch (IllegalArgumentException e) { LOGGER.log(Level.SEVERE, "Could not parse DateTime value {0}. Returning DateTime.now().", reader.getValue()); } return dateTime; }
Example #24
Source File: CommandDescriptionConverter.java From openhab-core with Eclipse Public License 2.0 | 5 votes |
@Override public final CommandDescription unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { NodeList nodes = (NodeList) context.convertAnother(context, NodeList.class); NodeIterator nodeIterator = new NodeIterator(nodes.getList()); NodeList commandOptionsNode = (NodeList) nodeIterator.next(); if (commandOptionsNode != null) { if ("options".equals(commandOptionsNode.getNodeName())) { CommandDescriptionBuilder commandDescriptionBuilder = CommandDescriptionBuilder.create(); for (Object coNodeObject : commandOptionsNode.getList()) { NodeValue optionsNode = (NodeValue) coNodeObject; if ("option".equals(optionsNode.getNodeName())) { String name = (String) optionsNode.getValue(); String command = optionsNode.getAttributes().get("value"); if (name != null && command != null) { commandDescriptionBuilder.withCommandOption(new CommandOption(command, name)); } } else { throw new ConversionException("The 'options' node must only contain 'option' nodes!"); } } nodeIterator.assertEndOfType(); return commandDescriptionBuilder.build(); } } nodeIterator.assertEndOfType(); return null; }
Example #25
Source File: AbstractCollectionConverter.java From depan with Apache License 2.0 | 5 votes |
/** * 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 #26
Source File: EdgeReferenceConverter.java From depan with Apache License 2.0 | 5 votes |
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 #27
Source File: ThingTypeConverter.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Override protected ThingTypeXmlResult unmarshalType(HierarchicalStreamReader reader, UnmarshallingContext context, Map<String, String> attributes, NodeIterator nodeIterator) throws ConversionException { ThingTypeXmlResult thingTypeXmlResult = new ThingTypeXmlResult( new ThingTypeUID(super.getUID(attributes, context)), readSupportedBridgeTypeUIDs(nodeIterator, context), super.readLabel(nodeIterator), super.readDescription(nodeIterator), readCategory(nodeIterator), getListed(attributes), getExtensibleChannelTypeIds(attributes), getChannelTypeReferenceObjects(nodeIterator), getProperties(nodeIterator), getRepresentationProperty(nodeIterator), super.getConfigDescriptionObjects(nodeIterator)); return thingTypeXmlResult; }
Example #28
Source File: ValueConverter.java From weblaf with GNU General Public License v3.0 | 5 votes |
@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 #29
Source File: EnumCaseForgivingConverter.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Override @SuppressWarnings({ "unchecked", "rawtypes" }) public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { Class type = context.getRequiredType(); if (type.getSuperclass() != Enum.class) { type = type.getSuperclass(); // polymorphic enums } String token = reader.getValue(); // this is the new bit (overriding superclass to accept case-insensitive) return resolve(type, token); }
Example #30
Source File: MapKeyValueCustomXstreamConverter.java From gatf with Apache License 2.0 | 5 votes |
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; }