Skip to main content
summaryrefslogtreecommitdiffstats
blob: abe10ed1fdda1a1454d5c2b6c84384929d41f0d3 (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
/**
* <copyright>
*
* Licensed Material - Property of IBM
* (C) Copyright IBM Corp. 2002 - All Rights Reserved.
* US Government Users Restricted Rights - Use, duplication or disclosure
* restricted by GSA ADP Schedule Contract with IBM Corp.
*
* </copyright>
*
* File plugins/com.ibm.etools.webservice.explorer/wsexplorer/src/com/ibm/etools/webservice/explorer/wsdl/fragment/XSDElementDeclarationToFragmentMapper.java, wsa.etools.ws.explorer, lunar-5.1.2, 20031231a 2
* Version 1.2 03/06/05 14:17:44
*/
package org.eclipse.wst.ws.internal.explorer.platform.wsdl.fragment;

import org.eclipse.wst.ws.internal.explorer.platform.wsdl.fragment.impl.XSDAttributeFragment;
import org.eclipse.wst.ws.internal.explorer.platform.wsdl.xsd.WSDLPartsToXSDTypeMapper;
import org.eclipse.xsd.XSDAttributeDeclaration;
import org.eclipse.xsd.XSDAttributeUse;
import org.eclipse.xsd.XSDComponent;
import org.eclipse.xsd.XSDTypeDefinition;

public class XSDAttributeUseToFragmentMapper extends XSDToFragmentMapper {
  public XSDAttributeUseToFragmentMapper(XSDToFragmentController controller, WSDLPartsToXSDTypeMapper wsdlToXSDMapper) {
    super(controller, wsdlToXSDMapper);
  }

  public IXSDFragment getFragment(XSDToFragmentConfiguration config, String id, String name) {
   	XSDAttributeUse attribute = (XSDAttributeUse)config.getXSDComponent();
    if (attribute != null && attribute.getAttributeDeclaration() != null) {
   	  XSDAttributeDeclaration resolvedAttribute = resolveXSDAttributeDeclaration(attribute.getAttributeDeclaration());
      XSDTypeDefinition typeDef = getXSDTypeDefinition(resolvedAttribute);
      IXSDAttributeFragment attributeFrag = new XSDAttributeFragment(id, resolvedAttribute.getName(), config);
      attributeFrag.setXSDTypeDefinition(typeDef);
      XSDToFragmentConfiguration attributeTypeConfig = new XSDToFragmentConfiguration();
      attributeTypeConfig.setXSDComponent(typeDef);
      attributeTypeConfig.setStyle(config.getStyle());
      attributeTypeConfig.setPartEncoding(config.getPartEncoding());
      attributeTypeConfig.setWSDLPartName(config.getWSDLPartName());
      IXSDFragment xsdFragment = getController().getFragment(attributeTypeConfig, attributeFrag.genID(), resolvedAttribute.getName());
      attributeFrag.setXSDDelegationFragment(xsdFragment);
      return attributeFrag;
    }
    return getXSDDefaultFragment(config, id, name);
  }

  private XSDAttributeDeclaration resolveXSDAttributeDeclaration(XSDAttributeDeclaration attribute) {
    // port to org.eclipse.xsd
    if (attribute.getResolvedAttributeDeclaration() != null)
    {
      XSDAttributeDeclaration resolvedAttribute = attribute.getResolvedAttributeDeclaration();
      if (!isComponentResolvable(resolvedAttribute))
      {
        XSDComponent resolvedComponent = getWSDLPartsToXSDTypeMapper().resolveXSDNamedComponent(resolvedAttribute);
        if (resolvedComponent != null && (resolvedComponent instanceof XSDAttributeDeclaration))
          resolvedAttribute = (XSDAttributeDeclaration)resolvedComponent;
      }
      return resolvedAttribute;
    }
    else
      return attribute;
  }

  private XSDTypeDefinition getXSDTypeDefinition(XSDAttributeDeclaration attribute) {
    // port to org.eclipse.xsd
    if (attribute.getTypeDefinition() != null)
      return attribute.getTypeDefinition();
    // port to org.eclipse.xsd
    else if (attribute.getAnonymousTypeDefinition() != null)
      return attribute.getAnonymousTypeDefinition();
    else
      return null;
    }

}

Back to the top