Java Code Examples for com.thoughtworks.xstream.XStream#registerConverter()

The following examples show how to use com.thoughtworks.xstream.XStream#registerConverter() . These examples are extracted from open source projects. 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 Project: ET_Redux   File: AnalysisFraction.java    License: Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param xstream
 */
public void customizeXstream(XStream xstream) {

    xstream.registerConverter(new AnalysisFractionXMLConverter());
    xstream.registerConverter(new MineralStandardModelXMLConverter());

    xstream.registerConverter(new InitialPbModelETXMLConverter());
    xstream.registerConverter(new ValueModelXMLConverter());
    xstream.registerConverter(new MeasuredRatioModelXMLConverter());

    // alias necessary to elide fully qualified name in xml8
    xstream.alias("AnalysisFraction", AnalysisFraction.class);
    xstream.alias("MeasuredRatioModel", MeasuredRatioModel.class);
    xstream.alias("InitialPbModelET", InitialPbModelET.class);
    xstream.alias("ValueModel", ValueModel.class);

    setClassXMLSchemaURL();
}
 
Example 2
private XStream createStream() {
	XStream stream = new XStream();
	stream.registerConverter(new BeanDefinitionConverter(stream.getMapper()));
	stream.registerConverter(new BeanDefinitionHolderConverter(stream.getMapper()));
	stream.registerConverter(new TypedStringValueConverter());
	stream.registerConverter(new ManagedCollectionConverter(stream.getMapper()));
	stream.registerConverter(new ManagedMapConverter(stream.getMapper()));
	stream.registerConverter(new RuntimeBeanReferenceConverter());
	stream.alias("map", ManagedMap.class);
	stream.alias("list", ManagedList.class);
	stream.alias("set", ManagedSet.class);
	stream.alias("array", ManagedArray.class);
	stream.aliasType("bean", BeanDefinition.class);
	stream.alias("bean", BeanDefinitionHolder.class);
	stream.alias("ref", RuntimeBeanReference.class);
	return stream;
}
 
Example 3
@Test
public void replace() {
  /* Mocks */
  Converter c1 = EasyMock.createMock(Converter.class);
  expect(c1.canConvert(Dummy.class)).andStubReturn(true);

  Converter c2 = EasyMock.createMock(Converter.class);
  expect(c2.canConvert(Dummy.class)).andStubReturn(true);

  c2.marshal(
      isA(Object.class), isA(HierarchicalStreamWriter.class), isA(MarshallingContext.class));
  EasyMock.expectLastCall().once();

  EasyMock.replay(c1, c2);

  /* XStream config */
  XStream xstream = XStreamFactory.getSecureXStream(new DomDriver());
  ReplaceableConverter resetable = new ReplaceableConverter(c1);
  xstream.registerConverter(resetable);

  /* Test it */
  resetable.reset();
  assertTrue("ReplaceableConverter was not properly reset", resetable.isReset());

  /*
   * This call should not reach any of the converters.
   */
  xstream.toXML(new Dummy());

  resetable.replace(c2);
  assertNotNull("Converter was not reactivated", xstream.toXML(new Dummy()));

  /*
   * Verify that the first converter is not called, and the second exactly
   * once
   */
  EasyMock.verify(c1, c2);
}
 
Example 4
Source Project: ET_Redux   File: InitialPbModel.java    License: Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param xstream
 */
public void customizeXstream ( XStream xstream ) {
    xstream.registerConverter( new InitialPbModelXMLConverter() );
    xstream.registerConverter( new ValueModelXMLConverter() );

    xstream.alias( "InitialPbModel", InitialPbModel.class );
    xstream.alias( "ValueModel", ValueModel.class );

    setClassXMLSchemaURL();
}
 
Example 5
Source Project: PoseidonX   File: PhysicalPlanWriter.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 将执行计划序列化成字符串
 */
public static String createStringPlan(PhysicalPlan plan)
{
    XStream xstream = new XStream(new DomDriver(XML_CHARSET));
    xstream.autodetectAnnotations(true);
    PhysicalPlanLoader.setAlias(xstream);
    xstream.registerConverter(new MapConverter(new DefaultMapper(new ClassLoaderReference(PhysicalPlanWriter.class.getClassLoader()))));
    return xstream.toXML(plan);
}
 
