Java Code Examples for com.thoughtworks.xstream.XStream#addImplicitCollection()

The following examples show how to use com.thoughtworks.xstream.XStream#addImplicitCollection() . These examples are extracted from open source projects. 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
private static XStream getxStream() {
    final XStream xStream = new XStreamValid();
    xStream.alias("toolchain", Configuration.class);
    xStream.aliasAttribute(Configuration.class, "name", "name");
    xStream.aliasAttribute(Configuration.class, "frequency", "frequency");
    xStream.aliasAttribute(Configuration.class, "clockGenerator", "clockGenerator");
    xStream.aliasAttribute(Configuration.class, "params", "params");
    xStream.registerConverter(new Resources.MapEntryConverter("param"));
    xStream.alias("command", Command.class);
    xStream.aliasAttribute(Command.class, "name", "name");
    xStream.aliasAttribute(Command.class, "requires", "requires");
    xStream.aliasAttribute(Command.class, "filter", "filter");
    xStream.aliasAttribute(Command.class, "timeout", "timeout");
    xStream.addImplicitCollection(Command.class, "args", "arg", String.class);
    xStream.alias("file", FileToCreate.class);
    xStream.aliasAttribute(FileToCreate.class, "name", "name");
    xStream.aliasAttribute(FileToCreate.class, "overwrite", "overwrite");
    xStream.aliasAttribute(FileToCreate.class, "filter", "filter");
    xStream.aliasAttribute(FileToCreate.class, "id", "id");
    xStream.aliasAttribute(FileToCreate.class, "referenceFilename", LOOK_AT_ALIAS);
    xStream.aliasAttribute(FileToCreate.class, "referenceId", REF_ALIAS);
    return xStream;
}
 
Example 2
Source Project: Digital   File: Bundle.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a new instance
 *
 * @param name the bundles name
 */
public Bundle(String name) {
    this.name = name;
    InputStream in = getClass().getClassLoader().getResourceAsStream(name + ".xml");
    XStream xStream = new XStreamValid();
    xStream.alias("languages", MyLang.class);
    xStream.addImplicitCollection(MyLang.class, "lang");
    xStream.alias("lang", MyLangEntry.class);
    xStream.aliasAttribute(MyLangEntry.class, "name", "name");
    xStream.aliasAttribute(MyLangEntry.class, "filename", "file");
    xStream.aliasAttribute(MyLangEntry.class, "displayName", "display");
    MyLang l = (MyLang) xStream.fromXML(in);
    languages = new HashMap<>();
    list = new ArrayList<>();
    for (MyLangEntry e : l.lang) {
        languages.put(e.name, e.displayName);
        list.add(new Language(e.name, e.displayName, e.filename));
    }
}
 
Example 3
Source Project: sass-lint-plugin   File: SassLint.java    License: MIT License 6 votes vote down vote up
public static SassLint read(String xml) {
        XStream xstream = new XStream();
        xstream.alias("checkstyle", SassLint.class);
        xstream.useAttributeFor(SassLint.class, "version");
        xstream.alias("file", File.class);
        xstream.alias("error", Issue.class);
        xstream.addImplicitCollection(File.class, "errors");
        xstream.useAttributeFor(File.class, "name");
        xstream.useAttributeFor(Issue.class, "source");
        xstream.useAttributeFor(Issue.class, "line");
//        xstream.useAttributeFor(Issue.class, "column");
        xstream.useAttributeFor(Issue.class, "severity");
        xstream.useAttributeFor(Issue.class, "message");
        SassLint lint = (SassLint) xstream.fromXML(xml);
        if (lint.file == null) {
            lint.file = new File();
        }
        if (lint.file.errors == null) {
            lint.file.errors = new ArrayList<Issue>();
        }
        return lint;
    }
 
