Search in sources :

Example 6 with WildcardTypePermission

use of com.thoughtworks.xstream.security.WildcardTypePermission in project jgnash by ccavanaugh.

the class AccountTreeXMLFactory method getStream.

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

        @Override
        protected MapperWrapper wrapMapper(final MapperWrapper next) {
            return new HibernateMapper(next);
        }
    };
    // configure XStream security
    xstream.addPermission(NoTypePermission.NONE);
    xstream.addPermission(PrimitiveTypePermission.PRIMITIVES);
    xstream.addPermission(ArrayTypePermission.ARRAYS);
    xstream.addPermission(new WildcardTypePermission(new String[] { "java.**", "jgnash.engine.**" }));
    // gracefully ignore fields in the file that do not have object members
    xstream.ignoreUnknownElements();
    xstream.setMode(XStream.ID_REFERENCES);
    // use date instead of local-date by default
    xstream.alias("date", LocalDate.class);
    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()));
    return xstream;
}
Also used : HibernatePersistentCollectionConverter(com.thoughtworks.xstream.hibernate.converter.HibernatePersistentCollectionConverter) StaxDriver(com.thoughtworks.xstream.io.xml.StaxDriver) MapperWrapper(com.thoughtworks.xstream.mapper.MapperWrapper) XStreamJVM9(jgnash.engine.xstream.XStreamJVM9) WildcardTypePermission(com.thoughtworks.xstream.security.WildcardTypePermission) 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)

Aggregations

WildcardTypePermission (com.thoughtworks.xstream.security.WildcardTypePermission)6 HibernatePersistentCollectionConverter (com.thoughtworks.xstream.hibernate.converter.HibernatePersistentCollectionConverter)2 HibernatePersistentMapConverter (com.thoughtworks.xstream.hibernate.converter.HibernatePersistentMapConverter)2 HibernateProxyConverter (com.thoughtworks.xstream.hibernate.converter.HibernateProxyConverter)2 AnyTypePermission (com.thoughtworks.xstream.security.AnyTypePermission)2 ExplicitTypePermission (com.thoughtworks.xstream.security.ExplicitTypePermission)2 TypePermission (com.thoughtworks.xstream.security.TypePermission)2 PureJavaReflectionProvider (com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider)1 HibernateMapper (com.thoughtworks.xstream.hibernate.mapper.HibernateMapper)1 StaxDriver (com.thoughtworks.xstream.io.xml.StaxDriver)1 MapperWrapper (com.thoughtworks.xstream.mapper.MapperWrapper)1 XStreamJVM9 (jgnash.engine.xstream.XStreamJVM9)1