Skip to main content
summaryrefslogtreecommitdiffstats
blob: bd457973066a37323627a5a91031652d779bda10 (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) 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.XSDGroupAllFragment;
import org.eclipse.wst.ws.internal.explorer.platform.wsdl.fragment.impl.XSDGroupChoiceFixFragment;
import org.eclipse.wst.ws.internal.explorer.platform.wsdl.fragment.impl.XSDGroupChoiceRangeFragment;
import org.eclipse.wst.ws.internal.explorer.platform.wsdl.fragment.impl.XSDGroupSeqFixFragment;
import org.eclipse.wst.ws.internal.explorer.platform.wsdl.fragment.impl.XSDGroupSeqRangeFragment;
import org.eclipse.wst.ws.internal.explorer.platform.wsdl.xsd.WSDLPartsToXSDTypeMapper;
import org.eclipse.xsd.XSDComponent;
import org.eclipse.xsd.XSDCompositor;
import org.eclipse.xsd.XSDConcreteComponent;
import org.eclipse.xsd.XSDModelGroup;
import org.eclipse.xsd.XSDModelGroupDefinition;
import org.eclipse.xsd.XSDParticle;
import org.eclipse.xsd.XSDParticleContent;
import org.eclipse.xsd.XSDWildcard;


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

  public IXSDFragment getFragment(XSDToFragmentConfiguration config, String id, String name) {
    XSDComponent component = config.getXSDComponent();
    XSDParticleContent xsdParticleContent;
    if (component instanceof XSDParticle)
      xsdParticleContent = ((XSDParticle)component).getContent();
    else if (component instanceof XSDParticleContent)
      xsdParticleContent = (XSDParticleContent)component;
    else
      xsdParticleContent = null;
    if (xsdParticleContent != null) {
      if (xsdParticleContent instanceof XSDModelGroupDefinition)
        return getXSDModelGroupDefFragment(config, id, name, (XSDModelGroupDefinition)xsdParticleContent);
      else if (xsdParticleContent instanceof XSDModelGroup)
        return getXSDModelGroupFragment(config, id, name, (XSDModelGroup)xsdParticleContent);
      else if (xsdParticleContent instanceof XSDWildcard)
        return getXSDWildcardFragment(config, id, name, (XSDWildcard)xsdParticleContent);
      else
        return getXSDDefaultFragment(config, id, name);
    }
    else
      return getXSDDefaultFragment(config, id, name);
  }

  private IXSDFragment getXSDModelGroupDefFragment(XSDToFragmentConfiguration config, String id, String name, XSDModelGroupDefinition xsdModelGroupDef) {
    XSDModelGroupDefinition resolvedXSDModelGroupDef = xsdModelGroupDef;
    if (xsdModelGroupDef.isModelGroupDefinitionReference())
      resolvedXSDModelGroupDef = xsdModelGroupDef.getResolvedModelGroupDefinition();
    XSDModelGroup xsdModelGroup = resolvedXSDModelGroupDef.getModelGroup();
    if (xsdModelGroup == null)
      return getXSDDefaultFragment(config, id, name);
    else
      return getXSDModelGroupFragment(config, id, name, xsdModelGroup);
  }

  private IXSDFragment getXSDModelGroupFragment(XSDToFragmentConfiguration config, String id, String name, XSDModelGroup xsdModelGroup) {
    int minOccurs = FragmentConstants.DEFAULT_MIN_OCCURS;
    int maxOccurs = FragmentConstants.DEFAULT_MAX_OCCURS;
    XSDConcreteComponent concreteComponent = xsdModelGroup.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);
    
    switch (xsdModelGroup.getCompositor().getValue()) {
      case XSDCompositor.SEQUENCE: 
        if (minOccurs == maxOccurs)
          return new XSDGroupSeqFixFragment(id, name, config, getController(), xsdModelGroup);
        else
          return new XSDGroupSeqRangeFragment(id, name, config, getController(), xsdModelGroup);
      case XSDCompositor.CHOICE:
        if (minOccurs == maxOccurs)
          return new XSDGroupChoiceFixFragment(id, name, config, getController(), xsdModelGroup);
        else
          return new XSDGroupChoiceRangeFragment(id, name, config, getController(), xsdModelGroup);
      case XSDCompositor.ALL:
        return new XSDGroupAllFragment(id, name, config, getController(), xsdModelGroup);
      default:
        return getXSDDefaultFragment(config, id, name);
    }
  }

  private IXSDFragment getXSDWildcardFragment(XSDToFragmentConfiguration config, String id, String name, XSDWildcard xsdParticleContent) {
    return getXSDDefaultFragment(config, id, name);
  }
}

Back to the top