Skip to main content
summaryrefslogtreecommitdiffstats
blob: 155b44bc9626c9d92d98ed29b70a737cc6f83b94 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*******************************************************************************
 * Copyright (c) 2001, 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.wst.wsdl.internal.util;

import java.util.Iterator;

import org.eclipse.emf.common.notify.impl.AdapterImpl;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.wst.wsdl.Definition;
import org.eclipse.wst.wsdl.XSDSchemaExtensibilityElement;
import org.eclipse.xsd.XSDSchema;
import org.eclipse.xsd.util.XSDSchemaLocator;

public class XSDSchemaLocatorImpl extends AdapterImpl implements XSDSchemaLocator
{
    /**
     * @see org.eclipse.xsd.util.XSDSchemaLocator#locateSchema(org.eclipse.xsd.XSDSchema,
     *      java.lang.String, java.lang.String, java.lang.String)
     */
    public XSDSchema locateSchema(XSDSchema xsdSchema, String namespaceURI, String rawSchemaLocationURI, String resolvedSchemaLocationURI)
    {
      XSDSchema resolvedSchema = null;

      // Bugzilla 122624:  WSDL model does not resolve <import> of inline schema with no namespace.
      // KB: We are not resolving <import>ed or <include>d schemas from the root inline schemas.
      // In other words, since we are resolving only between multiple root inline schemas,
      // do not attempt to resolve if "rawSchemaLocationURI" is not null. 
      if (namespaceURI != null && rawSchemaLocationURI == null)
      {
        Definition definition = null;

        for (EObject parent = xsdSchema.eContainer(); parent != null; parent = parent.eContainer())
        {
          if (parent instanceof Definition)
          {
            definition = (Definition) parent;
            break;
          }
        }

        if (definition != null && definition.getETypes() != null)
        {
          for (Iterator i = definition.getETypes().getEExtensibilityElements().iterator(); i.hasNext();)
          {
            Object o = i.next();
            if (o instanceof XSDSchemaExtensibilityElement)
            {
              XSDSchema schema = ((XSDSchemaExtensibilityElement) o).getSchema();
              if (schema != null && namespaceURI.equals(schema.getTargetNamespace()))
              {
                resolvedSchema = schema;
                break;
              }
            }
          }
        }
      }
      return resolvedSchema;      
    }

    public boolean isAdatperForType(Object type)
    {
      return type == XSDSchemaLocator.class;
    }  
}

Back to the top