public static void registerMapping(XStream xstream) { // In the XML the class is represented as a page - tag xstream.alias("page", CPNPage.class); xstream.useAttributeFor(CPNPage.class, "idattri"); xstream.aliasAttribute(CPNPage.class, "idattri", "id"); // In order not to display the places / transitions / arcs tag, but simply show // the page tags one after another. xstream.addImplicitCollection(CPNPage.class, "places", CPNPlace.class); xstream.addImplicitCollection(CPNPage.class, "transitions", CPNTransition.class); xstream.addImplicitCollection(CPNPage.class, "arcs", CPNArc.class); // Sometimes XStream cannot translate elements into a XML structure. // Therefore exists the possibility to create and register a converter for that element. xstream.registerConverter(new CPNTextConverter()); // These instance variables are not needed for the mapping, that's why they are excluded xstream.omitField(CPNPage.class, "arcRelation"); xstream.omitField(CPNPage.class, "nodePositions"); // Giving all fields a concrete name for the XML xstream.aliasField("Aux", CPNPage.class, "auxtag"); xstream.aliasField("group", CPNPage.class, "grouptag"); xstream.aliasField("vguidelines", CPNPage.class, "vguidelines"); xstream.aliasField("hguidelines", CPNPage.class, "hguidelines"); CPNPageattr.registerMapping(xstream); CPNModellingThing.registerMapping(xstream); CPNPlace.registerMapping(xstream); CPNTransition.registerMapping(xstream); CPNArc.registerMapping(xstream); CPNLittleProperty.registerMapping(xstream); }
/** @see org.olat.core.configuration.Initializable#init() */ public void init() { mystream = XStreamHelper.createXStreamInstance(); mystream.alias("versions", VersionsFileImpl.class); mystream.alias("revision", RevisionFileImpl.class); mystream.omitField(VersionsFileImpl.class, "currentVersion"); mystream.omitField(VersionsFileImpl.class, "versionFile"); mystream.omitField(RevisionFileImpl.class, "current"); mystream.omitField(RevisionFileImpl.class, "container"); mystream.omitField(RevisionFileImpl.class, "file"); }
@Override protected void configureXStream(XStream xstream) { xstream.omitField(BeanWithId.class, "m_id"); xstream.alias("entry", PhonebookEntry.class); xstream.aliasField("first-name", PhonebookEntry.class, "firstName"); xstream.aliasField("last-name", PhonebookEntry.class, "lastName"); xstream.aliasField("contact-information", PhonebookEntry.class, "addressBookEntry"); xstream.omitField(PhonebookEntry.class, "m_phonebook"); xstream.omitField(AddressBookEntry.class, "m_useBranchAddress"); xstream.omitField(AddressBookEntry.class, "m_branchOfficeAddress"); }
public void configure(XStream xStream) { xStream.alias("profile", RulesProfile.class); xStream.alias("alert", Alert.class); xStream.alias("active-rule", ActiveRule.class); xStream.aliasField("active-rules", RulesProfile.class, "activeRules"); xStream.aliasField("default-profile", RulesProfile.class, "defaultProfile"); xStream.omitField(RulesProfile.class, "id"); xStream.omitField(RulesProfile.class, "projects"); xStream.registerConverter(getActiveRuleConverter()); xStream.registerConverter(getAlertsConverter()); }
public XmlProjectDescriptorSerializer(boolean postProcess) { xstream = new XStream(new DomDriver()); xstream.ignoreUnknownElements(); xstream.omitField(ProjectDescriptor.class, "id"); // This field was deprecated xstream.omitField(ProjectDescriptor.class, "log"); xstream.omitField(ProjectDescriptor.class, "classLoader"); xstream.omitField(ProjectDescriptor.class, "projectFolder"); xstream.omitField(Module.class, "properties"); // properties doesn't supported by rules.xml xstream.omitField(Module.class, "wildcardName"); // runtime properties xstream.omitField(Module.class, "wildcardRulesRootPath"); // runtime properties xstream.omitField(Module.class, "project"); // runtime properties xstream.setMode(XStream.NO_REFERENCES); xstream.aliasType(PROJECT_DESCRIPTOR_TAG, ProjectDescriptor.class); xstream.aliasType(MODULE_TAG, Module.class); xstream.aliasType(DEPENDENCY_TAG, ProjectDependencyDescriptor.class); xstream.aliasType(PATH_TAG, PathEntry.class); xstream.aliasType(PROPERTY_TAG, Property.class); xstream.aliasField( PROPERTIES_FILE_NAME_PATTERN, ProjectDescriptor.class, "propertiesFileNamePattern"); xstream.aliasField( PROPERTIES_FILE_NAME_PROCESSOR, ProjectDescriptor.class, "propertiesFileNameProcessor"); xstream.addDefaultImplementation(HashSet.class, Collection.class); xstream.alias("value", String.class); xstream.useAttributeFor(PathEntry.class, "path"); xstream.aliasField("rules-root", Module.class, "rulesRootPath"); xstream.aliasField(METHOD_FILTER_TAG, Module.class, "methodFilter"); xstream.registerConverter(new StringValueConverter()); this.postProcess = postProcess; }
public String toXML(boolean omitId) { XStream xs = new XStream(); xs.alias("PedidoDeAbastecimiento", PedidoAbastecimientoVO.class); xs.alias("ocAsociada", OrdenDeCompraVO.class); xs.alias("Rodamiento", RodamientoVO.class); xs.alias("Proveedor", ProveedorVO.class); if (omitId) { xs.omitField(OrdenDeCompraVO.class, "idODV"); xs.omitField(ProveedorVO.class, "id"); xs.omitField(RodamientoVO.class, "id"); } xs.omitField(PedidoAbastecimientoVO.class, "cantidadPendiente"); xs.omitField(PedidoAbastecimientoVO.class, "ocAsociada"); return xs.toXML(this); }
/** * @param xstreamObject not null * @param jarFile not null * @param packageFilter a package name to filter. */ private void addAlias(XStream xstreamObject, File jarFile, String packageFilter) { JarInputStream jarStream = null; try { jarStream = new JarInputStream(new FileInputStream(jarFile)); JarEntry jarEntry = jarStream.getNextJarEntry(); while (jarEntry != null) { if (jarEntry.getName().toLowerCase(Locale.ENGLISH).endsWith(".class")) { String name = jarEntry.getName().substring(0, jarEntry.getName().indexOf(".")); name = name.replaceAll("/", "\\."); if (name.indexOf(packageFilter) != -1) { try { Class<?> clazz = ClassUtils.getClass(name); String alias = StringUtils.lowercaseFirstLetter(ClassUtils.getShortClassName(clazz)); xstreamObject.alias(alias, clazz); if (!clazz.equals(Model.class)) { xstreamObject.omitField(clazz, "modelEncoding"); // unnecessary field } } catch (ClassNotFoundException e) { e.printStackTrace(); } } } jarStream.closeEntry(); jarEntry = jarStream.getNextJarEntry(); } } catch (IOException e) { if (getLog().isDebugEnabled()) { getLog().debug("IOException: " + e.getMessage(), e); } } finally { IOUtil.close(jarStream); } }
private XStream createXStream() { XStream xstream = new XStream(new DomDriver()); xstream.registerConverter(new TileConverter()); // xstream.registerConverter(new PointConverter()); xstream.registerConverter(new SceneryConverter()); xstream.registerConverter(new SpriteConverter()); xstream.registerConverter(new DrawnTileConverter()); xstream.registerConverter(new SceneryBagConverter()); xstream.registerConverter(new LayerConverter()); xstream.registerConverter(new LayerArrayConverter()); xstream.alias("drawntile", DrawnTile.class); xstream.alias("point", Point.class); xstream.useAttributeFor("name", String.class); xstream.alias("project", Project.class); xstream.omitField(Project.class, "tileSetBag"); xstream.omitField(Project.class, "path"); return xstream; }
/** Returns a StringRepresentation with the status of the running threads in the thread pool. */ private void handleProgress(Request req, Response resp, ArrayList<GWCTaskStatus> taskList) throws RestletException { Object[] tasks = taskList.toArray(); StringBuilder strBld = new StringBuilder(); strBld.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); strBld.append("<Tasks>"); XStream xs = new XStream(); xs.omitField(GWCTask.class, "parsedType"); xs.omitField(GWCTask.class, "state"); xs.omitField(GWCTask.class, "sharedThreadCount"); xs.omitField(GWCTask.class, "groupStartTime"); xs.omitField(GWCTask.class, "storageBroker"); xs.alias("GWCTaskStatus", GWCTaskStatus.class); for (int i = 0; i < tasks.length; i++) { GWCTaskStatus taskStatus = (GWCTaskStatus) tasks[i]; Iterator<Entry<Long, GWCTask>> iter = seeder.getRunningTasksIterator(); while (iter.hasNext()) { Entry<Long, GWCTask> entry = iter.next(); GWCTask task = entry.getValue(); if (task.getDbId() == taskStatus.getDbId()) { taskStatus.setTaskId(task.getTaskId()); taskStatus.setThreadRunning(true); taskStatus.setTilesDone(task.getTilesDone()); taskStatus.setTilesTotal(task.getTilesTotal()); taskStatus.setTimeSpent(task.getTimeSpent()); taskStatus.setTimeRemaing(task.getTimeRemaining()); } } String task_xml = xs.toXML(taskStatus); strBld.append(task_xml); } strBld.append("</Tasks>"); resp.setEntity(strBld.toString(), MediaType.TEXT_XML); }
public void fromXML(String textReceived, boolean omitId) { XStream xs = new XStream(); xs.alias("PedidoDeAbastecimiento", PedidoAbastecimientoVO.class); xs.alias("ocAsociada", OrdenDeCompraVO.class); xs.alias("Rodamiento", RodamientoVO.class); xs.alias("Proveedor", ProveedorVO.class); if (omitId) { xs.omitField(OrdenDeCompraVO.class, "idODV"); xs.omitField(ProveedorVO.class, "id"); xs.omitField(RodamientoVO.class, "id"); } xs.omitField(PedidoAbastecimientoVO.class, "cantidadPendiente"); xs.omitField(PedidoAbastecimientoVO.class, "ocAsociada"); PedidoAbastecimientoVO pavo = (PedidoAbastecimientoVO) xs.fromXML(textReceived); this.setIdPedido(pavo.getIdPedido()); this.setRodamiento(pavo.getRodamiento()); this.setOcAsociada(pavo.getOcAsociada()); this.setProveedor(pavo.getProveedor()); this.setCantidadPedida(pavo.getCantidadPedida()); this.setCantidadPendiente(pavo.getCantidadPendiente()); }
protected XStream createXStream(ClassResolver resolver, ClassLoader classLoader) { if (xstreamDriver != null) { xstream = new XStream(xstreamDriver); } else { xstream = new XStream(); } if (mode != null) { xstream.setMode(getModeFromString(mode)); } ClassLoader xstreamLoader = xstream.getClassLoader(); if (classLoader != null && xstreamLoader instanceof CompositeClassLoader) { ((CompositeClassLoader) xstreamLoader).add(classLoader); } try { if (this.implicitCollections != null) { for (Entry<String, String[]> entry : this.implicitCollections.entrySet()) { for (String name : entry.getValue()) { xstream.addImplicitCollection(resolver.resolveMandatoryClass(entry.getKey()), name); } } } if (this.aliases != null) { for (Entry<String, String> entry : this.aliases.entrySet()) { xstream.alias(entry.getKey(), resolver.resolveMandatoryClass(entry.getValue())); // It can turn the auto-detection mode off xstream.processAnnotations(resolver.resolveMandatoryClass(entry.getValue())); } } if (this.omitFields != null) { for (Entry<String, String[]> entry : this.omitFields.entrySet()) { for (String name : entry.getValue()) { xstream.omitField(resolver.resolveMandatoryClass(entry.getKey()), name); } } } if (this.converters != null) { for (String name : this.converters) { Class<Converter> converterClass = resolver.resolveMandatoryClass(name, Converter.class); Converter converter; Constructor<Converter> con = null; try { con = converterClass.getDeclaredConstructor(new Class[] {XStream.class}); } catch (Exception e) { // swallow as we null check in a moment. } if (con != null) { converter = con.newInstance(xstream); } else { converter = converterClass.newInstance(); try { Method method = converterClass.getMethod("setXStream", new Class[] {XStream.class}); if (method != null) { ObjectHelper.invokeMethod(method, converter, xstream); } } catch (Throwable e) { // swallow, as it just means the user never add an XStream setter, which is optional } } xstream.registerConverter(converter); } } addDefaultPermissions(xstream); if (this.permissions != null) { // permissions ::= pterm (',' pterm)* # consits of one or more terms // pterm ::= aod? wterm # each term preceded by an optional sign // aod ::= '+' | '-' # indicates allow or deny where allow if omitted // wterm ::= a class name with optional wildcard characters addPermissions(xstream, permissions); } } catch (Exception e) { throw new RuntimeException("Unable to build XStream instance", e); } return xstream; }
private void ustawAliasy(XStream _xstream) { _xstream.alias("Sygnał", Sygnal.class); // _xstream.aliasField("Parametry", Sygnal.class, "sygnal_parametry"); _xstream.aliasField("typSygnału", Sygnal.class, "typ"); _xstream.aliasField("amplituda", Sygnal.class, "A"); _xstream.aliasField("czasPoczątkowy", Sygnal.class, "t1"); _xstream.aliasField("czasTrwania", Sygnal.class, "d"); _xstream.aliasField("okresPodstawowy", Sygnal.class, "T"); _xstream.aliasField("współczynnikWypełnienia", Sygnal.class, "kw"); _xstream.aliasField("punkty", Sygnal.class, "punktyY_wykres"); _xstream.aliasField("kroczek", Sygnal.class, "kroczek"); _xstream.aliasField("krok", Sygnal.class, "krok"); if (this.sygnal.getrodzaj() == rodzaj_sygnalu.CIAGLY) { _xstream.omitField(Sygnal.class, "ts"); _xstream.omitField(Sygnal.class, "krok"); _xstream.omitField(Sygnal.class, "kroczek"); _xstream.omitField(Sygnal.class, "punktyY_wykres"); _xstream.omitField(Sygnal.class, "punktyY_probkowanie"); _xstream.omitField(Sygnal.class, "punktyY_kwantyzacja"); _xstream.omitField(Sygnal.class, "poziom_kwantyzacji_krok"); _xstream.omitField(Sygnal.class, "poziomy_kwantyzacji"); if (this.sygnal.gettyp() != 9 || this.sygnal.gettyp() != 10) { _xstream.omitField(Sygnal.class, "skok"); } } if (this.sygnal.getrodzaj() == rodzaj_sygnalu.DYSKRETNY) { _xstream.omitField(Sygnal.class, "typ"); _xstream.omitField(Sygnal.class, "A"); _xstream.omitField(Sygnal.class, "skok"); _xstream.omitField(Sygnal.class, "kroczek"); _xstream.omitField(Sygnal.class, "kw"); _xstream.omitField(Sygnal.class, "ts"); _xstream.omitField(Sygnal.class, "T"); _xstream.omitField(Sygnal.class, "punktyY_probkowanie"); _xstream.omitField(Sygnal.class, "punktyY_kwantyzacja"); _xstream.omitField(Sygnal.class, "poziom_kwantyzacji_krok"); _xstream.omitField(Sygnal.class, "poziomy_kwantyzacji"); if (this.sygnal.gettyp() != 9 || this.sygnal.gettyp() != 10) { _xstream.omitField(Sygnal.class, "skok"); } } }
/** * Get configured xstream object. * * @return {@link XStream} */ private static XStream getXStream() { final XStream xStream = new XStream(new DomDriver()); xStream.alias("customer", CustomerEntity.class); xStream.omitField(CustomerEntity.class, "orders"); xStream.omitField(CustomerEntity.class, "address"); xStream.omitField(CustomerEntity.class, "shops"); xStream.omitField(CustomerEntity.class, "coupons"); xStream.alias("wishlist", CustomerWishListEntity.class); xStream.alias("customerAv", AttrValueEntityCustomer.class); xStream.omitField(AttrValueEntityCustomer.class, "customer"); xStream.alias("attribute", AttributeEntity.class); xStream.omitField(AttributeEntity.class, "etype"); xStream.omitField(AttributeEntity.class, "attributeGroup"); xStream.alias("address", AddressEntity.class); xStream.alias("customerShop", CustomerShopEntity.class); xStream.alias("payment", CustomerOrderPaymentEntity.class); xStream.alias("carrier", CarrierEntity.class); xStream.omitField(CarrierEntity.class, "carrierSla"); xStream.omitField(CarrierEntity.class, "shops"); xStream.alias("carrierSla", CarrierSlaEntity.class); xStream.alias("order", CustomerOrderEntity.class); xStream.omitField(CustomerOrderEntity.class, "shop"); xStream.alias("orderLine", CustomerOrderDetEntity.class); xStream.omitField(CustomerOrderDetEntity.class, "customerOrder"); xStream.alias("orderDelivery", CustomerOrderDeliveryEntity.class); xStream.omitField(CustomerOrderDeliveryEntity.class, "customerOrder"); xStream.alias("deliveryLine", CustomerOrderDeliveryDetEntity.class); xStream.omitField(CustomerOrderDeliveryDetEntity.class, "delivery"); xStream.alias("shop", ShopEntity.class); xStream.alias("shopurl", ShopUrlEntity.class); xStream.alias("pair", Pair.class); xStream.alias("orderDto", CustomerOrderDTOImpl.class); xStream.alias("orderDeliveryDto", CustomerOrderDeliveryDTOImpl.class); xStream.alias("orderLineDto", CustomerOrderDeliveryDetailDTOImpl.class); xStream.alias("shopDto", ShopDTOImpl.class); xStream.alias("shopAvDto", AttrValueShopDTOImpl.class); xStream.alias("inventoryDto", InventoryDTOImpl.class); xStream.registerConverter( new Converter() { @Override public void marshal( final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { if (source == null) { writer.setValue(""); } else { GregorianCalendar calendar = new GregorianCalendar(); calendar.setTime((Date) source); try { writer.setValue( DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar).toXMLFormat()); } catch (DatatypeConfigurationException e) { writer.setValue(""); } } } @Override public Object unmarshal( final HierarchicalStreamReader reader, final UnmarshallingContext context) { return null; // not needed } @Override public boolean canConvert(final Class type) { return Date.class.isAssignableFrom(type); } }); xStream.registerConverter( new Converter() { @Override public void marshal( final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { if (((AbstractPersistentCollection) source).wasInitialized()) { context.convertAnother(new ArrayList((Collection) source)); } } @Override public Object unmarshal( final HierarchicalStreamReader reader, final UnmarshallingContext context) { return null; // not needed } @Override public boolean canConvert(final Class type) { return PersistentBag.class == type || PersistentList.class == type || PersistentSet.class == type; } }); xStream.setMode(XStream.NO_REFERENCES); return xStream; }
/** * Configure the XStream instance with this marshaller's bean properties. * * @param xstream the {@code XStream} instance */ protected void configureXStream(XStream xstream) { if (this.converters != null) { for (int i = 0; i < this.converters.length; i++) { if (this.converters[i] instanceof Converter) { xstream.registerConverter((Converter) this.converters[i], i); } else if (this.converters[i] instanceof SingleValueConverter) { xstream.registerConverter((SingleValueConverter) this.converters[i], i); } else { throw new IllegalArgumentException( "Invalid ConverterMatcher [" + this.converters[i] + "]"); } } } if (this.marshallingStrategy != null) { xstream.setMarshallingStrategy(this.marshallingStrategy); } if (this.mode != null) { xstream.setMode(this.mode); } try { if (this.aliases != null) { Map<String, Class<?>> classMap = toClassMap(this.aliases); for (Map.Entry<String, Class<?>> entry : classMap.entrySet()) { xstream.alias(entry.getKey(), entry.getValue()); } } if (this.aliasesByType != null) { Map<String, Class<?>> classMap = toClassMap(this.aliasesByType); for (Map.Entry<String, Class<?>> entry : classMap.entrySet()) { xstream.aliasType(entry.getKey(), entry.getValue()); } } if (this.fieldAliases != null) { for (Map.Entry<String, String> entry : this.fieldAliases.entrySet()) { String alias = entry.getValue(); String field = entry.getKey(); int idx = field.lastIndexOf('.'); if (idx != -1) { String className = field.substring(0, idx); Class<?> clazz = ClassUtils.forName(className, this.beanClassLoader); String fieldName = field.substring(idx + 1); xstream.aliasField(alias, clazz, fieldName); } else { throw new IllegalArgumentException("Field name [" + field + "] does not contain '.'"); } } } } catch (ClassNotFoundException ex) { throw new IllegalStateException("Failed to load specified alias class", ex); } if (this.useAttributeForTypes != null) { for (Class<?> type : this.useAttributeForTypes) { xstream.useAttributeFor(type); } } if (this.useAttributeFor != null) { for (Map.Entry<?, ?> entry : this.useAttributeFor.entrySet()) { if (entry.getKey() instanceof String) { if (entry.getValue() instanceof Class) { xstream.useAttributeFor((String) entry.getKey(), (Class<?>) entry.getValue()); } else { throw new IllegalArgumentException( "'useAttributesFor' takes Map<String, Class> when using a map key of type String"); } } else if (entry.getKey() instanceof Class) { Class<?> key = (Class<?>) entry.getKey(); if (entry.getValue() instanceof String) { xstream.useAttributeFor(key, (String) entry.getValue()); } else if (entry.getValue() instanceof List) { @SuppressWarnings("unchecked") List<Object> listValue = (List<Object>) entry.getValue(); for (Object element : listValue) { if (element instanceof String) { xstream.useAttributeFor(key, (String) element); } } } else { throw new IllegalArgumentException( "'useAttributesFor' property takes either Map<Class, String> " + "or Map<Class, List<String>> when using a map key of type Class"); } } else { throw new IllegalArgumentException( "'useAttributesFor' property takes either a map key of type String or Class"); } } } if (this.implicitCollections != null) { for (Map.Entry<Class<?>, String> entry : this.implicitCollections.entrySet()) { String[] collectionFields = StringUtils.commaDelimitedListToStringArray(entry.getValue()); for (String collectionField : collectionFields) { xstream.addImplicitCollection(entry.getKey(), collectionField); } } } if (this.omittedFields != null) { for (Map.Entry<Class<?>, String> entry : this.omittedFields.entrySet()) { String[] fields = StringUtils.commaDelimitedListToStringArray(entry.getValue()); for (String field : fields) { xstream.omitField(entry.getKey(), field); } } } if (this.annotatedClasses != null) { xstream.processAnnotations(this.annotatedClasses); } if (this.autodetectAnnotations) { xstream.autodetectAnnotations(true); } }