Package org.apache.commons.betwixt

Examples of org.apache.commons.betwixt.ElementDescriptor


        }
       
        Object top = digester.peek();
        if ( top instanceof XMLBeanInfo ) {
            XMLBeanInfo beanInfo = (XMLBeanInfo) top;
            ElementDescriptor elementDescriptor = beanInfo.getElementDescriptor();
            if (elementDescriptor != null) {
                elementDescriptor.addContentDescriptor( descriptor );
            }
           
        } else if ( top instanceof ElementDescriptor ) {
            ElementDescriptor parent = (ElementDescriptor) top;
            parent.addContentDescriptor( descriptor );
           
        } else {
            throw new SAXException( "Invalid use of <text>. It should "
                + "be nested <text> nodes" );
        }
View Full Code Here


        //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 ( "examples".equals( elementDescriptors[i].getLocalName() ) ) {
                elementsElementDescriptor = elementDescriptors[i];
            }
        }
       
        assertNotNull("Element descriptor for elements not found", elementsElementDescriptor);
        assertEquals(
                    "Class property not set",
                    ExampleImpl.class,
                    elementsElementDescriptor.getImplementationClass());
    }
View Full Code Here

    private Rule valueRule;
    private ElementDescriptor elementDescriptor;

    protected void setUp() throws Exception {
        super.setUp();
        elementDescriptor = new ElementDescriptor();
        digester = new Digester();
        digester.push(elementDescriptor);
        optionRule = new OptionRule();
        optionRule.setDigester(digester);
        nameRule = optionRule.getNameRule();
View Full Code Here

           
        XMLBeanInfoDigester digester = new XMLBeanInfoDigester();
        digester.setXMLIntrospector(new XMLIntrospector());
        digester.setBeanClass(ExampleBean.class);
        XMLBeanInfo xmlBeanInfo = (XMLBeanInfo) digester.parse(new StringReader(xml));
        ElementDescriptor baseDescriptor = xmlBeanInfo.getElementDescriptor();
       
        assertEquals("Value one set on base", "value one",  baseDescriptor.getOptions().getValue("one"));
        assertEquals("Value two set on base", "value two",  baseDescriptor.getOptions().getValue("two"));
        assertNull("Value three not set on base",  baseDescriptor.getOptions().getValue("three"));

        assertEquals("Number of child elements", 1, baseDescriptor.getElementDescriptors().length);
       
        ElementDescriptor childDescriptor = baseDescriptor.getElementDescriptors()[0];
        assertNull("Value one set on base",  childDescriptor.getOptions().getValue("one"));
        assertNull("Value two set on base",  childDescriptor.getOptions().getValue("two"));
        assertEquals("Value three set on child", "value three",  childDescriptor.getOptions().getValue("three"));
    }
View Full Code Here

        BaseMixedContentEncodingStrategy mceStrategy = new TestBaseMixedContentEncoding(false);
        assertEquals("Check basic escaping", "<![CDATA[<greeting>ab]]&gt;ba</greeting>]]>", mceStrategy.encodeInCDATA("<greeting>ab]]>ba</greeting>"));
    }
   
    public void testBaseMixedEncode() {
        ElementDescriptor descriptor = new ElementDescriptor();
        TestBaseMixedContentEncoding mceStrategy = new TestBaseMixedContentEncoding(false);
        assertEquals(
                        "Using character escaping",
                        "&lt;exclaim&gt;hello, mum&lt;/exclaim&gt;",
                        mceStrategy.encode("<exclaim>hello, mum</exclaim>", descriptor));
View Full Code Here

       
        assertEquals("Descriptor set", descriptor, mceStrategy.element);
    }
   
    public void testDefaultImplementation() {
        ElementDescriptor descriptor = new ElementDescriptor();
        assertEquals(
            "Default implementation uses character escaping",
            "&lt;proclaim&gt;The King Is Dead, Long Live The King&lt;/proclaim&gt;",
            MixedContentEncodingStrategy.DEFAULT.encode("<proclaim>The King Is Dead, Long Live The King</proclaim>", descriptor));
    }
