Examples of XMLBeanInfo


Examples of org.apache.commons.betwixt.XMLBeanInfo

        bean.addActor(new PersonBean("Helen", "Mirren"));
        bean.addActor(new PersonBean("Nicol", "Williamson"));
       
        TestWritingAPI writer = new TestWritingAPI();
        writer.getXMLIntrospector().setAttributesForPrimitives(true);
        XMLBeanInfo movieXmlBeanInfo
            = writer.getXMLIntrospector().introspect(MovieBean.class);
        XMLBeanInfo personXmlBeanInfo
            = writer.getXMLIntrospector().introspect(PersonBean.class);
        writer.write(bean);
       
        List expected = new ArrayList();
        ElementDescriptor movieElementdescriptor
            = movieXmlBeanInfo.getElementDescriptor();
        ElementDescriptor nameDescriptor
            = movieElementdescriptor.getElementDescriptors()[0];
        ElementDescriptor yearDescriptor
            = movieElementdescriptor.getElementDescriptors()[1];
        ElementDescriptor directorDescriptor
            = movieElementdescriptor.getElementDescriptors()[2];
        ElementDescriptor actorsDescriptor
            = movieElementdescriptor.getElementDescriptors()[3];
        ElementDescriptor personDescriptor
            = personXmlBeanInfo.getElementDescriptor();           
       
        expected.add(
            new TestWritingAPI.Record(
                TestWritingAPI.START_ELEMENT,
                movieElementdescriptor));
View Full Code Here