Example 6
@Test
public void reset() {
  /* Mocks */
  Converter c1 = EasyMock.createMock(Converter.class);
  expect(c1.canConvert(Dummy.class)).andStubReturn(true);

  c1.marshal(
      isA(Object.class), isA(HierarchicalStreamWriter.class), isA(MarshallingContext.class));
  EasyMock.expectLastCall().once();

  EasyMock.replay(c1);

  /* XStream config */
  XStream xstream = XStreamFactory.getSecureXStream(new DomDriver());
  ReplaceableConverter resetable = new ReplaceableConverter(c1);
  xstream.registerConverter(resetable);

  /* Test it */
  assertFalse("ReplaceableConverter was not properly set up", resetable.isReset());

  assertNotNull("Converter cannot convert", xstream.toXML(new Dummy()));

  resetable.reset();
  assertTrue("ReplaceableConverter was not properly reset", resetable.isReset());

  /*
   * This call should not reach the converter.
   */
  xstream.toXML(new Dummy());

  /*
   * Verify that the converter was used exactly once, i.e. it was not
   * called while it was inactive.
   */
  EasyMock.verify(c1);
}
 
Example 7
private XStream getXStream(Schema schema) {
  XStream xstream = new XStream(new DomDriver());
  xstream.registerConverter(new DatabaseMetaConverter());
  xstream.registerConverter(new AggListConverter(aggList));
  xstream.registerConverter(new AttributeConverter(schema));
  xstream.registerConverter(new MeasureConverter(schema));
  return xstream;
}
 
Example 8
public XmlObjectSerializerIgnoreMissingFieldsServiceImpl() {

        xstream = new XStream(new ProxyAwareJavaReflectionProvider()) {
            @Override
            protected MapperWrapper wrapMapper(MapperWrapper next) {
                return new MapperWrapper(next) {
                    @Override
                    public boolean shouldSerializeMember(Class definedIn,
                            String fieldName) {
                        if (definedIn == Object.class) {
                            return false;
                        }
                      return super.shouldSerializeMember(definedIn, fieldName);
                   }
               };
           }
       };

		xstream.registerConverter(new ProxyConverter(xstream.getMapper(), xstream.getReflectionProvider() ));
        try {
        	Class<?> objListProxyClass = Class.forName("org.apache.ojb.broker.core.proxy.ListProxyDefaultImpl");
            xstream.addDefaultImplementation(ArrayList.class, objListProxyClass);
        } catch ( Exception ex ) {
        	// Do nothing - this will blow if the OJB class does not exist, which it won't in some installs
        }
        xstream.registerConverter(new DateTimeConverter());
	}
 
Example 9
Source Project: ET_Redux   File: PbBlank.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * registers converter for argument <code>xstream</code> and sets aliases to
 * make the XML file more human-readable
 *
 * @pre argument <code>xstream</code> is a valid <code>XStream</code> @post
 * argument <code>xstream</code> is customized to produce a cleaner output
 * <code>file</code>
 *
 * @param xstream <code>XStream</code> to be customized
 */
public void customizeXstream(XStream xstream) {

    xstream.registerConverter(new PbBlankXMLConverter());
    xstream.registerConverter(new ValueModelXMLConverter());

    xstream.alias("PbBlank", PbBlank.class);
    xstream.alias("ValueModel", ValueModel.class);

    setClassXMLSchemaURL();
}
 
Example 10
Source Project: Chronicle-Map   File: JsonSerializer.java    License: Apache License 2.0 5 votes vote down vote up
private static <K, V> XStream xStream(Map<K, V> map, List jsonConverters) {
    try {
        final XStream xstream = new XStream(new JettisonMappedXmlDriver());
        xstream.setMode(XStream.NO_REFERENCES);
        xstream.alias("cmap", map.getClass());

        registerChronicleMapConverter(map, xstream);
        xstream.registerConverter(new ByteBufferConverter());
        xstream.registerConverter(new ValueConverter());
        xstream.registerConverter(new StringBuilderConverter());
        xstream.registerConverter(new CharSequenceConverter());

        for (Object c : jsonConverters) {
            if (c instanceof Converter) {
                xstream.registerConverter((Converter) c);
            } else {
                LOG.warn("Skipping Converter of type class=" + c.getClass().getName() + " as " +
                        " expecting an object of type com.thoughtworks.xstream.converters" +
                        ".Converter");
            }
        }

        return xstream;
    } catch (NoClassDefFoundError e) {
        throw new RuntimeException(logErrorSuggestXStreem, e);
    }
}
 
