[ 
https://issues.apache.org/jira/browse/AXIS2-2395?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12502898
 ] 

Aaron Gourley commented on AXIS2-2395:
--------------------------------------

I have encountered another issue with this method.  Axis2 1.2 included a fix 
that was similar to Jeff's proposal, but it has a fundamental flaw.  It only 
returns the element if it is contained in the last schema, otherwise it will 
return null.  This caused me to be unable to generate unwrapped code using 
WSDL2Java.

I locally applied this code change and it fixed my problem:

public XmlSchemaElement getSchemaElement() {
    XmlSchemaElement xmlSchemaElement = null;
    AxisService service = (AxisService) getParent().getParent();
    ArrayList schemas = service.getSchema();
    for (Iterator schemaIter = schemas.iterator(); schemaIter.hasNext();){
        xmlSchemaElement = getSchemaElement((XmlSchema) schemaIter.next());
        if( xmlSchemaElement != null )
        {
            return xmlSchemaElement;
        }
    }
    return xmlSchemaElement;
}

> AxisMessage.getSchema() returns null when schema element is found in an 
> imported schema
> ---------------------------------------------------------------------------------------
>
>                 Key: AXIS2-2395
>                 URL: https://issues.apache.org/jira/browse/AXIS2-2395
>             Project: Axis 2.0 (Axis2)
>          Issue Type: Bug
>          Components: kernel
>    Affects Versions: 1.2, 1.1.1
>         Environment: All
>            Reporter: Jeff Faath
>            Assignee: Deepal Jayasinghe
>            Priority: Minor
>
> When calling getSchema() on an AxisMessage, 'null' is returned when the 
> schema element is found in an imported schema.  This is because the code does 
> not check imported schema.  I've devised a solution below which recursively 
> traverses any imported schema.  The original getSchema() method can be 
> replaced by the two methods below:
> public XmlSchemaElement getSchemaElement() {
>   AxisService service = (AxisService) getParent().getParent();
>     ArrayList schemas = service.getSchema();
>     for (int i = 0; i < schemas.size(); i++) {
>       XmlSchema schema = (XmlSchema) schemas.get(i);
>       return getSchemaElement(schema);
>     }
>     return null;
> }
> private XmlSchemaElement getSchemaElement(XmlSchema schema) {
>   XmlSchemaElement returnElement = null;
>   if (schema != null) {
>     if (schema.getItems() != null) {
>       Iterator schemaItems = schema.getItems().getIterator();
>       while (schemaItems.hasNext()) {
>         Object item = schemaItems.next();
>         if (item instanceof XmlSchemaElement) {
>           XmlSchemaElement xmlSchemaElement = (XmlSchemaElement) item;
>           if (xmlSchemaElement.getQName().equals(this.elementQname)) {
>             returnElement = xmlSchemaElement;
>           }
>         }
>        else if (item instanceof org.apache.ws.commons.schema.XmlSchemaImport) 
> {
>          returnElement = 
> getSchemaElement(((org.apache.ws.commons.schema.XmlSchemaImport)item).getSchema());
>        }
>        else if (item instanceof 
> org.apache.ws.commons.schema.XmlSchemaInclude) {
>          returnElement = 
> getSchemaElement(((org.apache.ws.commons.schema.XmlSchemaInclude)item).getSchema());
>        }
>        // We've found a matching element, no need to continue...
>        if (returnElement != null)
>          break;
>        }
>      }
>    }
>    return returnElement;
>  }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to