Package org.apache.axis.utils

Examples of org.apache.axis.utils.BeanPropertyDescriptor


        } else {
            BeanPropertyDescriptor[] pd = BeanUtils.getPd(javaType, null);
            propertyMap = new HashMap();
            // loop through properties and grab the names for later
            for (int i = 0; i < pd.length; i++) {
                BeanPropertyDescriptor descriptor = pd[i];
                propertyMap.put(descriptor.getName(), descriptor);
            }
        }

        return propertyMap;
    }
View Full Code Here


                                    DeserializationContext context)
        throws SAXException
    {
        handleMixedContent();

        BeanPropertyDescriptor propDesc = null;
        FieldDesc fieldDesc = null;

        SOAPConstants soapConstants = context.getSOAPConstants();
        String encodingStyle = context.getEncodingStyle();
        boolean isEncoded = Constants.isSOAP_ENC(encodingStyle);

        QName elemQName = new QName(namespace, localName);
        // The collectionIndex needs to be reset for Beans with multiple arrays
        if ((prevQName == null) || (!prevQName.equals(elemQName))) {
            collectionIndex = -1;
       
        prevQName = elemQName;

        if (typeDesc != null) {      
            // Lookup the name appropriately (assuming an unqualified
            // name for SOAP encoding, using the namespace otherwise)
            String fieldName = typeDesc.getFieldNameForElement(elemQName,
                                                               isEncoded);
            propDesc = (BeanPropertyDescriptor)propertyMap.get(fieldName);
            fieldDesc = typeDesc.getFieldByName(fieldName);
        }

        if (propDesc == null) {
            // look for a field by this name.
            propDesc = (BeanPropertyDescriptor) propertyMap.get(localName);
        }

        // try and see if this is an xsd:any namespace="##any" element before
        // reporting a problem
        if (propDesc == null) {
            // try to put unknown elements into a SOAPElement property, if
            // appropriate
            propDesc = getAnyPropertyDesc();
            if (propDesc != null) {
                try {
                    MessageElement [] curElements = (MessageElement[])propDesc.get(value);
                    int length = 0;
                    if (curElements != null) {
                        length = curElements.length;
                    }
                    MessageElement [] newElements = new MessageElement[length + 1];
                    if (curElements != null) {
                        System.arraycopy(curElements, 0,
                                         newElements, 0, length);
                    }
                    MessageElement thisEl = context.getCurElement();

                    newElements[length] = thisEl;
                    propDesc.set(value, newElements);
                    // if this is the first pass through the MessageContexts
                    // make sure that the correct any element is set,
                    // that is the child of the current MessageElement, however
                    // on the first pass this child has not been set yet, so
                    // defer it to the child SOAPHandler
                    if (!localName.equals(thisEl.getName())) {
                        return new SOAPHandler(newElements, length);
                    }
                    return new SOAPHandler();
                } catch (Exception e) {
                    throw new SAXException(e);
                }
            }
        }


        if (propDesc == null) {
            // No such field
            throw new SAXException(
                    Messages.getMessage("badElem00", javaType.getName(),
                                         localName));
        }

        // Get the child's xsi:type if available
        QName childXMLType = context.getTypeFromAttributes(namespace,
                                                            localName,
                                                            attributes);

        String href = attributes.getValue(soapConstants.getAttrHref());

        // If no xsi:type or href, check the meta-data for the field
        if (childXMLType == null && fieldDesc != null && href == null) {
            childXMLType = fieldDesc.getXmlType();
        }
       
        // Get Deserializer for child, default to using DeserializerImpl
        Deserializer dSer = getDeserializer(childXMLType, propDesc.getType(),
                                            href,
                                            context);

        // It is an error if the dSer is not found - the only case where we
        // wouldn't have a deserializer at this point is when we're trying
        // to deserialize something we have no clue about (no good xsi:type,
        // no good metadata).
        if (dSer == null) {
            dSer = context.getDeserializerForClass(propDesc.getType());
        }

        // Fastpath nil checks...
        if (context.isNil(attributes)) {
            if (propDesc != null && propDesc.isIndexed()) {
                if (!((dSer != null) && (dSer instanceof ArrayDeserializer)) ||
                        propDesc.getType().isArray()) {
                    collectionIndex++;
                    dSer.registerValueTarget(new BeanPropertyTarget(value,
                            propDesc, collectionIndex));
                    addChildDeserializer(dSer);
                    return (SOAPHandler)dSer;
                }
            }
            return null;
        }           
         
        if (dSer == null) {
            throw new SAXException(Messages.getMessage("noDeser00",
                                                       childXMLType.toString()));
        }

        if (constructorToUse != null) {
            if (constructorTarget == null) {
                constructorTarget = new ConstructorTarget(constructorToUse, this);
            }
            dSer.registerValueTarget(constructorTarget);
        } else if (propDesc.isWriteable()) {        // Register value target
            // If this is an indexed property, and the deserializer we found
            // was NOT the ArrayDeserializer, this is a non-SOAP array:
            // <bean>
            //   <field>value1</field>
            //   <field>value2</field>
            // ...
            // In this case, we want to use the collectionIndex and make sure
            // the deserialized value for the child element goes into the
            // right place in the collection.
            if (propDesc.isIndexed() && (
                    !(dSer instanceof ArrayDeserializer) ||
                    propDesc.getType().isArray())) {
                    collectionIndex++;
                    dSer.registerValueTarget(new BeanPropertyTarget(value,
                                                    propDesc, collectionIndex));
            } else {
                // If we're here, the element maps to a single field value,
View Full Code Here

        } else if (value instanceof QName) {
            return context.qName2String((QName)value);
        }

        if (propertyDescriptor != null && !(value instanceof SimpleType)) {
            BeanPropertyDescriptor pd = BeanUtils.getSpecificPD(propertyDescriptor, "_value");
            if(pd != null) {
                try {
                    return pd.get(value).toString();
                } catch (Exception e) {
                }
            }
        }
        return value.toString();
View Full Code Here

                    }
                }
                continue;
            }

            BeanPropertyDescriptor bpd = propertyDescriptor[i];
            Class type = bpd.getType();
            // Attribute must extend a simple type, enum or SimpleType
            if (!types.isAcceptableAsAttribute(type)) {
                throw new AxisFault(Messages.getMessage("AttrNotSimpleType01",
                        type.getName()));
            }
