Search in sources :

Example 1 with MapperWrapper

use of com.thoughtworks.xstream.mapper.MapperWrapper in project nhin-d by DirectProject.

the class XStreamFactory method getXStreamInstance.

/**
	 * Gets an instance of an {@link XStream} object.  This factory method creates a specialized implementation of the XStream engine
	 * to properly support XML object referencing
	 * @return An instance of an {@link XStream} XML serialization engine object.
	 */
public static XStream getXStreamInstance() {
    final XStream xStreamWithFieldIgnore = new XStream() {

        protected MapperWrapper wrapMapper(final MapperWrapper next) {
            return new MapperWrapper(next) {

                public boolean shouldSerializeMember(@SuppressWarnings("rawtypes") final Class definedIn, final String fieldName) {
                    ///CLOVER:OFF
                    if (definedIn == Object.class)
                        return false;
                    ///CLOVER:ON
                    return super.shouldSerializeMember(definedIn, fieldName);
                }
            };
        }
    };
    xStreamWithFieldIgnore.setMode(XStream.NO_REFERENCES);
    return xStreamWithFieldIgnore;
}
Also used : MapperWrapper(com.thoughtworks.xstream.mapper.MapperWrapper) XStream(com.thoughtworks.xstream.XStream)

Example 2 with MapperWrapper

use of com.thoughtworks.xstream.mapper.MapperWrapper in project hudson-2.x by hudson.

the class XStream2 method wrapMapper.

@Override
protected MapperWrapper wrapMapper(MapperWrapper next) {
    Mapper m = new CompatibilityMapper(new MapperWrapper(next) {

        @Override
        public String serializedClass(Class type) {
            if (type != null && ImmutableMap.class.isAssignableFrom(type))
                return super.serializedClass(ImmutableMap.class);
            else
                return super.serializedClass(type);
        }
    });
    AnnotationMapper a = new AnnotationMapper(m, getConverterRegistry(), getClassLoader(), getReflectionProvider(), getJvm());
    a.autodetectAnnotations(true);
    return a;
}
Also used : Mapper(com.thoughtworks.xstream.mapper.Mapper) AnnotationMapper(com.thoughtworks.xstream.mapper.AnnotationMapper) MapperWrapper(com.thoughtworks.xstream.mapper.MapperWrapper) AnnotationMapper(com.thoughtworks.xstream.mapper.AnnotationMapper)

Example 3 with MapperWrapper

use of com.thoughtworks.xstream.mapper.MapperWrapper in project spatial-portal by AtlasOfLivingAustralia.

the class MapComposer method loadUserSession.