View Full Code Here

            "&lt;proclaim&gt;The King Is Dead, Long Live The King&lt;/proclaim&gt;",
            MixedContentEncodingStrategy.DEFAULT.encode("<proclaim>The King Is Dead, Long Live The King</proclaim>", descriptor));
    }
   
    public void testEscapedCharactersImplementation() {
        ElementDescriptor descriptor = new ElementDescriptor();
        assertEquals(
            "Default implementation uses character escaping",
            "&lt;proclaim&gt;The King Is Dead, Long Live The King&lt;/proclaim&gt;",
            MixedContentEncodingStrategy.ESCAPED_CHARACTERS.encode("<proclaim>The King Is Dead, Long Live The King</proclaim>", descriptor));
    }
View Full Code Here

            "&lt;proclaim&gt;The King Is Dead, Long Live The King&lt;/proclaim&gt;",
            MixedContentEncodingStrategy.ESCAPED_CHARACTERS.encode("<proclaim>The King Is Dead, Long Live The King</proclaim>", descriptor));
    }
   
    public void testCDATAImplementation() {
        ElementDescriptor descriptor = new ElementDescriptor();
        assertEquals(
            "Default implementation uses character escaping",
            "<![CDATA[<proclaim>The King Is Dead, Long Live The King</proclaim>]]>",
            MixedContentEncodingStrategy.CDATA.encode("<proclaim>The King Is Dead, Long Live The King</proclaim>", descriptor));
    }
View Full Code Here

       
        XMLBeanInfo info = introspector.introspect( bean );
       
        assertTrue( "Found XMLBeanInfo", info != null );
       
        ElementDescriptor descriptor = info.getElementDescriptor();
       
        assertTrue( "Found root element descriptor", descriptor != null );
       
        AttributeDescriptor[] attributes = descriptor.getAttributeDescriptors();
       
        assertTrue( "Found attributes", attributes != null && attributes.length > 0 );
       
        // test second introspection with caching on
        info = introspector.introspect( bean );
       
        assertTrue( "Found XMLBeanInfo", info != null );
       
        descriptor = info.getElementDescriptor();
       
        assertTrue( "Found root element descriptor", descriptor != null );
       
        attributes = descriptor.getAttributeDescriptors();
       
        assertTrue( "Found attributes", attributes != null && attributes.length > 0 );


        // test introspection with caching off     
        //introspector.setCachingEnabled(false); 
        introspector.setRegistry(new NoCacheRegistry());
        info = introspector.introspect( bean );
       
        assertTrue( "Found XMLBeanInfo", info != null );
       
        descriptor = info.getElementDescriptor();
       
        assertTrue( "Found root element descriptor", descriptor != null );
       
        attributes = descriptor.getAttributeDescriptors();
       
        assertTrue( "Found attributes", attributes != null && attributes.length > 0 );


        // test introspection after flushing cache
//        introspector.setCachingEnabled(true);
        introspector.setRegistry(new DefaultXMLBeanInfoRegistry());
        //introspector.flushCache();
        info = introspector.introspect( bean );
       
        assertTrue( "Found XMLBeanInfo", info != null );
       
        descriptor = info.getElementDescriptor();
       
        assertTrue( "Found root element descriptor", descriptor != null );
       
        attributes = descriptor.getAttributeDescriptors();
       
        assertTrue( "Found attributes", attributes != null && attributes.length > 0 );

    }
View Full Code Here

    public void testDefaultClassNormalizer() throws Exception {
        XMLIntrospector introspector = new XMLIntrospector();
       
        FaceImpl face = new FaceImpl();
        XMLBeanInfo info = introspector.introspect( face );
        ElementDescriptor elementDescriptor = info.getElementDescriptor();
   
        AttributeDescriptor[] attributeDescriptor = elementDescriptor.getAttributeDescriptors();     
        ElementDescriptor[] children = elementDescriptor.getElementDescriptors();
       
        assertEquals("Expected no attributes", 0, attributeDescriptor.length);
        assertEquals("Expected two elements", 2, children.length);
   
View Full Code Here

TOP

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

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.