Examples of org.apache.commons.betwixt.XMLBeanInfo

        if ( log.isTraceEnabled() ) {
            log.trace( "Writing bean graph (qualified name '" + qualifiedName + "'" );
        }
       
        // introspect to obtain bean info
        XMLBeanInfo beanInfo = introspector.introspect( bean );
        if ( beanInfo != null ) {
            ElementDescriptor elementDescriptor = beanInfo.getElementDescriptor();
            if ( elementDescriptor != null ) {
                context = context.newContext( bean );
                if ( qualifiedName == null ) {
                    qualifiedName = elementDescriptor.getQualifiedName();
                }
                if ( namespaceUri == null ) {
                    namespaceUri = elementDescriptor.getURI();
                }
                if ( localName == null ) {
                    localName = elementDescriptor.getLocalName();
                }

                String ref = null;
                String id = null;
               
                // only give id's to non-primatives
                if ( elementDescriptor.isPrimitiveType() ) {
                    // write without an id
                    writeElement(
                        namespaceUri,
                        localName,
                        qualifiedName,
                        elementDescriptor,
                        context );
                       
                } else {
                    pushBean ( context.getBean() );
                    if ( getBindingConfiguration().getMapIDs() ) {
                        ref = (String) idMap.get( context.getBean() );
                    }
                    if ( ref == null ) {
                        // this is the first time that this bean has be written
                        AttributeDescriptor idAttribute = beanInfo.getIDAttribute();
                        if (idAttribute == null) {
                            // use a generated id
                            id = idGenerator.nextId();
                            idMap.put( bean, id );
                           
                            if ( getBindingConfiguration().getMapIDs() ) {
                                // write element with id
                                writeElement(
                                    namespaceUri,
                                    localName,
                                    qualifiedName,
                                    elementDescriptor,
                                    context ,
                                    beanInfo.getIDAttributeName(),
                                    id);
                                   
                            } else {   
                                // write element without ID
                                writeElement(
                                    namespaceUri,
                                    localName,
                                    qualifiedName,
                                    elementDescriptor,
                                    context );
                            }
                                                       
                        } else {
                            // use id from bean property
                            // it's up to the user to ensure uniqueness
                            // XXX should we trap nulls?
                            Object exp = idAttribute.getTextExpression().evaluate( context );
                            if (exp == null) {
                                // we'll use a random id
                                log.debug("Using random id");
                                id = idGenerator.nextId();
                               
                            } else {
                                // convert to string
                                id = exp.toString();
                            }
                            idMap.put( bean, id);
                           
                            // the ID attribute should be written automatically
                            writeElement(
                                namespaceUri,
                                localName,
                                qualifiedName,
                                elementDescriptor,
                                context );
                        }
                    } else {
                       
                        if ( !ignoreElement( elementDescriptor, context )) {
                            // we've already written this bean so write an IDREF
                            writeIDREFElement(
                                            elementDescriptor,
                                            namespaceUri,
                                            localName,
                                            qualifiedName, 
                                            beanInfo.getIDREFAttributeName(),
                                            ref);
                        }
                    }
                    popBean();
                }
View Full Code Here

Examples of org.apache.commons.betwixt.XMLBeanInfo

    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

Examples of org.apache.commons.betwixt.XMLBeanInfo

     * @throws SAXException if the primitiveTypes attribute contains an invalid value
     */
    public void begin(Attributes attributes) throws SAXException {
        Class beanClass = getBeanClass();
       
        xmlBeanInfo = new XMLBeanInfo( beanClass );
       
        String value = attributes.getValue( "primitiveTypes" );
        if ( value != null ) {
            if ( value.equalsIgnoreCase( "element" ) ) {
                getXMLInfoDigester().setAttributesForPrimitives( false );
View Full Code Here

Examples of org.apache.commons.betwixt.XMLBeanInfo

            if ( beanClass != null && !Map.class.isAssignableFrom( beanClass ) ) {
                if (log.isTraceEnabled()) {
                    log.trace("Filling descriptor for: " + beanClass);
                }
                try {
                    XMLBeanInfo xmlInfo = introspector.introspect( beanClass );
                    if (log.isTraceEnabled()) {
                        log.trace("Is wrapped? "
                        + xmlInfo.getElementDescriptor().isWrapCollectionsInElement());
                    }
                    return xmlInfo.getElementDescriptor();
                   
                } catch (Exception e) {
                    log.warn( "Could not introspect class: " + beanClass, e );
                }
            }
View Full Code Here

Examples of org.apache.commons.betwixt.XMLBeanInfo

    protected void addDescriptor( Descriptor nodeDescriptor ) throws SAXException {
        Object top = digester.peek();
        if ( top instanceof XMLBeanInfo ) {
            log.warn( "It is advisable to put an <addDefaults/> element inside an <element> tag" );
           
            XMLBeanInfo beanInfo = (XMLBeanInfo) top;
            // if there is already a root element descriptor then use it
            // otherwise use this descriptor
            if ( nodeDescriptor instanceof ElementDescriptor ) {
                ElementDescriptor elementDescriptor = (ElementDescriptor) nodeDescriptor;
                ElementDescriptor root = beanInfo.getElementDescriptor() ;
                if ( root == null ) {
                    beanInfo.setElementDescriptor( elementDescriptor );
                } else {
                    root.addElementDescriptor( elementDescriptor );
                }
            } else {
                throw new SAXException(
View Full Code Here

Examples of org.apache.commons.betwixt.XMLBeanInfo

     * Otherwise null.
     */
    protected ElementDescriptor getRootElementDescriptor() {
        Object top = digester.peek();
        if ( top instanceof XMLBeanInfo ) {
            XMLBeanInfo beanInfo = (XMLBeanInfo) top;
            return beanInfo.getElementDescriptor();
           
        } else if ( top instanceof ElementDescriptor ) {
            ElementDescriptor parent = (ElementDescriptor) top;
            // XXX: could maybe walk up the parent hierarchy?
            return parent;
View Full Code Here

Examples of org.apache.commons.betwixt.XMLBeanInfo

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

Examples of org.apache.commons.betwixt.XMLBeanInfo

                log.trace( "Registering class " + beanClass );
            }
            registeredClasses.add( beanClass );
           
            // introspect and find the ElementDescriptor to use as the root
            XMLBeanInfo xmlInfo = introspector.introspect( beanClass );
            ElementDescriptor elementDescriptor = xmlInfo.getElementDescriptor();       

            String path = elementDescriptor.getQualifiedName();
            if (log.isTraceEnabled()) {
                log.trace("Added path: " + path + ", mapped to: " + beanClass.getName());
            }
View Full Code Here

Examples of org.apache.commons.betwixt.XMLBeanInfo

    public void registerBeanClass(String path, Class beanClass) throws IntrospectionException {
        if ( ! registeredClasses.contains( beanClass ) ) {
            registeredClasses.add( beanClass );
           
            // introspect and find the ElementDescriptor to use as the root
            XMLBeanInfo xmlInfo = introspector.introspect( beanClass );
            ElementDescriptor elementDescriptor = xmlInfo.getElementDescriptor();       

            addBeanCreateRule( path, elementDescriptor, beanClass );
        } else {
            if ( log.isWarnEnabled() ) {
                log.warn("Cannot add class "  + beanClass.getName() + " since it already exists");
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.