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

The following examples show how to use com.thoughtworks.xstream.XStream#useAttributeFor() . 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
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 2
Source Project: onetwo   File: ExcelUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static XStream registerExcelModel(){
		XStream xstream = new XStream(new DomDriver());
		xstream.alias("workbook", WorkbookModel.class);
		xstream.alias("vars", List.class);
		xstream.alias("var", VarModel.class);
		xstream.alias("sheets", List.class);
		xstream.alias("template", TemplateModel.class);
		xstream.alias("sheet", TemplateModel.class);
		xstream.alias("rows", List.class);
		xstream.alias("row", RowModel.class);
		xstream.alias("field", FieldModel.class);
		xstream.alias("valueExecutors", List.class);
		xstream.alias("valueExecutor", ExecutorModel.class);
//		xstream.useAttributeFor(Number.class);
//		xstream.useAttributeFor(boolean.class);
//		xstream.useAttributeFor(String.class); 
//		xstream.useAttributeFor(int.class); 
		xstream.useAttributeFor(String.class);
		for(Class<?> btype : getBaseTypeClass()){
			xstream.useAttributeFor(btype);
		}
		return xstream;
	}
 
Example 3
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 4
Source Project: onetwo   File: XMLReader.java    License: Apache License 2.0 5 votes vote down vote up
protected XStream newXStream(){
//		XStream xstream = new XStream(new DomDriver());
		xstream = new XStream();//xpp3
		if(primitiveAsAttribute){
			xstream.useAttributeFor(String.class);
			xstream.useAttributeFor(Integer.class);
			xstream.useAttributeFor(int.class);
			xstream.useAttributeFor(Long.class);
			xstream.useAttributeFor(long.class);
			xstream.useAttributeFor(Boolean.class);
			xstream.useAttributeFor(boolean.class);
		}
		return xstream;
	}
 
Example 5
Source Project: depan   File: JavaXStreamConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void config(XStream xstream) {
  xstream.alias("java-field", FieldElement.class);
  xstream.alias("java-interface", InterfaceElement.class);
  xstream.alias("java-method", MethodElement.class);
  xstream.alias("java-package", PackageElement.class);
  xstream.alias("java-type", TypeElement.class);
  xstream.alias("java-relation", JavaRelation.class);

  xstream.useAttributeFor(TypeElement.class, "fullyQualifiedName");
  xstream.aliasAttribute(TypeElement.class, "fullyQualifiedName", "name");
}
 
Example 6
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 7
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 8
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 9
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 10
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 11
@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);
            }
        }
    }

}
 
Example 12
Source Project: weblaf   File: XmlUtils.java    License: GNU General Public License v3.0 4 votes vote down vote up
/**
 * Initializes global XStream instance.
 */
private static void initializeXStream ()
{
    try
    {
        // Custom ReflectionProvider to provide pure-java objects instantiation
        // Unlike default SunUnsafeReflectionProvider it has limited objects instantiation options
        // Also it properly initializes object field values specified directly near the fields
        final PureJavaReflectionProvider reflectionProvider = new PureJavaReflectionProvider ();

        // Custom HierarchicalStreamDriver implementation based on StaxDriver
        // It provides us HierarchicalStreamReader to allow XStreamContext usage
        hierarchicalStreamDriver = new XmlDriver ();

        // XStream instance initialization
        xStream = new XStream ( reflectionProvider, hierarchicalStreamDriver );

        // Make sure that XStream ClassLoader finds WebLaF classes in cases where multiple ClassLoaders are used
        // E.g. IntelliJ IDEA uses different ClassLoaders for plugins (e.g. JFormDesigner) and its core (which includes XStream)
        if ( XmlUtils.class.getClassLoader () != xStream.getClass ().getClassLoader () )
        {
            final ClassLoader classLoader = xStream.getClassLoader ();
            if ( classLoader instanceof CompositeClassLoader )
            {
                ( ( CompositeClassLoader ) classLoader ).add ( XmlUtils.class.getClassLoader () );
            }
            else
            {
                final CompositeClassLoader compositeClassLoader = new CompositeClassLoader ();
                compositeClassLoader.add ( XmlUtils.class.getClassLoader () );
                xStream.setClassLoader ( compositeClassLoader );
            }
        }

        // Standard Java-classes aliases
        if ( aliasJdkClasses )
        {
            // Custom {@link java.awt.Point} mapping
            xStream.alias ( "Point", Point.class );
            xStream.useAttributeFor ( Point.class, "x" );
            xStream.useAttributeFor ( Point.class, "y" );

            // Custom {@link java.awt.geom.Point2D} mapping
            xStream.alias ( "Point2D", Point2D.class );
            xStream.registerConverter ( new Point2DConverter () );

            // Custom {@link java.awt.Dimension} mapping
            xStream.alias ( "Dimension", Dimension.class );
            xStream.registerConverter ( new DimensionConverter () );

            // Custom {@link java.awt.Rectangle} mapping
            xStream.alias ( "Rectangle", Rectangle.class );
            xStream.useAttributeFor ( Rectangle.class, "x" );
            xStream.useAttributeFor ( Rectangle.class, "y" );
            xStream.useAttributeFor ( Rectangle.class, "width" );
            xStream.useAttributeFor ( Rectangle.class, "height" );

            // Custom {@link java.awt.Font} mapping
            xStream.alias ( "Font", Font.class );

            // Custom {@link java.awt.Color} mapping
            xStream.alias ( "Color", Color.class );
            xStream.registerConverter ( new ColorConverter () );

            // Custom {@link java.awt.Insets} mapping
            xStream.alias ( "Insets", Insets.class );
            xStream.registerConverter ( new InsetsConverter () );

            // Custom {@link java.awt.Stroke} mapping
            xStream.alias ( "Stroke", Stroke.class );
            xStream.registerConverter ( new StrokeConverter () );
        }

        // Additional WebLaF data classes aliases
        xStream.processAnnotations ( Pair.class );
        xStream.processAnnotations ( Scale.class );
    }
    catch ( final Exception e )
    {
        // It is a pretty fatal for library if something goes wrong here
        throw new UtilityException ( "Unable to initialize XStream instance", e );
    }
}