View Full Code Here

                        }
                    }
                }
            }

            BeanPropertyDescriptor anyDesc = typeDesc == null ? null :
                    typeDesc.getAnyDesc();
            if (anyDesc != null) {
                // If we have "extra" content here, it'll be an array
                // of MessageElements.  Serialize each one.
                Object anyVal = anyDesc.get(value);
                if (anyVal != null && anyVal instanceof MessageElement[]) {
                    MessageElement [] anyContent = (MessageElement[])anyVal;
                    for (int i = 0; i < anyContent.length; i++) {
                        MessageElement element = anyContent[i];
                        element.output(context);
View Full Code Here

                continue;

            FieldDesc fieldDesc = typeDesc.getFieldByName(fieldName);
           
            // look for the attribute property
            BeanPropertyDescriptor bpd =
                    (BeanPropertyDescriptor) propertyMap.get(fieldName);
            if (bpd != null) {
                if (constructorToUse == null) {
                    // check only if default constructor
                    if (!bpd.isWriteable() || bpd.isIndexed()) continue ;
                }
               
                // Get the Deserializer for the attribute
                Deserializer dSer = getDeserializer(fieldDesc.getXmlType(),
                                                    bpd.getType(),
                                                    null,
                                                    context);
                if (dSer == null) {
                    dSer = context.getDeserializerForClass(bpd.getType());
                }
                if (dSer == null)
                    throw new SAXException(
                            Messages.getMessage("unregistered00",
                                                 bpd.getType().toString()));
               
                if (! (dSer instanceof SimpleDeserializer))
                    throw new SAXException(
                            Messages.getMessage("AttrNotSimpleType00",
                                                 bpd.getName(),
                                                 bpd.getType().toString()));
               
                // Success!  Create an object from the string and set
                // it in the bean
                try {
                    dSer.onStartElement(namespace, localName, prefix,
                                        attributes, context);
                    Object val = ((SimpleDeserializer)dSer).
                        makeValue(attributes.getValue(i));
                    if (constructorToUse == null) {
                        bpd.set(value, val);
                    } else {
                        // add value for our constructor
                        if (constructorTarget == null) {
                            constructorTarget = new ConstructorTarget(constructorToUse, this);
                        }
View Full Code Here

                             DeserializationContext context) throws SAXException {
        handleMixedContent();
    }

    protected void handleMixedContent() throws SAXException {
        BeanPropertyDescriptor propDesc = getAnyPropertyDesc();
        if (propDesc == null || val.size() == 0) {
            return;
        }
        String textValue = val.toString().trim();
        val.reset();
        if (textValue.length() == 0) {
            return;
        }
        try {
            MessageElement[] curElements = (MessageElement[]) propDesc.get(value);
            int length = 0;
            if (curElements != null) {
                length = curElements.length;
            }
            MessageElement[] newElements = new MessageElement[length + 1];
            if (curElements != null) {
                System.arraycopy(curElements, 0,
                        newElements, 0, length);
            }
            MessageElement thisEl = new MessageElement(new org.apache.axis.message.Text(textValue));
            newElements[length] = thisEl;
            propDesc.set(value, newElements);
        } catch (Exception e) {
            throw new SAXException(e);
        }
    }
View Full Code Here

                    }
                }
                continue;
            }

            BeanPropertyDescriptor bpd = propertyDescriptor[i];
            Class type = bpd.getType();
            // Attribute must extend a simple type, enum or SimpleType
            if (!types.isAcceptableAsAttribute(type)) {
                throw new AxisFault(JavaUtils.getMessage("AttrNotSimpleType01",
                        type.getName()));
            }           
View Full Code Here

        this.typeDesc = typeDesc;
        // Get a list of the bean properties
        BeanPropertyDescriptor[] pd = BeanUtils.getPd(javaType, typeDesc);
        // loop through properties and grab the names for later
        for (int i = 0; i < pd.length; i++) {
            BeanPropertyDescriptor descriptor = pd[i];
            propertyMap.put(descriptor.getName(), descriptor);
        }
        // create a value
        try {
            value=javaType.newInstance();
        } catch (Exception e) {
View Full Code Here

                                    String prefix,
                                    Attributes attributes,
                                    DeserializationContext context)
        throws SAXException
    {
        BeanPropertyDescriptor propDesc = null;
       
        QName elemQName = new QName(namespace, localName);
        // The collectionIndex needs to be reset for Beans with multiple arrays
        if ((prevQName == null) || (!prevQName.equals(elemQName))) {
            prevQName = elemQName;
            collectionIndex = -1;
       
        prevQName = elemQName;

        if (typeDesc != null) {      
           
            // First lookup the field using the target namespace context
            // and local name.  If this fails and the incoming element
            // name is not prefixed, lookup the name assuming an unqualified
            // name.
            String fieldName = typeDesc.getFieldNameForElement(elemQName,
                                                               false);
            if (fieldName == null && (prefix == null || prefix.equals(""))) {
                fieldName =
                    typeDesc.getFieldNameForElement(
                      new QName("", elemQName.getLocalPart()), false);
            }

            propDesc = (BeanPropertyDescriptor)propertyMap.get(fieldName);
        }

        if (propDesc == null) {
            // look for a field by this name.
            propDesc = (BeanPropertyDescriptor) propertyMap.get(localName);
        }

        // Currently the meta data does not consider inheritance.
        // Glen is working on a fix.  In the meantime, the following
        // code attempts to get the meta data from the base class. 
        // (this fix does not work in all cases, but is necessary to
        // get comprehensive tests Animal - Cat inheritance to work).
        if (propDesc == null) {
            Class superClass = javaType;
            while (superClass != null && propDesc == null) {
                superClass = superClass.getSuperclass();
                if (superClass != null) {
                    TypeDesc td = TypeDesc.getTypeDescForClass(superClass);
                    if (td != null) {
                        String fieldName =
                            td.getFieldNameForElement(elemQName,
                                                      false);
                        if (fieldName == null &&
                            (prefix == null || prefix.equals(""))) {
                            fieldName =
                                td.getFieldNameForElement(
                                new QName("", elemQName.getLocalPart()), false);
                        }
                       
                        propDesc =
                            (BeanPropertyDescriptor)propertyMap.get(fieldName);
                    }
                }
            }
        }
        // try and see if this is an xsd:any namespace="##any" element before reporting a problem
        QName qn = null;
        Deserializer dSer = null;
        MessageContext messageContext = context.getMessageContext();
        if (propDesc == null && !messageContext.isEncoded()) {
            // try to put unknown elements into an Object property
            propDesc = getObjectPropertyDesc(elemQName, context);
            if (propDesc != null) {
                Boolean deserializeAny =  (Boolean) messageContext.getProperty(DESERIALIZE_ANY);
                if ((deserializeAny != null) && (deserializeAny.booleanValue())) {
                  dSer = context.getDeserializerForType(elemQName);
                }
                if (dSer == null)  {
                    qn = Constants.XSD_ANY;
                    // make sure that the Element Deserializer deserializes the current element and not the child
                    messageContext.setProperty(ElementDeserializer.DESERIALIZE_CURRENT_ELEMENT, Boolean.TRUE);
                } else {
                    qn = elemQName;
                }
            }
        }


        if (propDesc == null) {
            // No such field
            throw new SAXException(
                    JavaUtils.getMessage("badElem00", javaType.getName(),
                                         localName));
        }

        // Determine the QName for this child element.
        // Look at the type attribute specified.  If this fails,
        // use the javaType of the property to get the type qname.
        if (qn == null) {
            qn = context.getTypeFromAttributes(namespace, localName, attributes);
        }
       
        // get the deserializer
        if (dSer == null) {
            dSer = context.getDeserializerForType(qn);
        }
       
        // If no deserializer, use the base DeserializerImpl.
        // There may not be enough information yet to choose the
        // specific deserializer.
        if (dSer == null) {
            dSer = new DeserializerImpl();
            // determine a default type for this child element
            TypeMapping tm = context.getTypeMapping();
            Class type = propDesc.getType();
            dSer.setDefaultType(tm.getTypeQName(type));
        }
               
        if (propDesc.isWriteable()) {
            if (!propDesc.isIndexed()) {
                // Success!  Register the target and deserializer.
                collectionIndex = -1;
                dSer.registerValueTarget(
                                         new BeanPropertyTarget(value, propDesc));
            } else {
View Full Code Here

TOP

Related Classes of org.apache.axis.utils.BeanPropertyDescriptor

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.