com.thoughtworks.xstream.core.util.CompositeClassLoader Java Examples

The following examples show how to use com.thoughtworks.xstream.core.util.CompositeClassLoader. 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: ClassLoaderReference.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private Object readResolve() {
    this.reference = new CompositeClassLoader();
    return this;
}
 
Example #2
Source File: XmlUtils.java    From weblaf with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Initializes global XStream instance.
 */
private static void initializeXStream ()
{
    try
    {
        // Custom ReflectionProvider to provide pure-java objects instantiation
        // Unlike default SunUnsafeReflectionProvider it has limited objects instantiation options
        // Also it properly initializes object field values specified directly near the fields
        final PureJavaReflectionProvider reflectionProvider = new PureJavaReflectionProvider ();

        // Custom HierarchicalStreamDriver implementation based on StaxDriver
        // It provides us HierarchicalStreamReader to allow XStreamContext usage
        hierarchicalStreamDriver = new XmlDriver ();

        // XStream instance initialization
        xStream = new XStream ( reflectionProvider, hierarchicalStreamDriver );

        // Make sure that XStream ClassLoader finds WebLaF classes in cases where multiple ClassLoaders are used
        // E.g. IntelliJ IDEA uses different ClassLoaders for plugins (e.g. JFormDesigner) and its core (which includes XStream)
        if ( XmlUtils.class.getClassLoader () != xStream.getClass ().getClassLoader () )
        {
            final ClassLoader classLoader = xStream.getClassLoader ();
            if ( classLoader instanceof CompositeClassLoader )
            {
                ( ( CompositeClassLoader ) classLoader ).add ( XmlUtils.class.getClassLoader () );
            }
            else
            {
                final CompositeClassLoader compositeClassLoader = new CompositeClassLoader ();
                compositeClassLoader.add ( XmlUtils.class.getClassLoader () );
                xStream.setClassLoader ( compositeClassLoader );
            }
        }

        // Standard Java-classes aliases
        if ( aliasJdkClasses )
        {
            // Custom {@link java.awt.Point} mapping
            xStream.alias ( "Point", Point.class );
            xStream.useAttributeFor ( Point.class, "x" );
            xStream.useAttributeFor ( Point.class, "y" );

            // Custom {@link java.awt.geom.Point2D} mapping
            xStream.alias ( "Point2D", Point2D.class );
            xStream.registerConverter ( new Point2DConverter () );

            // Custom {@link java.awt.Dimension} mapping
            xStream.alias ( "Dimension", Dimension.class );
            xStream.registerConverter ( new DimensionConverter () );

            // Custom {@link java.awt.Rectangle} mapping
            xStream.alias ( "Rectangle", Rectangle.class );
            xStream.useAttributeFor ( Rectangle.class, "x" );
            xStream.useAttributeFor ( Rectangle.class, "y" );
            xStream.useAttributeFor ( Rectangle.class, "width" );
            xStream.useAttributeFor ( Rectangle.class, "height" );

            // Custom {@link java.awt.Font} mapping
            xStream.alias ( "Font", Font.class );

            // Custom {@link java.awt.Color} mapping
            xStream.alias ( "Color", Color.class );
            xStream.registerConverter ( new ColorConverter () );

            // Custom {@link java.awt.Insets} mapping
            xStream.alias ( "Insets", Insets.class );
            xStream.registerConverter ( new InsetsConverter () );

            // Custom {@link java.awt.Stroke} mapping
            xStream.alias ( "Stroke", Stroke.class );
            xStream.registerConverter ( new StrokeConverter () );
        }

        // Additional WebLaF data classes aliases
        xStream.processAnnotations ( Pair.class );
        xStream.processAnnotations ( Scale.class );
    }
    catch ( final Exception e )
    {
        // It is a pretty fatal for library if something goes wrong here
        throw new UtilityException ( "Unable to initialize XStream instance", e );
    }
}
 
Example #3
Source File: XStream.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Constructs an XStream with a special {@link HierarchicalStreamDriver},
 * {@link ReflectionProvider} and a prepared {@link Mapper} chain.
 * 
 * @param reflectionProvider the reflection provider to use or <em>null</em> for best
 *            matching Provider
 * @param mapper the instance with the {@link Mapper} chain or <em>null</em> for the default
 *            chain
 * @param driver the driver instance
 * @throws InitializationException in case of an initialization problem
 * @deprecated As of 1.3, use
 *             {@link #XStream(ReflectionProvider, HierarchicalStreamDriver, ClassLoader, Mapper)}
 *             instead
 */
public XStream(
    ReflectionProvider reflectionProvider, Mapper mapper, HierarchicalStreamDriver driver) {
    this(reflectionProvider, driver, new CompositeClassLoader(), mapper);
}