Example 4
Source Project: jscs-plugin   File: JscsLint.java    License: MIT License 6 votes vote down vote up
public static JscsLint read(String xml) {
    XStream xstream = new XStream();
    xstream.alias("checkstyle", JscsLint.class);
    xstream.useAttributeFor(JscsLint.class, "version");
    xstream.alias("file", File.class);
    xstream.alias("error", Issue.class);
    xstream.addImplicitCollection(File.class, "errors");
    xstream.useAttributeFor(File.class, "name");
    xstream.useAttributeFor(Issue.class, "source");
    xstream.useAttributeFor(Issue.class, "line");
    xstream.useAttributeFor(Issue.class, "column");
    xstream.useAttributeFor(Issue.class, "severity");
    xstream.useAttributeFor(Issue.class, "message");
    JscsLint lint = (JscsLint) xstream.fromXML(xml);
    if (lint.file.errors == null) {
        lint.file.errors = new ArrayList<Issue>();
    }
    return lint;
}
 
Example 5
Source Project: TestingApp   File: MyXmlProcessor.java    License: Apache License 2.0 5 votes vote down vote up
public MyXmlProcessor(){
    xstream = new XStream();
    xstream.alias("user", UserPayload.class);
    xstream.alias("users", UserListPayload.class);
    xstream.alias("lists", ListOfListicatorListsPayload.class);
    xstream.addImplicitCollection(ListOfListicatorListsPayload.class, "lists");
    xstream.alias("list", ListicatorListPayload.class);
    xstream.alias("toggles", ListOfFeatureTogglesPayload.class);
    xstream.addImplicitCollection(ListOfFeatureTogglesPayload.class, "toggles");
    xstream.alias("toggle", FeatureTogglePayload.class);
}
 
Example 6
Source Project: PoseidonX   File: PhysicalPlanLoader.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 设置Xstream别名
 *
 */
public static void setAlias(XStream xstream)
{
    for (Map.Entry< String, Class< ? > > et : ALIAS_MAPPING.entrySet())
    {
        xstream.alias(et.getKey(), et.getValue());
    }
    xstream.addImplicitCollection(Schema.class, "cols", "attribute", Column.class);
}
 
Example 7
private ConfigPersister() {
	_xstream = new XStream(new DomDriver());
   	_xstream.alias("launch4jConfig", Config.class);
   	_xstream.alias("classPath", ClassPath.class);
   	_xstream.alias("jre", Jre.class);
   	_xstream.alias("splash", Splash.class);
   	_xstream.alias("versionInfo", VersionInfo.class);

   	_xstream.addImplicitCollection(Config.class, "headerObjects", "obj",
   			String.class);
   	_xstream.addImplicitCollection(Config.class, "libs", "lib", String.class);
   	_xstream.addImplicitCollection(Config.class, "variables", "var", String.class);
   	_xstream.addImplicitCollection(ClassPath.class, "paths", "cp", String.class);
   	_xstream.addImplicitCollection(Jre.class, "options", "opt", String.class);
}
 
Example 8
Source Project: mamute   File: FeedConverter.java    License: Apache License 2.0 5 votes vote down vote up
public FeedConverter(RSSType rss) {
	xStream = new XStream();
	xStream.alias("rss", RSSFeed.class);
	xStream.alias("channel", RSSChannel.class);
	xStream.alias("image", RSSImage.class);
	xStream.alias("item", RSSItem.class);
	xStream.addImplicitCollection(RSSChannel.class, "items");
	xStream.addImplicitCollection(RSSItem.class, "category", String.class);
	xStream.processAnnotations(RSSItem.class);
	xStream.registerConverter(new RSSDateTimeConverter(rss.getDateFormat()));
}
 
Example 9
private ConfigPersister() {
	_xstream = new XStream(new DomDriver());
   	_xstream.alias("launch4jConfig", Config.class);
   	_xstream.alias("classPath", ClassPath.class);
   	_xstream.alias("jre", Jre.class);
   	_xstream.alias("splash", Splash.class);
   	_xstream.alias("versionInfo", VersionInfo.class);

   	_xstream.addImplicitCollection(Config.class, "headerObjects", "obj",
   			String.class);
   	_xstream.addImplicitCollection(Config.class, "libs", "lib", String.class);
   	_xstream.addImplicitCollection(Config.class, "variables", "var", String.class);
   	_xstream.addImplicitCollection(ClassPath.class, "paths", "cp", String.class);
   	_xstream.addImplicitCollection(Jre.class, "options", "opt", String.class);
}
 
