Package org.apache.commons.betwixt

Examples of org.apache.commons.betwixt.ElementDescriptor


               
       
                // 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


        }
       
        // 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( currentDescriptor );
        //ElementDescriptor typeDescriptor = descriptor;

       
        ElementDescriptor[] childDescriptors = typeDescriptor.getElementDescriptors();
        if ( childDescriptors != null ) {
            for ( int i = 0, size = childDescriptors.length; i < size; i++ ) {
                final ElementDescriptor childDescriptor = childDescriptors[i];
                if (log.isTraceEnabled()) {
                    log.trace("Processing child " + childDescriptor);
                }
               
                String qualifiedName = childDescriptor.getQualifiedName();
                if ( qualifiedName == null ) {
                    log.trace( "Ignoring" );
                    continue;
                }
                String path = prefix + qualifiedName;
                // this code is for making sure that recursive elements
                // can also be used..
               
                if ( qualifiedName.equals( currentDescriptor.getQualifiedName() )
                        && currentDescriptor.getPropertyName() != null ) {
                    log.trace("Creating generic rule for recursive elements");
                    int index = -1;
                    if (childDescriptor.isWrapCollectionsInElement()) {
                        index = prefix.indexOf(qualifiedName);
                        if (index == -1) {
                            // shouldn't happen..
                            log.debug( "Oops - this shouldn't happen" );
                            continue;
                        }
                        int removeSlash = prefix.endsWith("/")?1:0;
                        path = "*/" + prefix.substring(index, prefix.length()-removeSlash);
                    }else{
                        // we have a element/element type of thing..
                        ElementDescriptor[] desc = currentDescriptor.getElementDescriptors();
                        if (desc.length == 1) {
                            path = "*/"+desc[0].getQualifiedName();
                        }
                    }
                    Rule rule = new BeanCreateRule( childDescriptor, context, path, matchIDs);
                    addRule(path, rule);
                    continue;
                }
                if ( childDescriptor.getUpdater() != null ) {
                    if (log.isTraceEnabled()) {
                        log.trace("Element has updater "
                         + ((MethodUpdater) childDescriptor.getUpdater()).getMethod().getName());
                    }
                    if ( childDescriptor.isPrimitiveType() ) {
                        addPrimitiveTypeRule(path, childDescriptor);
                       
                    } else {
                        // add the first child to the path
                        ElementDescriptor[] grandChildren = childDescriptor.getElementDescriptors();
                        if ( grandChildren != null && grandChildren.length > 0 ) {
                            ElementDescriptor grandChild = grandChildren[0];
                            String grandChildQName = grandChild.getQualifiedName();
                            if ( grandChildQName != null && grandChildQName.length() > 0 ) {
                                if (childDescriptor.isWrapCollectionsInElement()) {
                                    path += '/' + grandChildQName;
                                   
                                } else {
View Full Code Here

            }
        }

        Object top = digester.peek();
        if ( top instanceof ElementDescriptor ) {
            ElementDescriptor parent = (ElementDescriptor) top;
            parent.addAttributeDescriptor( descriptor );
        } else {
            throw new SAXException( "Invalid use of <attribute>. It should "
                + "be nested inside an <element> element" );
        }           
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( currentDescriptor );
            //ElementDescriptor typeDescriptor = descriptor;
   
           
            ElementDescriptor[] childDescriptors = typeDescriptor.getElementDescriptors();
            if ( childDescriptors != null ) {
                for ( int i = 0, size = childDescriptors.length; i < size; i++ ) {
                    final ElementDescriptor childDescriptor = childDescriptors[i];
                    if (log.isTraceEnabled()) {
                        log.trace("Processing child " + childDescriptor);
                    }
                   
                    String qualifiedName = childDescriptor.getQualifiedName();
                    if ( qualifiedName == null ) {
                        log.trace( "Ignoring" );
                        continue;
                    }
                    String path = prefix + qualifiedName;
                    // this code is for making sure that recursive elements
                    // can also be used..
                   
                    if ( qualifiedName.equals( currentDescriptor.getQualifiedName() )
                            && currentDescriptor.getPropertyName() != null ) {
                        log.trace("Creating generic rule for recursive elements");
                        int index = -1;
                        if (childDescriptor.isWrapCollectionsInElement()) {
                            index = prefix.indexOf(qualifiedName);
                            if (index == -1) {
                                // shouldn't happen..
                                log.debug( "Oops - this shouldn't happen" );
                                continue;
                            }
                            int removeSlash = prefix.endsWith("/")?1:0;
                            path = "*/" + prefix.substring(index, prefix.length()-removeSlash);
                            if (log.isTraceEnabled()) {
                                log.trace("Added wrapped rule for " + childDescriptor);
                            }
                        } else {
                            // we have a element/element type of thing..
                            ElementDescriptor[] desc = currentDescriptor.getElementDescriptors();
                            if (desc.length == 1) {
                                path = "*/"+desc[0].getQualifiedName();
                            }
                            if (log.isTraceEnabled()) {
                                log.trace("Added not wrapped rule for " + childDescriptor);
                            }
                        }
                        addRule( path, childDescriptor, context );
                        continue;
                    }
                    if ( childDescriptor.getUpdater() != null ) {
                        if (
                            log.isTraceEnabled()
                            && childDescriptor.getUpdater() instanceof MethodUpdater) {
                           
                            log.trace("Element has updater "
                            + ((MethodUpdater) childDescriptor.getUpdater()).getMethod().getName());
                        }
                        if ( childDescriptor.isPrimitiveType() ) {
                            addPrimitiveTypeRule( path, childDescriptor, context );
                           
                        } else {
                            // add the first child to the path
                            ElementDescriptor[] grandChildren
                                = childDescriptor.getElementDescriptors();
                            if ( grandChildren != null && grandChildren.length > 0 ) {
                                ElementDescriptor grandChild = grandChildren[0];
                                String grandChildQName = grandChild.getQualifiedName();
                                if ( grandChildQName != null && grandChildQName.length() > 0 ) {
                                    if (childDescriptor.isWrapCollectionsInElement()) {
                                        path += '/' + grandChildQName;
                                        if (log.isTraceEnabled()) {
                                            log.trace(
View Full Code Here

           
            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 instance = null;
                // 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 );
                if ( typeDescriptor.getUpdater() == null && beanClass == null ) {
                    // we try to get the instance from the context.
                    instance = context.getBean();
                    if ( instance == null ) {
                        return;
                    }
                } else {
                    instance = createBean( namespace, name, attributes );
                    if ( instance != null ) {
                        createdBean = true;
                        context.setBean( instance );
                        digester.push( instance );
                    } else {
                        // we don't do anything if the instance is null.
                        return;
                    }
                }
       
                // 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

                    log.trace("Body with text " + text);
                }
                if ( digester.getCount() > 0 ) {
                    Context bodyContext = context.newContext( digester.peek() );
                    // Take the first content descriptor
                    ElementDescriptor typeDescriptor = getElementDescriptor( descriptor );
                    TextDescriptor descriptor = typeDescriptor.getPrimaryBodyTextDescriptor();
                    if ( descriptor != null ) {
                        if ( log.isTraceEnabled() ) {
                            log.trace("Setting mixed content for:");
                            log.trace(descriptor);
                        }
View Full Code Here

        // check that name is well formed
        if ( !XMLUtils.isWellFormedXMLName( name ) ) {
            throw new SAXException("'" + name + "' would not be a well formed xml element name.");
        }
       
        ElementDescriptor descriptor = new ElementDescriptor();
        descriptor.setQualifiedName( name );
        descriptor.setLocalName( name );
        String uri = attributes.getValue( "uri" );
        if ( uri != null ) {
            descriptor.setURI( uri );       
        }
       
        String propertyName = attributes.getValue( "property" );
        descriptor.setPropertyName( propertyName );
       
        String propertyType = attributes.getValue( "type" );
       
        if (log.isTraceEnabled()) {
            log.trace(
                    "(BEGIN) name=" + name + " uri=" + uri
                    + " property=" + propertyName + " type=" + propertyType);
        }
       
        // set the property type using reflection
        descriptor.setPropertyType(
            getPropertyType( propertyType, beanClass, propertyName )
        );
       
        String implementationClass = attributes.getValue( "class" );
        if ( log.isTraceEnabled() ) {
            log.trace("'class' attribute=" + implementationClass);
        }
        if ( implementationClass != null ) {
            try {
               
                Class clazz = Class.forName(implementationClass);
                descriptor.setImplementationClass( clazz );
               
            } catch (Exception e)  {
                if ( log.isDebugEnabled() ) {
                    log.debug("Cannot load class named: " + implementationClass, e);
                }
                throw new SAXException("Cannot load class named: " + implementationClass);
            }
        }
       
        if ( propertyName != null && propertyName.length() > 0 ) {
            configureDescriptor(descriptor, attributes.getValue( "updater" ));
           
        } else {
            String value = attributes.getValue( "value" );
            if ( value != null ) {
                descriptor.setTextExpression( new ConstantExpression( value ) );
            }
        }
       
        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 );
           
        } else {
            throw new SAXException( "Invalid use of <element>. It should "
                + "be nested inside <info> or other <element> nodes" );
        }
View Full Code Here

            }
            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());
            }
            addBeanCreateRule( path, elementDescriptor, beanClass );
           
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.