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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
/*******************************************************************************
* 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.emf.common.util.EList;
import org.eclipse.wst.ws.internal.explorer.platform.wsdl.constants.FragmentConstants;
import org.eclipse.wst.ws.internal.explorer.platform.wsdl.fragment.impl.SOAPEncArrayFixFragment;
import org.eclipse.wst.ws.internal.explorer.platform.wsdl.fragment.impl.SOAPEncArrayRangeFragment;
import org.eclipse.wst.ws.internal.explorer.platform.wsdl.fragment.impl.SOAPEncodingWrapperFragment;
import org.eclipse.wst.ws.internal.explorer.platform.wsdl.fragment.util.XSDTypeDefinitionUtil;
import org.eclipse.wst.ws.internal.explorer.platform.wsdl.xsd.WSDLPartsToXSDTypeMapper;
import org.eclipse.xsd.XSDAttributeGroupContent;
import org.eclipse.xsd.XSDComplexTypeContent;
import org.eclipse.xsd.XSDComplexTypeDefinition;
import org.eclipse.xsd.XSDComponent;
import org.eclipse.xsd.XSDModelGroup;
import org.eclipse.xsd.XSDParticle;
import org.eclipse.xsd.XSDParticleContent;
import org.eclipse.xsd.XSDTypeDefinition;
import org.w3c.dom.Element;
public class XSDSOAPEncodingToFragmentMapper extends XSDToFragmentMapper {
private XSDLiteralXMLEncodingToFragmentMapper xsdLiteralMapper_;
private XSDComplexTypeToFragmentMapper xsdComplexMapper_;
public XSDSOAPEncodingToFragmentMapper(XSDToFragmentController controller, WSDLPartsToXSDTypeMapper wsdlToXSDMapper) {
super(controller, wsdlToXSDMapper);
xsdLiteralMapper_ = null;
xsdComplexMapper_ = null;
}
private XSDLiteralXMLEncodingToFragmentMapper getXSDLiteralMapper() {
if (xsdLiteralMapper_ == null)
xsdLiteralMapper_ = new XSDLiteralXMLEncodingToFragmentMapper(getController(), getWSDLPartsToXSDTypeMapper());
return xsdLiteralMapper_;
}
private XSDComplexTypeToFragmentMapper getXSDComplexMapper() {
if (xsdComplexMapper_ == null)
xsdComplexMapper_ = new XSDComplexTypeToFragmentMapper(getController(), getWSDLPartsToXSDTypeMapper());
return xsdComplexMapper_;
}
public IXSDFragment getFragment(XSDToFragmentConfiguration config, String id, String name) {
if (config.getIsWSDLPart()) {
ISOAPEncodingWrapperFragment wrapperFragment = new SOAPEncodingWrapperFragment(id, name, null);
String delegationFragId = wrapperFragment.genID();
IXSDFragment delegationFragment = getFragmentDelegate(config, delegationFragId, name);
wrapperFragment.setXSDDelegationFragment(delegationFragment);
getController().addToCache(delegationFragId, delegationFragment);
return wrapperFragment;
}
else
return getFragmentDelegate(config, id, name);
}
public IXSDFragment getFragmentDelegate(XSDToFragmentConfiguration config, String id, String name) {
config = resolveXSDComponent(config);
XSDComponent component = config.getXSDComponent();
if (!isComponentResolvable(component))
return getXSDDefaultFragment(config, id, name);
else if (component instanceof XSDComplexTypeDefinition) {
XSDComplexTypeDefinition complexType = (XSDComplexTypeDefinition)component;
if (XSDTypeDefinitionUtil.isSoapEncArray(complexType))
return getSOAPEncArrayFragment(config, id, name, complexType);
else
return getXSDComplexMapper().getFragment(config, id, name);
}
else
return getXSDLiteralMapper().getFragment(config, id, name);
}
private IXSDFragment getSOAPEncArrayFragment(XSDToFragmentConfiguration config, String id, String name, XSDComplexTypeDefinition complexType) {
EList xsdAttrContents = complexType.getAttributeContents();
for (int i = 0; i < xsdAttrContents.size(); i++) {
String soapEncArrayTypeNamespaceURI = null;
String soapEncArrayTypeLocalName = null;
int soapEncArrayDimension = 0;
XSDAttributeGroupContent xsdAttrContent = (XSDAttributeGroupContent)xsdAttrContents.get(i);
Element element = xsdAttrContent.getElement();
String arrayTypeAttr = element.getAttributeNS(FragmentConstants.URI_WSDL, FragmentConstants.QNAME_LOCAL_NAME_ARRAY_TYPE);
if (arrayTypeAttr != null && arrayTypeAttr.length() > 0) {
int colon = arrayTypeAttr.indexOf(FragmentConstants.COLON);
String nsPrefix = (colon > 0) ? arrayTypeAttr.substring(0, colon) : null;
soapEncArrayTypeNamespaceURI = (String)xsdAttrContent.getSchema().getQNamePrefixToNamespaceMap().get(nsPrefix);
int dimensionIndex = arrayTypeAttr.indexOf(FragmentConstants.LEFT_SQUARE_BRACKET);
soapEncArrayTypeLocalName = arrayTypeAttr.substring(colon + 1, dimensionIndex);
String dimensionString = arrayTypeAttr.substring(dimensionIndex, arrayTypeAttr.length());
for (int j = 0; j < dimensionString.length() - 1; j++) {
if (dimensionString.charAt(j) == FragmentConstants.LEFT_SQUARE_BRACKET.charAt(0) && dimensionString.charAt(j + 1) == FragmentConstants.RIGHT_SQUARE_BRACKET.charAt(0)) {
soapEncArrayDimension++;
j++;
}
else {
soapEncArrayDimension = 0;
break;
}
}
}
if (soapEncArrayTypeNamespaceURI != null && soapEncArrayTypeLocalName != null && soapEncArrayDimension == 1) {
XSDComponent soapEncArrayType = getWSDLPartsToXSDTypeMapper().getXSDTypeFromSchema(soapEncArrayTypeNamespaceURI, soapEncArrayTypeLocalName, false);
if (soapEncArrayType != null && soapEncArrayType instanceof XSDTypeDefinition) {
XSDModelGroup sequence = null;
XSDComplexTypeContent complexTypeContent = XSDTypeDefinitionUtil.getXSDComplexTypeContent(complexType);
if (complexTypeContent != null && (complexTypeContent instanceof XSDParticle)) {
XSDParticleContent xsdParticleContent = ((XSDParticle)complexTypeContent).getContent();
if (xsdParticleContent instanceof XSDModelGroup)
sequence = (XSDModelGroup)xsdParticleContent;
}
ISOAPEncArrayFragment frag;
if (config.getMinOccurs() == config.getMaxOccurs())
frag = new SOAPEncArrayFixFragment(id, name, config, getController(), sequence);
else
frag = new SOAPEncArrayRangeFragment(id, name, config, getController(), sequence);
frag.setXSDTypeDefinition((XSDTypeDefinition)soapEncArrayType);
return frag;
}
}
}
return getXSDComplexMapper().getFragment(config, id, name);
}
}
|