Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: 108c163373bcf90663c1540e53f843f1a1e380cd (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*******************************************************************************
 * Copyright (c) 2001, 2006 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.ui.internal.util;

import java.util.Iterator;

import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolverPlugin;
import org.eclipse.wst.common.uriresolver.internal.util.URIHelper;
import org.eclipse.wst.wsdl.Definition;
import org.eclipse.wst.wsdl.Import;
import org.eclipse.wst.wsdl.Types;
import org.eclipse.wst.wsdl.XSDSchemaExtensibilityElement;
import org.eclipse.wst.wsdl.internal.impl.WSDLElementImpl;
import org.eclipse.wst.wsdl.internal.util.WSDLModelLocator;
import org.eclipse.xsd.XSDSchema;
import org.eclipse.xsd.XSDSchemaDirective;
import org.w3c.dom.Element;


public class WSDLResourceUtil
{
  public static void reloadDirectives(Definition definition)
  {
    Resource rootResource = definition.eResource();
    ResourceSet resourceSet = rootResource.getResourceSet();

    for (Iterator i = resourceSet.getResources().iterator(); i.hasNext();)
    {
      Resource resource = (Resource) i.next();
      if (resource != rootResource)
      {
        //  TODO... consider unloading the resources  	
        //  resource.unload();		      
        i.remove();
      }
    }
    ReloadDirectiveVisitor visitor = new ReloadDirectiveVisitor();
    visitor.visitDefinition(definition);
  }

  static class ReloadDirectiveVisitor
  {

    public void visitImport(Import theImport)
    {
      // force the import to reload
      Element element = WSDLEditorUtil.getInstance().getElementForObject(theImport);
      if (element != null)
      {
        ((WSDLElementImpl)theImport).elementChanged(element);
      }
    }

    public void visitXSDSchemaDirective(XSDSchemaDirective directive)
    {
      // force the schema directive to reload
      Element element = directive.getElement();
      if (element != null)
      {
        directive.elementAttributesChanged(element);
      }
    }

    public void visitDefinition(Definition definition)
    {
      if (definition != null)
      {
        for (Iterator i = definition.getEImports().iterator(); i.hasNext();)
        {
          visitImport((Import) i.next());
        }
        Types types = definition.getETypes();
        if (types != null)
        {

          for (Iterator i = types.getEExtensibilityElements().iterator(); i.hasNext();)
          {
            Object o = i.next();
            if (o instanceof XSDSchemaExtensibilityElement)
            {
              XSDSchemaExtensibilityElement e = (XSDSchemaExtensibilityElement) o;
              if (e.getSchema() != null)
              {
                visitSchema(e.getSchema());
              }
            }
          }
        }
      }
    }

    public void visitSchema(XSDSchema schema)
    {
      for (Iterator i = schema.getContents().iterator(); i.hasNext();)
      {
        Object o = i.next();
        if (o instanceof XSDSchemaDirective)
        {
          visitXSDSchemaDirective((XSDSchemaDirective) o);
        }
      }
    }
  }


  public static class InternalURIResolver implements WSDLModelLocator
  {
    //IdResolver idResolver = new IdResolverImpl(null, true);
    org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver resolver = URIResolverPlugin.createResolver();

    InternalURIResolver()
    {  
    }

    public String resolveURI(String baseLocation, String namespace, String location)
    {
      String resolvedLocation = resolver.resolve(baseLocation, namespace, location);

      // here's an ugly hack... Platform.resolve() returns Windows files with the pattern "file:D:/hello.xsd"
      // but EMF's URI class expects a pattern like this "file:///D:/hello.xsd"
      //        
      if (resolvedLocation != null)
      {
		String fileProtocol = "file:";      	 //$NON-NLS-1$
        if (resolvedLocation.startsWith(fileProtocol) && !resolvedLocation.startsWith(fileProtocol + "/")) //$NON-NLS-1$
        {
          resolvedLocation = resolvedLocation.substring(fileProtocol.length());
        }
        resolvedLocation = URIHelper.addImpliedFileProtocol(resolvedLocation);
      }
      // end ugly hack
      return resolvedLocation;
    }
  }
}

Back to the top