Package org.apache.commons.betwixt

Examples of org.apache.commons.betwixt.XMLIntrospector


     * / Turbine projects. Maybe a static helper method - question is what to
     * call it???
     */
    protected XMLIntrospector createXMLIntrospector()
    {
        XMLIntrospector introspector = new XMLIntrospector();

        // set elements for attributes to true
        introspector.getConfiguration().setAttributesForPrimitives(false);

        // wrap collections in an XML element
        //introspector.setWrapCollectionsInElement(true);

        // turn bean elements into lower case
        introspector.getConfiguration().setElementNameMapper(new HyphenatedNameMapper());

        return introspector;
    }
View Full Code Here


    }

    public void testIntrospection() throws Exception {
        log.info("testIntrospection() started");

        XMLIntrospector introspector = new XMLIntrospector();
        XMLBeanInfo beanInfo = introspector
                .introspect(VersioningTestData.class);

        // 2 Element descriptors
        ElementDescriptor[] elementDescriptors = beanInfo
                .getElementDescriptor().getElementDescriptors();
View Full Code Here

        "  </class>\n"+
        "</betwixt-config>";
   
    public void testRegisterThenResolve() throws Exception
    {
        XMLIntrospector introspector = new XMLIntrospector();
        introspector.register(new InputSource(new StringReader(MAPPING)));
       
       
        ElementDescriptor descriptor = introspector.introspect(Element.class).getElementDescriptor();
        ElementMapping elementMapping = new ElementMapping();
        elementMapping.setAttributes(new AttributesImpl());
        elementMapping.setName("Bogus");
        elementMapping.setDescriptor(descriptor);
        elementMapping.setType(Iterator.class);
        ReadContext readContext = new ReadContext(new BindingConfiguration(), new ReadConfiguration());
       
        assertNull(introspector.getPolymorphicReferenceResolver().resolveType(elementMapping, readContext));
       
        elementMapping.setName("elementA");
        Class resolution = introspector.getPolymorphicReferenceResolver().resolveType(elementMapping, readContext);
        assertEquals("Should resolve to the element about", ElementA.class, resolution);
    }
View Full Code Here

        result.getBindingConfiguration().setMapIDs(false);
        return result;
    }

    private XMLIntrospector newXMLIntrospector(NameMapper mapper) {
        XMLIntrospector introspector = new XMLIntrospector();
        introspector.getConfiguration().setAttributesForPrimitives(true);
        introspector.getConfiguration().setWrapCollectionsInElement(false);
        introspector.getConfiguration().setElementNameMapper(mapper);
        return introspector;
    }
View Full Code Here

                "    <element name='jelly'>" +
                "        <element name='wibble' property='alpha'/>" +
                "        <element name='wobble' property='beta'/>" +
                "    </element>" +
                "</info>");
        XMLIntrospector introspector = new XMLIntrospector();
        XMLBeanInfo xmlBeanInfo = introspector.introspect(SimpleTestBean.class, new InputSource(reader));
       
        ElementDescriptor elementDescriptor = xmlBeanInfo.getElementDescriptor();
        assertEquals("Root is jelly", "jelly", elementDescriptor.getLocalName());
        ElementDescriptor[] childDescriptors = elementDescriptor.getElementDescriptors();
        assertEquals("Expected two child elements", 2, childDescriptors.length);
        assertEquals("Wibble comes first", "wibble", childDescriptors[0].getLocalName());
        assertEquals("Wobble comes last", "wobble", childDescriptors[1].getLocalName());
       
        reader = new StringReader(
                "<?xml version='1.0' ?>" +
                "<info>" +
                "    <element name='not-jelly'>" +
                "        <element name='no-wibble' property='alpha'/>" +
                "        <element name='no-wobble' property='beta'/>" +
                "    </element>" +
                "</info>");

        xmlBeanInfo = introspector.introspect(SimpleTestBean.class, new InputSource(reader));
       
        elementDescriptor = xmlBeanInfo.getElementDescriptor();
        assertEquals("Root is not-jelly", "not-jelly", elementDescriptor.getLocalName());
        childDescriptors = elementDescriptor.getElementDescriptors();
        assertEquals("Expected two child elements", 2, childDescriptors.length);