Example 10
public static XStream getXstream() {
	XStream xstream = new XStream();
	xstream.alias("stream-element", StreamElement4Rest.class);
	xstream.alias("field", Field4Rest.class);
	xstream.useAttributeFor(StreamElement4Rest.class,"timestamp");
	xstream.addImplicitCollection(StreamElement4Rest.class, "fields");
	xstream.registerConverter(new Field4RestConverter());
	xstream.alias("strcture", DataField.class);
	
	
	return xstream;
}
 
Example 11
Source Project: cobarclient   File: InternalRules.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
        XStream xstream = new XStream();
        xstream.alias("rules", InternalRules.class);
        xstream.alias("rule", InternalRule.class);
        xstream.addImplicitCollection(InternalRules.class, "rules");
        xstream.useAttributeFor(InternalRule.class, "merger");

        InternalRules rules = new InternalRules();
        List<InternalRule> rList = new ArrayList<InternalRule>();
        InternalRule r1 = new InternalRule();
        r1.setNamespace("com.alibaba.cobar.client.entity.Follower");
        r1.setShards("partition1");
        rList.add(r1);
        InternalRule r2 = new InternalRule();
        r2.setSqlmap("com.alibaba.cobar.client.entity.Follower.create");
        r2.setShards("p1, p2");
        rList.add(r2);
        InternalRule r3 = new InternalRule();
        r3.setSqlmap("com.alibaba.cobar.client.entity.Follower.create");
        r3.setShardingExpression("id>10000 and id< 20000");
        r3.setShards("p1, p2");
        rList.add(r3);
        InternalRule r4 = new InternalRule();
        r4.setNamespace("com.alibaba.cobar.client.entity.Follower");
        r4.setShardingExpression("id>10000 and id< 20000");
        r4.setShards("p1, p2");
//        r4.setMerger(Runnable.class);
        rList.add(r4);
        rules.setRules(rList);

        String xml = xstream.toXML(rules);
        System.out.println(xml);
    }
 
Example 12
protected static XStream createXStream() {
    XStream xstream = new XStream(new DomDriver("UTF-8"));
    xstream.alias("schema", PersistedSchema.class);
    xstream.alias("schemas", PersistedSchemas.class);
    xstream.addImplicitCollection(PersistedSchemas.class, "list");
    xstream.aliasField("names", PersistedSchema.class, "schemas");
    xstream.useAttributeFor(PersistedSchemas.class, "version");   
    return xstream;
}
 
Example 13
protected static XStream createXStream() {
    XStream xstream = new XStream(new DomDriver("UTF-8"));
    xstream.alias("datasource", DataSource.class);
    xstream.alias("datasources", DataSources.class);
    xstream.addImplicitCollection(DataSources.class, "list");
    xstream.useAttributeFor(DataSources.class, "version");
    return xstream;
}
 
Example 14
public static XStream createXStream() {
    XStream xstream = new XStream(new DomDriver("UTF-8"));
    xstream.alias("datasource", DataSource.class);
    xstream.alias("datasources", DataSources.class);
    xstream.addImplicitCollection(DataSources.class, "list");
    xstream.useAttributeFor(DataSources.class, "version");
    
    return xstream;
}
 
Example 15
public List<DriverTemplate> getDriverTemplates() {
    XStream xstream = new XStream(new DomDriver());        
    xstream.alias("driver", DriverTemplate.class);
    xstream.alias("drivers", DriverTemplates.class);
    xstream.addImplicitCollection(DriverTemplates.class, "list");
    InputStream input = getClass().getResourceAsStream("/driver-templates.xml");
    /*
    if (input == null) {
        throw new Exception("Cannot find 'driver-templates.xml' file in classpath");
    }
    */

    return ((DriverTemplates) xstream.fromXML(input)).getList();
}
 
