public void testBeanSerialize() { Id id = new Id("id_123"); ClassName className = new ClassName("ciaociaosonouna classe"); BeanContext beanContext = new BeanContext(id, className); Context context = new Context(); context.add(beanContext); XStream xstream = new XStream(); xstream.alias("context", Context.class); xstream.alias("beancontext", BeanContext.class); xstream.alias("id", Id.class); xstream.alias("classname", ClassName.class); xstream.useAttributeFor(BeanContext.class, "id"); xstream.registerConverter(new IdConverter()); xstream.useAttributeFor(BeanContext.class, "classname"); xstream.registerConverter(new ClassNameConverter()); xstream.addImplicitCollection(Context.class, "beanscontext"); // String expected = "<context>\r\n <beancontext id=\"id_123\" classname=\"ciaociaosonouna // classe\"/>\r\n</context>\r\n"; System.out.println(xstream.toXML(context)); System.out.println("\r\n"); System.out.println("\r\n"); // assertEquals(expected, xstream.toXML(context)); }
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()); }
static { XSTREAM.registerConverter( new AbstractSingleValueConverter() { @Override @SuppressWarnings("unchecked") public boolean canConvert(Class klazz) { return hudson.model.Item.class.isAssignableFrom(klazz); } @Override public Object fromString(String string) { Object item = Hudson.getInstance().getItemByFullName(string); if (item == null) throw new NoSuchElementException("No such job exists: " + string); return item; } @Override public String toString(Object item) { return ((hudson.model.Item) item).getFullName(); } }); XSTREAM.registerConverter( new AbstractSingleValueConverter() { @SuppressWarnings("unchecked") @Override public boolean canConvert(Class klazz) { return Run.class.isAssignableFrom(klazz); } @Override public Object fromString(String string) { String[] split = string.split("#"); String projectName = split[0]; int buildNumber = Integer.parseInt(split[1]); Job<?, ?> job = (Job<?, ?>) Hudson.getInstance().getItemByFullName(projectName); if (job == null) throw new NoSuchElementException("No such job exists: " + projectName); Run<?, ?> run = job.getBuildByNumber(buildNumber); if (run == null) throw new NoSuchElementException("No such build: " + string); return run; } @Override public String toString(Object object) { Run<?, ?> run = (Run<?, ?>) object; return run.getParent().getFullName() + "#" + run.getNumber(); } }); }
@Test public void testName() throws Exception { XStream xStream = new XStream(); xStream.registerConverter(new ToSingleValue()); Mapper mapper = xStream.getMapper(); ReflectionProvider reflectionProvider = xStream.getReflectionProvider(); ConverterLookup converterLookup = xStream.getConverterLookup(); String valueField = null; ToAttributedValueConverter converter = new ToAttributedValueConverter( AClass.class, mapper, reflectionProvider, converterLookup, valueField); xStream.registerConverter(converter); System.out.println(xStream.toXML(new AClass())); }
static { XSTREAM.alias("fingerprint", Fingerprint.class); XSTREAM.alias("range", Range.class); XSTREAM.alias("ranges", RangeSet.class); XSTREAM.registerConverter(new HexBinaryConverter(), 10); XSTREAM.registerConverter( new RangeSet.ConverterImpl( new CollectionConverter(XSTREAM.getMapper()) { @Override protected Object createCollection(Class type) { return new ArrayList(); } }), 10); }
private void doRegisterConverter(Class<?> c) { if (c.isAnnotationPresent(Converter.class)) { Class<? extends ConverterMatcher> clazz = c.getAnnotation(Converter.class).value(); try { if (SingleValueConverter.class.isAssignableFrom(clazz)) { converter.registerConverter((SingleValueConverter) clazz.newInstance()); } else { converter.registerConverter( (com.thoughtworks.xstream.converters.Converter) clazz.newInstance()); } } catch (Exception e) { log.error("", e); } } }
/** * Perform converter initialization. This operation is time consuming, so you can call this before * you start conversion, otherwise this will be called before first conversion and due to that you * can notice some delay in this case. * * @return true if converter has been initialized, false otherwise */ public static synchronized boolean initialize() { if (initialized) { return false; } xstream = new XStream(); xstream.processAnnotations(FIXMLRoot.class); xstream.registerConverter(new GroupConverter()); xstream.registerConverter(new ComponentConverter()); xstream.registerConverter(new MessageConverter()); xstream.registerConverter(new RootConverter()); initialized = true; return true; }
@Test public void testSerializeApplicationVersionWithLiveMarshallers() throws Exception { underTest.setArchive(false); underTest.setMarshallerMap(liveMarshallerMap); // Set a spy on the ApplicationVersionConverter ApplicationVersionConverter applicationVersionConverter = spy(new ApplicationVersionConverter()); XStreamMarshaller xsm = (XStreamMarshaller) underTest.getMarshallerMap().get(StreamId.APPLICATION_VERSION).getMarshaller(); XStream x = xsm.getXStream(); x.registerConverter( applicationVersionConverter, XStream.PRIORITY_VERY_HIGH); // because there is a non-spy // version of this already // registered in the configure // method ByteArrayOutputStream result = new ByteArrayOutputStream(); underTest.serialize(state, StreamId.APPLICATION_VERSION, result); verify(applicationVersionConverter, atLeastOnce()).canConvert(ApplicationVersion.class); // cant verify the marshal(...) method b/c it's final verify(applicationVersionConverter) .marshalInternal( eq(applicationVersion), any(HierarchicalStreamWriter.class), any(MarshallingContext.class)); assertTrue(result.size() > 1); }
private void test(HierarchicalStreamDriver driver) { XStream xstream = new XStream(driver); xstream.registerConverter( new CollectionConverter(xstream.getMapper()) { public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { ExtendedHierarchicalStreamReader exReader = (ExtendedHierarchicalStreamReader) reader; if (exReader.peekNextChild() == null) { return new ArrayList(); } return super.unmarshal(reader, context); } }); SampleLists in = new SampleLists(); in.good.add("one"); in.good.add("two"); in.good.add("three"); in.bad.add(Boolean.TRUE); in.bad.add(Boolean.FALSE); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); xstream.toXML(in, buffer); Object out = xstream.fromXML(new ByteArrayInputStream(buffer.toByteArray())); Assert.assertEquals(in, out); }
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); }
@Override public Set<Currency> getCurrencies() throws AmountMoneyCurrencyStorageException { if (!file.exists()) { LOGGER.info( String.format( "Currency storage file '%s' doesn't exist, creating it " + "with default currencies", file)); if (!file.getParentFile().exists()) { if (!file.getParentFile().mkdirs()) { throw new AmountMoneyCurrencyStorageException( String.format( "Currency " + "storage file's parent directory '%s' couldn't " + "be created", file.getParentFile())); } } saveCurrencies(AmountMoneyComponent.DEFAULT_CURRENCIES); } try { InputStream inputStream = new FileInputStream(file); XStream xStream = new XStream(); xStream.registerConverter(CURRENCY_CONVERTER); Set<Currency> currencies = (Set<Currency>) xStream.fromXML(inputStream); if (currencies.isEmpty()) { LOGGER.info( String.format( "Currency storage file '%s' contains " + "0 currency, using default currencies", file)); saveCurrencies(AmountMoneyComponent.DEFAULT_CURRENCIES); return AmountMoneyComponent.DEFAULT_CURRENCIES; } return currencies; } catch (IOException ex) { throw new AmountMoneyCurrencyStorageException(ex); } }
public static XStream getXStream() { if (xStream == null) { synchronized (DashboardModelUtils.class) { if (xStream == null) { xStream = new XStream(); xStream.alias("dashboard", Dashboard.class); xStream.alias("widget", Widget.class); xStream.alias("parameters", IParameters.class, Parameters.class); xStream.aliasAttribute(Dashboard.class, "title", "title"); xStream.aliasAttribute(Dashboard.class, "layoutConstraints", "layoutConstraints"); xStream.aliasAttribute(Dashboard.class, "rowConstraints", "rowConstraints"); xStream.aliasAttribute(Dashboard.class, "colConstraints", "colConstraints"); xStream.aliasAttribute(Widget.class, "classname", "classname"); xStream.aliasAttribute(Widget.class, "id", "id"); xStream.aliasAttribute(Widget.class, "style", "style"); xStream.aliasAttribute(Widget.class, "title", "title"); xStream.aliasAttribute(Widget.class, "collapsible", "collapsible"); xStream.aliasAttribute(Widget.class, "collapsed", "collapsed"); xStream.aliasAttribute(Widget.class, "hideTitleBar", "hideTitleBar"); xStream.aliasAttribute(Widget.class, "layoutData", "layoutData"); xStream.aliasAttribute(Widget.class, "listenToWidgets", "listenToWidgets"); xStream.addImplicitCollection(Dashboard.class, "widgets", Widget.class); xStream.registerConverter(new ParametersConverter(xStream.getMapper())); } } } return xStream; }
public CswRecordConverter() { xstream = new XStream(new Xpp3Driver()); xstream.setClassLoader(this.getClass().getClassLoader()); xstream.registerConverter(this); xstream.alias(CswConstants.CSW_RECORD_LOCAL_NAME, Metacard.class); xstream.alias(CswConstants.CSW_RECORD, Metacard.class); }
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; }
/** * Tests {@link * TriggerContextConverter#unmarshal(com.thoughtworks.xstream.io.HierarchicalStreamReader, * com.thoughtworks.xstream.converters.UnmarshallingContext)}. With "matrix_build.xml" as input. * * @throws Exception if so. */ @Test public void testUnmarshalOldMatrixBuild() throws Exception { XStream xStream = new XStream2(); xStream.registerConverter(new TriggerContextConverter()); xStream.alias("matrix-run", MatrixRun.class); Object obj = xStream.fromXML(getClass().getResourceAsStream("matrix_build.xml")); assertTrue(obj instanceof MatrixRun); MatrixRun run = (MatrixRun) obj; Cause.UpstreamCause upCause = run.getCause(Cause.UpstreamCause.class); List upstreamCauses = Whitebox.getInternalState(upCause, "upstreamCauses"); GerritCause cause = (GerritCause) upstreamCauses.get(0); assertNotNull(cause.getEvent()); assertEquals("platform/project", cause.getEvent().getChange().getProject()); assertNotNull(cause.getContext()); assertNotNull(cause.getContext().getThisBuild()); assertEquals("Gerrit_master-theme_matrix", cause.getContext().getThisBuild().getProjectId()); assertEquals(102, cause.getContext().getThisBuild().getBuildNumber().intValue()); assertNotNull(cause.getContext().getOthers()); assertEquals(1, cause.getContext().getOthers().size()); TriggeredItemEntity entity = cause.getContext().getOthers().get(0); assertEquals("master-theme", entity.getProjectId()); assertNull(entity.getBuildNumber()); }
/** * Tests {@link TriggerContextConverter#marshal(Object, * com.thoughtworks.xstream.io.HierarchicalStreamWriter, * com.thoughtworks.xstream.converters.MarshallingContext)}. With an empty list of "others". * * @throws Exception if so. */ @Test public void testMarshalNoOthers() throws Exception { TriggeredItemEntity entity = new TriggeredItemEntity(100, "projectX"); PatchsetCreated event = Setup.createPatchsetCreated(); TriggerContext context = new TriggerContext(event); context.setThisBuild(entity); context.setOthers(new LinkedList<TriggeredItemEntity>()); TestMarshalClass t = new TestMarshalClass(context, "Bobby", new TestMarshalClass(context, "SomeoneElse")); XStream xStream = new XStream2(); xStream.registerConverter(new TriggerContextConverter()); String xml = xStream.toXML(t); TestMarshalClass readT = (TestMarshalClass) xStream.fromXML(xml); assertNotNull(readT.getEntity()); assertNotNull(readT.getEntity().getEvent()); assertNotNull(readT.getEntity().getThisBuild()); assertEquals("project", readT.getEntity().getEvent().getChange().getProject()); assertEquals(100, readT.getEntity().getThisBuild().getBuildNumber().intValue()); assertEquals("projectX", readT.getEntity().getThisBuild().getProjectId()); assertSame(readT.getEntity(), readT.getTestClass().getEntity()); }
/** * Tests {@link * TriggerContextConverter#unmarshal(com.thoughtworks.xstream.io.HierarchicalStreamReader, * com.thoughtworks.xstream.converters.UnmarshallingContext)}. With "retriggerAction_oldData2.xml" * as input. * * @throws Exception if so. */ @Test public void testUnmarshalOldData2() throws Exception { XStream xStream = new XStream2(); xStream.registerConverter(new TriggerContextConverter()); Object obj = xStream.fromXML(getClass().getResourceAsStream("retriggerAction_oldData2.xml")); assertTrue(obj instanceof RetriggerAction); RetriggerAction action = (RetriggerAction) obj; TriggerContext context = Whitebox.getInternalState(action, "context"); assertNotNull(context.getEvent()); assertEquals( "semctools/hudson/plugins/gerrit-trigger-plugin", context.getEvent().getChange().getProject()); assertEquals("1", context.getEvent().getPatchSet().getNumber()); assertNotNull(context.getThisBuild()); assertEquals(6, context.getThisBuild().getBuildNumber().intValue()); assertEquals("EXPERIMENTAL_Gerrit_Trigger_1", context.getThisBuild().getProjectId()); assertNotNull(context.getOthers()); assertEquals(2, context.getOthers().size()); TriggeredItemEntity entity = context.getOthers().get(0); assertEquals(16, entity.getBuildNumber().intValue()); assertEquals("EXPERIMENTAL_Gerrit_Trigger_2", entity.getProjectId()); entity = context.getOthers().get(1); assertEquals(15, entity.getBuildNumber().intValue()); assertEquals("EXPERIMENTAL_Gerrit_Trigger_3", entity.getProjectId()); }
private void initXStream() { // CGLIB - related settings start /* * xStream.addDefaultImplementation( org.hibernate.collection.PersistentList.class, java.util.List.class); * xStream.addDefaultImplementation( org.hibernate.collection.PersistentMap.class, java.util.Map.class); * xStream.addDefaultImplementation( org.hibernate.collection.PersistentSet.class, java.util.Set.class); * * Mapper mapper = xStream.getMapper(); xStream.registerConverter(new HibernateCollectionConverter(mapper)); * xStream.registerConverter(new HibernateMapConverter(mapper)); */ // CGLIB - related settings end xStream.alias("participant", Participant.class); xStream.alias("race", Race.class); xStream.alias("collectionProtocol", CollectionProtocol.class); xStream.alias("collectionProtocolRegistration", CollectionProtocolRegistration.class); xStream.alias("consentTierResponse", ConsentTierResponse.class); xStream.alias("consentTier", ConsentTier.class); xStream.alias("participantMedicalIdentifier", ParticipantMedicalIdentifier.class); final String[] accFrmts = new String[] { "", "yyyyMMdd", "yyyy-MM-dd", "MM/dd/yyyy", // catissue formats "yyyy-MM-dd HH:mm:ss.S a", "yyyy-MM-dd HH:mm:ssz", "yyyy-MM-dd HH:mm:ss z", // JDK 1.3 needs both // versions "yyyy-MM-dd HH:mm:ssa" }; // backwards compatibility xStream.registerConverter(new DateConverter("yyyy-MM-dd HH:mm:ss.S z", accFrmts, true)); }
/** @return lazy loading xstream object. */ private XStream getXStream() { if (xstream == null) { xstream = new XStream(); addAlias(xstream); // handle Properties a la Maven xstream.registerConverter( new PropertiesConverter() { /** {@inheritDoc} */ public boolean canConvert(@SuppressWarnings("rawtypes") Class type) { return Properties.class == type; } /** {@inheritDoc} */ public void marshal( Object source, HierarchicalStreamWriter writer, MarshallingContext context) { Properties properties = (Properties) source; Map<?, ?> map = new TreeMap<Object, Object>(properties); // sort for (Map.Entry<?, ?> entry : map.entrySet()) { writer.startNode(entry.getKey().toString()); writer.setValue(entry.getValue().toString()); writer.endNode(); } } }); } return xstream; }
public static XStream getConfiguredXStream(XStream xs) { xs.setMode(XStream.NO_REFERENCES); xs.alias("gwcQuotaConfiguration", DiskQuotaConfig.class); xs.alias("layerQuotas", List.class); xs.alias("LayerQuota", LayerQuota.class); xs.alias("Quota", Quota.class); xs.registerConverter(new QuotaXSTreamConverter()); return xs; }
/** @return */ private XStream initXStream(final Session session, final boolean nullifyPk) { final XStream xstream = new XStream() { @Override protected MapperWrapper wrapMapper(final MapperWrapper next) { return new HibernateMapper(new HibernateCollectionsMapper(next)); } }; // Converter für die Hibernate-Collections xstream.registerConverter(new HibernateCollectionConverter(xstream.getConverterLookup())); xstream.registerConverter( new HibernateProxyConverter( xstream.getMapper(), new PureJavaReflectionProvider(), xstream.getConverterLookup()), XStream.PRIORITY_VERY_HIGH); xstream.setMarshallingStrategy( new XStreamMarshallingStrategy(XStreamMarshallingStrategy.RELATIVE)); init(xstream); return xstream; }
@Test public void testArchiveSerializeApplicationVersion() throws Exception { underTest.setArchive(true); underTest.setMarshallerMap(liveMarshallerMap); // Set a spy on the ApplicationVersionConverter ApplicationVersionConverter applicationVersionConverter = spy(new ApplicationVersionConverter()); XStreamMarshaller xsm = (XStreamMarshaller) underTest.getMarshallerMap().get(StreamId.APPLICATION_VERSION).getMarshaller(); XStream x = xsm.getXStream(); x.registerConverter( applicationVersionConverter, XStream.PRIORITY_VERY_HIGH); // because there is a non-spy // version of this already // registered in the configure // method ByteArrayOutputStream result = new ByteArrayOutputStream(); when(arxFactory.newArchiveOutputStream(result)) .thenAnswer( invocationOnMock -> new ArchiveOutputStream() { @Override public void putArchiveEntry(ArchiveEntry archiveEntry) throws IOException {} @Override public void closeArchiveEntry() throws IOException {} @Override public void finish() throws IOException {} @Override public ArchiveEntry createArchiveEntry(File file, String s) throws IOException { return mock(ArchiveEntry.class); } @Override public void write(byte[] b, int off, int len) throws IOException { result.write(b, off, len); } }); underTest.serialize(state, StreamId.APPLICATION_VERSION, result); verify(applicationVersionConverter, atLeastOnce()).canConvert(ApplicationVersion.class); // cant verify the marshal(...) method b/c it's final verify(applicationVersionConverter) .marshalInternal( eq(applicationVersion), any(HierarchicalStreamWriter.class), any(MarshallingContext.class)); assertTrue(result.size() > 1); }
@PostConstruct public void init() { monitoringService = (ActorRef) context.getAttribute(MonitoringService.class.getName()); configuration = (Configuration) context.getAttribute(Configuration.class.getName()); configuration = configuration.subset("runtime-settings"); daos = (DaoManager) context.getAttribute(DaoManager.class.getName()); super.init(configuration); CallinfoConverter converter = new CallinfoConverter(configuration); MonitoringServiceConverter listConverter = new MonitoringServiceConverter(configuration); builder = new GsonBuilder(); builder.registerTypeAdapter(CallInfo.class, converter); builder.registerTypeAdapter(MonitoringServiceResponse.class, listConverter); builder.setPrettyPrinting(); gson = builder.create(); xstream = new XStream(); xstream.alias("RestcommResponse", RestCommResponse.class); xstream.registerConverter(converter); xstream.registerConverter(listConverter); xstream.registerConverter(new RestCommResponseConverter(configuration)); }
/** Creates serializer instance and registers converters. */ public JSONSerializer() { xstream = new XStream( new JsonHierarchicalStreamDriver() { @Override public HierarchicalStreamWriter createWriter(Writer writer) { return new JsonWriter(writer, JsonWriter.DROP_ROOT_MODE); } }); xstream.registerConverter(new SubscriptionStatusConverter()); }
private void saveCurrencies(Set<Currency> currencies) throws AmountMoneyCurrencyStorageException { try { try (OutputStream outputStream = new FileOutputStream(file)) { XStream xStream = new XStream(); xStream.registerConverter(CURRENCY_CONVERTER); xStream.toXML(currencies, outputStream); outputStream.flush(); } } catch (IOException ex) { throw new AmountMoneyCurrencyStorageException(ex); } }
private XStream createXStream(final String elementName) { GetRecordsResponseConverter rrConverter = new GetRecordsResponseConverter(mockProvider); XStream xstream = new XStream(new StaxDriver(new NoNameCoder())); xstream.registerConverter(rrConverter); xstream.alias( CswConstants.CSW_NAMESPACE_PREFIX + CswConstants.NAMESPACE_DELIMITER + elementName, CswRecordCollection.class); return xstream; }
public GmdTransformer() { QNameMap qmap = new QNameMap(); qmap.setDefaultNamespace(GmdMetacardType.GMD_NAMESPACE); qmap.setDefaultPrefix(""); StaxDriver staxDriver = new StaxDriver(qmap); xstream = new XStream(staxDriver); xstream.setClassLoader(this.getClass().getClassLoader()); XstreamPathConverter converter = new XstreamPathConverter(); converter.setPaths(PATHS); xstream.registerConverter(converter); xstream.alias("MD_Metadata", XstreamPathValueTracker.class); }
/** Performs tasks to resolve the lazy instantiation. */ private synchronized void init() { if (!initialized) { // Mimic the behavior of XStream's JVM class String vendor = System.getProperty("java.vm.vendor"); float version = 1.3f; try { version = Float.parseFloat(System.getProperty("java.version").substring(0, 3)); } catch (NumberFormatException nfe) { // Keep the default } Class unsafe = null; try { unsafe = Class.forName("sun.misc.Unsafe", false, getClass().getClassLoader()); } catch (ClassNotFoundException cnfe) { // Keep the default } ReflectionProvider reflectionProvider = null; if ((vendor.contains("Sun") || vendor.contains("Oracle") || vendor.contains("Apple") || vendor.contains("Hewlett-Packard") || vendor.contains("IBM") || vendor.contains("Blackdown")) && version >= 1.4f && unsafe != null) { try { reflectionProvider = (ReflectionProvider) Class.forName( "com.thoughtworks.xstream.converters.reflection.Sun14ReflectionProvider", false, getClass().getClassLoader()) .newInstance(); } catch (InstantiationException ie) { reflectionProvider = new PureJavaReflectionProvider(); } catch (IllegalAccessException iae) { reflectionProvider = new PureJavaReflectionProvider(); } catch (ClassNotFoundException cnfe) { reflectionProvider = new PureJavaReflectionProvider(); } } else { reflectionProvider = new PureJavaReflectionProvider(); } HierarchicalStreamDriver driver = new DomDriver(); xs = new XStream(reflectionProvider, driver); xs.setMarshallingStrategy(new LockssReferenceByXPathMarshallingStrategy(lockssContext)); xs.registerConverter(new LockssDateConverter()); initialized = true; } }
@PostConstruct public void init() { configuration = (Configuration) context.getAttribute(Configuration.class.getName()); configuration = configuration.subset("runtime-settings"); callManager = (ActorRef) context.getAttribute("org.mobicents.servlet.restcomm.telephony.CallManager"); daos = (DaoManager) context.getAttribute(DaoManager.class.getName()); super.init(configuration); CallDetailRecordConverter converter = new CallDetailRecordConverter(configuration); listConverter = new CallDetailRecordListConverter(configuration); builder = new GsonBuilder(); builder.registerTypeAdapter(CallDetailRecord.class, converter); builder.registerTypeAdapter(CallDetailRecordList.class, listConverter); builder.setPrettyPrinting(); gson = builder.create(); xstream = new XStream(); xstream.alias("RestcommResponse", RestCommResponse.class); xstream.registerConverter(converter); xstream.registerConverter(new RestCommResponseConverter(configuration)); xstream.registerConverter(listConverter); normalizePhoneNumbers = configuration.getBoolean("normalize-numbers-for-outbound-calls"); }
public static void configure(XStream xStream) { xStream.registerConverter(new StringPropertyConverter(xStream.getMapper())); xStream.registerConverter(new BooleanPropertyConverter(xStream.getMapper())); xStream.registerConverter(new ObjectPropertyConverter(xStream.getMapper())); xStream.registerConverter(new DoublePropertyConverter(xStream.getMapper())); xStream.registerConverter(new LongPropertyConverter(xStream.getMapper())); xStream.registerConverter(new IntegerPropertyConverter(xStream.getMapper())); xStream.registerConverter(new ObservableListConverter(xStream.getMapper())); }