public void loadUserSession(String sessionid) {
    onClick$removeAllLayers();
    Scanner scanner = null;
    try {
        String sfld = getSettingsSupplementary().getProperty(StringConstants.ANALYSIS_OUTPUT_DIR) + "session/" + sessionid;
        File sessfolder = new File(sfld);
        if (!sessfolder.exists()) {
            showMessage("Session information does not exist. Please provide a valid session id");
            return;
        }
        scanner = new Scanner(new File(sfld + "/details.txt"));
        // first grab the zoom level and bounding box
        String[] mapdetails = scanner.nextLine().split(",");
        BoundingBox bb = new BoundingBox();
        bb.setMinLongitude(Float.parseFloat(mapdetails[1]));
        bb.setMinLatitude(Float.parseFloat(mapdetails[2]));
        bb.setMaxLongitude(Float.parseFloat(mapdetails[3]));
        bb.setMaxLatitude(Float.parseFloat(mapdetails[4]));
        openLayersJavascript.setAdditionalScript(openLayersJavascript.zoomToBoundingBox(bb, true));
        String[] scatterplotNames = null;
        while (scanner.hasNextLine()) {
            String line = scanner.nextLine();
            if (line.startsWith("scatterplotNames")) {
                scatterplotNames = line.substring(17).split("___");
            }
        }
        ArrayUtils.reverse(scatterplotNames);
        // ignore fields not found
        XStream xstream = new XStream(new DomDriver()) {

            protected MapperWrapper wrapMapper(MapperWrapper next) {
                return new MapperWrapper(next) {

                    public boolean shouldSerializeMember(Class definedIn, String fieldName) {
                        if (definedIn == Object.class || !super.shouldSerializeMember(definedIn, fieldName))
                            System.out.println("faled to read: " + definedIn + ", " + fieldName);
                        return definedIn != Object.class ? super.shouldSerializeMember(definedIn, fieldName) : false;
                    }
                };
            }

            @Override
            public Object unmarshal(HierarchicalStreamReader reader) {
                Object o = super.unmarshal(reader);
                if (o instanceof BiocacheQuery)
                    ((BiocacheQuery) o).getFullQ(false);
                return o;
            }

            @Override
            public Object unmarshal(HierarchicalStreamReader reader, Object root) {
                Object o = super.unmarshal(reader, root);
                if (o instanceof BiocacheQuery)
                    ((BiocacheQuery) o).getFullQ(false);
                return o;
            }

            @Override
            public Object unmarshal(HierarchicalStreamReader reader, Object root, DataHolder dataHolder) {
                Object o = super.unmarshal(reader, root, dataHolder);
                if (o instanceof BiocacheQuery)
                    ((BiocacheQuery) o).getFullQ(false);
                return o;
            }
        };
        PersistenceStrategy strategy = new FilePersistenceStrategy(new File(sfld), xstream);
        List list = new XmlArrayList(strategy);
        ListIterator it = list.listIterator(list.size());
        int scatterplotIndex = 0;
        while (it.hasPrevious()) {
            Object o = it.previous();
            MapLayer ml = null;
            if (o instanceof MapLayer) {
                ml = (MapLayer) o;
                LOGGER.debug("Loading " + ml.getName() + " -> " + ml.isDisplayed());
                addUserDefinedLayerToMenu(ml, false);
            } else if (o instanceof ScatterplotDataDTO) {
                ScatterplotDataDTO spdata = (ScatterplotDataDTO) o;
                loadScatterplot(spdata, "My Scatterplot " + scatterplotIndex++);
            }
            if (ml != null) {
                addUserDefinedLayerToMenu(ml, true);
            }
        }
    } catch (Exception e) {
        try {
            File f = new File("/data/sessions/" + sessionid + ".txt");
            PrintWriter pw = new PrintWriter(f);
            e.printStackTrace(pw);
            pw.close();
        } catch (Exception ex) {
        }
        LOGGER.error("Unable to load session data", e);
        showMessage("Unable to load session data");
    } finally {
        if (scanner != null) {
            scanner.close();
        }
        try {
            File f = new File("/data/sessions/ok/" + sessionid + ".txt");
            FileUtils.writeStringToFile(f, "ok");
        } catch (Exception ex) {
        }
    }
}
Also used : ScatterplotDataDTO(au.org.ala.spatial.dto.ScatterplotDataDTO) XStream(com.thoughtworks.xstream.XStream) HasMapLayer(au.org.emii.portal.menu.HasMapLayer) MapLayer(au.org.emii.portal.menu.MapLayer) XmlArrayList(com.thoughtworks.xstream.persistence.XmlArrayList) ParseException(org.json.simple.parser.ParseException) PersistenceStrategy(com.thoughtworks.xstream.persistence.PersistenceStrategy) FilePersistenceStrategy(com.thoughtworks.xstream.persistence.FilePersistenceStrategy) DomDriver(com.thoughtworks.xstream.io.xml.DomDriver) MapperWrapper(com.thoughtworks.xstream.mapper.MapperWrapper) DataHolder(com.thoughtworks.xstream.converters.DataHolder) BoundingBox(au.org.emii.portal.value.BoundingBox) HierarchicalStreamReader(com.thoughtworks.xstream.io.HierarchicalStreamReader) JSONObject(org.json.simple.JSONObject) LegendObject(au.org.ala.legend.LegendObject) XmlArrayList(com.thoughtworks.xstream.persistence.XmlArrayList) List(java.util.List) FilePersistenceStrategy(com.thoughtworks.xstream.persistence.FilePersistenceStrategy)

