Package org.apache.axiom.om

Examples of org.apache.axiom.om.OMElement


        Element1 element1 = new Element1();
        ComplexType1 complexType1 = new ComplexType1();
        element1.setElement1(complexType1);

        try {
            OMElement omElement = element1.getOMElement(Element1.MY_QNAME,OMAbstractFactory.getOMFactory());
            String omElementString = omElement.toStringWithConsume();
            System.out.println("OM String ==> " + omElementString);
            XMLStreamReader xmlReader = StAXUtils.createXMLStreamReader(new ByteArrayInputStream(omElementString.getBytes()));
            Element1 result = Element1.Factory.parse(xmlReader);
            assertNotNull(result);
        } catch (ADBException e) {
View Full Code Here


        ComplexType1 complexType3 = new ComplexType1();
        complexType2.setElement1(complexType3);


        try {
            OMElement omElement = element1.getOMElement(Element1.MY_QNAME,OMAbstractFactory.getOMFactory());
            String omElementString = omElement.toStringWithConsume();
            System.out.println("OM String ==> " + omElementString);
            XMLStreamReader xmlReader = StAXUtils.createXMLStreamReader(new ByteArrayInputStream(omElementString.getBytes()));
            Element1 result = Element1.Factory.parse(xmlReader);
            assertNotNull(result);
            assertNotNull(result.getElement1());
View Full Code Here

        Element2_type0 element2_type1 = new Element2_type0();
        element2_type1.setParam1("test string2");
        element2_type0.setElement2(element2_type1);

        try {
            OMElement omElement = element2.getOMElement(Element2.MY_QNAME,OMAbstractFactory.getOMFactory());
            String omElmentString = omElement.toStringWithConsume();
            System.out.println("OM element ==>" + omElmentString);
            XMLStreamReader xmlReader = StAXUtils.createXMLStreamReader(new ByteArrayInputStream(omElmentString.getBytes()));
            Element2 result = Element2.Factory.parse(xmlReader);
            assertEquals(result.getElement2().getParam1(),"test string1");
            assertEquals(result.getElement2().getElement2().getParam1(), "test string2");
View Full Code Here

//        discard_transferToken.setAuthInfo(authInfo_type1);
        discard_transferToken.setParam1("New parm");
        testSimpleReference.setTestSimpleReference(discard_transferToken);

        try {
            OMElement omElement = testSimpleReference.getOMElement(TestSimpleReference.MY_QNAME,
                    OMAbstractFactory.getOMFactory());
            String omElmentString = omElement.toStringWithConsume();
            System.out.println("OM element ==>" + omElmentString);
            XMLStreamReader xmlReader = StAXUtils.createXMLStreamReader(new ByteArrayInputStream(omElmentString.getBytes()));
            TestSimpleReference result = TestSimpleReference.Factory.parse(xmlReader);
            assertEquals(result.getTestSimpleReference().getParam1(),"New parm");
// See FIXME above:
View Full Code Here

        final Method method,
        final Object[] arguments,
        final TypeMapper typeMapper)
    {
        final Class serviceClass = method.getDeclaringClass();
        OMElement operationOMElement = null;
        try
        {
            final String operationName = method.getName();
            final String serviceName = serviceClass.getSimpleName();
            final Element operationElement = getElementByAttribute(
                    definition,
                    NAME,
                    operationName);
            final Schema operationSchema = Axis2ClientUtils.getElementSchemaByAttribute(
                    definition,
                    NAME,
                    operationName);
            if (operationSchema != null)
            {
                final OMFactory factory = OMAbstractFactory.getOMFactory();

                // - collect all the namespaces
                final Map<String, OMNamespace> namespaces = new HashMap<String, OMNamespace>();
                final OMNamespace xsiNamespace = factory.createOMNamespace(XSI_NS, XSI_PREFIX);
                namespaces.put(XSI_PREFIX, xsiNamespace);

                final Collection<Schema> schemas = getSchemas(definition);
                for (final Schema schema : schemas)
                {
                    final String namespace = Axis2ClientUtils.getTargetNamespace(schema);
                    final String prefix = getNamespacePrefix(
                            definition,
                            namespace);
                    namespaces.put(prefix, factory.createOMNamespace(namespace, prefix));
                }

                operationOMElement =
                    getOMElement(
                        definition,
                        operationSchema,
                        null,
                        null,
                        operationName,
                        factory,
                        namespaces,
                        typeMapper);
                if (operationElement == null)
                {
                    throw new RuntimeException("No operation with name '" + operationName + "' can be found on service: " +
                        serviceName);
                }
                final List argumentElements = Axis2ClientUtils.getElementsWithAttribute(
                        operationElement,
                        TYPE);
                final Class[] parameterTypes = method.getParameterTypes();
                if (argumentElements.size() != arguments.length)
                {
                    throw new RuntimeException("Operation: " + operationName + " takes " + parameterTypes.length +
                        " argument(s), and 'arguments' only contains: " + arguments.length);
                }

                // - declare all the namespaces
                operationOMElement.declareNamespace(xsiNamespace);
                for (final OMNamespace namespace : namespaces.values())
                {
                    operationOMElement.declareNamespace(namespace);
                }

                // - add the argument children
                for (int ctr = 0; ctr < argumentElements.size(); ctr++)
                {
                    final Element argument = (Element)argumentElements.get(ctr);
                    final String argumentName = getAttributeValue(
                            argument,
                            NAME);
                    final OMElement element = getOMElement(
                            definition,
                            operationSchema,
                            argument,
                            arguments[ctr],
                            argumentName,
View Full Code Here

                    definition,
                    namespace);
            omNamespace = namespaces.get(namespacePrefix);
        }

        final OMElement omElement =
            factory.createOMElement(
                elementName,
                omNamespace);
        if (bean != null && evaluatingBeans != null && !evaluatingBeans.contains(bean))
        {
            evaluatingBeans.add(bean);
            if (isSimpleType(bean, typeMapper))
            {
                omElement.addChild(factory.createOMText(typeMapper.getStringValue(bean)));
            }
            else if (bean instanceof byte[])
            {
                omElement.addChild(factory.createOMText(Base64.encode((byte[])bean)));
            }
            else
            {
                final Element currentComponentElement =
                    Axis2ClientUtils.getElementByAttribute(
                        definition,
                        NAME,
                        bean.getClass().getSimpleName());
                final Class beanType = bean.getClass();
                if (beanType.isArray())
                {
                    final Element arrayElement = Axis2ClientUtils.getRequiredElementByAttribute(
                            definition,
                            componentElement,
                            NAME,
                            elementName);
                    final Element arrayTypeElement =
                        Axis2ClientUtils.getElementByAttribute(
                            definition,
                            NAME,
                            stripPrefix(arrayElement.getAttribute(TYPE)));
                    final String arrayComponentName = Axis2ClientUtils.getAttributeValueFromChildElement(
                            arrayTypeElement,
                            NAME,
                            0);
                    for (int ctr = 0; ctr < Array.getLength(bean); ctr++)
                    {
                        omElement.addChild(
                            getOMElement(
                                definition,
                                schema,
                                currentComponentElement,
                                Array.get(
                                    bean,
                                    ctr),
                                arrayComponentName,
                                factory,
                                namespaces,
                                typeMapper,
                                evaluatingBeans));
                    }
                }
                else
                {


                    final String attributeValue = omNamespace != null ?
                        omNamespace.getPrefix() + NS_SEPARATOR + beanType.getSimpleName() : beanType.getSimpleName();
                    // - add the xsi:type attribute for complex types
                    omElement.addAttribute(TYPE, attributeValue, namespaces.get(XSI_PREFIX));
                }
                try
                {
                    final java.util.Map properties = PropertyUtils.describe(bean);
                    for (final Iterator iterator = properties.keySet().iterator(); iterator.hasNext();)
                    {
                        final String name = (String)iterator.next();
                        if (!CLASS.equals(name))
                        {
                            final Object value = properties.get(name);
                            if (value != null)
                            {
                                omElement.addChild(
                                    getOMElement(
                                        definition,
                                        schema,
                                        currentComponentElement,
                                        value,
View Full Code Here

            if (type.isArray())
            {
                final Collection<Object> elements = new ArrayList<Object>();
                for (final Iterator iterator = element.getChildElements(); iterator.hasNext();)
                {
                    OMElement omElement = (OMElement)iterator.next();
                    elements.add(deserialize(
                            omElement,
                            type.getComponentType(),
                            typeMapper));
                }
                bean =
                    elements.toArray((Object[])Array.newInstance(
                            type.getComponentType(),
                            0));
            }
            else
            {
                try
                {
                    type = getAppropriateType(element, type);
                    bean = typeMapper.getObject(type);
                    final java.beans.PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors(type);
                    for (int ctr = 0; ctr < descriptors.length; ctr++)
                    {
                        final java.beans.PropertyDescriptor descriptor = descriptors[ctr];
                        final String name = descriptor.getName();
                        if (!CLASS.equals(name))
                        {
                            final OMElement propertyElement = findElementByName(
                                    element,
                                    name);

                            if (propertyElement != null)
                            {
View Full Code Here

     */
    private static OMElement findElementByName(
        final OMElement element,
        final String name)
    {
        OMElement found = null;
        for (final Iterator iterator = element.getChildElements(); iterator.hasNext();)
        {
            final OMElement child = (OMElement)iterator.next();
            if (child.getLocalName().equals(name))
            {
                found = child;
                break;
            }
        }
View Full Code Here

        Object[] arguments)
    {
        final Method method = this.getMethod(
                operationName,
                arguments);
        OMElement omElement = this.getOperationElement(method, arguments);
        Object result = null;
        try
        {
            OMElement response = this.serviceClient.sendReceive(omElement);
            if (method.getReturnType() != void.class)
            {
                result =
                    Axis2ClientUtils.deserialize(
                        response.getFirstElement(),
                        method.getReturnType(),
                        this.typeMapper);
            }
            omElement = null;
            response = null;
View Full Code Here

     * @param arguments the arguments of the method
     * @return the found operation element
     */
    private OMElement getOperationElement(final Method method, Object[] arguments)
    {
        OMElement element = null;
        synchronized (this.definitionMonitor)
        {
            element =
                Axis2ClientUtils.getOperationOMElement(
                    this.definition,
View Full Code Here

TOP

Related Classes of org.apache.axiom.om.OMElement

Copyright © 2015 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.