com.thoughtworks.xstream.io.xml.StaxDriver Java Examples

The following examples show how to use com.thoughtworks.xstream.io.xml.StaxDriver. 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: ZigBeeDataStore.java    From com.zsmartsystems.zigbee with Eclipse Public License 1.0 6 votes vote down vote up
private XStream openStream() {
    XStream stream = new XStream(new StaxDriver());
    stream.alias("ZigBeeKey", ZigBeeKey.class);
    stream.alias("ZigBeeNode", ZigBeeNodeDao.class);
    stream.alias("ZigBeeEndpoint", ZigBeeEndpointDao.class);
    stream.alias("ZclCluster", ZclClusterDao.class);
    stream.alias("ZclAttribute", ZclAttributeDao.class);
    stream.alias("MacCapabilitiesType", MacCapabilitiesType.class);
    stream.alias("ServerCapabilitiesType", ServerCapabilitiesType.class);
    stream.alias("PowerSourceType", PowerSourceType.class);
    stream.alias("FrequencyBandType", FrequencyBandType.class);
    stream.alias("BindingTable", BindingTable.class);
    stream.alias("IeeeAddress", IeeeAddress.class);
    stream.registerConverter(new IeeeAddressConverter());

    // stream.registerLocalConverter(ZigBeeKey.class, "key", new KeyArrayConverter());
    // stream.registerLocalConverter(ZigBeeKey.class, "address", new IeeeAddressConverter());
    // stream.registerLocalConverter(BindingTable.class, "srcAddr", new IeeeAddressConverter());
    // stream.registerLocalConverter(BindingTable.class, "dstAddr", new IeeeAddressConverter());
    return stream;
}
 
Example #2
Source File: XStreamUtils.java    From groovy with Apache License 2.0 6 votes vote down vote up
public static void serialize(final String name, final Object ast) {
    if (name == null || name.length() == 0) return;

    XStream xstream = new XStream(new StaxDriver());
    FileWriter astFileWriter = null;
    try {
        File astFile = astFile(name);
        if (astFile == null) {
            System.out.println("File-name for writing " + name + " AST could not be determined!");
            return;
        }
        astFileWriter = new FileWriter(astFile, false);
        xstream.toXML(ast, astFileWriter);
        System.out.println("Written AST to " + name + ".xml");

    } catch (Exception e) {
        System.out.println("Couldn't write to " + name + ".xml");
        e.printStackTrace();
    } finally {
        DefaultGroovyMethods.closeQuietly(astFileWriter);
    }
}
 
