@Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { Birthday birthday = new Birthday(); String gender = reader.getAttribute("gender"); if (gender != null) { if (gender.length() > 0) { if (gender.startsWith("f")) { birthday.setGenderFemale(); } else if (gender.startsWith("m")) { birthday.setGenderMale(); } else { throw new ConversionException("Invalid gender value: " + gender); } } else { throw new ConversionException("Empty string is invalid gender value"); } } while (reader.hasMoreChildren()) { reader.moveDown(); if ("person".equals(reader.getNodeName())) { Person person = (Person) context.convertAnother(birthday, Person.class); birthday.setPerson(person); } else if ("birth".equals(reader.getNodeName())) { Calendar date = (Calendar) context.convertAnother(birthday, Calendar.class); birthday.setDate(date); } reader.moveUp(); } return birthday; }
@Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { if (reader.getNodeName().equals(Constants.TAG_TRUE)) return new TrueXML(); else if (reader.getNodeName().equals(Constants.TAG_FALSE)) return new FalseXML(); else { System.out.println("Boolean Unmarshal unexpectd result"); return null; } }
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { final Enhancer enhancer = new Enhancer(); reader.moveDown(); enhancer.setSuperclass((Class) context.convertAnother(null, Class.class)); reader.moveUp(); reader.moveDown(); List interfaces = new ArrayList(); while (reader.hasMoreChildren()) { reader.moveDown(); interfaces.add(context.convertAnother(null, mapper.realClass(reader.getNodeName()))); reader.moveUp(); } enhancer.setInterfaces((Class[]) interfaces.toArray(new Class[interfaces.size()])); reader.moveUp(); reader.moveDown(); boolean useFactory = Boolean.valueOf(reader.getValue()).booleanValue(); enhancer.setUseFactory(useFactory); reader.moveUp(); List callbacksToEnhance = new ArrayList(); List callbacks = new ArrayList(); Map callbackIndexMap = null; reader.moveDown(); if ("callbacks".equals(reader.getNodeName())) { reader.moveDown(); callbackIndexMap = (Map) context.convertAnother(null, HashMap.class); reader.moveUp(); while (reader.hasMoreChildren()) { reader.moveDown(); readCallback(reader, context, callbacksToEnhance, callbacks); reader.moveUp(); } } else { readCallback(reader, context, callbacksToEnhance, callbacks); } enhancer.setCallbacks( (Callback[]) callbacksToEnhance.toArray(new Callback[callbacksToEnhance.size()])); if (callbackIndexMap != null) { enhancer.setCallbackFilter(new ReverseEngineeredCallbackFilter(callbackIndexMap)); } reader.moveUp(); Object result = null; while (reader.hasMoreChildren()) { reader.moveDown(); if (reader.getNodeName().equals("serialVersionUID")) { enhancer.setSerialVersionUID(Long.valueOf(reader.getValue())); } else if (reader.getNodeName().equals("instance")) { result = create(enhancer, callbacks, useFactory); super.doUnmarshalConditionally(result, reader, context); } reader.moveUp(); } if (result == null) { result = create(enhancer, callbacks, useFactory); } return serializationMethodInvoker.callReadResolve(result); }
@Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { reader.moveDown(); TurnXML turn = (TurnXML) context.convertAnother(null, TurnXML.class); reader.moveUp(); reader.moveDown(); List<IAdminResponse> responses = new ArrayList<IAdminResponse>(); while (reader.hasMoreChildren()) { reader.moveDown(); String tag = reader.getNodeName(); /*AdminResponse is: -- Tile of false -- Boolean -- Tiles */ IAdminResponse response = null; if (tag.equals(Constants.TAG_TILE)) response = (TileXML) context.convertAnother(null, TileXML.class); else if (tag.equals(Constants.TAG_FALSE)) response = (FalseXML) context.convertAnother(null, FalseXML.class); else if (tag.equals(Constants.TAG_TRUE)) response = (TrueXML) context.convertAnother(null, TrueXML.class); else if (tag.equals(Constants.TAG_RERACK)) response = (RerackXML) context.convertAnother(null, RerackXML.class); responses.add(response); reader.moveUp(); } reader.moveUp(); reader.moveDown(); List<ITurnAction> actions = new ArrayList<ITurnAction>(); while (reader.hasMoreChildren()) { reader.moveDown(); String tag = reader.getNodeName(); ITurnAction action = null; if (tag.equals(Constants.TAG_PLACEMENT)) action = (PlacementXML) context.convertAnother(null, PlacementXML.class); else if (tag.equals(Constants.TAG_RERACKABLE)) action = (RerackableXML) context.convertAnother(null, RerackableXML.class); else if (tag.equals(Constants.TAG_RERACK)) action = (RerackXML) context.convertAnother(null, RerackXML.class); actions.add(action); reader.moveUp(); } reader.moveUp(); TurnTestXML pojo = new TurnTestXML(turn, actions, responses); return pojo; }
/** * Unmarshal all the elements to their field values if the fields have the {@link Auto} annotation * defined. * * @param reader - The reader where the elements can be read. * @param o - The object for which the value of fields need to be populated. */ private static void autoUnmarshalEligible(HierarchicalStreamReader reader, Object o) { try { String nodeName = reader.getNodeName(); Class c = o.getClass(); Field f = null; try { f = c.getDeclaredField(nodeName); } catch (NoSuchFieldException e) { UNMARSHALL_ERROR_COUNTER.increment(); } if (f == null) { return; } Annotation annotation = f.getAnnotation(Auto.class); if (annotation == null) { return; } f.setAccessible(true); String value = reader.getValue(); Class returnClass = f.getType(); if (value != null) { if (!String.class.equals(returnClass)) { Method method = returnClass.getDeclaredMethod("valueOf", java.lang.String.class); Object valueObject = method.invoke(returnClass, value); f.set(o, valueObject); } else { f.set(o, value); } } } catch (Throwable th) { logger.error("Error in unmarshalling the object:", th); } }
private Class determineType( HierarchicalStreamReader reader, boolean validField, Object result, String fieldName, Class definedInCls) { String classAttribute = reader.getAttribute(mapper.aliasForAttribute("class")); Class fieldType = reflectionProvider.getFieldType(result, fieldName, definedInCls); if (classAttribute != null) { Class specifiedType = mapper.realClass(classAttribute); if (fieldType.isAssignableFrom(specifiedType)) // make sure that the specified type in XML is compatible with the field type. // this allows the code to evolve in more flexible way. return specifiedType; } if (!validField) { Class itemType = mapper.getItemTypeForItemFieldName(result.getClass(), fieldName); if (itemType != null) { return itemType; } else { return mapper.realClass(reader.getNodeName()); } } else { return mapper.defaultImplementationOf(fieldType); } }
private Map<String, String> readNode(HierarchicalStreamReader reader) { Map<String, String> values = new HashMap<String, String>(); while (reader.hasMoreChildren()) { reader.moveDown(); values.put(reader.getNodeName(), reader.getValue()); reader.moveUp(); } return values; }
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { String node = reader.getNodeName(); reader.moveDown(); GithubSecurityRealm realm = new GithubSecurityRealm(); node = reader.getNodeName(); String value = reader.getValue(); setValue(realm, node, value); reader.moveUp(); reader.moveDown(); node = reader.getNodeName(); value = reader.getValue(); setValue(realm, node, value); reader.moveUp(); if (reader.hasMoreChildren()) { reader.moveDown(); node = reader.getNodeName(); value = reader.getValue(); setValue(realm, node, value); reader.moveUp(); } if (realm.getGithubUri() == null) { realm.setGithubUri(DEFAULT_URI); } return realm; }
@Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { Map<String, String> map = new HashMap<String, String>(); while (reader.hasMoreChildren()) { reader.moveDown(); map.put(reader.getNodeName(), reader.getValue()); reader.moveUp(); } return map; }
@Override protected void unmarshalEntry( HierarchicalStreamReader reader, UnmarshallingContext context, Map map) { String key = reader.getNodeName(); if (key.equals(getEntryNodeName())) key = reader.getAttribute("key"); if (key == null) { super.unmarshalEntry(reader, context, map); } else { unmarshalStringKey(reader, context, map, key); } }
private Wfs20FeatureCollection addMetacardToFeatureCollection( Wfs20FeatureCollection featureCollection, UnmarshallingContext context, HierarchicalStreamReader reader) { featureCollection .getMembers() .add( (Metacard) context.convertAnother( null, MetacardImpl.class, featureConverterMap.get(reader.getNodeName()))); return featureCollection; }
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { EasyApiMessageDto dto = null; String nodeName = reader.getNodeName(); if (StringUtil.equals(nodeName, "request")) { dto = new RequestDto(); } else if (StringUtil.equals(nodeName, "response")) { dto = new ResponseDto(); } else { throw new XStreamException("unknown node name"); } while (reader.hasMoreChildren()) { reader.moveDown(); if (StringUtil.equals(reader.getNodeName(), "head")) { dto.header = (HeaderDto) context.convertAnother(dto, HeaderDto.class); } else if (StringUtil.equals(reader.getNodeName(), "body")) { dto.body = context.convertAnother(dto, bodyDtoClass.get()); } reader.moveUp(); } return dto; }
/* * (non-Javadoc) * * @see * com.thoughtworks.xstream.converters.Converter#unmarshal(com.thoughtworks * .xstream.io.HierarchicalStreamReader, * com.thoughtworks.xstream.converters.UnmarshallingContext) */ @Override @SuppressWarnings("unchecked") public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { InstanceInfo.Builder builder = InstanceInfo.Builder.newBuilder(); while (reader.hasMoreChildren()) { reader.moveDown(); String nodeName = reader.getNodeName(); if (ELEM_HOST.equals(nodeName)) { builder.setHostName(reader.getValue()); } else if (ELEM_INSTANCE_ID.equals(nodeName)) { builder.setInstanceId(reader.getValue()); } else if (ELEM_APP.equals(nodeName)) { builder.setAppName(reader.getValue()); } else if (ELEM_IP.equals(nodeName)) { builder.setIPAddr(reader.getValue()); } else if (ELEM_SID.equals(nodeName)) { builder.setSID(reader.getValue()); } else if (ELEM_IDENTIFYING_ATTR.equals(nodeName)) { // nothing; } else if (ELEM_STATUS.equals(nodeName)) { builder.setStatus(InstanceStatus.toEnum(reader.getValue())); } else if (ELEM_OVERRIDDEN_STATUS.equals(nodeName)) { builder.setOverriddenStatus(InstanceStatus.toEnum(reader.getValue())); } else if (ELEM_PORT.equals(nodeName)) { builder.setPort(Integer.valueOf(reader.getValue()).intValue()); // Defaults to true builder.enablePort(PortType.UNSECURE, !"false".equals(reader.getAttribute(ATTR_ENABLED))); } else if (ELEM_SECURE_PORT.equals(nodeName)) { builder.setSecurePort(Integer.valueOf(reader.getValue()).intValue()); // Defaults to false builder.enablePort(PortType.SECURE, "true".equals(reader.getAttribute(ATTR_ENABLED))); } else if (ELEM_COUNTRY_ID.equals(nodeName)) { builder.setCountryId(Integer.valueOf(reader.getValue()).intValue()); } else if (NODE_DATACENTER.equals(nodeName)) { builder.setDataCenterInfo( (DataCenterInfo) context.convertAnother(builder, DataCenterInfo.class)); } else if (NODE_LEASE.equals(nodeName)) { builder.setLeaseInfo((LeaseInfo) context.convertAnother(builder, LeaseInfo.class)); } else if (NODE_METADATA.equals(nodeName)) { builder.setMetadata((Map<String, String>) context.convertAnother(builder, Map.class)); } else { autoUnmarshalEligible(reader, builder.getRawInstance()); } reader.moveUp(); } return builder.build(); }
/* * (non-Javadoc) * * @see * com.thoughtworks.xstream.converters.Converter#unmarshal(com.thoughtworks * .xstream.io.HierarchicalStreamReader, * com.thoughtworks.xstream.converters.UnmarshallingContext) */ @Override @SuppressWarnings("unchecked") public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { DataCenterInfo info = null; while (reader.hasMoreChildren()) { reader.moveDown(); if (ELEM_NAME.equals(reader.getNodeName())) { final String dataCenterName = reader.getValue(); if (DataCenterInfo.Name.Amazon.name().equalsIgnoreCase(dataCenterName)) { info = new AmazonInfo(); } else { final DataCenterInfo.Name name = DataCenterInfo.Name.valueOf(dataCenterName); info = new DataCenterInfo() { @Override public Name getName() { return name; } }; } } else if (NODE_METADATA.equals(reader.getNodeName())) { if (info.getName() == Name.Amazon) { Map<String, String> metadataMap = (Map<String, String>) context.convertAnother(info, Map.class); Map<String, String> metadataMapInter = new HashMap<String, String>(metadataMap.size()); for (Map.Entry<String, String> entry : metadataMap.entrySet()) { metadataMapInter.put( StringCache.intern(entry.getKey()), StringCache.intern(entry.getValue())); } ((AmazonInfo) info).setMetadata(metadataMapInter); } } reader.moveUp(); } return info; }
@Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { Wfs20FeatureCollection featureCollection = new Wfs20FeatureCollection(); while (reader.hasMoreChildren()) { reader.moveDown(); String nodeName = reader.getNodeName(); // Its important to note that the reader appears to drop the // namespace. if (FEATURE_MEMBER.equals(nodeName)) { reader.moveDown(); String subNodeName = reader.getNodeName(); // If the member contains a sub feature collection, step in and get members if (subNodeName.equals(FEATURE_COLLECTION)) { while (reader.hasMoreChildren()) { reader.moveDown(); String subNodeName2 = reader.getNodeName(); if (FEATURE_MEMBER.equals(subNodeName2)) { reader.moveDown(); // lookup the converter for this featuretype featureCollection = addMetacardToFeatureCollection(featureCollection, context, reader); reader.moveUp(); } reader.moveUp(); } } else { // lookup the converter for this featuretype featureCollection = addMetacardToFeatureCollection(featureCollection, context, reader); } reader.moveUp(); } reader.moveUp(); } return featureCollection; }
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); } }
@Override public Object unmarshalInternal(HierarchicalStreamReader reader, UnmarshallingContext context) { List<URI> uris = new ArrayList<>(); if (!E_DOMAINURIS.equals(reader.getNodeName())) { throw new ConversionException( String.format(ERR_MISSING_EXPECTED_ELEMENT, E_DOMAINURIS, reader.getNodeName())); } try { while (reader.hasMoreChildren()) { reader.moveDown(); if (E_URI.equals(reader.getNodeName())) { uris.add(new URI(reader.getValue())); } reader.moveUp(); } } catch (URISyntaxException e) { throw new ConversionException(e.getMessage(), e); } return uris; }
@Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { if (Constants.TAG_NULL_TILE.equals(reader.getNodeName())) { Tile tile = new NullTile(); return tile; } else { String c0 = reader.getAttribute(Constants.ATTRIBUTE_TILE_C0); String c1 = reader.getAttribute(Constants.ATTRIBUTE_TILE_C1); Tile tile = new Tile(Color.valueOf(c0), Color.valueOf(c1)); return new TileXML(tile); } }
/** * @see * com.thoughtworks.xstream.converters.Converter#unmarshal(com.thoughtworks.xstream.io.HierarchicalStreamReader, * com.thoughtworks.xstream.converters.UnmarshallingContext) */ public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { Quota quota = new Quota(); reader.moveDown(); String nodeName = reader.getNodeName(); Assert.isTrue("value".equals(nodeName)); String nodevalue = reader.getValue(); double value = Double.parseDouble(nodevalue); reader.moveUp(); reader.moveDown(); nodeName = reader.getNodeName(); Assert.isTrue("units".equals(nodeName)); nodevalue = reader.getValue(); StorageUnit unit = StorageUnit.valueOf(nodevalue); reader.moveUp(); quota.setValue(value, unit); return quota; }
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(); }
/* * (non-Javadoc) * * @see * com.thoughtworks.xstream.converters.Converter#unmarshal(com.thoughtworks * .xstream.io.HierarchicalStreamReader, * com.thoughtworks.xstream.converters.UnmarshallingContext) */ @Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { Application app = new Application(); while (reader.hasMoreChildren()) { reader.moveDown(); String nodeName = reader.getNodeName(); if (ELEM_NAME.equals(nodeName)) { app.setName(reader.getValue()); } else if (NODE_INSTANCE.equals(nodeName)) { app.addInstance((InstanceInfo) context.convertAnother(app, InstanceInfo.class)); } reader.moveUp(); } return app; }
private Map<String, String> unmarshalMap( HierarchicalStreamReader reader, UnmarshallingContext context) { Map<String, String> map = Collections.emptyMap(); while (reader.hasMoreChildren()) { if (map == Collections.EMPTY_MAP) { map = new HashMap<String, String>(); } reader.moveDown(); String key = reader.getNodeName(); String value = reader.getValue(); reader.moveUp(); map.put(StringCache.intern(key), value); } return map; }
/* * (non-Javadoc) * * @see * com.thoughtworks.xstream.converters.Converter#unmarshal(com.thoughtworks * .xstream.io.HierarchicalStreamReader, * com.thoughtworks.xstream.converters.UnmarshallingContext) */ @Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { Applications apps = new Applications(); while (reader.hasMoreChildren()) { reader.moveDown(); String nodeName = reader.getNodeName(); if (NODE_APP.equals(nodeName)) { apps.addApplication((Application) context.convertAnother(apps, Application.class)); } else if (VERSIONS_DELTA.equals(nodeName)) { apps.setVersion(Long.valueOf(reader.getValue())); } else if (APPS_HASHCODE.equals(nodeName)) { apps.setAppsHashCode(reader.getValue()); } reader.moveUp(); } return apps; }
@SuppressWarnings("unchecked") public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { List interfaces = new ArrayList(); InvocationHandler handler = null; while (reader.hasMoreChildren()) { reader.moveDown(); String elementName = reader.getNodeName(); if (elementName.equals("interface")) { interfaces.add(mapper.realClass(reader.getValue())); } else if (elementName.equals("handler")) { Class handlerType = mapper.realClass(reader.getAttribute("class")); handler = (InvocationHandler) context.convertAnother(null, handlerType); } reader.moveUp(); } if (handler == null) { throw new ConversionException("No InvocationHandler specified for dynamic proxy"); } Class[] interfacesAsArray = new Class[interfaces.size()]; interfaces.toArray(interfacesAsArray); return Proxy.newProxyInstance(classLoader, interfacesAsArray, handler); }
/* * (non-Javadoc) * * @see * com.thoughtworks.xstream.converters.Converter#unmarshal(com.thoughtworks * .xstream.io.HierarchicalStreamReader, * com.thoughtworks.xstream.converters.UnmarshallingContext) */ @Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { LeaseInfo.Builder builder = LeaseInfo.Builder.newBuilder(); while (reader.hasMoreChildren()) { reader.moveDown(); String nodeName = reader.getNodeName(); String nodeValue = reader.getValue(); if (nodeValue == null) { continue; } long longValue = 0; try { longValue = Long.valueOf(nodeValue).longValue(); } catch (NumberFormatException ne) { continue; } if (ELEM_DURATION.equals(nodeName)) { builder.setDurationInSecs((int) longValue); } else if (ELEM_EVICTION_TIMESTAMP.equals(nodeName)) { builder.setEvictionTimestamp(longValue); } else if (ELEM_LAST_RENEW_TIMETSTAMP.equals(nodeName)) { builder.setRenewalTimestamp(longValue); } else if (ELEM_REG_TIMESTAMP.equals(nodeName)) { builder.setRegistrationTimestamp(longValue); } else if (ELEM_RENEW_INT.equals(nodeName)) { builder.setRenewalIntervalInSecs((int) longValue); } else if (ELEM_SERVICE_UP_TIMESTAMP.equals(nodeName)) { builder.setServiceUpTimestamp(longValue); } reader.moveUp(); } return builder.build(); }
public Object unmarshal( final HierarchicalStreamReader reader, final UnmarshallingContext context) { final Object result = instantiateNewInstance(context); while (reader.hasMoreChildren()) { reader.moveDown(); String propertyName = classMapper.realMember(result.getClass(), reader.getNodeName()); boolean propertyExistsInClass = beanProvider.propertyDefinedInClass(propertyName, result.getClass()); Class type = determineType(reader, result, propertyName); Object value = context.convertAnother(result, type); if (propertyExistsInClass) { beanProvider.writeProperty(result, propertyName, value); } reader.moveUp(); } return result; }
public Object doUnmarshal( final Object result, final HierarchicalStreamReader reader, final UnmarshallingContext context) { final SeenFields seenFields = new SeenFields(); Iterator it = reader.getAttributeNames(); // Remember outermost Saveable encountered, for reporting below if (result instanceof Saveable && context.get("Saveable") == null) context.put("Saveable", result); // Process attributes before recursing into child elements. while (it.hasNext()) { String attrAlias = (String) it.next(); String attrName = mapper.attributeForAlias(attrAlias); Class classDefiningField = determineWhichClassDefinesField(reader); boolean fieldExistsInClass = fieldDefinedInClass(result, attrName); if (fieldExistsInClass) { Field field = reflectionProvider.getField(result.getClass(), attrName); SingleValueConverter converter = mapper.getConverterFromAttribute(field.getDeclaringClass(), attrName, field.getType()); Class type = field.getType(); if (converter == null) { converter = mapper.getConverterFromItemType(type); } if (converter != null) { Object value = converter.fromString(reader.getAttribute(attrAlias)); if (type.isPrimitive()) { type = Primitives.box(type); } if (value != null && !type.isAssignableFrom(value.getClass())) { throw new ConversionException( "Cannot convert type " + value.getClass().getName() + " to type " + type.getName()); } reflectionProvider.writeField(result, attrName, value, classDefiningField); seenFields.add(classDefiningField, attrName); } } } Map implicitCollectionsForCurrentObject = null; while (reader.hasMoreChildren()) { reader.moveDown(); try { String fieldName = mapper.realMember(result.getClass(), reader.getNodeName()); boolean implicitCollectionHasSameName = mapper.getImplicitCollectionDefForFieldName(result.getClass(), reader.getNodeName()) != null; Class classDefiningField = determineWhichClassDefinesField(reader); boolean fieldExistsInClass = !implicitCollectionHasSameName && fieldDefinedInClass(result, fieldName); Class type = determineType(reader, fieldExistsInClass, result, fieldName, classDefiningField); final Object value; if (fieldExistsInClass) { Field field = reflectionProvider.getField(result.getClass(), fieldName); value = unmarshalField(context, result, type, field); // TODO the reflection provider should have returned the proper field in first place .... Class definedType = reflectionProvider.getFieldType(result, fieldName, classDefiningField); if (!definedType.isPrimitive()) { type = definedType; } } else { value = context.convertAnother(result, type); } if (value != null && !type.isAssignableFrom(value.getClass())) { LOGGER.warning( "Cannot convert type " + value.getClass().getName() + " to type " + type.getName()); // behave as if we didn't see this element } else { if (fieldExistsInClass) { reflectionProvider.writeField(result, fieldName, value, classDefiningField); seenFields.add(classDefiningField, fieldName); } else { implicitCollectionsForCurrentObject = writeValueToImplicitCollection( context, value, implicitCollectionsForCurrentObject, result, fieldName); } } } catch (NonExistentFieldException e) { LOGGER.log(WARNING, "Skipping a non-existent field " + e.getFieldName(), e); addErrorInContext(context, e); } catch (CannotResolveClassException e) { LOGGER.log(WARNING, "Skipping a non-existent type", e); addErrorInContext(context, e); } catch (LinkageError e) { LOGGER.log(WARNING, "Failed to resolve a type", e); addErrorInContext(context, e); } reader.moveUp(); } // Report any class/field errors in Saveable objects if (context.get("ReadError") != null && context.get("Saveable") == result) { OldDataMonitor.report((Saveable) result, (ArrayList<Throwable>) context.get("ReadError")); context.put("ReadError", null); } return result; }
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { ChartModel chartModel = new ChartModel(); chartModel.setChartEngineId(reader.getAttribute("chartEngine")); String attribute = reader.getAttribute("theme"); if (attribute != null) { try { chartModel.setTheme(Enum.valueOf(ChartTheme.class, attribute.toUpperCase())); } catch (Exception e) { // Do nothing } } String cssStyle = reader.getAttribute("style"); if (cssStyle != null) { chartModel.getStyle().setStyleString(cssStyle); } while (reader.hasMoreChildren()) { reader.moveDown(); if (reader.getNodeName().equals("title")) { String title = reader.getValue(); if (title != null) { chartModel.getTitle().setText(title); } cssStyle = reader.getAttribute("style"); if (cssStyle != null) { chartModel.getTitle().getStyle().setStyleString(cssStyle); } attribute = reader.getAttribute("location"); if (attribute != null) { try { chartModel .getTitle() .setLocation(Enum.valueOf(TitleLocation.class, attribute.toUpperCase())); } catch (Exception e) { // Do nothing } } } else if (reader.getNodeName().equals("subtitle")) { String subtitle = reader.getValue(); if ((subtitle != null) && (subtitle.trim().length() > 0)) { StyledText styledText = new StyledText(subtitle); cssStyle = reader.getAttribute("style"); if (cssStyle != null) { styledText.getStyle().setStyleString(cssStyle); } chartModel.getSubtitles().add(styledText); } } else if (reader.getNodeName().equals("legend")) { chartModel.getLegend().setVisible(true); cssStyle = reader.getAttribute("style"); if (cssStyle != null) { chartModel.getLegend().getStyle().setStyleString(cssStyle); } } else if (reader.getNodeName().equals("barPlot") || reader.getNodeName().equals("linePlot") || reader.getNodeName().equals("areaPlot") || reader.getNodeName().equals("piePlot") || reader.getNodeName().equals("dialPlot") || reader.getNodeName().equals("scatterPlot")) { chartModel.setPlot(createPlot(reader)); } reader.moveUp(); } return chartModel; }
private Plot createPlot(HierarchicalStreamReader reader) { Plot plot = null; if (reader.getNodeName().equals("barPlot")) { BarPlot barPlot = new BarPlot(); barPlot.getGrid().setVisible(false); String flavor = reader.getAttribute("flavor"); if (flavor != null) { try { barPlot.setFlavor(Enum.valueOf(BarPlotFlavor.class, flavor.toUpperCase())); } catch (Exception ex) { // Do nothing, we'll stay with the default. } } plot = barPlot; } else if (reader.getNodeName().equals("linePlot")) { LinePlot linePlot = new LinePlot(); linePlot.getGrid().setVisible(false); String flavor = reader.getAttribute("flavor"); if (flavor != null) { try { linePlot.setFlavor(Enum.valueOf(LinePlotFlavor.class, flavor.toUpperCase())); } catch (Exception ex) { // Do nothing, we'll stay with the default. } } plot = linePlot; } else if (reader.getNodeName().equals("areaPlot")) { AreaPlot areaPlot = new AreaPlot(); areaPlot.getGrid().setVisible(false); plot = areaPlot; } else if (reader.getNodeName().equals("scatterPlot")) { ScatterPlot scatterPlot = new ScatterPlot(); scatterPlot.getGrid().setVisible(false); plot = scatterPlot; } else if (reader.getNodeName().equals("piePlot")) { PiePlot piePlot = new PiePlot(); piePlot.getLabels().setVisible(false); piePlot.setAnimate(Boolean.parseBoolean(reader.getAttribute("animate"))); try { piePlot.setStartAngle(Integer.parseInt(reader.getAttribute("startAngle"))); } catch (Exception ex) { // Do nothing.We won't set the start angle } plot = piePlot; } else if (reader.getNodeName().equals("dialPlot")) { DialPlot dialPlot = new DialPlot(); dialPlot.setAnimate(Boolean.parseBoolean(reader.getAttribute("animate"))); plot = dialPlot; } String orientation = reader.getAttribute("orientation"); if (orientation != null) { try { plot.setOrientation(Enum.valueOf(Orientation.class, orientation.toUpperCase())); } catch (Exception ex) { // Do nothing, we'll stay with the default. } } String cssStyle = reader.getAttribute("style"); if (cssStyle != null) { plot.getStyle().setStyleString(cssStyle); } while (reader.hasMoreChildren()) { reader.moveDown(); if (reader.getNodeName().equals("palette")) { CssStyle paintStyle = new CssStyle(); Palette palette = new Palette(); while (reader.hasMoreChildren()) { reader.moveDown(); if (reader.getNodeName().equals("paint")) { cssStyle = reader.getAttribute("style"); if (cssStyle != null) { paintStyle.setStyleString(cssStyle); Integer color = paintStyle.getColor(); if (color != null) { palette.add(color); } } } reader.moveUp(); } if (palette.size() > 0) { plot.setPalette(palette); } } if ((reader.getNodeName().equals("verticalAxis") || reader.getNodeName().equals("horizontalAxis")) && (plot instanceof TwoAxisPlot)) { TwoAxisPlot twoAxisPlot = (TwoAxisPlot) plot; Axis axis = (reader.getNodeName().equals("verticalAxis") ? twoAxisPlot.getVerticalAxis() : twoAxisPlot.getHorizontalAxis()); String axisLabelOrientation = reader.getAttribute("labelOrientation"); try { axis.setLabelOrientation( Enum.valueOf(LabelOrientation.class, axisLabelOrientation.toUpperCase())); } catch (Exception ex) { // Do nothing, we'll stay with the default. } if (axis instanceof NumericAxis) { NumericAxis numericAxis = (NumericAxis) axis; String minValueStr = reader.getAttribute("minValue"); if (minValueStr != null) { try { numericAxis.setMinValue(Integer.parseInt(minValueStr)); } catch (NumberFormatException ex) { try { numericAxis.setMinValue(Double.parseDouble(minValueStr)); } catch (NumberFormatException ex2) { // Do nothing. No min value will be assigned. } } } String maxValueStr = reader.getAttribute("maxValue"); if (maxValueStr != null) { if (maxValueStr != null) { try { numericAxis.setMaxValue(Integer.parseInt(maxValueStr)); } catch (NumberFormatException ex) { try { numericAxis.setMaxValue(Double.parseDouble(maxValueStr)); } catch (NumberFormatException ex2) { // Do nothing. No min value will be assigned. } } } } } cssStyle = reader.getAttribute("style"); if (cssStyle != null) { axis.getStyle().setStyleString(cssStyle); } while (reader.hasMoreChildren()) { reader.moveDown(); String legend = reader.getValue(); if (legend != null) { axis.getLegend().setText(legend); } cssStyle = reader.getAttribute("style"); if (cssStyle != null) { axis.getLegend().getStyle().setStyleString(cssStyle); } reader.moveUp(); } } if (reader.getNodeName().equals("grid") && (plot instanceof TwoAxisPlot)) { TwoAxisPlot twoAxisPlot = (TwoAxisPlot) plot; Grid grid = twoAxisPlot.getGrid(); grid.setVisible(true); while (reader.hasMoreChildren()) { reader.moveDown(); if (reader.getNodeName().equals("verticalLines")) { cssStyle = reader.getAttribute("style"); if (cssStyle != null) { grid.getVerticalLineStyle().setStyleString(cssStyle); } } else if (reader.getNodeName().equals("horizontalLines")) { cssStyle = reader.getAttribute("style"); if (cssStyle != null) { grid.getHorizontalLineStyle().setStyleString(cssStyle); } } reader.moveUp(); } } if (reader.getNodeName().equals("scale") && (plot instanceof DialPlot)) { while (reader.hasMoreChildren()) { CssStyle rangeStyle = new CssStyle(); Integer color = null; Double rangeMin = null; Double rangeMax = null; reader.moveDown(); if (reader.getNodeName().equals("range")) { cssStyle = reader.getAttribute("style"); if (cssStyle != null) { rangeStyle.setStyleString(cssStyle); color = rangeStyle.getColor(); } String str = reader.getAttribute("min"); if (str != null) { rangeMin = new Double(str); } str = reader.getAttribute("max"); if (str != null) { rangeMax = new Double(str); } ((DialPlot) plot).getScale().addRange(new DialRange(rangeMin, rangeMax, color)); } reader.moveUp(); } } if (reader.getNodeName().equals("labels") && (plot instanceof PiePlot)) { PiePlot piePlot = (PiePlot) plot; piePlot.getLabels().setVisible(true); cssStyle = reader.getAttribute("style"); if (cssStyle != null) { piePlot.getLabels().getStyle().setStyleString(cssStyle); } } if (reader.getNodeName().equals("annotation") && (plot instanceof DialPlot)) { DialPlot dialPlot = (DialPlot) plot; String annotation = reader.getValue(); if (annotation != null) { dialPlot.getAnnotation().setText(annotation); } cssStyle = reader.getAttribute("style"); if (cssStyle != null) { dialPlot.getAnnotation().getStyle().setStyleString(cssStyle); } } reader.moveUp(); } return plot; }
/** {@inheritDoc} */ public boolean isLegacyNode(HierarchicalStreamReader reader, final UnmarshallingContext context) { return reader.getNodeName().startsWith("org.spearce"); }