Package org.apache.commons.betwixt

Examples of org.apache.commons.betwixt.XMLBeanInfo


        assertEquals("2", two.alpha());
    }

  public void testIntrospection() throws Exception   {
    XMLIntrospector introspector = new XMLIntrospector();
    XMLBeanInfo beanInfo = introspector.introspect(AlphaList.class);
    ElementDescriptor[] descriptors = beanInfo.getElementDescriptor().getElementDescriptors();
    assertEquals("One descriptor", 1, descriptors.length);
        assertTrue(descriptors[0].isHollow());
        assertNotNull(descriptors[0].getContextExpression());
        assertNotNull(descriptors[0].getUpdater());
        assertEquals("A list can contain any object", Object.class, descriptors[0].getSingularPropertyType());
View Full Code Here


        XMLIntrospector introspector = new XMLIntrospector();
       
        StringReader mapping = new StringReader(MAPPING);
        introspector.register(new InputSource(mapping));
      
        XMLBeanInfo beanInfo = introspector.introspect(AlphaListHolder.class);
        ElementDescriptor descriptor = beanInfo.getElementDescriptor();
        assertNotNull(descriptor);
        ElementDescriptor[] descriptors = descriptor.getElementDescriptors();
        assertNotNull(descriptors);
        assertEquals("Only one descriptor", 1, descriptors.length);
        assertNotNull("Expected updater", descriptors[0].getUpdater());
View Full Code Here

            }
        }
       
        Object top = digester.peek();
        if ( top instanceof XMLBeanInfo ) {
            XMLBeanInfo beanInfo = (XMLBeanInfo) top;
            beanInfo.setElementDescriptor( descriptor );
            beanClass = beanInfo.getBeanClass();
            descriptor.setPropertyType( beanClass );
           
        } else if ( top instanceof ElementDescriptor ) {
            ElementDescriptor parent = (ElementDescriptor) top;
            parent.addElementDescriptor( descriptor );
View Full Code Here

        StringWriter out = new StringWriter();
        out.write("<?xml version='1.0'?>");
        BeanWriter writer = new BeanWriter(out);
        writer.getXMLIntrospector().getConfiguration().setAttributesForPrimitives(false);
        writer.getBindingConfiguration().setMapIDs(false);
        XMLBeanInfo elementInfo = writer.getXMLIntrospector().introspect(Element.class);
        elementInfo.getElementDescriptor().getElementDescriptors()[0]
            .getOptions().addOption(MixedContentEncodingStrategy.ENCODING_OPTION_NAME, "CDATA")
        
        writer.write(element);
       
        String expected = "<?xml version='1.0'?><Element>\n<value><![CDATA[<greeting>What Ho Jeeves!</greeting>]]></value>\n</Element>\n";
View Full Code Here

        StringWriter out = new StringWriter();
        out.write("<?xml version='1.0'?>");
        BeanWriter writer = new BeanWriter(out);
        writer.getXMLIntrospector().getConfiguration().setAttributesForPrimitives(false);
        writer.getBindingConfiguration().setMapIDs(false);
        XMLBeanInfo elementInfo = writer.getXMLIntrospector().introspect(Element.class);
        elementInfo.getElementDescriptor().getElementDescriptors()[0]
            .getOptions().addOption("org.apache.commons.betwixt.mixed-content-encoding", "escaped");
        writer.write(element);
       
        String expected = "<?xml version='1.0'?><Element>\n<value>&lt;greeting&gt;What Ho Jeeves!&lt;/greeting&gt;</value>\n</Element>\n";
        String xml = out.getBuffer().toString();
View Full Code Here

            }
        }
       
        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 ) {
View Full Code Here

    protected ElementDescriptor getElementDescriptor( ElementDescriptor propertyDescriptor ) {
        Class beanClass = propertyDescriptor.getSingularPropertyType();
        if ( beanClass != null ) {
            XMLIntrospector introspector = getBeanReader().getXMLIntrospector();
            try {
                XMLBeanInfo xmlInfo = introspector.introspect( beanClass );
                return xmlInfo.getElementDescriptor();
               
            } catch (Exception e) {
                log.warn( "Could not introspect class: " + beanClass, e );
            }
        }
View Full Code Here

       
        introspector.getConfiguration().setAttributesForPrimitives(true);
       
        Object bean = createBean();
       
        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();
       
View Full Code Here

        XMLIntrospector introspector = new XMLIntrospector();
        introspector.getConfiguration().setAttributesForPrimitives(false);
//        introspector.setLog(log);
       
        XMLBeanInfo xmlBeanInfo = introspector.introspect(BeanWithBeanInfoBean.class);
       
        ElementDescriptor[] elementDescriptors = xmlBeanInfo.getElementDescriptor().getElementDescriptors();
       
//        log = new SimpleLog("[testBeanWithBeanInfo]");
//        log.setLevel(SimpleLog.LOG_LEVEL_DEBUG);
       
//        log.debug("XMLBeanInfo:");
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);
View Full Code Here

TOP

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

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.