Example 4 with MapperWrapper

use of com.thoughtworks.xstream.mapper.MapperWrapper in project restfulie-java by caelum.

the class XStreamHelper method getXStream.

/**
	 * Extension point for configuring your xstream instance.
	 *
	 * @param typesToEnhance
	 * @param list
	 * @return an xstream instance with support for link enhancement.
	 */
@SuppressWarnings("rawtypes")
public XStream getXStream(List<Class> typesToEnhance, List<String> collectionNames) {
    ReflectionProvider provider = getProvider();
    XStream xstream = new XStream(provider, driver) {

        @Override
        protected MapperWrapper wrapMapper(MapperWrapper next) {
            return new LinkSupportWrapper(next);
        }
    };
    xstream.useAttributeFor(DefaultRelation.class, "rel");
    xstream.useAttributeFor(DefaultRelation.class, "href");
    xstream.useAttributeFor(DefaultRelation.class, "type");
    for (Class type : typesToEnhance) {
        realTypes.put(type, enhancer.enhanceResource(type));
        xstream.processAnnotations(type);
    }
    Class enhancedType = enhancer.enhanceResource(EnhancedList.class);
    realTypes.put(EnhancedList.class, enhancedType);
    for (String name : collectionNames) {
        xstream.alias(name, enhancedType);
    }
    for (Class type : typesToEnhance) {
        xstream.addImplicitCollection(enhancedType, "elements", xstream.getMapper().serializedClass(type), type);
    }
    for (Class customType : realTypes.values()) {
        xstream.addImplicitCollection(customType, "link", "link", DefaultRelation.class);
    }
    return xstream;
}
Also used : MapperWrapper(com.thoughtworks.xstream.mapper.MapperWrapper) XStream(com.thoughtworks.xstream.XStream) Sun14ReflectionProvider(com.thoughtworks.xstream.converters.reflection.Sun14ReflectionProvider) ReflectionProvider(com.thoughtworks.xstream.converters.reflection.ReflectionProvider)

Example 5 with MapperWrapper

use of com.thoughtworks.xstream.mapper.MapperWrapper in project jgnash by ccavanaugh.

the class AccountTreeXMLFactory method getStream.