View Full Code Here

                "    <element name='jelly'>" +
                "        <element name='wibble' property='alpha'/>" +
                "        <element name='wobble' property='beta'/>" +
                "    </element>" +
                "</info>");
        XMLIntrospector introspector = new XMLIntrospector();
        introspector.register(SimpleTestBean.class, new InputSource(reader));
        XMLBeanInfo xmlBeanInfo = introspector.introspect(SimpleTestBean.class);
       
        ElementDescriptor elementDescriptor = xmlBeanInfo.getElementDescriptor();
        assertEquals("Root is jelly", "jelly", elementDescriptor.getLocalName());
        ElementDescriptor[] childDescriptors = elementDescriptor.getElementDescriptors();
        assertEquals("Expected two child elements", 2, childDescriptors.length);
View Full Code Here

    public void testClassAttribute() throws Exception {
        //SimpleLog log = new SimpleLog("[testClassAttribute:ElementRule]");
        //log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
        //ElementRule.setLog(log);
       
        XMLIntrospector introspector = new XMLIntrospector();
        XMLBeanInfo beanInfo = introspector.introspect(ExampleBean.class);
        ElementDescriptor[] elementDescriptors = beanInfo.getElementDescriptor().getElementDescriptors();
        ElementDescriptor elementsElementDescriptor = null;
        for ( int i=0, size = elementDescriptors.length; i<size ; i++ ) {
            if ( "example".equals( elementDescriptors[i].getLocalName() ) ) {
                elementsElementDescriptor = elementDescriptors[i];
View Full Code Here

    public void testDefaultExceptionType() throws Exception {
         assertEquals(TypeBindingStrategy.BindingType.COMPLEX, TypeBindingStrategy.DEFAULT.bindingType(RuntimeException.class));
    }
   
    public void testNewStrategy() throws Exception {
        XMLIntrospector introspector = new XMLIntrospector();
        introspector.getConfiguration().setSimpleTypeMapper(new StringsAsElementsSimpleTypeMapper());
        introspector.getConfiguration().setWrapCollectionsInElement(true);
       
        XMLBeanInfo beanInfo = introspector.introspect(TuneBean.class);
        ElementDescriptor tuneBeanDescriptor = beanInfo.getElementDescriptor();
       
        AttributeDescriptor[] tuneBeanAttributes = tuneBeanDescriptor.getAttributeDescriptors();
        assertEquals("Only expect one attribute", 1, tuneBeanAttributes.length);
        AttributeDescriptor recordedAttribute = tuneBeanAttributes[0];
View Full Code Here

            "Spouse should not get set because it is not in the .betwixt file",
            result.getSpouse());
    }

    public void testIgnoredProperty() throws Exception {
        XMLIntrospector introspector = new XMLIntrospector();
        XMLBeanInfo beanInfo = introspector.introspect(IgnoreBean.class);
        ElementDescriptor ignoreDescriptor = beanInfo.getElementDescriptor();
       
        assertEquals("element name matches", "ignore", ignoreDescriptor.getLocalName());
        ElementDescriptor[] childDescriptors = ignoreDescriptor.getElementDescriptors();
        assertEquals("number of child elements", 1, childDescriptors.length);
View Full Code Here

    /**
     * Basic test for add-adders attribute of addDefaults tag.
     * @throws Exception
     */
    public void testIgnoredAdders() throws Exception {
        XMLIntrospector introspector = new XMLIntrospector();
        // ignore adders bean uses a dot betwixt file with add-adders false
        XMLBeanInfo beanInfo = introspector.introspect(IgnoreAddersBean.class);
        ElementDescriptor ignoreDescriptor = beanInfo.getElementDescriptor();
       
        assertEquals("element name matches", "ignore", ignoreDescriptor.getLocalName());
        ElementDescriptor[] childDescriptors = ignoreDescriptor.getElementDescriptors();
        assertEquals("number of child elements", 2, childDescriptors.length);
View Full Code Here

TOP

Related Classes of org.apache.commons.betwixt.XMLIntrospector

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.