Package org.apache.commons.betwixt

Examples of org.apache.commons.betwixt.ElementDescriptor


           
            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(
                    "the <addDefaults> element should be within an <element> tag" );
            }
        } else if ( top instanceof ElementDescriptor ) {
            ElementDescriptor parent = (ElementDescriptor) top;
            if ( nodeDescriptor instanceof ElementDescriptor ) {
                parent.addElementDescriptor( (ElementDescriptor) nodeDescriptor );
            } else {
                parent.addAttributeDescriptor( (AttributeDescriptor) nodeDescriptor );
            }
        } else {
            throw new SAXException(
                "Invalid use of <addDefaults>. It should be nested inside <element> element" );
        }           
View Full Code Here


        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;
        }
        return null;
    }
View Full Code Here

                      Object bean,
                      Context context,
                      XMLBeanInfo beanInfo)
                      throws IOException, SAXException, IntrospectionException {
        if ( beanInfo != null ) {
            ElementDescriptor elementDescriptor = beanInfo.getElementDescriptor();
            if ( elementDescriptor != null ) {
               
                // Construct the options
                Options combinedOptions = new Options();

                // Add options defined by the current bean's element descriptor
                combinedOptions.addOptions(elementDescriptor.getOptions());
               
                // The parent descriptor may have defined options
                // for the current bean.  These options take precedence
                // over the options of the current class descriptor
                if( context.getOptions() != null) {
                    combinedOptions.addOptions(context.getOptions());
                }
                context = context.newContext( bean );
                context.pushOptions(combinedOptions);
               
                if ( qualifiedName == null ) {
                    qualifiedName = elementDescriptor.getQualifiedName();
                }
                if ( namespaceUri == null ) {
                    namespaceUri = elementDescriptor.getURI();
                }
                if ( localName == null ) {
                    localName = elementDescriptor.getLocalName();
                }

                String ref = null;
                String id = null;
               
                // simple type should not have IDs
                if ( elementDescriptor.isSimple() ) {
                    // 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;
                    childContext.pushOptions(childDescriptor.getOptions());
                    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,
                                            childDescriptor,
                                            context );
                                }
                            } else {
                                writeBean(
                                            namespaceUri,
                                            localName,
                                            qualifiedName,
                                            childBean,
                                            childDescriptor,
                                            context );
                            }
                        }                   
                    } else {
                        writeElement(
                                    childDescriptor.getURI(),
                                    childDescriptor.getLocalName(),
                                    childDescriptor.getQualifiedName(),
                                    childDescriptor,
                                    childContext );
                    }
                    childContext.popOptions();
                } else {
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

               
       
                // if we are a reference to a type we should lookup the original
                // as this ElementDescriptor will be 'hollow' and have no child attributes/elements.
                // XXX: this should probably be done by the NodeDescriptors...
                ElementDescriptor typeDescriptor = getElementDescriptor( descriptor );
                //ElementDescriptor typeDescriptor = descriptor;
       
                // iterate through all attributes       
                AttributeDescriptor[] attributeDescriptors
                    = typeDescriptor.getAttributeDescriptors();
                if ( attributeDescriptors != null ) {
                    for ( int i = 0, size = attributeDescriptors.length; i < size; i++ ) {
                        AttributeDescriptor attributeDescriptor = attributeDescriptors[i];
                       
                        // The following isn't really the right way to find the attribute
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.