Package org.codehaus.xfire.aegis.type

Examples of org.codehaus.xfire.aegis.type.Type


            while (reader.hasMoreAttributeReaders())
            {
                MessageReader childReader = reader.getNextAttributeReader();
                QName name = childReader.getName();

                Type type = info.getType(name);

                if (type != null)
                {
                    Object writeObj = type.readObject(childReader, context);
                    if (isProxy)
                    {
                        delegate.writeProperty(name.getLocalPart(), writeObj);
                    }
                    else
                    {
                        writeProperty(name, object, writeObj, clazz, info);
                    }
                }
            }

            // Read child elements
            while (reader.hasMoreElementReaders())
            {
                MessageReader childReader = reader.getNextElementReader();
                QName name = childReader.getName();

                BeanType parent = getBeanTypeWithProperty(name);
                Type defaultType = null;
                if (parent != null)
                {
                    info = parent.getTypeInfo();
                    defaultType = info.getType(name);
                }
                else
                {
                  defaultType = null;
                }
               
                Type type = AegisBindingProvider.getReadType(childReader.getXMLStreamReader(),
                    context, defaultType, getTypeMapping());
               
                if (type != null)
                {
                    if (!childReader.isXsiNil())
                    {
                        Object writeObj = type.readObject(childReader, context);

                        if (isProxy)
                        {
                            delegate.writeProperty(name.getLocalPart(), writeObj);
                        }
View Full Code Here


        root.addContent(complex);

        Element seq = new Element("sequence", SoapConstants.XSD_PREFIX, SoapConstants.XSD);
        complex.addContent(seq);

        Type keyType = getKeyType();
        Type valueType = getValueType();

        Element element = new Element("element", SoapConstants.XSD_PREFIX, SoapConstants.XSD);
        seq.addContent(element);

        element.setAttribute(new Attribute("name", getEntryName().getLocalPart()));
View Full Code Here

            QName name = (QName) itr.next();

            Object value = readProperty(object, name);
            if (value != null)
            {
                Type type = getType(info, name);

                if (type == null)
                    throw new XFireRuntimeException("Couldn't find type for " + value.getClass()
                            + " for property " + name);

                MessageWriter cwriter = writer.getAttributeWriter(name);

                type.writeObject(value, cwriter, context);

                cwriter.close();
            }
        }

        for (Iterator itr = info.getElements(); itr.hasNext();)
        {
            QName name = (QName) itr.next();

            if (info.isExtension()
                    && info.getPropertyDescriptorFromMappedName(name).getReadMethod()
                            .getDeclaringClass() != info.getTypeClass())
            {
                continue;
            }
            Object value = readProperty(object, name);

            Type type = getType(info, name);
            type = AegisBindingProvider.getWriteType(context, value, type);
            MessageWriter cwriter;

            // Write the value if it is not null.
            if (value != null)
            {
                cwriter = getWriter(writer, name, type);

                if (type == null)
                    throw new XFireRuntimeException("Couldn't find type for " + value.getClass()
                            + " for property " + name);

                type.writeObject(value, cwriter, context);

                cwriter.close();
            }
            else if (info.isNillable(name))
            {
                cwriter = getWriter(writer, name, type);

                // Write the xsi:nil if it is null.
                cwriter.writeXsiNil();

                cwriter.close();
            }
        }
        if (info.isExtension())
        {
            Type t = getSuperType();
            if (t != null)
            {
                t.writeObject(object, writer, context);
            }
        }
    }
View Full Code Here

        BeanTypeInfo info = getTypeInfo();
        Element complex = new Element("complexType", SoapConstants.XSD_PREFIX, SoapConstants.XSD);
        complex.setAttribute(new Attribute("name", getSchemaType().getLocalPart()));
        root.addContent(complex);

        Type sooperType = getSuperType();

        /*
         * See Java Virtual Machine specification:
         * http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html#75734
         */
        if (((info.getTypeClass().getModifiers() & Modifier.ABSTRACT) != 0) &&
                !info.getTypeClass().isInterface())
        {
            complex.setAttribute(new Attribute("abstract", "true"));
        }

        if (info.isExtension() && sooperType != null)
        {
            Element complexContent = new Element("complexContent", SoapConstants.XSD_PREFIX,
                    SoapConstants.XSD);
            complex.addContent(complexContent);
            complex = complexContent;
        }

        /*
         * Decide if we're going to extend another type. If we are going to
         * defer, then make sure that we extend the type for our superclass.
         */
        boolean isExtension = info.isExtension();

        Element dummy = complex;

        if (isExtension && sooperType != null)
        {

            Element extension = new Element("extension", SoapConstants.XSD_PREFIX,
                    SoapConstants.XSD);
            complex.addContent(extension);
            QName baseType = sooperType.getSchemaType();
            extension.setAttribute(new Attribute("base", getNameWithPrefix2(root, baseType
                    .getNamespaceURI(), baseType.getLocalPart())));

            dummy = extension;
        }

        Element seq = null;

        // Write out schema for elements
        for (Iterator itr = info.getElements(); itr.hasNext();)
        {

            QName name = (QName) itr.next();

            if (isExtension)
            {
                PropertyDescriptor pd = info.getPropertyDescriptorFromMappedName(name);

                assert pd.getReadMethod() != null && pd.getWriteMethod() != null;
                if (pd.getReadMethod().getDeclaringClass() != info.getTypeClass())
                {
                    continue;
                }
            }

            if (seq == null)
            {
                seq = new Element("sequence", SoapConstants.XSD_PREFIX, SoapConstants.XSD);
                dummy.addContent(seq);
            }

            Element element = new Element("element", SoapConstants.XSD_PREFIX, SoapConstants.XSD);
            seq.addContent(element);

            Type type = getType(info, name);

            String nameNS = name.getNamespaceURI();
            String nameWithPrefix = getNameWithPrefix(root, nameNS, name.getLocalPart());

            String prefix = NamespaceHelper.getUniquePrefix((Element) root.getParent(), type
                    .getSchemaType().getNamespaceURI());

            writeTypeReference(name, nameWithPrefix, element, type, prefix);
        }

        /**
         * if future proof then add <xsd:any/> element
         */
        if (info.isExtensibleElements())
        {
            if (seq == null)
            {
                seq = new Element("sequence", SoapConstants.XSD_PREFIX, SoapConstants.XSD);
                dummy.addContent(seq);
            }
            seq.addContent(createAnyElement());
        }

        // Write out schema for attributes
        for (Iterator itr = info.getAttributes(); itr.hasNext();)
        {
            QName name = (QName) itr.next();

            Element element = new Element("attribute", SoapConstants.XSD_PREFIX, SoapConstants.XSD);
            dummy.addContent(element);

            Type type = getType(info, name);

            String nameNS = name.getNamespaceURI();
            String nameWithPrefix = getNameWithPrefix(root, nameNS, name.getLocalPart());

            String prefix = NamespaceHelper.getUniquePrefix((Element) root.getParent(), type
                    .getSchemaType().getNamespaceURI());
            element.setAttribute(new Attribute("name", nameWithPrefix));
            element.setAttribute(new Attribute("type", prefix + ':'
                    + type.getSchemaType().getLocalPart()));
        }

        /**
         * If extensible attributes then add <xsd:anyAttribute/>
         */
 
View Full Code Here

        return prefix + ":" + localName;
    }

    private Type getType(BeanTypeInfo info, QName name)
    {
        Type type = info.getType(name);

        if (type == null)
        {
            throw new NullPointerException("Couldn't find type for" + name + " in class "
                    + getTypeClass().getName());
View Full Code Here

        /*
         * Automagically add chain of superclasses *if* this is an an extension.
         */
        if (info.isExtension())
        {
            Type sooperType = getSuperType();
            if (sooperType != null)
            {
                deps.add(sooperType);
            }
        }
View Full Code Here

    }

    private BeanType getBeanTypeWithProperty(QName name)
    {
        BeanType sooper = this;
        Type type = null;

        while (type == null && sooper != null)
        {
            type = sooper.getTypeInfo().getType(name);
View Full Code Here

   
        try
        {
            Collection list = (Collection) object;

            Type type = getComponentType();

            if (type == null)
                throw new XFireRuntimeException("Couldn't find type.");

            for (Iterator itr = list.iterator(); itr.hasNext();)
            {
                String ns = null;
                if (type.isAbstract())
                    ns = getSchemaType().getNamespaceURI();
                else
                    ns = type.getSchemaType().getNamespaceURI();

                writeValue(itr.next(), writer, context, type, type.getSchemaType().getLocalPart(), ns);
            }
        }
        catch (IllegalArgumentException e)
        {
            throw new XFireRuntimeException("Illegal argument.", e);
View Full Code Here

        if( null == typeName  && !readToDocument )
        {
            throw new XFireFault( "Missing 'xsi:type' attribute value", XFireFault.SENDER);
        }

        Type type = null;
    QName typeQName = null;
    if (typeName != null)
        {
            typeQName = extractQName(reader, typeName);
        }
        else
        {
            typeQName = reader.getName();
        }

        TypeMapping tm = (TypeMapping) context.getService().getProperty(AegisBindingProvider.TYPE_MAPPING_KEY);
        if (tm == null)
        {
            tm = getTypeMapping();
        }
       
        type = tm.getType( typeQName );
       
        if (type == null)
        {
            type = tm.getType(getSchemaType());
        }

        if (type == null && readToDocument)
    {
      type = getTypeMapping().getType(Document.class);
    }

        if( null == type )
        {
            //TODO should check namespace as well..
            if( serializedWhenUnknown && "serializedJavaObject".equals( typeName ) )
            {
                return reconstituteJavaObject( reader );
            }

            throw new XFireFault( "No mapped type for '" + typeName + "' (" + typeQName + ")", XFireFault.SENDER);
        }

        return type.readObject( reader, context );
    }
View Full Code Here

            nilWriter.close();
        }
        else
        {
            Type type = determineType( context, object.getClass() );

            if( null == type )
            {
              TypeMapping tm = (TypeMapping) context.getService().getProperty(AegisBindingProvider.TYPE_MAPPING_KEY);
                if (tm == null)
                {
                    tm = getTypeMapping();
                }
               
              type = tm.getTypeCreator().createType(object.getClass());
                tm.register(type);
            }
           
            String prefix = writer.getPrefixForNamespace( type.getSchemaType().getNamespaceURI() );

            if( null == prefix || prefix.length() == 0 )
            {
                addXsiType( writer, type.getSchemaType().getLocalPart() );
            }
            else
            {
                addXsiType( writer, prefix + ":" + type.getSchemaType().getLocalPart() );
            }

            type.writeObject( object, writer, context );
        }
    }
View Full Code Here

TOP

Related Classes of org.codehaus.xfire.aegis.type.Type

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.