Example #3
Source File: ObjectWrapper.java    From gate-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * De-serialises an {@link ObjectWrapper} instance from a string previously 
 * obtained by calling {@link #toString()}.
 * @param xmlSerialisation the XML string representing the saved 
 * {@link ObjectWrapper} instance.
 */
public ObjectWrapper(String xmlSerialisation) {
  XStream xstream = new XStream(new StaxDriver());
  Object other = xstream.fromXML(xmlSerialisation);
  if(other instanceof ObjectWrapper) {
    this.value = ((ObjectWrapper)other).value;
  } else {
    log.error("Value de-serialised from XML is of type \"" + 
        other.getClass().getName() + "\", instead of expected \"" + 
        ObjectWrapper.class.getName() + ". Value was lost.");
    value = null;
  }
}
 
Example #4
Source File: XMLExport.java    From MtgDesktopCompanion with GNU General Public License v3.0 5 votes vote down vote up
public XMLExport() {
	xstream = new XStream(new StaxDriver());
	xstream.alias("deck", MagicDeck.class);
	xstream.alias("rarity", MTGRarity.class);
	xstream.alias("color", MTGColor.class);
	xstream.alias("stock",MagicCardStock.class);
	xstream.alias("set", MagicEdition.class);
	xstream.alias("foreigneData", MagicCardNames.class);
	xstream.alias("legality", MagicFormat.class);
	xstream.registerConverter(new NamedMapConverter(xstream.getMapper(), "entry", "card", MagicCard.class, "qty", Integer.class));
}
 
Example #5
Source File: XmlDocumentReader.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * The default constructor of this class initializes the {@code XStream} object, and calls
 * the abstract methods {@link #registerConverters()} and {@link #registerAliases()}.
 */
public XmlDocumentReader() {
    StaxDriver driver = new StaxDriver();

    this.xstream = new XStream(driver);

    registerConverters(this.xstream);
    registerAliases(this.xstream);
}
 
Example #6
Source File: XMLConfigProvider.java    From audit4j-core with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 * 
 * @see org.audit4j.core.ConfigProvider#readConfig(java.lang.String)
 * 
 */
@SuppressWarnings("unchecked")
@Override
public T readConfig(String filePath) throws ConfigurationException {
    XStream xstream = new XStream(new StaxDriver());
    xstream.alias("configuration", clazz);
    return (T) xstream.fromXML(new File(filePath));
}
 
Example #7
Source File: XMLConfigProvider.java    From audit4j-core with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 * 
 * @see org.audit4j.core.ConfigProvider#readConfig(java.io.InputStream)
 *
 */
@SuppressWarnings("unchecked")
@Override
public T readConfig(InputStream fileAsStream) throws ConfigurationException {
    XStream xstream = new XStream(new StaxDriver());
    xstream.alias("configuration", clazz);
    return (T) xstream.fromXML(fileAsStream);
}
 
Example #8
Source File: XMLConfigProvider.java    From audit4j-core with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 * 
 * 
 */
@Override
public void generateConfig(T config, String filePath) throws ConfigurationException {
    XStream xstream = new XStream(new StaxDriver());
    xstream.alias("configuration", clazz);
    BufferedOutputStream stdout = null;
    try {
        stdout = new BufferedOutputStream(new FileOutputStream(filePath));
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    xstream.marshal(config, new PrettyPrintWriter(new OutputStreamWriter(stdout)));
}
 
Example #9
Source File: ZWaveProductDatabase.java    From openhab1-addons with Eclipse Public License 2.0 5 votes vote down vote up
private void loadDatabase() {
    URL entry = FrameworkUtil.getBundle(ZWaveProductDatabase.class).getEntry("database/products.xml");
    if (entry == null) {
        database = null;
        logger.error("Unable to load ZWave product database!");
        return;
    }

    XStream xstream = new XStream(new StaxDriver());
    xstream.alias("Manufacturers", ZWaveDbRoot.class);
    xstream.alias("Manufacturer", ZWaveDbManufacturer.class);
    xstream.alias("Product", ZWaveDbProduct.class);
    xstream.alias("Reference", ZWaveDbProductReference.class);

    xstream.processAnnotations(ZWaveDbRoot.class);

    try {
        // this.Manufacturer = (ZWaveDbManufacturer)
        InputStream x = entry.openStream();
        database = (ZWaveDbRoot) xstream.fromXML(x);
        if (database == null) {
            return;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example #10
Source File: XStreamValid.java    From Digital with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates a new instance.
 */
public XStreamValid() {
    super(new StaxDriver());
}
 
Example #11
Source File: DexterParamsXMLParser.java    From dexter with Apache License 2.0 4 votes vote down vote up
public static DexterParamsXMLParser load(String xmlConfig) {
	logger.info("loading configuration from {} ", xmlConfig);
	XStream xstream = new XStream(new StaxDriver());
	xstream.alias("config", DexterParamsXMLParser.class);
	xstream.alias("model", Model.class);
	xstream.alias("labels", Labels.class);
	xstream.alias("index", Index.class);

	xstream.alias("thresholds", Thresholds.class);

	xstream.addImplicitCollection(Thresholds.class, "thresholds");
	xstream.alias("threshold", Threshold.class);
	xstream.alias("spotFilter", SpotFilter.class);
	xstream.alias("spotFilters", SpotFilters.class);

	xstream.addImplicitCollection(SpotFilters.class, "spotFilters");
	xstream.aliasField("class", SpotFilter.class, "clazz");

	xstream.alias("graph", Graph.class);
	xstream.alias("graphs", Graphs.class);
	xstream.addImplicitCollection(Graphs.class, "graphs");

	xstream.alias("rankers", Rankers.class);
	xstream.addImplicitCollection(Models.class, "models");
	xstream.aliasField("default", Models.class, "defaultModel");

	xstream.aliasField("default", Disambiguators.class,
			"defaultDisambiguator");

	xstream.aliasField("default", Spotters.class, "defaultSpotter");

	xstream.aliasField("default", Taggers.class, "defaultTagger");

	xstream.addImplicitCollection(Rankers.class, "rankers");
	xstream.alias("ranker", Ranker.class);
	xstream.aliasField("class", Ranker.class, "clazz");

	xstream.alias("params", Params.class);
	xstream.alias("param", Param.class);

	xstream.addImplicitCollection(Params.class, "params");

	xstream.alias("libs", Libs.class);

	xstream.addImplicitCollection(RelatednessFunctions.class,
			"relatednessFunctions");
	xstream.aliasField("default", RelatednessFunctions.class,
			"defaultFunction");

	xstream.alias("relatednessFunctions", RelatednessFunctions.class);
	xstream.alias("relatednessFunction", RelatednessFunction.class);

	xstream.addImplicitCollection(Caches.class, "caches");
	xstream.alias("caches", Caches.class);
	xstream.alias("cache", Cache.class);

	xstream.alias("disambiguators", Disambiguators.class);
	xstream.addImplicitCollection(Disambiguators.class, "disambiguators");
	xstream.alias("disambiguator", Disambiguator.class);

	xstream.alias("spotters", Spotters.class);
	xstream.addImplicitCollection(Spotters.class, "spotters");
	xstream.alias("spotter", Spotter.class);

	xstream.alias("filter", Filter.class);
	xstream.addImplicitCollection(Filter.class, "filters");

	xstream.aliasField("class", RelatednessFunction.class, "clazz");
	xstream.aliasField("class", Disambiguator.class, "clazz");
	xstream.aliasField("class", Spotter.class, "clazz");

	xstream.alias("taggers", Taggers.class);
	xstream.addImplicitCollection(Taggers.class, "taggers");
	xstream.alias("tagger", Tagger.class);

	xstream.alias("spotRepository", SpotRepository.class);

	String xml = IOUtils.getFileAsString(xmlConfig);
	DexterParamsXMLParser config = (DexterParamsXMLParser) xstream
			.fromXML(xml);
	return config;
}
 
Example #12
Source File: ZWaveProductDatabase.java    From openhab1-addons with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Loads the product file relating to the requested version.
 *
 * @param version the required device version
 * @return filename of the product file
 */
private ZWaveDbProductFile LoadProductFile() {
    // If the file is already loaded, then just return the class
    if (productFile != null) {
        return productFile;
    }

    // Have we selected a product?
    if (selProduct == null) {
        return null;
    }

    String cfgFile = selProduct.getConfigFile(productVersion);
    if (cfgFile == null || cfgFile.isEmpty()) {
        return null;
    }

    URL entry = FrameworkUtil.getBundle(ZWaveProductDatabase.class).getEntry("database/" + cfgFile);
    if (entry == null) {
        database = null;
        logger.error("Unable to load ZWave product file: '{}'", cfgFile);
        return null;
    }

    XStream xstream = new XStream(new StaxDriver());
    xstream.alias("Product", ZWaveDbProductFile.class);
    xstream.alias("Configuration", ZWaveDbProductFile.ZWaveDbConfiguration.class);
    xstream.alias("Parameter", ZWaveDbConfigurationParameter.class);
    xstream.alias("Item", ZWaveDbConfigurationListItem.class);
    xstream.alias("Associations", ZWaveDbProductFile.ZWaveDbAssociation.class);
    xstream.alias("Group", ZWaveDbAssociationGroup.class);
    xstream.alias("CommandClass", ZWaveDbProductFile.ZWaveDbCommandClassList.class);
    xstream.alias("Class", ZWaveDbCommandClass.class);

    xstream.processAnnotations(ZWaveDbProductFile.class);

    try {
        // this.Manufacturer = (ZWaveDbManufacturer)
        InputStream x = entry.openStream();
        productFile = (ZWaveDbProductFile) xstream.fromXML(x);
    } catch (IOException e) {
        logger.error("Unable to load ZWave product file '{}' : {}", cfgFile, e.toString());
    }

    return productFile;
}
 
Example #13
Source File: XStreamFactory.java    From depan with Apache License 2.0 2 votes vote down vote up
/**
 * Provide an XStream instance that is initialized to use the StAX XML
 * toolkit.  The returned instance will still need to be configured
 * for DepAn.
 * 
 * @return StAX configured XStream
 */
public static XStream newStaxXStream() {
  XStream result = new XStream(new StaxDriver());
  return result;
}