blob: a8e250f8705fd0c3b3d13b9da5946d6837a4dd37 (
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
105
106
107
108
109
110
111
112
113
114
|
/*******************************************************************************
* 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.util;
import org.eclipse.wst.ws.internal.explorer.platform.wsdl.constants.FragmentConstants;
import org.eclipse.xsd.XSDComplexTypeContent;
import org.eclipse.xsd.XSDComplexTypeDefinition;
import org.eclipse.xsd.XSDTypeDefinition;
public class XSDTypeDefinitionUtil {
private XSDTypeDefinitionUtil() {
}
public static boolean isXSDBuiltInTypeDefinition(XSDTypeDefinition type) {
if (type == null)
return false;
String ns = type.getTargetNamespace();
return (ns != null && ns.equals(FragmentConstants.URI_XSD));
}
public static boolean isRootTypeDefinition(XSDTypeDefinition type) {
if (type == null)
return true;
XSDTypeDefinition baseType = type.getBaseType();
if (baseType == null)
return true;
String typeNS = type.getTargetNamespace();
String baseTypeNS = baseType.getTargetNamespace();
String typeName = type.getName();
String baseTypeName = baseType.getName();
boolean sameNS;
boolean sameName;
if (typeNS == null && baseTypeNS == null)
sameNS = true;
else if (typeNS != null && baseTypeNS != null && typeNS.equals(baseTypeNS))
sameNS = true;
else
sameNS = false;
if (typeName == null && baseTypeName == null)
sameName = true;
else if (typeName != null && baseTypeName != null && typeName.equals(baseTypeName))
sameName = true;
else
sameName = false;
return (sameNS && sameName);
}
public static XSDTypeDefinition resolveToXSDBuiltInTypeDefinition(XSDTypeDefinition type) {
if (type == null)
return null;
XSDTypeDefinition currType = type;
while (!isXSDBuiltInTypeDefinition(currType)) {
if (isRootTypeDefinition(currType))
return null;
currType = currType.getBaseType();
}
return currType;
}
public static boolean isSoapEncArray(XSDTypeDefinition type) {
XSDTypeDefinition currType = type;
if (currType != null)
while(currType != null) {
String ns = currType.getTargetNamespace();
String name = currType.getName();
if (FragmentConstants.URI_SOAP.equals(ns) && FragmentConstants.QNAME_LOCAL_NAME_ARRAY.equals(name))
return true;
else if (isRootTypeDefinition(currType))
return false;
else
currType = currType.getBaseType();
}
return false;
}
/**
* Returns the complex type content given a complex type.
* If complexType is a user defined type:
* This method will return the user defined complex content of this type or the content of the extended
* or derived type iff the extended or derived type is not a built-in XSD type (for example, xsd:anyType).
* If complexType is a built-in XSD type:
* It will return the complex content of this built-in XSD complex type. It will not return the
* complex content of its extended or derived type.
* @param complexType XSDComplexTypeDefinition complex type.
* @return XSDComplexTypeContent XSDComplexTypeContent the resolved complex type content.
**/
public static XSDComplexTypeContent getXSDComplexTypeContent(XSDComplexTypeDefinition complexType)
{
if (!isXSDBuiltInTypeDefinition(complexType))
{
XSDTypeDefinition type = complexType;
while (!isXSDBuiltInTypeDefinition(type) && (type instanceof XSDComplexTypeDefinition))
{
XSDComplexTypeContent complexTypeContent = ((XSDComplexTypeDefinition)type).getContent();
if (complexTypeContent != null)
return complexTypeContent;
if (isRootTypeDefinition(type))
return null;
type = type.getBaseType();
}
return null;
}
else
return complexType.getContent();
}
}
|