com.thoughtworks.xstream.converters.MarshallingContext Java Examples
The following examples show how to use
com.thoughtworks.xstream.converters.MarshallingContext.
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: GamaMapConverter.java From gama with GNU General Public License v3.0 | 6 votes |
@Override public void marshal(final Object arg0, final HierarchicalStreamWriter writer, final MarshallingContext arg2) { final IMap mp = (IMap) arg0; // GamaMapReducer m = new GamaMapReducer(mp); // writer.startNode("GamaMap"); // // writer.startNode("KeysType"); // arg2.convertAnother(m.getKeysType()); // writer.endNode(); // // writer.startNode("ValueType"); // arg2.convertAnother(m.getDataType()); // writer.endNode(); // // for(GamaPair gm : m.getValues()) { // arg2.convertAnother(gm); // } // // writer.endNode(); arg2.convertAnother(new GamaMapReducer(mp)); }
Example #2
Source File: NamedArrayConverter.java From lams with GNU General Public License v2.0 | 6 votes |
public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { final int length = Array.getLength(source); for (int i = 0; i < length; ++i) { final Object item = Array.get(source, i); final Class itemType = item == null ? Mapper.Null.class : arrayType.getComponentType().isPrimitive() ? Primitives.unbox(item.getClass()) : item.getClass(); ExtendedHierarchicalStreamWriterHelper.startNode(writer, itemName, itemType); if (!itemType.equals(arrayType.getComponentType())) { final String attributeName = mapper.aliasForSystemAttribute("class"); if (attributeName != null) { writer.addAttribute(attributeName, mapper.serializedClass(itemType)); } } if (item != null) { context.convertAnother(item); } writer.endNode(); } }
Example #3
Source File: FontConverter.java From lams with GNU General Public License v2.0 | 6 votes |
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { Font font = (Font)source; Map attributes = font.getAttributes(); if (mapper != null) { String classAlias = mapper.aliasForSystemAttribute("class"); for (Iterator iter = attributes.entrySet().iterator(); iter.hasNext();) { Map.Entry entry = (Map.Entry)iter.next(); String name = textAttributeConverter.toString(entry.getKey()); Object value = entry.getValue(); Class type = value != null ? value.getClass() : Mapper.Null.class; ExtendedHierarchicalStreamWriterHelper.startNode(writer, name, type); writer.addAttribute(classAlias, mapper.serializedClass(type)); if (value != null) { context.convertAnother(value); } writer.endNode(); } } else { writer.startNode("attributes"); // <attributes> context.convertAnother(attributes); writer.endNode(); // </attributes> } }
Example #4
Source File: PbBlankXMLConverter.java From ET_Redux with Apache License 2.0 | 6 votes |
/** * writes the argument <code>value</code> to the XML file specified through <code>writer</code> * * @pre <code>value</code> is a valid <code>PbBlank</code>, <code> * writer</code> is a valid <code>HierarchicalStreamWriter</code>, * and <code>context</code> is a valid <code>MarshallingContext</code> * @post <code>value</code> is written to the XML file specified via <code>writer</code> * @param value <code>PbBlank</code> that you wish to write to a file * @param writer stream to write through * @param context <code>MarshallingContext</code> used to store generic data */ public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) { PbBlank pbBlank = (PbBlank) value; writer.startNode("name"); writer.setValue(pbBlank.getName()); writer.endNode(); writer.startNode("ratios"); context.convertAnother(pbBlank.getRatios()); writer.endNode(); writer.startNode("rhoCorrelations"); context.convertAnother(pbBlank.getRhoCorrelations()); writer.endNode(); }
Example #5
Source File: WxPayOrderNotifyResultConverter.java From weixin-java-tools with Apache License 2.0 | 6 votes |
@Override public void marshal(Object original, HierarchicalStreamWriter writer, MarshallingContext context) { super.marshal(original, writer, context); WxPayOrderNotifyResult obj = (WxPayOrderNotifyResult) original; List<WxPayOrderNotifyCoupon> list = obj.getCouponList(); if (list == null || list.size() == 0) { return; } for (int i = 0; i < list.size(); i++) { WxPayOrderNotifyCoupon coupon = list.get(i); writer.startNode("coupon_id_" + i); writer.setValue(coupon.getCouponId()); writer.endNode(); writer.startNode("coupon_type_" + i); writer.setValue(coupon.getCouponType()); writer.endNode(); writer.startNode("coupon_fee_" + i); writer.setValue(coupon.getCouponFee() + ""); writer.endNode(); } }
Example #6
Source File: ViewDocumentConverter.java From depan with Apache License 2.0 | 6 votes |
/** * No need to start a node, since the caller ensures we are wrapped correctly. */ @Override public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { ViewDocument viewInfo = (ViewDocument) source; Components components = viewInfo.getComponents(); // Save the graph reference. marshalObject(components.getParentGraph(), writer, context); // Save all node references. marshalNodes(components.getViewNodes(), VIEW_NODES, writer, context); // Save the preferences. marshalObject(components.getUserPrefs(), writer, context); }
Example #7
Source File: AbstractReflectionConverter.java From lams with GNU General Public License v2.0 | 6 votes |
public void marshal(Object original, final HierarchicalStreamWriter writer, final MarshallingContext context) { final Object source = serializationMembers.callWriteReplace(original); if (source != original && context instanceof ReferencingMarshallingContext) { ((ReferencingMarshallingContext)context).replace(original, source); } if (source.getClass() != original.getClass()) { String attributeName = mapper.aliasForSystemAttribute("resolves-to"); if (attributeName != null) { writer.addAttribute(attributeName, mapper.serializedClass(source.getClass())); } context.convertAnother(source); } else { doMarshal(source, writer, context); } }
Example #8
Source File: WSRequestCodec.java From SI with BSD 2-Clause "Simplified" License | 5 votes |
public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) { AbstractMap map = (AbstractMap) value; for (Object obj : map.entrySet()) { Map.Entry entry = (Map.Entry) obj; writer.startNode(entry.getKey().toString()); Object val = entry.getValue(); if ( null != val ) { writer.setValue(val.toString()); } writer.endNode(); } }
Example #9
Source File: GregorianCalendarConverter.java From lams with GNU General Public License v2.0 | 5 votes |
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { GregorianCalendar calendar = (GregorianCalendar) source; ExtendedHierarchicalStreamWriterHelper.startNode(writer, "time", long.class); long timeInMillis = calendar.getTime().getTime(); // calendar.getTimeInMillis() not available under JDK 1.3 writer.setValue(String.valueOf(timeInMillis)); writer.endNode(); ExtendedHierarchicalStreamWriterHelper.startNode(writer, "timezone", String.class); writer.setValue(calendar.getTimeZone().getID()); writer.endNode(); }
Example #10
Source File: AbstractMappingConverter.java From depan with Apache License 2.0 | 5 votes |
protected void marshalObject(Object item, HierarchicalStreamWriter writer, MarshallingContext context) { String nodeLabel = mapper.serializedClass(item.getClass()); writer.startNode(nodeLabel); context.convertAnother(item); writer.endNode(); }
Example #11
Source File: GamaSpeciesConverter.java From gama with GNU General Public License v3.0 | 5 votes |
@Override public void marshal(final Object arg0, final HierarchicalStreamWriter writer, final MarshallingContext context) { // System.out.println("ConvertAnother : ConvertGamaSpecies " + arg0.getClass()); DEBUG.OUT("ConvertAnother : ConvertGamaSpecies " + arg0.getClass()); final AbstractSpecies spec = (AbstractSpecies) arg0; final GamaPopulation<? extends IAgent> pop = (GamaPopulation<? extends IAgent>) spec.getPopulation(convertScope.getScope()); writer.startNode("agentSetFromPopulation"); context.convertAnother(pop.getAgents(convertScope.getScope())); writer.endNode(); // System.out.println("===========END ConvertAnother : ConvertGamaSpecies"); DEBUG.OUT("===========END ConvertAnother : ConvertGamaSpecies"); }
Example #12
Source File: KeyArrayConverter.java From com.zsmartsystems.zigbee with Eclipse Public License 1.0 | 5 votes |
@Override public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) { StringBuilder builder = new StringBuilder(); int[] arrayValue = (int[]) value; for (int cnt = 0; cnt < 16; cnt++) { builder.append(String.format("%02X", arrayValue[cnt])); } writer.setValue(builder.toString()); }
Example #13
Source File: DynamicProxyConverter.java From lams with GNU General Public License v2.0 | 5 votes |
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { InvocationHandler invocationHandler = Proxy.getInvocationHandler(source); addInterfacesToXml(source, writer); writer.startNode("handler"); String attributeName = mapper.aliasForSystemAttribute("class"); if (attributeName != null) { writer.addAttribute(attributeName, mapper.serializedClass(invocationHandler.getClass())); } context.convertAnother(invocationHandler); writer.endNode(); }
Example #14
Source File: XMLConfigurer.java From oval with Eclipse Public License 2.0 | 5 votes |
@Override public void marshal(final Object value, final HierarchicalStreamWriter writer, final MarshallingContext context) { final AssertCheck assertCheck = (AssertCheck) value; writer.addAttribute("lang", assertCheck.getLang()); if (!"net.sf.oval.constraint.Assert.violated".equals(assertCheck.getMessage())) { writer.addAttribute("message", assertCheck.getMessage()); } if (!"net.sf.oval.constraint.Assert".equals(assertCheck.getErrorCode())) { writer.addAttribute("errorCode", assertCheck.getErrorCode()); } writer.addAttribute("severity", Integer.toString(assertCheck.getSeverity())); if (assertCheck.getWhen() != null) { writer.addAttribute("when", assertCheck.getWhen()); } writer.startNode("expr"); writer.setValue(assertCheck.getExpr()); writer.endNode(); final String[] profiles = assertCheck.getProfiles(); if (profiles != null && profiles.length > 0) { writer.startNode("profiles"); for (final String profile : profiles) { writer.startNode("string"); writer.setValue(profile); writer.endNode(); } writer.endNode(); } final ConstraintTarget[] appliesTo = assertCheck.getAppliesTo(); if (appliesTo != null && appliesTo.length > 0) { writer.startNode("appliesTo"); for (final ConstraintTarget ctarget : appliesTo) { writer.startNode("constraintTarget"); writer.setValue(ctarget.name()); writer.endNode(); } writer.endNode(); } }
Example #15
Source File: GraphModelReferenceConverter.java From depan with Apache License 2.0 | 5 votes |
/** * Simply output the workspace relative name for the referenced GraphModel. */ @Override public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { GraphModelReference graphRef = (GraphModelReference) source; context.convertAnother(graphRef.getGraphPath()); }
Example #16
Source File: PhysicalConstantsXMLConverter.java From ET_Redux with Apache License 2.0 | 5 votes |
/** * * @param value * @param writer * @param context */ @Override public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) { PhysicalConstants physicalConstants = (PhysicalConstants) value; writer.startNode("name"); writer.setValue(physicalConstants.getName()); writer.endNode(); writer.startNode("version"); writer.setValue(Integer.toString(physicalConstants.getVersion())); writer.endNode(); writer.startNode("atomicMolarMasses"); context.convertAnother(physicalConstants.getAtomicMolarMasses()); writer.endNode(); writer.startNode("measuredConstants"); context.convertAnother(physicalConstants.getMeasuredConstants()); writer.endNode(); writer.startNode("physicalConstantsComment"); writer.setValue(physicalConstants.getPhysicalConstantsComment()); writer.endNode(); }
Example #17
Source File: SubjectConverter.java From lams with GNU General Public License v2.0 | 5 votes |
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { Subject subject = (Subject) source; marshalPrincipals(subject.getPrincipals(), writer, context); marshalPublicCredentials(subject.getPublicCredentials(), writer, context); marshalPrivateCredentials(subject.getPrivateCredentials(), writer, context); marshalReadOnly(subject.isReadOnly(), writer); }
Example #18
Source File: StringKeyMapConverter.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Override protected void marshalEntry(HierarchicalStreamWriter writer, MarshallingContext context, Entry entry) { if (entry.getKey() instanceof String) { marshalStringKey(writer, context, entry); } else { super.marshalEntry(writer, context, entry); } }
Example #19
Source File: MeasuredRatioModelXMLConverter.java From ET_Redux with Apache License 2.0 | 5 votes |
/** * writes the argument <code>value</code> to the XML file specified through <code>writer</code> * * @pre <code>value</code> is a valid <code>MeasuredRatioModel</code>, * <code>writer</code> is a valid <code>HierarchicalStreamWriter</code>, * and <code>context</code> is a valid <code>MarshallingContext</code> * @post <code>value</code> is written to the XML file specified via <code>writer</code> * @param value <code>MeasuredRatioModel</code> that you wish to write to a file * @param writer stream to write through * @param context <code>MarshallingContext</code> used to store generic data */ public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) { ValueModel measuredRatio = (MeasuredRatioModel) value; writer.startNode("name"); writer.setValue(measuredRatio.getName()); writer.endNode(); writer.startNode("value"); writer.setValue(measuredRatio.getValue().toPlainString()); writer.endNode(); writer.startNode("uncertaintyType"); writer.setValue(measuredRatio.getUncertaintyType()); writer.endNode(); writer.startNode("oneSigma"); writer.setValue(measuredRatio.getOneSigma().toPlainString()); writer.endNode(); writer.startNode("fracCorr"); writer.setValue(Boolean.toString(((MeasuredRatioModel) measuredRatio).isFracCorr())); writer.endNode(); writer.startNode("oxideCorr"); writer.setValue(Boolean.toString(((MeasuredRatioModel) measuredRatio).isOxideCorr())); writer.endNode(); }
Example #20
Source File: ReportCategoryXMLConverter.java From ET_Redux with Apache License 2.0 | 5 votes |
/** * writes the argument <code>value</code> to the XML file specified through <code>writer</code> * * @pre <code>value</code> is a valid <code>reportSettings</code>, <code> * writer</code> is a valid <code>HierarchicalStreamWriter</code>, * and <code>context</code> is a valid <code>MarshallingContext</code> * @post <code>value</code> is written to the XML file specified via <code>writer</code> * @param value <code>reportSettings</code> that you wish to write to a file * @param writer stream to write through * @param context <code>MarshallingContext</code> used to store generic data */ @Override public void marshal ( Object value, HierarchicalStreamWriter writer, MarshallingContext context ) { ReportCategory reportCategory = (ReportCategory) value; writer.startNode( "displayName" ); writer.setValue( reportCategory.getDisplayName() ); writer.endNode(); writer.startNode( "positionIndex" ); writer.setValue( Integer.toString( reportCategory.getPositionIndex() ) ); writer.endNode(); writer.startNode( "categoryColumns" ); context.convertAnother( reportCategory.getCategoryColumns() ); writer.endNode(); writer.startNode( "categoryColor" ); writer.setValue( Integer.toString(reportCategory.getCategoryColor().getRGB() )); writer.endNode(); writer.startNode( "visible" ); writer.setValue( Boolean.toString( reportCategory.isVisible() ) ); writer.endNode(); writer.startNode( "legacyData" ); writer.setValue( Boolean.toString( reportCategory.isLegacyData() ) ); writer.endNode(); }
Example #21
Source File: ArrayConverter.java From lams with GNU General Public License v2.0 | 5 votes |
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { int length = Array.getLength(source); for (int i = 0; i < length; i++) { final Object item = Array.get(source, i); writeCompleteItem(item, context, writer); } }
Example #22
Source File: RelationSetConverters.java From depan with Apache License 2.0 | 5 votes |
@Override public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { RelationSets.Array relationSet = (RelationSets.Array) source; marshalCollection( Arrays.asList(relationSet.getRelations()), writer, context); }
Example #23
Source File: MapConverter.java From lams with GNU General Public License v2.0 | 5 votes |
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { Map map = (Map) source; String entryName = mapper().serializedClass(Map.Entry.class); for (Iterator iterator = map.entrySet().iterator(); iterator.hasNext();) { Map.Entry entry = (Map.Entry) iterator.next(); ExtendedHierarchicalStreamWriterHelper.startNode(writer, entryName, entry.getClass()); writeCompleteItem(entry.getKey(), context, writer); writeCompleteItem(entry.getValue(), context, writer); writer.endNode(); } }
Example #24
Source File: TreeMapConverter.java From lams with GNU General Public License v2.0 | 5 votes |
protected void marshalComparator(Comparator comparator, HierarchicalStreamWriter writer, MarshallingContext context) { if (comparator != null) { writer.startNode("comparator"); writer.addAttribute(mapper().aliasForSystemAttribute("class"), mapper().serializedClass(comparator.getClass())); context.convertAnother(comparator); writer.endNode(); } }
Example #25
Source File: CollectionConverter.java From lams with GNU General Public License v2.0 | 5 votes |
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { Collection collection = (Collection) source; for (Iterator iterator = collection.iterator(); iterator.hasNext();) { Object item = iterator.next(); writeCompleteItem(item, context, writer); } }
Example #26
Source File: SavedAgentConverter.java From gama with GNU General Public License v3.0 | 5 votes |
@Override public void marshal(final Object arg0, final HierarchicalStreamWriter writer, final MarshallingContext context) { final SavedAgent savedAgt = (SavedAgent) arg0; writer.startNode("index"); writer.setValue("" + savedAgt.getIndex()); writer.endNode(); final ArrayList<String> keys = new ArrayList<>(); final ArrayList<Object> datas = new ArrayList<>(); for (final String ky : savedAgt.getKeys()) { final Object val = savedAgt.get(ky); if (!(val instanceof ExperimentAgent) && !(val instanceof SimulationAgent)) { keys.add(ky); datas.add(val); } } writer.startNode("variables"); writer.startNode("keys"); context.convertAnother(keys); writer.endNode(); writer.startNode("data"); context.convertAnother(datas); writer.endNode(); writer.endNode(); final Map<String, List<SavedAgent>> inPop = savedAgt.getInnerPopulations(); if (inPop != null) { writer.startNode("innerPopulations"); context.convertAnother(inPop); writer.endNode(); } }
Example #27
Source File: MapConverter.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Override @SuppressWarnings({ "rawtypes" }) public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { Map map = (Map) source; try { for (Iterator iterator = map.entrySet().iterator(); iterator.hasNext();) { Map.Entry entry = (Map.Entry) iterator.next(); marshalEntry(writer, context, entry); } } catch (ConcurrentModificationException e) { log.debug("Map " // seems there is no non-deprecated way to get the path... + (context instanceof ReferencingMarshallingContext ? "at "+((ReferencingMarshallingContext)context).currentPath() : "") + "["+source+"] modified while serializing; will fail, and retry may be attempted"); throw e; // would be nice to attempt to re-serialize being slightly more defensive, as code below; // but the code above may have written partial data so that is dangerous, we could have corrupted output. // if we could mark and restore in the output stream then we could do this below (but we don't have that in our stream), // or we could try this copying code in the first instance (but that's slow); // error is rare most of the time (e.g. attribute being updated) so we bail on this whole attempt // and simply try serializing the map-owner (e.g. an entity) again. // ImmutableList entries = ImmutableList.copyOf(map.entrySet()); // for (Iterator iterator = entries.iterator(); iterator.hasNext();) { // Map.Entry entry = (Map.Entry) iterator.next(); // marshalEntry(writer, context, entry); // } } }
Example #28
Source File: GamaPointConverter.java From gama with GNU General Public License v3.0 | 5 votes |
@Override public void marshal(Object arg0, HierarchicalStreamWriter writer, MarshallingContext arg2) { GamaPoint pt = (GamaPoint) arg0; String line=pt.getX()+SEPARATOR+pt.getY()+SEPARATOR+pt.getZ(); writer.startNode(TAG); writer.setValue(line); writer.endNode(); }
Example #29
Source File: AbstractCollectionConverter.java From lams with GNU General Public License v2.0 | 5 votes |
/** * @deprecated As of 1.4.11 use {@link #writeCompleteItem(Object, MarshallingContext, HierarchicalStreamWriter)} * instead. */ protected void writeItem(Object item, MarshallingContext context, HierarchicalStreamWriter writer) { // PUBLISHED API METHOD! If changing signature, ensure backwards compatibility. if (item == null) { // todo: this is duplicated in TreeMarshaller.start() writeNullItem(context, writer); } else { String name = mapper().serializedClass(item.getClass()); ExtendedHierarchicalStreamWriterHelper.startNode(writer, name, item.getClass()); writeBareItem(item, context, writer); writer.endNode(); } }
Example #30
Source File: MapConverter.java From yes-cart with Apache License 2.0 | 5 votes |
protected void writeItem(String nodeName, Object item, MarshallingContext context, HierarchicalStreamWriter writer) { // PUBLISHED API METHOD! If changing signature, ensure backwards compatibility. if (item != null) { ExtendedHierarchicalStreamWriterHelper.startNode(writer, nodeName, item.getClass()); context.convertAnother(item); writer.endNode(); } }