Package org.apache.commons.betwixt

Examples of org.apache.commons.betwixt.ElementDescriptor


               
            });
       
        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();
       
        assertEquals("Expected no attributes", 0, attributeDescriptor.length);
        assertEquals("Expected one elements", 1, children.length);
        assertEquals("Expected element", "name", children[0].getLocalName());
   
View Full Code Here


        introspector.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);
        assertEquals("Expected one elements", 1, children.length);
        assertEquals("Expected element", "name", children[0].getLocalName());
    }     
View Full Code Here

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

        }
       
        // 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,
View Full Code Here

        if ( childDescriptors != null && childDescriptors.length > 0 ) {
            // process child elements
            for ( int i = 0, size = childDescriptors.length; i < size; i++ ) {
                if (childDescriptors[i] instanceof ElementDescriptor) {
                    // Element content
                    ElementDescriptor childDescriptor = (ElementDescriptor) childDescriptors[i];
                    Context childContext = context;
                    Expression childExpression = childDescriptor.getContextExpression();
                    if ( childExpression != null ) {
                        Object childBean = childExpression.evaluate( context );
                        if ( childBean != null ) {
                            String qualifiedName = childDescriptor.getQualifiedName();
                            String namespaceUri = childDescriptor.getURI();
                            String localName = childDescriptor.getLocalName();
                            // XXXX: should we handle nulls better
                            if ( childBean instanceof Iterator ) {
                                for ( Iterator iter = (Iterator) childBean; iter.hasNext(); ) {
                                    Object object = iter.next();
                                    if (object == null) {
                                        continue;
                                    }
                                    writeBean(
                                            namespaceUri,
                                            localName,
                                            qualifiedName,
                                            object,
                                            context );
                                }
                            } else {
                                writeBean(
                                            namespaceUri,
                                            localName,
                                            qualifiedName,
                                            childBean,
                                            context );
                            }
                        }                   
                    } else {
                        writeElement(
                                    childDescriptor.getURI(),
                                    childDescriptor.getLocalName(),
                                    childDescriptor.getQualifiedName(),
                                    childDescriptor,
                                    childContext );
                    }
                } else {
                    // Mixed text content
View Full Code Here

                nodeDescriptor = new AttributeDescriptor();
            } else {
                if (log.isTraceEnabled()) {
                    log.trace( "Adding property as element: " + name );
                }
                nodeDescriptor = new ElementDescriptor(true);
            }
            nodeDescriptor.setTextExpression( new MethodExpression( readMethod ) );
           
            if ( writeMethod != null ) {
                nodeDescriptor.setUpdater( new MethodUpdater( writeMethod ) );
            }
        } else if ( isLoopType( type ) ) {
            if (log.isTraceEnabled()) {
                log.trace("Loop type: " + name);
                log.trace("Wrap in collections? " + introspector.isWrapCollectionsInElement());
            }
            ElementDescriptor loopDescriptor = new ElementDescriptor();
            loopDescriptor.setContextExpression(
                new IteratorExpression( new MethodExpression( readMethod ) )
            );
            loopDescriptor.setWrapCollectionsInElement(
                        introspector.isWrapCollectionsInElement());
            // XXX: need to support some kind of 'add' or handle arrays, Lists or indexed properties
            //loopDescriptor.setUpdater( new MethodUpdater( writeMethod ) );
            if ( Map.class.isAssignableFrom( type ) ) {
                loopDescriptor.setQualifiedName( "entry" );
                // add elements for reading
                loopDescriptor.addElementDescriptor( new ElementDescriptor( "key" ) );
                loopDescriptor.addElementDescriptor( new ElementDescriptor( "value" ) );
            }

            ElementDescriptor elementDescriptor = new ElementDescriptor();
            elementDescriptor.setWrapCollectionsInElement(
                        introspector.isWrapCollectionsInElement());
            elementDescriptor.setElementDescriptors( new ElementDescriptor[] { loopDescriptor } );
           
            nodeDescriptor = elementDescriptor;           
        } else {
            if (log.isTraceEnabled()) {
                log.trace( "Standard property: " + name);
            }
            ElementDescriptor elementDescriptor = new ElementDescriptor();
            elementDescriptor.setContextExpression( new MethodExpression( readMethod ) );
            if ( writeMethod != null ) {
                elementDescriptor.setUpdater( new MethodUpdater( writeMethod ) );
            }
           
            nodeDescriptor = elementDescriptor;         
        }
View Full Code Here

   
                            // now lets try find the ElementDescriptor which displays
                            // a property which starts with propertyName
                            // and if so, we'll set a new Updater on it if there
                            // is not one already
                            ElementDescriptor descriptor =
                                findGetCollectionDescriptor(
                                                            introspector,
                                                            rootDescriptor,
                                                            propertyName );
   
                            if ( log.isDebugEnabled() ) {
                                log.debug( "!! " + propertyName + " -> " + descriptor );
                                log.debug( "!! " + name + " -> "
                                + (descriptor!=null?descriptor.getPropertyName():"") );
                            }
                            if ( descriptor != null ) {
                                boolean isMapDescriptor
                                    = Map.class.isAssignableFrom( descriptor.getPropertyType() );
                                if ( !isMapDescriptor && types.length == 1 ) {
                                    // this may match a standard collection or iteration
                                    log.trace("Matching collection or iteration");
                                   
                                    descriptor.setUpdater( new MethodUpdater( method ) );
                                    descriptor.setSingularPropertyType( types[0] );
                                   
                                    if ( log.isDebugEnabled() ) {
                                        log.debug( "!! " + method);
                                        log.debug( "!! " + types[0]);
                                    }
                                   
                                    // is there a child element with no localName
                                    ElementDescriptor[] children
                                        = descriptor.getElementDescriptors();
                                    if ( children != null && children.length > 0 ) {
                                        ElementDescriptor child = children[0];
                                        String localName = child.getLocalName();
                                        if ( localName == null || localName.length() == 0 ) {
                                            child.setLocalName(
                                                introspector.getElementNameMapper()
                                                    .mapTypeToElementName( propertyName ) );
                                        }
                                    }
View Full Code Here

            map.put(propertyName, rootDescriptor);
        }
        makeElementDescriptorMap( rootDescriptor, map );
       
        PluralStemmer stemmer = introspector.getPluralStemmer();
        ElementDescriptor elementDescriptor = stemmer.findPluralDescriptor( propertyName, map );
       
        if ( log.isTraceEnabled() ) {
            log.trace(
                "findPluralDescriptor( " + propertyName
                    + " ):ElementDescriptor=" + elementDescriptor );
View Full Code Here

     */
    protected static void makeElementDescriptorMap( ElementDescriptor rootDescriptor, Map map ) {
        ElementDescriptor[] children = rootDescriptor.getElementDescriptors();
        if ( children != null ) {
            for ( int i = 0, size = children.length; i < size; i++ ) {
                ElementDescriptor child = children[i];               
                String propertyName = child.getPropertyName();               
                if ( propertyName != null ) {
                    map.put( propertyName, child );
                }
                makeElementDescriptorMap( child, map );
            }
View Full Code Here

                                ElementDescriptor oldValue,
                                ElementDescriptor newValue ) {
        ElementDescriptor[] children = rootDescriptor.getElementDescriptors();
        if ( children != null ) {
            for ( int i = 0, size = children.length; i < size; i++ ) {
                ElementDescriptor child = children[i];
                if ( child == oldValue ) {
                    children[i] = newValue;
                    break;
                }
                swapDescriptor( child, oldValue, newValue );
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.