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

import java.util.Collection;
import java.util.Iterator;

import org.eclipse.wst.wsdl.WSDLElement;
import org.eclipse.wst.wsdl.internal.impl.WSDLElementImpl;
import org.eclipse.xsd.impl.XSDComponentImpl;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

public class WSDLNodeAssociationProvider implements INodeAssociationProvider
{                    
  public Object getModelObject(Object parentModelObject, Element[] elementChain, int start, int[] end)
  {                 
    Object currentObject = parentModelObject;
    for (int i = start; i < elementChain.length; i++)
    {
      Object o = getModelObjectHelper(currentObject, elementChain[i]);
      if (o == null)
      {              
        end[0] = i;
        break;
      }            
      else
      {              
        currentObject = o;
      }
    }                                                               
    return currentObject != parentModelObject ? currentObject : null;                                                  
  }

  public Node getNode(Object modelObject)
  {
    if (modelObject instanceof WSDLElement)
      return ((WSDLElementImpl)modelObject).getElement();
    else
      return null;
  }
      
  protected Object getModelObjectHelper(Object parentObject, Element elementNode)
  {          
		Object result = null;
		Collection childComponentList = ((WSDLElementImpl) parentObject).getWSDLContents();
		for (Iterator i = childComponentList.iterator(); i.hasNext();)
		{
			Object o = i.next();
			Element element = null;

      if (o != null)
      {
        if (o instanceof WSDLElementImpl)
        {
          element = ((WSDLElementImpl)o).getElement();
        }
        else if (o instanceof XSDComponentImpl)
        {
          element = ((XSDComponentImpl)o).getElement();
        }
      }
      
			if (element == elementNode)
			{
				result = o;
				break;
			}
		}
		return result;
  }
}    

Back to the top