Package org.apache.commons.betwixt

Examples of org.apache.commons.betwixt.XMLBeanInfo


               // no type!
               // TODO: handle this
               // TODO: add support for logging
               // TODO: maybe should try singular type?
            } else {
                XMLBeanInfo filledBeanInfo = schema.introspect(type);
                elementDescriptor = filledBeanInfo.getElementDescriptor();
            }
        }
        return elementDescriptor;
    }
View Full Code Here


   * Generates an XML Schema model for the given class.
   * @param clazz not null
   * @return Schema model, not null
   */
  public Schema generate(Class clazz) throws IntrospectionException {
        XMLBeanInfo beanInfo = introspector.introspect(clazz);
    return generate(beanInfo);
  }
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.setEndOfLine("\n"); //force to \n so expected values match for sure
        writer.write(element);
       
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.setEndOfLine("\n"); //force to \n so expected values match for sure
        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";
View Full Code Here

    public void testNoNameIntrospection() throws Exception {
       
        XMLIntrospector xmlIntrospector = new XMLIntrospector();
        xmlIntrospector.getConfiguration().setWrapCollectionsInElement(false);
        XMLBeanInfo xmlBeanInfo = xmlIntrospector.introspect(MixedCollectionBean.class);
        ElementDescriptor elementDescriptor = xmlBeanInfo.getElementDescriptor();
        ElementDescriptor[] childDescriptors = elementDescriptor.getElementDescriptors();
        assertEquals("One child", 1, childDescriptors.length);  
        assertNull("Expected null name", childDescriptors[0].getLocalName());  
    }
View Full Code Here

//---------------------------------- Tests
   
    public void testForceAccessibleSuper() throws Exception {
        XMLIntrospector xmlIntrospector = new XMLIntrospector();
        XMLBeanInfo xmlBeanInfo = xmlIntrospector.introspect(MixedUpdatersBean.class);
        ElementDescriptor[] descriptors = xmlBeanInfo.getElementDescriptor().getElementDescriptors();
        boolean propertyFound = false;
        for (int i=0; i<descriptors.length ; i++) {
            ElementDescriptor descriptor = descriptors[i];
            if ("private-super".equals(descriptor.getLocalName())) {
                propertyFound = true;
View Full Code Here

        XMLIntrospector xmlIntrospector = new XMLIntrospector();
        Class[] mapped = xmlIntrospector.register(new InputSource(new StringReader(MAPPING)));
       
        assertEquals("Mapped classes", 3, mapped.length);
       
        XMLBeanInfo beanInfo = xmlIntrospector.introspect(AddressBean.class);
        assertNotNull("Bean info mapping", beanInfo);
        ElementDescriptor descriptor = beanInfo.getElementDescriptor();
        assertEquals("Root element name", "not-address", descriptor.getLocalName());
        ElementDescriptor[] childDescriptors = descriptor.getElementDescriptors();
        assertEquals("4 child elements", 4, childDescriptors.length);
        assertEquals("First element", "not-street", childDescriptors[0].getLocalName());
        assertEquals("Second element", "not-city", childDescriptors[1].getLocalName());
        assertEquals("Third element", "not-code", childDescriptors[2].getLocalName());
        assertEquals("Forth element", "not-country", childDescriptors[3].getLocalName());
             
        beanInfo = xmlIntrospector.introspect(SimpleTestBean.class);
        assertNotNull("Bean info mapping", beanInfo);
        descriptor = beanInfo.getElementDescriptor();
        assertEquals("Root element name", "jelly", descriptor.getLocalName());
        childDescriptors = descriptor.getElementDescriptors();
        assertEquals("Child elements", 2, childDescriptors.length);
        assertEquals("First element", "wibble", childDescriptors[0].getLocalName());
        assertEquals("Second element", "wobble", childDescriptors[1].getLocalName());
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();
        assertEquals("Need 2 element descriptors", 2, elementDescriptors.length);

        ElementDescriptor element1Descriptor = beanInfo.getElementDescriptor()
                .getElementDescriptor("element1");
        log.info("element1Descriptor: " + element1Descriptor);
        debugOptions(element1Descriptor.getOptions());
        assertNotNull(element1Descriptor);
        assertEquals("1", element1Descriptor.getOptions().getValue(
                "version-from"));
        assertNull(element1Descriptor.getOptions().getValue("version-until"));

        ElementDescriptor element2Descriptor = beanInfo.getElementDescriptor()
                .getElementDescriptor("element2");
        log.info("element2Descriptor: " + element2Descriptor);
        debugOptions(element2Descriptor.getOptions());
        assertNotNull(element2Descriptor);
        assertEquals("2", element2Descriptor.getOptions().getValue(
                "version-from"));
        assertNull(element2Descriptor.getOptions().getValue("version-until"));

        // 2 Attribute descriptors
        AttributeDescriptor[] attributeDescriptors = beanInfo
                .getElementDescriptor().getAttributeDescriptors();
        assertEquals("Need 2 attribute descriptors", 2,
                attributeDescriptors.length);

        AttributeDescriptor attribute1Descriptor = beanInfo
                .getElementDescriptor().getAttributeDescriptor("attribute1");
        log.info("attribute1Descriptor: " + attribute1Descriptor);
        debugOptions(attribute1Descriptor.getOptions());
        assertNotNull(attribute1Descriptor);
        assertEquals("2", attribute1Descriptor.getOptions().getValue(
                "version-from"));
        assertNull(attribute1Descriptor.getOptions().getValue("version-until"));

        AttributeDescriptor attribute2Descriptor = beanInfo
                .getElementDescriptor().getAttributeDescriptor("attribute2");
        log.info("attribute2Descriptor: " + attribute2Descriptor);
        debugOptions(attribute2Descriptor.getOptions());
        assertNotNull(attribute2Descriptor);
        assertEquals("1", attribute2Descriptor.getOptions().getValue(
View Full Code Here

    }
   
    public void testNoCache() throws Exception {
        XMLBeanInfoRegistry registry = new NoCacheRegistry();
       
        XMLBeanInfo xbi = new XMLBeanInfo(Long.class);
       
        assertNull("No cache XML register (1)", registry.get(Long.class));
       
        registry.put(Long.class, xbi);
       
View Full Code Here

   
    public void testDefault() throws Exception {
       
        XMLBeanInfoRegistry registry = new DefaultXMLBeanInfoRegistry();
       
        XMLBeanInfo xbi = new XMLBeanInfo(Long.class);
       
        assertNull("Default XML register (1)", registry.get(Long.class));
       
        registry.put(Long.class, xbi);
       
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.