Example 16
public static SuccessResponse successFromXML (final String xml) {
    XStream xStreamInstance = new XStream();
    xStreamInstance.setMode(XStream.NO_REFERENCES);
    xStreamInstance.autodetectAnnotations(false);
    xStreamInstance.alias("response", SuccessResponse.class);
    xStreamInstance.alias("row", Row.class);
    xStreamInstance.alias("cells", HashMap.class);
    xStreamInstance.alias("roi", Integer.class);
    xStreamInstance.registerConverter(new AmforeasMapConverter());
    xStreamInstance.addImplicitCollection(SuccessResponse.class, "rows", Row.class);
    return (SuccessResponse) xStreamInstance.fromXML(xml);
}
 
Example 17
public static HeadResponse headFromXML (final String xml) {
    XStream xStreamInstance = new XStream();
    xStreamInstance.setMode(XStream.NO_REFERENCES);
    xStreamInstance.autodetectAnnotations(false);
    xStreamInstance.alias("response", HeadResponse.class);
    xStreamInstance.alias("row", Row.class);
    xStreamInstance.registerConverter(new AmforeasMapConverter());
    xStreamInstance.addImplicitCollection(HeadResponse.class, "rows", Row.class);
    return (HeadResponse) xStreamInstance.fromXML(xml);
}
 
Example 18
private ConfigPersister() {
	_xstream = new XStream(new DomDriver());
   	_xstream.alias("launch4jConfig", Config.class);
   	_xstream.alias("classPath", ClassPath.class);
   	_xstream.alias("jre", Jre.class);
   	_xstream.alias("splash", Splash.class);
   	_xstream.alias("versionInfo", VersionInfo.class);

   	_xstream.addImplicitCollection(Config.class, "headerObjects", "obj",
   			String.class);
   	_xstream.addImplicitCollection(Config.class, "libs", "lib", String.class);
   	_xstream.addImplicitCollection(Config.class, "variables", "var", String.class);
   	_xstream.addImplicitCollection(ClassPath.class, "paths", "cp", String.class);
   	_xstream.addImplicitCollection(Jre.class, "options", "opt", String.class);
}
 
Example 19
Source Project: Digital   File: Circuit.java    License: GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates a proper configured XStream instance
 *
 * @return the XStream instance
 */
public static XStream getxStream() {
    XStream xStream = new XStreamValid();
    xStream.alias("attributes", ElementAttributes.class);
    xStream.alias("visualElement", VisualElement.class);
    xStream.alias("wire", Wire.class);
    xStream.alias("circuit", Circuit.class);
    xStream.alias("intFormat", IntFormat.class);
    xStream.alias("barrelShifterMode", BarrelShifterMode.class);
    xStream.alias("direction", LeftRightFormat.class);
    xStream.alias("rotation", Rotation.class);
    xStream.aliasAttribute(Rotation.class, "rotation", "rotation");
    xStream.alias("language", Language.class);
    xStream.aliasAttribute(Language.class, "name", "name");
    xStream.alias("vector", Vector.class);
    xStream.aliasAttribute(Vector.class, "x", "x");
    xStream.aliasAttribute(Vector.class, "y", "y");
    xStream.alias("value", InValue.class);
    xStream.aliasAttribute(InValue.class, "value", "v");
    xStream.aliasAttribute(InValue.class, "highZ", "z");
    xStream.addImplicitCollection(ElementAttributes.class, "attributes");
    xStream.alias("data", DataField.class);
    xStream.registerConverter(new DataFieldConverter());
    xStream.alias("testData", TestCaseDescription.class);
    xStream.alias("inverterConfig", InverterConfig.class);
    xStream.addImplicitCollection(InverterConfig.class, "inputs");
    xStream.alias("storedRoms", ROMManger.class);
    xStream.addImplicitCollection(ROMManger.class, "roms");
    xStream.alias("appType", Application.Type.class);
    xStream.ignoreUnknownElements();
    xStream.alias("shape", CustomShapeDescription.class);
    xStream.alias("pin", CustomShapeDescription.Pin.class);
    xStream.alias("circle", CustomShapeDescription.CircleHolder.class);
    xStream.alias("line", CustomShapeDescription.LineHolder.class);
    xStream.alias("poly", CustomShapeDescription.PolygonHolder.class);
    xStream.alias("text", CustomShapeDescription.TextHolder.class);
    xStream.alias("polygon", Polygon.class);
    xStream.alias("shapeType", CustomCircuitShapeType.class);
    xStream.alias("transform", TransformHolder.class);
    xStream.registerConverter(new PolygonConverter());
    return xStream;
}
 
