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;
}
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;
}
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) {
}
}
}
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;
}
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;
}
Aggregations