Example 11
private XStream getxStream() {
    XStream xStream = new XStream();
    xStream.registerConverter(new DataFieldConverter());
    xStream.alias("dataField", DataField.class);
    xStream.alias("test", Test.class);
    return xStream;
}
 
Example 12
@Override
public void registerConverters(XStream xstream) {
    xstream.registerConverter(new NodeValueConverter());
    xstream.registerConverter(new NodeListConverter());
    xstream.registerConverter(new NodeAttributesConverter());
    xstream.registerConverter(new ConfigDescriptionConverter());
    xstream.registerConverter(new ConfigDescriptionParameterConverter());
    xstream.registerConverter(new ConfigDescriptionParameterGroupConverter());
    xstream.registerConverter(new FilterCriteriaConverter());
}
 
Example 13
Source Project: ET_Redux   File: TracerUPbModel.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void customizeXstream(XStream xstream) {
    xstream.registerConverter(new ValueModelXMLConverter());
    xstream.registerConverter(new TracerUPbModelXMLConverter());

    xstream.alias("TracerUPbModel", TracerUPbModel.class);
    xstream.alias("ValueModel", ValueModel.class);

    setClassXMLSchemaURL("URI_TracerUPbModelXMLSchema");
}
 
Example 14
@Override
public void registerConverters(XStream xstream) {
    xstream.registerConverter(new NodeValueConverter());
    xstream.registerConverter(new NodeListConverter());
    xstream.registerConverter(new NodeAttributesConverter());
    xstream.registerConverter(new ConfigDescriptionConverter());
    xstream.registerConverter(new ConfigDescriptionParameterConverter());
    xstream.registerConverter(new ConfigDescriptionParameterGroupConverter());
    xstream.registerConverter(new FilterCriteriaConverter());
}
 
Example 15
Source Project: depan   File: NodeReferenceConverter.java    License: Apache License 2.0 4 votes vote down vote up
public static void configXStream(
    XStream xstream, ReferencedGraphDocumentConverter refConverter) {
  xstream.aliasType(NODE_REF_TAG, GraphNode.class);
  xstream.registerConverter(new NodeReferenceConverter(refConverter));
}
 
Example 16
@Override
protected void registerConverters(XStream xstream) {
    super.registerConverters(xstream);
    xstream.registerConverter(new Inet4AddressConverter());
}
 
Example 17
Source Project: depan   File: ViewExtensionConverter.java    License: Apache License 2.0 4 votes vote down vote up
public static void configXStream(XStream xstream) {
  xstream.registerConverter(new ViewExtensionConverter());
}
 
Example 18
protected static XStream getXStream() {
   	final XStream xstream = new XStream(new DomDriver());	// does not require XPP3 library
   	xstream.registerConverter(new Converter(xstream.getMapper(), xstream.getReflectionProvider()));
   	return xstream;
}
 
Example 19
Source Project: ET_Redux   File: ValueModelReferenced.java    License: Apache License 2.0 1 votes vote down vote up
/**
 * registers converter for argument <code>xstream</code> and sets aliases to
 * make the XML file more human-readable
 *
 * @pre argument <code>xstream</code> is a valid <code>XStream</code> @post
 * argument <code>xstream</code> is customized to produce a cleaner output
 * <code>file</code>
 *
 * @param xstream <code>XStream</code> to be customized
 */
@Override
public void customizeXstream(XStream xstream) {

    xstream.registerConverter(new ValueModelReferencedXMLConverter());

    xstream.alias("ValueModelReferenced", ValueModelReferenced.class);

    setClassXMLSchemaURL();
}
 
Example 20
Source Project: ET_Redux   File: ValueModel.java    License: Apache License 2.0 1 votes vote down vote up
/**
 * registers converter for argument <code>xstream</code> and sets aliases to
 * make the XML file more human-readable
 *
 * @pre argument <code>xstream</code> is a valid <code>XStream</code> @post
 * argument <code>xstream</code> is customized to produce a cleaner output
 * <code>file</code>
 *
 * @param xstream <code>XStream</code> to be customized
 */
public void customizeXstream(XStream xstream) {

    xstream.registerConverter(new ValueModelXMLConverter());

    xstream.alias("ValueModel", ValueModel.class);

    setClassXMLSchemaURL();
}