Package org.apache.commons.betwixt

Examples of org.apache.commons.betwixt.ElementDescriptor


  public void pushElement(String elementName) throws Exception {

    elementMappingStack.push(elementName);
    // special case to ensure that root class is appropriately marked
    //TODO: is this really necessary?
        ElementDescriptor nextDescriptor = null;
    if (elementMappingStack.size() == 1 && rootClass != null) {
      markClassMap(rootClass);
            XMLBeanInfo rootClassInfo
                = getXMLIntrospector().introspect(rootClass);
            nextDescriptor = rootClassInfo.getElementDescriptor();
    } else {
            ElementDescriptor currentDescriptor = getCurrentDescriptor();
            if (currentDescriptor != null) {
                nextDescriptor = currentDescriptor.getElementDescriptor(elementName);
            }
        }
        Updater updater = null;
        Options options = null;
        if (nextDescriptor != null) {
View Full Code Here


            mappedClazz = mappedClazz.getComponentType();
        }
    elementMappingStack.push(mappedClazz);
       
        XMLBeanInfo mappedClassInfo = getXMLIntrospector().introspect(mappedClazz);
        ElementDescriptor mappedElementDescriptor = mappedClassInfo.getElementDescriptor();
        descriptorStack.push(mappedElementDescriptor);
       
        Updater updater = mappedElementDescriptor.getUpdater();
        updaterStack.push(updater);
  }
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

     * @return <code>ElementDescriptor</code> or null if there is no
     * current mapping
     * @throws Exception
     */
  public ElementDescriptor getCurrentDescriptor() throws Exception {
    ElementDescriptor result = null;
        if (!descriptorStack.empty()) {
            result = (ElementDescriptor) descriptorStack.peek();
        }
    return result;
  }
