Skip to main content
summaryrefslogtreecommitdiffstats
blob: 939623b6e37ef3d4f2add4de0cba2586846fca80 (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
/*******************************************************************************
 * Copyright (c) 2002, 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.ws.internal.explorer.platform.wsdl.fragment;

import org.eclipse.wst.ws.internal.explorer.platform.wsdl.constants.FragmentConstants;
import org.eclipse.wst.ws.internal.explorer.platform.wsdl.fragment.impl.XSDElementFragment;
import org.eclipse.wst.ws.internal.explorer.platform.wsdl.xsd.WSDLPartsToXSDTypeMapper;
import org.eclipse.xsd.XSDComponent;
import org.eclipse.xsd.XSDConcreteComponent;
import org.eclipse.xsd.XSDElementDeclaration;
import org.eclipse.xsd.XSDParticle;
import org.eclipse.xsd.XSDTypeDefinition;


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

  public IXSDFragment getFragment(XSDToFragmentConfiguration config, String id, String name) {
    XSDElementDeclaration element = (XSDElementDeclaration)config.getXSDComponent();
    if (element != null) {
      XSDElementDeclaration resolvedElement = resolveXSDElementDeclaration(element);
      XSDTypeDefinition typeDef = getXSDTypeDefinition(resolvedElement);
      if (typeDef != null) {
        int minOccurs = FragmentConstants.DEFAULT_MIN_OCCURS;
        int maxOccurs = FragmentConstants.DEFAULT_MAX_OCCURS;
        XSDConcreteComponent concreteComponent = element.getContainer();
        if (concreteComponent != null && concreteComponent instanceof XSDParticle) {
          XSDParticle particle = (XSDParticle)concreteComponent;
          if (particle.isSetMinOccurs())
            minOccurs = particle.getMinOccurs();
          if (particle.isSetMaxOccurs())
            maxOccurs = particle.getMaxOccurs();
        }
        config.setMinOccurs(minOccurs);
        config.setMaxOccurs(maxOccurs);
        IXSDElementFragment elementFrag = new XSDElementFragment(id, resolvedElement.getName(), config);
        elementFrag.setXSDTypeDefinition(typeDef);
        XSDToFragmentConfiguration elementTypeConfig = new XSDToFragmentConfiguration();
        elementTypeConfig.setXSDComponent(typeDef);
        elementTypeConfig.setMinOccurs(minOccurs);
        elementTypeConfig.setMaxOccurs(maxOccurs);
        elementTypeConfig.setStyle(config.getStyle());
        elementTypeConfig.setPartEncoding(config.getPartEncoding());
        elementTypeConfig.setWSDLPartName(config.getWSDLPartName());
        IXSDFragment xsdFragment = getController().getFragment(elementTypeConfig, elementFrag.genID(), resolvedElement.getName());
        elementFrag.setXSDDelegationFragment(xsdFragment);
        return elementFrag;
      }
    }
    return getXSDDefaultFragment(config, id, name);
  }

  private XSDElementDeclaration resolveXSDElementDeclaration(XSDElementDeclaration element) {
    // port to org.eclipse.xsd
    if (element.getResolvedElementDeclaration() != null)
    {
      XSDElementDeclaration resolvedElement = element.getResolvedElementDeclaration();
      if (!isComponentResolvable(resolvedElement))
      {
        XSDComponent resolvedComponent = getWSDLPartsToXSDTypeMapper().resolveXSDNamedComponent(resolvedElement);
        if (resolvedComponent != null && (resolvedComponent instanceof XSDElementDeclaration))
          resolvedElement = (XSDElementDeclaration)resolvedComponent;
      }
      return resolvedElement;
    }
    else
      return element;
  }

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

}

Back to the top