Skip to content

Commit a630d29

Browse files
author
Eran Chinthaka
committed
One more schenario done. Two more to go (having problems in retrieving all the schemas)
1 parent acd74e0 commit a630d29

2 files changed

Lines changed: 215 additions & 111 deletions

File tree

‎modules/codegen/src/org/apache/axis2/wsdl/codegen/extension/SchemaUnwrapperExtension.java‎

Lines changed: 148 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@
4141
* such as the databinding extension may well depend on the schema being unwrapped
4242
* previously.
4343
* For a complete unwrap the following format of the schema is expected
44-
* < element >
45-
* < complexType >
46-
* < sequence >
47-
* < element />
48-
* < /sequence >
49-
* < /complexType >
44+
* < element >
45+
* < complexType >
46+
* < sequence >
47+
* < element />
48+
* < /sequence >
49+
* < /complexType >
5050
* < /element >
51-
*
51+
* <p/>
5252
* When an unwrapped WSDL is encountered Axis2 generates a wrapper schema
5353
* and that wrapper schema has the above mentioned format. This unwrapping algorithm
5454
* will work on a pure doc/lit WSDL if it has the above mentioned format
@@ -57,30 +57,29 @@
5757
public class SchemaUnwrapperExtension extends AbstractCodeGenerationExtension {
5858

5959
/**
60-
*
6160
* @param configuration
6261
* @throws CodeGenerationException
6362
*/
6463
public void engage(CodeGenConfiguration configuration) throws CodeGenerationException {
65-
if (!configuration.isParametersWrapped()){
64+
if (!configuration.isParametersWrapped()) {
6665

6766
// A check to avoid nasty surprises - Since unwrapping is not
6867
// supported by all frameworks, we check the framework name to be
6968
// compatible
7069
if (!ConfigPropertyFileLoader.getUnwrapSupportedFrameworkNames().
71-
contains(configuration.getDatabindingType())){
70+
contains(configuration.getDatabindingType())) {
7271
throw new CodeGenerationException(
7372
CodegenMessages.getMessage("extension.unsupportedforunwrapping"));
7473
}
7574

7675
//walk the schema and find the top level elements
7776
AxisService axisService = configuration.getAxisService();
7877

79-
for(Iterator operations = axisService.getOperations();
80-
operations.hasNext();){
81-
AxisOperation op = (AxisOperation)operations.next();
78+
for (Iterator operations = axisService.getOperations();
79+
operations.hasNext();) {
80+
AxisOperation op = (AxisOperation) operations.next();
8281

83-
if (WSDLUtil.isInputPresentForMEP(op.getMessageExchangePattern())){
82+
if (WSDLUtil.isInputPresentForMEP(op.getMessageExchangePattern())) {
8483
walkSchema(op.getMessage(
8584
WSDLConstants.MESSAGE_LABEL_IN_VALUE));
8685
}
@@ -94,127 +93,166 @@ public void engage(CodeGenConfiguration configuration) throws CodeGenerationExce
9493
* For a successful unwrapping the element should have the
9594
* following structure
9695
* &lt; element &gt;
97-
* &lt; complexType &gt;
98-
* &lt; sequence &gt;
99-
* &lt; element /&gt;
100-
* &lt; /sequence &gt;
101-
* &lt; /complexType &gt;
96+
* &lt; complexType &gt;
97+
* &lt; sequence &gt;
98+
* &lt; element /&gt;
99+
* &lt; /sequence &gt;
100+
* &lt; /complexType &gt;
102101
* &lt; /element &gt;
103102
*/
104103

105104
public void walkSchema(AxisMessage message)
106-
throws CodeGenerationException{
105+
throws CodeGenerationException {
107106
//nothing to unwrap
108-
if (message.getSchemaElement()==null){
107+
if (message.getSchemaElement() == null) {
109108
return;
110109
}
111110

112-
XmlSchemaType schemaType = message.getSchemaElement().getSchemaType();
113-
if (schemaType.getQName()!=null){
114-
throw new CodeGenerationException(CodegenMessages.getMessage("extension.unsupportedSchemaFormat",
115-
"named type","anonymous type"));
116-
}
117111

112+
List partNameList = new LinkedList();
118113

119-
//create a type mapper
120-
if (schemaType instanceof XmlSchemaComplexType){
121-
XmlSchemaComplexType cmplxType = (XmlSchemaComplexType)schemaType;
122-
XmlSchemaParticle particle = cmplxType.getParticle();
123-
if (particle instanceof XmlSchemaSequence){
124-
// get the name of the operation name and namespace,
125-
// part name and hang them somewhere ? The ideal place
126-
// would be the property bag in the codegen config!
127-
QName opName = ((AxisOperation)message.getParent()).getName();
128-
List partNameList = new LinkedList();
129-
130-
XmlSchemaSequence sequence = (XmlSchemaSequence)particle;
131-
XmlSchemaObjectCollection items = sequence.getItems();
132-
for (Iterator i = items.getIterator();i.hasNext();){
133-
Object item = i.next();
134-
// get each and every element in the sequence and
135-
// traverse through them
136-
if (item instanceof XmlSchemaElement){
137-
//add the element name to the part name list
138-
String partName = ((XmlSchemaElement) item).getName();
139-
140-
// part names are not unique across messages. Hence
141-
// we need some way of making the part name a unique
142-
// one (due to the fact that the type mapper
143-
// is a global list of types).
144-
// The seemingly best way to do that is to
145-
// specify a namespace for the part QName reference which
146-
// is stored in the list. This part qname is
147-
// temporary and should not be used with it's
148-
// namespace URI (which happened to be the operation name)
149-
// with _input attached to it
150-
151-
152-
partNameList.add(
153-
WSDLUtil.getPartQName(opName.getLocalPart(),
154-
WSDLConstants.INPUT_PART_QNAME_SUFFIX,
155-
partName));
156-
157-
// if the particle contains anything other than
158-
// a XMLSchemaElement then we are not in a position
159-
// to unwrap it
160-
}else{
161-
throw new CodeGenerationException(CodegenMessages.getMessage("extension.unsupportedSchemaFormat",
162-
"unknown type","Element"));
163-
}
164-
}
114+
XmlSchemaElement schemaElement = message.getSchemaElement();
115+
XmlSchemaType schemaType = schemaElement.getSchemaType();
165116

166-
try {
167-
//set in the axis message that the unwrapping was success
168-
message.addParameter(getParameter(
169-
Constants.UNWRAPPED_KEY,
170-
Boolean.TRUE));
171-
172-
// attach the opName and the parts name list into the
173-
// axis message by using the holder
174-
MessagePartInformationHolder infoHolder = new MessagePartInformationHolder();
175-
infoHolder.setOperationName(opName);
176-
infoHolder.setPartsList(partNameList);
177-
178-
//attach it to the parameters
179-
message.addParameter(
180-
getParameter(Constants.UNWRAPPED_DETAILS,
181-
infoHolder));
182-
183-
} catch (AxisFault axisFault) {
184-
throw new CodeGenerationException(axisFault);
185-
}
117+
// this type should be a complex type or it should have a name which refer to another type definition
186118

187-
//we do not know how to deal with other particles
188-
//such as xs:all or xs:choice. Usually occurs when
189-
//passed with the user built WSDL where the style
190-
//is document.
191-
}else if (particle instanceof XmlSchemaChoice){
192-
throw new CodeGenerationException(CodegenMessages.getMessage("extension.unsupportedSchemaFormat",
193-
"choice","sequence"));
194-
195-
}else if (particle instanceof XmlSchemaAll){
196-
throw new CodeGenerationException(CodegenMessages.getMessage("extension.unsupportedSchemaFormat",
197-
"all","sequence"));
198-
}else{
199-
throw new CodeGenerationException(CodegenMessages.getMessage("extension.unsupportedSchemaFormat",
200-
"unknown","sequence"));
119+
// first let's handle this being a complex type
120+
if (schemaType instanceof XmlSchemaComplexType) {
121+
XmlSchemaComplexType cmplxType = (XmlSchemaComplexType) schemaType;
122+
if (cmplxType.getContentModel() == null) {
123+
processComplexType(cmplxType.getParticle(), message, partNameList);
124+
} else {
125+
// now lets handle case with extensions
126+
processComplexContentModel(cmplxType, message, partNameList);
201127
}
202-
}else{
128+
129+
130+
} else {
203131
//we've no idea how to unwrap a non complexType!!!!!!
204132
throw new CodeGenerationException(CodegenMessages.getMessage("extension.unsupportedSchemaFormat",
205-
"unknown","complexType"));
133+
"unknown", "complexType"));
134+
}
206135

136+
try {
137+
//set in the axis message that the unwrapping was success
138+
message.addParameter(getParameter(
139+
Constants.UNWRAPPED_KEY,
140+
Boolean.TRUE));
141+
142+
// attach the opName and the parts name list into the
143+
// axis message by using the holder
144+
MessagePartInformationHolder infoHolder = new MessagePartInformationHolder();
145+
infoHolder.setOperationName(((AxisOperation) message.getParent()).getName());
146+
infoHolder.setPartsList(partNameList);
147+
148+
//attach it to the parameters
149+
message.addParameter(
150+
getParameter(Constants.UNWRAPPED_DETAILS,
151+
infoHolder));
152+
153+
} catch (AxisFault axisFault) {
154+
throw new CodeGenerationException(axisFault);
207155
}
208156

209157
}
210158

159+
private void processComplexContentModel(XmlSchemaComplexType cmplxType, AxisMessage message, List partNameList) throws CodeGenerationException {
160+
XmlSchemaContentModel contentModel = cmplxType.getContentModel();
161+
if (contentModel instanceof XmlSchemaComplexContent) {
162+
XmlSchemaComplexContent xmlSchemaComplexContent = (XmlSchemaComplexContent) contentModel;
163+
XmlSchemaContent content = xmlSchemaComplexContent.getContent();
164+
if (content instanceof XmlSchemaComplexContentExtension) {
165+
XmlSchemaComplexContentExtension schemaExtension = (XmlSchemaComplexContentExtension) content;
166+
167+
// process particles inside this extension, if any
168+
processComplexType(schemaExtension.getParticle(), message, partNameList);
169+
170+
// AxisService axisService = (AxisService) message.getParent().getParent();
171+
// XmlSchemaElement schemaElement = axisService.getSchemaElement(schemaExtension.getBaseTypeName());
172+
// if (schemaElement != null) {
173+
// XmlSchemaType schemaType = schemaElement.getSchemaType();
174+
//
175+
// if (schemaType instanceof XmlSchemaComplexType) {
176+
// XmlSchemaComplexType xmlSchemaComplexType = (XmlSchemaComplexType) schemaType;
177+
// processComplexType(xmlSchemaComplexType, message, partNameList);
178+
//
179+
// } else {
180+
// //we've no idea how to unwrap a non complexType!!!!!!
181+
// throw new CodeGenerationException(CodegenMessages.getMessage("extension.unsupportedSchemaFormat",
182+
// "unknown", "complexType"));
183+
// }
184+
// }
185+
}
186+
}
187+
}
188+
189+
private void processComplexType(XmlSchemaParticle schemaParticle, AxisMessage message, List partNameList) throws CodeGenerationException {
190+
if (schemaParticle instanceof XmlSchemaSequence) {
191+
// get the name of the operation name and namespace,
192+
// part name and hang them somewhere ? The ideal place
193+
// would be the property bag in the codegen config!
194+
QName opName = ((AxisOperation) message.getParent()).getName();
195+
196+
XmlSchemaSequence sequence = (XmlSchemaSequence) schemaParticle;
197+
XmlSchemaObjectCollection items = sequence.getItems();
198+
for (Iterator i = items.getIterator(); i.hasNext();) {
199+
Object item = i.next();
200+
// get each and every element in the sequence and
201+
// traverse through them
202+
if (item instanceof XmlSchemaElement) {
203+
//add the element name to the part name list
204+
String partName = ((XmlSchemaElement) item).getName();
205+
206+
// part names are not unique across messages. Hence
207+
// we need some way of making the part name a unique
208+
// one (due to the fact that the type mapper
209+
// is a global list of types).
210+
// The seemingly best way to do that is to
211+
// specify a namespace for the part QName reference which
212+
// is stored in the list. This part qname is
213+
// temporary and should not be used with it's
214+
// namespace URI (which happened to be the operation name)
215+
// with _input attached to it
216+
217+
218+
partNameList.add(
219+
WSDLUtil.getPartQName(opName.getLocalPart(),
220+
WSDLConstants.INPUT_PART_QNAME_SUFFIX,
221+
partName));
222+
223+
// if the particle contains anything other than
224+
// a XMLSchemaElement then we are not in a position
225+
// to unwrap it
226+
} else {
227+
throw new CodeGenerationException(CodegenMessages.getMessage("extension.unsupportedSchemaFormat",
228+
"unknown type", "Element"));
229+
}
230+
}
231+
232+
//we do not know how to deal with other particles
233+
//such as xs:all or xs:choice. Usually occurs when
234+
//passed with the user built WSDL where the style
235+
//is document.
236+
} else if (schemaParticle instanceof XmlSchemaChoice) {
237+
throw new CodeGenerationException(CodegenMessages.getMessage("extension.unsupportedSchemaFormat",
238+
"choice", "sequence"));
239+
240+
} else if (schemaParticle instanceof XmlSchemaAll) {
241+
throw new CodeGenerationException(CodegenMessages.getMessage("extension.unsupportedSchemaFormat",
242+
"all", "sequence"));
243+
} else {
244+
throw new CodeGenerationException(CodegenMessages.getMessage("extension.unsupportedSchemaFormat",
245+
"unknown", "sequence"));
246+
}
247+
}
248+
211249
/**
212250
* Generate a parametes object
251+
*
213252
* @param key
214253
* @param value
215-
* @return
216254
*/
217-
private Parameter getParameter(String key,Object value){
255+
private Parameter getParameter(String key, Object value) {
218256
Parameter myParameter = new Parameter();
219257
myParameter.setName(key);
220258
myParameter.setValue(value);
@@ -223,5 +261,4 @@ private Parameter getParameter(String key,Object value){
223261
}
224262

225263

226-
227264
}

0 commit comments

Comments
 (0)