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


        ReadContext context)
                    throws Exception {
                       
        Log log = context.getLog();

        ElementDescriptor computedDescriptor = context.getCurrentDescriptor();

        if (log.isTraceEnabled()) {
            log.trace("Element Pushed: " + name);
        }

        // default to ignoring the current element
        MappingAction action = MappingAction.EMPTY;

        Object instance = null;
        Class beanClass = null;
        if (computedDescriptor == null) {
            log.trace("No Descriptor");
        } else {
            beanClass = computedDescriptor.getSingularPropertyType();
        }
        // TODO: this is a bit of a workaround
        // need to come up with a better way of doing maps
        if (beanClass != null && !Map.class.isAssignableFrom(beanClass)) {

            instance =
                createBean(
                    namespace,
                    name,
                    attributes,
                    computedDescriptor,
                    context);
                   
            if (instance != null) {
                action = this;
                if (computedDescriptor.isUseBindTimeTypeForMapping())
                {
                    beanClass = instance.getClass();
                }
                context.markClassMap(beanClass);

                if (log.isTraceEnabled()) {
                    log.trace("Marked: " + beanClass);
                }

                context.pushBean(instance);

                // 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(computedDescriptor, context);

                // iterate through all attributes       
                AttributeDescriptor[] attributeDescriptors =
                    typeDescriptor.getAttributeDescriptors();
                context.populateAttributes(attributeDescriptors, attributes);

                if (log.isTraceEnabled()) {
                    log.trace("Created bean " + instance);
                }
View Full Code Here


    public void body(String text, ReadContext context) throws Exception {
        Log log = context.getLog();
        // Take the first content descriptor
        ElementDescriptor currentDescriptor = context.getCurrentDescriptor();
        if (currentDescriptor == null) {
            if (log.isTraceEnabled()) {
                log.trace("path descriptor is null:");
            }
        } else {
            TextDescriptor bodyTextdescriptor =
                currentDescriptor.getPrimaryBodyTextDescriptor();
            if (bodyTextdescriptor != null) {
                if (log.isTraceEnabled()) {
                    log.trace("Setting mixed content for:");
                    log.trace(bodyTextdescriptor);
                }
View Full Code Here

     *         If more than one descriptor matches, then the best match is returned.
     */
    public ElementDescriptor findPluralDescriptor( String propertyName, Map map ) {
        int foundKeyCount = 0;
        String keyFound = null;
        ElementDescriptor answer = (ElementDescriptor) map.get( propertyName + "s" );

        if ( answer == null && !propertyName.endsWith( "y" )) {
            answer = (ElementDescriptor) map.get( propertyName + "es" );
        }

        if ( answer == null ) {
            int length = propertyName.length();
            if ( propertyName.endsWith( "y" ) && length > 1 ) {
                String key = propertyName.substring(0, length - 1) + "ies";               
                answer = (ElementDescriptor) map.get( key );            
            }
           
            if ( answer == null ) {
                // lets find the first one that starts with the propertyName
                for ( Iterator iter = map.keySet().iterator(); iter.hasNext(); ) {
                    String key = (String) iter.next();
                    if ( key.startsWith( propertyName ) ) {
                        if (answer == null) {
                            answer = (ElementDescriptor) map.get(key);
                            if (key.equals(propertyName)) {
                                // we found the best match..
                                break;
                            }
                            foundKeyCount++;
                            keyFound = key;
                           
                        } else {
                            // check if we have a better match,,
                            if (keyFound.length() > key.length()) {
                                answer = (ElementDescriptor) map.get(key);
                                keyFound = key;
                            }
                            foundKeyCount++;

                        }
                    }
                }
            }
        }
        if (foundKeyCount > 1) {
            log.warn("More than one type matches, using closest match "+answer.getQualifiedName());
        }
        return answer;
       
    }
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

    /**
     * Process the end of this element.
     */
    public void end(String name, String namespace) {
        AttributeDescriptor descriptor = (AttributeDescriptor)digester.pop();
        ElementDescriptor parent = (ElementDescriptor)digester.peek();

        // check for attribute suppression
        if( getXMLIntrospector().getConfiguration().getAttributeSuppressionStrategy().suppress(descriptor)) {
            parent.removeAttributeDescriptor(descriptor);
        }
    }
View Full Code Here

                            Attributes attributes,
                            ReadContext context)
        throws Exception {
        MappingAction result = MappingAction.EMPTY;
           
        ElementDescriptor activeDescriptor = context.getCurrentDescriptor();
        if (activeDescriptor != null) {
            if (activeDescriptor.isHollow()) {
                if (isArrayDescriptor(activeDescriptor)) {
                    result = ArrayBindAction.createMappingAction(activeDescriptor);
                } else {
                    result = BeanBindAction.INSTANCE;
                }
            }
            else if (activeDescriptor.isSimple())
            {
                result = SimpleTypeBindAction.INSTANCE;
            }
            else
            {
                ElementDescriptor[] descriptors
                    = activeDescriptor.getElementDescriptors();
                if (descriptors.length == 1) {
                    ElementDescriptor childDescriptor = descriptors[0];
                    if (childDescriptor.isHollow()
                            && isArrayDescriptor(childDescriptor)) {
                        result = ArrayBindAction.createMappingAction(childDescriptor);
                    }
                }
            }
View Full Code Here

            log.trace( "Registering class " + beanClass );
        }
        XMLBeanInfo xmlInfo = introspector.introspect( beanClass );
        registeredClasses.add( beanClass );

        ElementDescriptor elementDescriptor = xmlInfo.getElementDescriptor();       

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

        }
        return lastMapped;
  }

    private ElementDescriptor getParentDescriptor() throws IntrospectionException {
        ElementDescriptor result = null;
        if (descriptorStack.size() > 1) {
            result = (ElementDescriptor) descriptorStack.peek(1);
        }
        return result;
    }
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

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.