private static XStream getStream() {
    final XStream xstream = new XStream(new PureJavaReflectionProvider(), new KXml2Driver()) {

        @Override
        protected MapperWrapper wrapMapper(final MapperWrapper next) {
            return new HibernateMapper(next);
        }
    };
    // gracefully ignore fields in the file that do not have object members
    xstream.ignoreUnknownElements();
    xstream.setMode(XStream.ID_REFERENCES);
    xstream.alias("Account", Account.class);
    xstream.alias("RootAccount", RootAccount.class);
    xstream.alias("CurrencyNode", CurrencyNode.class);
    xstream.alias("SecurityNode", SecurityNode.class);
    xstream.useAttributeFor(Account.class, "placeHolder");
    xstream.useAttributeFor(Account.class, "locked");
    xstream.useAttributeFor(Account.class, "visible");
    xstream.useAttributeFor(Account.class, "name");
    xstream.useAttributeFor(Account.class, "description");
    xstream.useAttributeFor(CommodityNode.class, "symbol");
    xstream.useAttributeFor(CommodityNode.class, "scale");
    xstream.useAttributeFor(CommodityNode.class, "prefix");
    xstream.useAttributeFor(CommodityNode.class, "suffix");
    xstream.useAttributeFor(CommodityNode.class, "description");
    xstream.omitField(StoredObject.class, "uuid");
    xstream.omitField(StoredObject.class, "markedForRemoval");
    // Ignore fields required for JPA
    xstream.omitField(StoredObject.class, "version");
    xstream.omitField(Account.class, "transactions");
    xstream.omitField(Account.class, "accountBalance");
    xstream.omitField(Account.class, "reconciledBalance");
    xstream.omitField(Account.class, "attributes");
    xstream.omitField(Account.class, "propertyMap");
    xstream.omitField(Account.class, "amortizeObject");
    xstream.omitField(SecurityNode.class, "historyNodes");
    xstream.omitField(SecurityNode.class, "securityHistoryEvents");
    // Filters out the hibernate
    xstream.registerConverter(new HibernateProxyConverter());
    xstream.registerConverter(new HibernatePersistentCollectionConverter(xstream.getMapper()));
    xstream.registerConverter(new HibernatePersistentMapConverter(xstream.getMapper()));
    xstream.registerConverter(new HibernatePersistentSortedMapConverter(xstream.getMapper()));
    xstream.registerConverter(new HibernatePersistentSortedSetConverter(xstream.getMapper()));
    // Converters for new Java time API
    xstream.registerConverter(new LocalDateConverter());
    xstream.registerConverter(new LocalDateTimeConverter());
    return xstream;
}
Also used : HibernatePersistentCollectionConverter(com.thoughtworks.xstream.hibernate.converter.HibernatePersistentCollectionConverter) MapperWrapper(com.thoughtworks.xstream.mapper.MapperWrapper) LocalDateConverter(jgnash.engine.xstream.LocalDateConverter) KXml2Driver(com.thoughtworks.xstream.io.xml.KXml2Driver) HibernatePersistentSortedMapConverter(com.thoughtworks.xstream.hibernate.converter.HibernatePersistentSortedMapConverter) HibernatePersistentSortedSetConverter(com.thoughtworks.xstream.hibernate.converter.HibernatePersistentSortedSetConverter) XStream(com.thoughtworks.xstream.XStream) HibernateMapper(com.thoughtworks.xstream.hibernate.mapper.HibernateMapper) HibernatePersistentMapConverter(com.thoughtworks.xstream.hibernate.converter.HibernatePersistentMapConverter) PureJavaReflectionProvider(com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider) HibernateProxyConverter(com.thoughtworks.xstream.hibernate.converter.HibernateProxyConverter) LocalDateTimeConverter(jgnash.engine.xstream.LocalDateTimeConverter)

Aggregations

MapperWrapper (com.thoughtworks.xstream.mapper.MapperWrapper)5 XStream (com.thoughtworks.xstream.XStream)4 LegendObject (au.org.ala.legend.LegendObject)1 ScatterplotDataDTO (au.org.ala.spatial.dto.ScatterplotDataDTO)1 HasMapLayer (au.org.emii.portal.menu.HasMapLayer)1 MapLayer (au.org.emii.portal.menu.MapLayer)1 BoundingBox (au.org.emii.portal.value.BoundingBox)1 DataHolder (com.thoughtworks.xstream.converters.DataHolder)1 PureJavaReflectionProvider (com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider)1 ReflectionProvider (com.thoughtworks.xstream.converters.reflection.ReflectionProvider)1 Sun14ReflectionProvider (com.thoughtworks.xstream.converters.reflection.Sun14ReflectionProvider)1 HibernatePersistentCollectionConverter (com.thoughtworks.xstream.hibernate.converter.HibernatePersistentCollectionConverter)1 HibernatePersistentMapConverter (com.thoughtworks.xstream.hibernate.converter.HibernatePersistentMapConverter)1 HibernatePersistentSortedMapConverter (com.thoughtworks.xstream.hibernate.converter.HibernatePersistentSortedMapConverter)1 HibernatePersistentSortedSetConverter (com.thoughtworks.xstream.hibernate.converter.HibernatePersistentSortedSetConverter)1 HibernateProxyConverter (com.thoughtworks.xstream.hibernate.converter.HibernateProxyConverter)1 HibernateMapper (com.thoughtworks.xstream.hibernate.mapper.HibernateMapper)1 HierarchicalStreamReader (com.thoughtworks.xstream.io.HierarchicalStreamReader)1 DomDriver (com.thoughtworks.xstream.io.xml.DomDriver)1 KXml2Driver (com.thoughtworks.xstream.io.xml.KXml2Driver)1