Example 20
@Override
protected void assembleRulesForRouter(
                                      CobarClientInternalRouter router,
                                      Resource configLocation,
                                      Set<IRoutingRule<IBatisRoutingFact, List<String>>> sqlActionShardingRules,
                                      Set<IRoutingRule<IBatisRoutingFact, List<String>>> sqlActionRules,
                                      Set<IRoutingRule<IBatisRoutingFact, List<String>>> namespaceShardingRules,
                                      Set<IRoutingRule<IBatisRoutingFact, List<String>>> namespaceRules)
        throws IOException {
    XStream xstream = new XStream();
    xstream.alias("rules", InternalRules.class);
    xstream.alias("rule", InternalRule.class);
    xstream.addImplicitCollection(InternalRules.class, "rules");
    xstream.useAttributeFor(InternalRule.class, "merger");

    InternalRules internalRules = (InternalRules) xstream.fromXML(configLocation
            .getInputStream());
    List<InternalRule> rules = internalRules.getRules();
    if (CollectionUtils.isEmpty(rules)) {
        return;
    }

    for (InternalRule rule : rules) {
        String namespace = StringUtils.trimToEmpty(rule.getNamespace());
        String sqlAction = StringUtils.trimToEmpty(rule.getSqlmap());
        String shardingExpression = StringUtils.trimToEmpty(rule.getShardingExpression());
        String destinations = StringUtils.trimToEmpty(rule.getShards());

        Validate.notEmpty(destinations, "destination shards must be given explicitly.");

        if (StringUtils.isEmpty(namespace) && StringUtils.isEmpty(sqlAction)) {
            throw new IllegalArgumentException(
                    "at least one of 'namespace' or 'sqlAction' must be given.");
        }
        if (StringUtils.isNotEmpty(namespace) && StringUtils.isNotEmpty(sqlAction)) {
            throw new IllegalArgumentException(
                    "'namespace' and 'sqlAction' are alternatives, can't guess which one to use if both of them are provided.");
        }

        if (StringUtils.isNotEmpty(namespace)) {
            if (StringUtils.isEmpty(shardingExpression)) {
                namespaceRules.add(new IBatisNamespaceRule(namespace, destinations));
            } else {
                IBatisNamespaceShardingRule insr = new IBatisNamespaceShardingRule(namespace,
                        destinations, shardingExpression);
                if (MapUtils.isNotEmpty(getFunctionsMap())) {
                    insr.setFunctionMap(getFunctionsMap());
                }
                namespaceShardingRules.add(insr);
            }
        }
        if (StringUtils.isNotEmpty(sqlAction)) {
            if (StringUtils.isEmpty(shardingExpression)) {
                sqlActionRules.add(new IBatisSqlActionRule(sqlAction, destinations));
            } else {
                IBatisSqlActionShardingRule issr = new IBatisSqlActionShardingRule(sqlAction,
                        destinations, shardingExpression);
                if (MapUtils.isNotEmpty(getFunctionsMap())) {
                    issr.setFunctionMap(getFunctionsMap());
                }
                sqlActionShardingRules.add(issr);
            }
        }
    }

}