View Full Code Here

     */
    public Class resolvePolymorphicType(ElementMapping mapping) {
        Class result = null;
        Log log = getLog();
        try {
            ElementDescriptor currentDescriptor = getCurrentDescriptor();
            if (currentDescriptor != null) {
                if (currentDescriptor.isPolymorphic()) {
                    PolymorphicReferenceResolver resolver = getXMLIntrospector().getPolymorphicReferenceResolver();
                    result = resolver.resolveType(mapping, this);
                    if (result == null) {
                        // try the other polymorphic descriptors
                        ElementDescriptor parent = getParentDescriptor();
                        if (parent != null) {
                            ElementDescriptor[] descriptors = parent.getElementDescriptors();
                            ElementDescriptor originalDescriptor = mapping.getDescriptor();
                            boolean resolved = false;
                            for (int i=0; i<descriptors.length;i++) {
                                ElementDescriptor descriptor = descriptors[i];
                                if (descriptor.isPolymorphic()) {
                                    mapping.setDescriptor(descriptor);
                                    result = resolver.resolveType(mapping, this);
                                    if (result != null) {
                                        resolved = true;
                                        descriptorStack.pop();
                                        popOptions();
                                        descriptorStack.push(descriptor);
                                        pushOptions(descriptor.getOptions());
                                        Updater originalUpdater = originalDescriptor.getUpdater();
                                        Updater newUpdater = descriptor.getUpdater();
                                        substituteUpdater(originalUpdater, newUpdater);
                                        break;
                                    }
                                }
                            }
View Full Code Here

     */
    public void begin(String name, String namespace, Attributes attributes)
            throws SAXException {
        String nameAttributeValue = attributes.getValue("name");

        ElementDescriptor descriptor = new ElementDescriptor();
        descriptor.setLocalName(nameAttributeValue);
        String uri = attributes.getValue("uri");
        String qName = nameAttributeValue;
        if (uri != null && nameAttributeValue != null) {
            descriptor.setURI(uri);
            String prefix = getXMLIntrospector().getConfiguration()
                    .getPrefixMapper().getPrefix(uri);
            qName = prefix + ":" + nameAttributeValue;
        }
        descriptor.setQualifiedName(qName);

        String propertyName = attributes.getValue("property");
        descriptor.setPropertyName(propertyName);

        String propertyType = attributes.getValue("type");

        if (log.isTraceEnabled()) {
            log.trace("(BEGIN) name=" + nameAttributeValue + " uri=" + uri
                    + " property=" + propertyName + " type=" + propertyType);
        }

        // set mapping derivation
        String mappingDerivation = attributes.getValue("mappingDerivation");
        if ("introspection".equals(mappingDerivation)) {
            descriptor.setUseBindTimeTypeForMapping(false);
        } else if ("bind".equals(mappingDerivation)) {
            descriptor.setUseBindTimeTypeForMapping(true);
        }

        // set the property type using reflection
        descriptor.setPropertyType(getPropertyType(propertyType, beanClass,
                propertyName));

        boolean isCollective = getXMLIntrospector().getConfiguration()
                .isLoopType(descriptor.getPropertyType());

        descriptor.setCollective(isCollective);

        // check that the name attribute is present
        if (!isCollective
                && (nameAttributeValue == null || nameAttributeValue.trim()
                        .equals(""))) {
            // allow polymorphic mappings but log note for user
            log
                    .info("No name attribute has been specified. This element will be polymorphic.");
        }

        // check that name is well formed
        if (nameAttributeValue != null
                && !XMLUtils.isWellFormedXMLName(nameAttributeValue)) {
            throw new SAXException("'" + nameAttributeValue
                    + "' would not be a well formed xml element name.");
        }

        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) {
            boolean forceAccessible = "true".equals(attributes
                    .getValue("forceAccessible"));
            configureDescriptor(descriptor, attributes.getValue("updater"),
                    forceAccessible);

        } 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();
            descriptor.setPropertyType(beanClass);

        } 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

     * @since 0.7
     */
    public Class resolveType(ElementMapping mapping, ReadContext context) {
        Class result = null;
        Collection cachedClasses = getCachedClasses();
        ElementDescriptor mappedDescriptor = mapping.getDescriptor();
        Class mappedType = mappedDescriptor.getSingularPropertyType();
        if (mappedType == null) {
            mappedType = mappedDescriptor.getPropertyType();
        }
        for (Iterator it = cachedClasses.iterator(); it.hasNext();) {
            XMLBeanInfo  beanInfo  = get((Class)it.next());
            ElementDescriptor typeDescriptor = beanInfo.getElementDescriptor();
            boolean sameName = mapping.getName().equals(typeDescriptor.getQualifiedName());
            if (sameName)
            {
               
                boolean compatibleClass = mappedType.isAssignableFrom(beanInfo.getBeanClass());
                if (compatibleClass ) {
View Full Code Here

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

            // check for element suppression
            if( getXMLIntrospector().getConfiguration().getElementSuppressionStrategy().suppress(descriptor)) {
                parent.removeElementDescriptor(descriptor);
            }
        }
    }
View Full Code Here

            writeMethod = null;

            if (Map.class.isAssignableFrom(type)) {
                elementDescriptor.setLocalName("entry");
                // add elements for reading
                ElementDescriptor keyDescriptor = new ElementDescriptor("key");
                keyDescriptor.setHollow(true);
                elementDescriptor.addElementDescriptor(keyDescriptor);

                ElementDescriptor valueDescriptor = new ElementDescriptor(
                        "value");
                valueDescriptor.setHollow(true);
                elementDescriptor.addElementDescriptor(valueDescriptor);
            }

        } else {
            log.trace("Standard property");
View Full Code Here

            ReadContext context)
            throws Exception {
            // TODO: i'm not too sure about this part of the design
            // i'm not sure whether base should give base behaviour or if it should give standard behaviour
            // i'm hoping that things will become clearer once the descriptor logic has been cleared
            ElementDescriptor descriptor = context.getCurrentDescriptor();
            if (descriptor != null) {

                AttributeDescriptor[] attributeDescriptors =
                    descriptor.getAttributeDescriptors();
                context.populateAttributes(attributeDescriptors, attributes);
            }
            return this;
        }
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.