Skip to main content
summaryrefslogtreecommitdiffstats
blob: b1fb0aca4a0b7cfb747eb69625b13f9f8b87494f (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
/*******************************************************************************
 * 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.text;

import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.hyperlink.IHyperlink;
import org.eclipse.wst.sse.core.StructuredModelManager;
import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
import org.eclipse.wst.wsdl.Definition;
import org.eclipse.wst.wsdl.ui.internal.util.OpenOnSelectionHelper;
import org.eclipse.wst.wsdl.util.WSDLConstants;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
import org.eclipse.wst.xsd.editor.BaseHyperlinkDetector;
/**
 * Detects hyperlinks for WSDL files. Used by the WSDL text editor to provide a
 * "Go to declaration" functionality similar with the one provided by the Java
 * editor.
 */
public class WSDLHyperlinkDetector extends BaseHyperlinkDetector
{
  /*
   * (non-Javadoc)
   */
  protected IHyperlink createHyperlink(IDocument document, IDOMNode node, IRegion region)
  {
    // Here we're trying to find the target component's resource and spec.

    Definition definition = getDefinition(document);
    OpenOnSelectionHelper helper = new OpenOnSelectionHelper(definition);
    String[] targetData = helper.computeSpecification(node);

    if (targetData != null)
    {
      String resource = targetData[0];
      String spec = targetData[1];
      return new WSDLHyperlink(region, resource, spec);
    }

    return null;
  }

  /**
   * Gets the definition from document
   * 
   * @param document
   * @return Definition
   */
  private Definition getDefinition(IDocument document)
  {
    Definition definition = null;
    IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForRead(document);
    if (model != null)
    {
      try
      {
        if (model instanceof IDOMModel)
        {
          IDOMDocument domDoc = ((IDOMModel) model).getDocument();
          if (domDoc != null)
          {
            WSDLModelAdapter modelAdapter = (WSDLModelAdapter) domDoc.getAdapterFor(WSDLModelAdapter.class);
            // ISSUE: if adapter does not already exist for domDoc getAdapterFor
            // will create one. So why is this null check/creation needed?
            if (modelAdapter == null)
            {
              modelAdapter = new WSDLModelAdapter();
              domDoc.addAdapter(modelAdapter);
              modelAdapter.createDefinition(domDoc.getDocumentElement(), domDoc);
            }
            definition = modelAdapter.getDefinition();
          }
        }
      }
      finally
      {
        model.releaseFromRead();
      }
    }
    return definition;
  }

  /*
   * (non-Javadoc)
   */
  protected boolean isLinkableAttribute(String name)
  {
    boolean isLinkable = name.equals(WSDLConstants.BINDING_ATTRIBUTE) || 
    name.equals(WSDLConstants.ELEMENT_ATTRIBUTE) || 
    name.equals(WSDLConstants.TYPE_ATTRIBUTE) || 
    name.equals(WSDLConstants.MESSAGE_ATTRIBUTE); 
    return isLinkable;
  }
}

Back to the top