public void getParametersFromParts()

in axis-rt-core/src/main/java/org/apache/axis/wsdl/symbolTable/SymbolTable.java [2102:2309]


    public void getParametersFromParts(Vector v,
                                       Collection parts,
                                       boolean literal,
                                       String opName,
                                       BindingEntry bindingEntry)
            throws IOException {

        // Determine if there's only one element.  For wrapped
        // style, we normally only have 1 part which is an
        // element.  But with MIME we could have any number of
        // types along with that single element.  As long as
        // there's only ONE element, and it's the same name as
        // the operation, we can unwrap it.
        int numberOfElements = 0;
        boolean possiblyWrapped = false;
        Iterator i = parts.iterator();

        while (i.hasNext()) {
            Part part = (Part) i.next();

            if (part.getElementName() != null) {
                ++numberOfElements;

                if (part.getElementName().getLocalPart().equals(opName)) {
                    possiblyWrapped = true;
                }
            }
        }

        // Try to sense "wrapped" document literal mode
        // if we haven't been told not to.
        // Criteria:
        // - If there is a single element part,
        // - That part is an element
        // - That element has the same name as the operation
        // - That element has no attributes (check done below)

        if (!nowrap && literal && (numberOfElements == 1) && possiblyWrapped) {
            wrapped = true;
        }

        i = parts.iterator();

        while (i.hasNext()) {
            Parameter param = new Parameter();
            Part part = (Part) i.next();
            QName elementName = part.getElementName();
            QName typeName = part.getTypeName();
            String partName = part.getName();

            // if we are either:
            //   1. encoded
            //   2. literal & not wrapped.
            if (!literal || !wrapped || (elementName == null)) {
                param.setName(partName);

                // Add this type or element name
                if (typeName != null) {
                    param.setType(getType(typeName));
                } else if (elementName != null) {

                    // Just an FYI: The WSDL spec says that for use=encoded
                    // that parts reference an abstract type using the type attr
                    // but we kinda do the right thing here, so let it go.
                    // if (!literal)
                    // error...
                    param.setType(getElement(elementName));
                } else {

                    // no type or element
                    throw new IOException(
                            Messages.getMessage(
                                    "noTypeOrElement00", new String[]{partName,
                                                                      opName}));
                }

                fillParamInfo(param, bindingEntry, opName, partName);
                v.add(param);

                continue;    // next part
            }

            // flow to here means wrapped literal !
            // See if we can map all the XML types to java(?) types
            // if we can, we use these as the types
            Node node = null;
            TypeEntry typeEntry = null;

            if ((typeName != null)
                    && (bindingEntry == null || bindingEntry.getMIMETypes().size() == 0)) {

                // Since we can't (yet?) make the Axis engine generate the right
                // XML for literal parts that specify the type attribute,
                // (unless they're MIME types) abort processing with an
                // error if we encounter this case
                //
                // node = getTypeEntry(typeName, false).getNode();
                String bindingName = (bindingEntry == null)
                        ? "unknown"
                        : bindingEntry.getBinding().getQName().toString();

                throw new IOException(Messages.getMessage("literalTypePart00",
                        new String[]{
                            partName,
                            opName,
                            bindingName}));
            }

            // Get the node which corresponds to the type entry for this
            // element.  i.e.:
            // <part name="part" element="foo:bar"/>
            // ...
            // <schema targetNamespace="foo">
            // <element name="bar"...>  <--- This one
            typeEntry = getTypeEntry(elementName, true);
            node = typeEntry.getNode();

            // Check if this element is of the form:
            // <element name="foo" type="tns:foo_type"/>
            BooleanHolder forElement = new BooleanHolder();
            QName type = Utils.getTypeQName(node, forElement,
                    false);
            if ((type != null) && !forElement.value) {

                // If in fact we have such a type, go get the node that
                // corresponds to THAT definition.
                typeEntry = getTypeEntry(type, false);
                node = typeEntry.getNode();
            }

            Vector vTypes = null;

            // If we have nothing at this point, we're in trouble.
            if (node == null) {
              // If node is null, that means the element in question has no type declaration,
              // therefore is not a wrapper element.
              wrapped = false;
                if (verbose) {
                    System.out.println(Messages.getMessage("cannotDoWrappedMode00", elementName.toString()));
                }
            } else {

                // check for attributes
                if (typeEntry.getContainedAttributes() != null) {
                    // can't do wrapped mode
                    wrapped = false;
                }

                if (!SchemaUtils.isWrappedType(node)) {
                    // mark the type entry as not just literal referenced
                    // This doesn't work, but it may help in the future.
                    // The problem is "wrapped" is a symbol table wide flag,
                    // which means if one operation breaks the rules
                    // implemented in isWrappedType(), then everything goes bad
                    // For example, see bug Axis-1900.
                    typeEntry.setOnlyLiteralReference(false);
                    wrapped = false;
                }

                // Get the nested type entries.
                // TODO - If we are unable to represent any of the types in the
                // element, we need to use SOAPElement/SOAPBodyElement.
                // I don't believe getContainedElementDecl does the right thing yet.
                vTypes = typeEntry.getContainedElements();
            }

            // IF we got the type entries and we didn't find attributes
            // THEN use the things in this element as the parameters
            if ((vTypes != null) && wrapped) {

                // add the elements in this list
                for (int j = 0; j < vTypes.size(); j++) {
                    ElementDecl elem = (ElementDecl) vTypes.elementAt(j);
                    Parameter p = new Parameter();

                    p.setQName(elem.getQName());
                    // If the parameter is a anonymous complex type, the parameter
                    // name should just be the name of the element, not >foo>element
                    String paramName = p.getName();
                    final int gt = paramName.lastIndexOf(ANON_TOKEN);
                    if (gt != 1) {
                        paramName = paramName.substring(gt+1);
                    }
                    p.setName(paramName);
                    p.setType(elem.getType());
                    p.setOmittable(elem.getMinOccursIs0());
                    p.setNillable(elem.getNillable());
                    fillParamInfo(p, bindingEntry, opName, partName);
                    v.add(p);
                }
            } else {

                // - we were unable to get the types OR
                // - we found attributes
                // so we can't use wrapped mode.
                param.setName(partName);

                if (typeName != null) {
                    param.setType(getType(typeName));
                } else if (elementName != null) {
                    param.setType(getElement(elementName));
                }

                fillParamInfo(param, bindingEntry, opName, partName);
                v.add(param);
            }
        }                    // while
    }                        // getParametersFromParts