Package org.apache.commons.betwixt

Examples of org.apache.commons.betwixt.XMLIntrospector


    }
   
    public void testIntrospector() throws Exception {
        //SimpleLog log = new SimpleLog("testIntrospector:introspector");
        //log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
        XMLIntrospector introspector = new XMLIntrospector();
        //introspector.setLog(log);
       
        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();
       
View Full Code Here


            "        </element>" +
            "    </element>" +
            "</info>";
           
        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"));
View Full Code Here

        propertyDescriptors = null;

//        SimpleLog log = new SimpleLog("[testBeanWithBeanInfo:XMLIntrospector]");
//        log.setLevel(SimpleLog.LOG_LEVEL_TRACE);

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

                    parseString(out.toString()));
        }
    }
   
    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();
       
View Full Code Here

        assertEquals("Expected no attributes", 0, attributeDescriptor.length);
        assertEquals("Expected two elements", 2, children.length);
   
   
    public void testClassNormalizer() throws Exception {
        XMLIntrospector introspector = new XMLIntrospector();
        introspector.getConfiguration().setClassNormalizer( new ClassNormalizer() {
               
                public Class normalize(Class clazz) {
                    if (IFace.class.isAssignableFrom( clazz )) {
                        return IFace.class;
                   
                    return super.normalize( clazz );
               
            });
       
        FaceImpl face = new FaceImpl();
        XMLBeanInfo info = introspector.introspect( face );
        ElementDescriptor elementDescriptor = info.getElementDescriptor();
        assertEquals("Expected only itself", 1, elementDescriptor.getElementDescriptors().length);
   
        AttributeDescriptor[] attributeDescriptor = elementDescriptor.getAttributeDescriptors();     
        ElementDescriptor[] children = elementDescriptor.getElementDescriptors();
View Full Code Here

   
   
    public void testListedClassNormalizer() throws Exception {
        ListedClassNormalizer classNormalizer = new ListedClassNormalizer();
        classNormalizer.addSubstitution( IFace.class );
        XMLIntrospector introspector = new XMLIntrospector();
        introspector.getConfiguration().setClassNormalizer(classNormalizer);
       
        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

        "    </element>" +
        "  </class>" +
        "</betwixt-config>";
       
        MultiMappingBeanInfoDigester digester = new MultiMappingBeanInfoDigester();
        digester.setXMLIntrospector(new XMLIntrospector());
        digester.setBeanClass(ExampleBean.class);
       
        digester.parse(new StringReader(xml));
        Map beanInfoMap = digester.getBeanInfoMap();
        assertTrue( beanInfoMap.containsKey(TestDigestMultiMapping.class));
View Full Code Here

                            parseString(xml),
                            true);
   
   
    public void testBetwixtFileType() throws Exception {
      XMLIntrospector introspector = new XMLIntrospector();
      XMLBeanInfo info = introspector.introspect( Channel.class );
     
      ElementDescriptor elementDescriptor = info.getElementDescriptor();
     
    Class clazz = elementDescriptor.getSingularPropertyType();
    assertEquals( "Element type correct", Channel.class , clazz);
View Full Code Here

   
    assertEquals( "Element name correct", "rss", elementDescriptor.getLocalName());
    }
   
    public void testIgnoreAllBeanInfo() throws Exception {
        XMLIntrospector introspector = new XMLIntrospector();
        introspector.getConfiguration().setIgnoreAllBeanInfo( false );
        introspector.setRegistry(new NoCacheRegistry());
        XMLBeanInfo info = introspector.introspect( BeanWithBeanInfoBean.class );
        ElementDescriptor[] elementDescriptors = info.getElementDescriptor().getElementDescriptors();
        // When BeanInfo is used the properties alpha and gamma will be found
        if ("alpha".equals(elementDescriptors[0].getPropertyName())) {
            assertEquals("Second element name", "gamma" , elementDescriptors[1].getPropertyName());
        } else {
            assertEquals("First element name", "gamma" , elementDescriptors[0].getPropertyName());
            assertEquals("Second element name", "alpha" , elementDescriptors[1].getPropertyName());
        }

        introspector.getConfiguration().setIgnoreAllBeanInfo( true );
        info = introspector.introspect( BeanWithBeanInfoBean.class );
        elementDescriptors = info.getElementDescriptor().getElementDescriptors();
        // When BeanInfo is ignored the properties alpha and beta will be found
        if ("alpha".equals(elementDescriptors[0].getPropertyName())) {
            assertEquals("Second element name", "beta" , elementDescriptors[1].getPropertyName());
        } else {
View Full Code Here

        AddressBean bean = new AddressBean();
        bean.setStreet("DEFAULT");
        bean.setCode("DEFAULT");
        bean.setCountry("DEFAULT");
       
        XMLIntrospector introspector = new XMLIntrospector();
        ElementDescriptor elementDescriptor = introspector.introspect(AddressBean.class).getElementDescriptor();
       
        ReadContext context = new ReadContext(new BindingConfiguration(), new ReadConfiguration());
        context.setBean(bean);
        context.markClassMap(AddressBean.class);
        context.pushElement("NoMatch");
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.