use of org.apache.ws.commons.schema.XmlSchemaType in project cxf by apache.
the class ObjectReferenceVisitor method visitCustomTypeObjectReference.
private void visitCustomTypeObjectReference(AST node) {
QName bindingName = null;
QName referenceName = null;
String repositoryID = null;
Scope currentScope = getScope();
Scope customScope = null;
if ((node.getFirstChild() == null) || (node.getFirstChild() != null && node.getFirstChild().getType() != IDLTokenTypes.SCOPEOP)) {
while (bindingName == null && currentScope != currentScope.getParent()) {
if (ScopedNameVisitor.isFullyScopedName(node)) {
customScope = ScopedNameVisitor.getFullyScopedName(currentScope, node);
} else {
customScope = new Scope(currentScope, node);
}
if (mapper.isDefaultMapping()) {
referenceName = new QName(schema.getTargetNamespace(), customScope.toString() + "Ref");
} else {
String tns = mapper.map(customScope.getParent());
referenceName = new QName(tns, customScope.tail() + "Ref");
}
repositoryID = customScope.toIDLRepositoryID();
bindingName = getBindingQNameByID(definition, repositoryID, objRefWsdlVisitor);
currentScope = currentScope.getParent();
}
}
if (bindingName == null) {
// Global scope is our last chance to resolve the node
if (ScopedNameVisitor.isFullyScopedName(node)) {
customScope = ScopedNameVisitor.getFullyScopedName(new Scope(), node);
if (mapper.isDefaultMapping()) {
referenceName = new QName(schema.getTargetNamespace(), customScope.toString() + "Ref");
} else {
String tns = mapper.map(customScope.getParent());
referenceName = new QName(tns, customScope.tail() + "Ref");
}
} else {
// customScope = currentScope;
customScope = new Scope(new Scope(), node);
if (mapper.isDefaultMapping()) {
referenceName = new QName(schema.getTargetNamespace(), customScope.toString() + "Ref");
} else {
String tns = mapper.map(customScope.getParent());
referenceName = new QName(tns, customScope.tail() + "Ref");
}
}
repositoryID = customScope.toIDLRepositoryID();
bindingName = getBindingQNameByID(definition, repositoryID, objRefWsdlVisitor);
if (bindingName == null) {
// check bindingName with prefix
customScope.setPrefix(objRefWsdlVisitor.getPragmaPrefix());
repositoryID = customScope.toIDLRepositoryID();
bindingName = getBindingQNameByID(definition, repositoryID, objRefWsdlVisitor);
}
}
if (bindingName == null) {
// We need to have a binding for this kind of object reference to work
throw new RuntimeException("[ObjectReferenceVisitor: No binding available for endpoint]");
}
// Create a schema namespace for WS addressing and use it to create an endpoint
// reference type. This will be used as the type for our endpoint reference.
XmlSchema[] scs = schemas.getXmlSchema(ReferenceConstants.WSADDRESSING_NAMESPACE);
XmlSchema wsaSchema = null;
if (scs != null) {
for (XmlSchema sc : scs) {
if (ReferenceConstants.WSADDRESSING_NAMESPACE.equals(sc.getTargetNamespace())) {
wsaSchema = sc;
break;
}
}
}
if (wsaSchema == null) {
wsaSchema = new XmlSchema(ReferenceConstants.WSADDRESSING_NAMESPACE, schemas);
}
XmlSchemaType wsaType = new XmlSchemaSimpleType(wsaSchema, true);
wsaType.setName(ReferenceConstants.WSADDRESSING_LOCAL_NAME);
// Check to see if we have already defined an element for this reference type. If
// we have, then there is no need to add it to the schema again.
isDuplicateReference(referenceName, bindingName, customScope, wsaType, node);
setSchemaType(wsaType);
// Build and assign the corba:object to the visitor
Object corbaObject = new Object();
corbaObject.setBinding(bindingName);
corbaObject.setQName(new QName(typeMap.getTargetNamespace(), customScope.toString()));
corbaObject.setRepositoryID(repositoryID);
corbaObject.setType(wsaType.getQName());
setCorbaType(corbaObject);
// type once.
if (!isReferenceCORBATypeDefined(corbaObject.getQName())) {
typeMap.getStructOrExceptionOrUnion().add(corbaObject);
}
}
use of org.apache.ws.commons.schema.XmlSchemaType in project cxf by apache.
the class OperationVisitor method visitOpTypeSpec.
private void visitOpTypeSpec(AST node, XmlSchemaSequence outputWrappingSequence) {
if (node.getType() == IDLTokenTypes.LITERAL_void) {
// nothing to do here, move along
return;
}
ParamTypeSpecVisitor visitor = new ParamTypeSpecVisitor(getScope(), definition, schema, wsdlVisitor);
visitor.visit(node);
XmlSchemaType schemaType = visitor.getSchemaType();
CorbaTypeImpl corbaType = visitor.getCorbaType();
Scope fqName = visitor.getFullyQualifiedName();
addElement(outputWrappingSequence, schemaType, fqName, RETURN_PARAMETER);
addCorbaReturn(corbaType, fqName, RETURN_PARAMETER);
}
use of org.apache.ws.commons.schema.XmlSchemaType in project cxf by apache.
the class OperationVisitor method visit.
public void visit(AST node) {
// <op_dcl> ::= [<op_attribute>] <op_type_spec>
// <identifier> <parameter_dcls>
// [<raises_expr>] [<context_expr>]
// <op_attribute> ::= "oneway"
// <op_type_spec> ::= <param_type_spec>
// | "void"
// <parameter_dcls> ::= "(" <param_dcl> {"," <param_dcl>}* ")"
// | "(" ")"
// <raises_expr> ::= "raises" "(" <scoped_name> {"," <scoped_name>}* ")"
// <context_expr> ::= "context" "(" <string_literal> {"," <string_literal>}* ")"
QName operationQName = new QName(schema.getTargetNamespace(), node.toString());
boolean isDuplicate = false;
if (schema.getElements().containsKey(operationQName)) {
isDuplicate = true;
}
Operation operation = generateOperation(operationQName.getLocalPart(), isDuplicate);
final BindingOperation bindingOperation;
if (isDuplicate) {
bindingOperation = generateBindingOperation(binding, operation, operationQName.getLocalPart());
} else {
bindingOperation = generateBindingOperation(binding, operation, operation.getName());
}
XmlSchemaSequence inputWrappingSequence = new XmlSchemaSequence();
XmlSchemaElement inputElement = generateWrapper(new QName(schema.getTargetNamespace(), operation.getName()), inputWrappingSequence);
inputMsg = generateInputMessage(operation, bindingOperation);
generateInputPart(inputMsg, inputElement);
// <op_attribute>
node = node.getFirstChild();
XmlSchemaSequence outputWrappingSequence = null;
if (node != null && (node.getType() == IDLTokenTypes.LITERAL_oneway)) {
// oneway operations map to operations with only input message
// no outputMsg nor outputPart need be created
node = node.getNextSibling();
} else {
// normal operations map to request-response operations
// with input and output messages
outputWrappingSequence = new XmlSchemaSequence();
XmlSchemaElement outputElement = generateWrapper(new QName(schema.getTargetNamespace(), operation.getName() + RESPONSE_SUFFIX), outputWrappingSequence);
outputMsg = generateOutputMessage(operation, bindingOperation);
generateOutputPart(outputMsg, outputElement);
}
// <op_type_spec>
visitOpTypeSpec(node, outputWrappingSequence);
// <parameter_dcls>
node = TypesUtils.getCorbaTypeNameNode(node);
while (ParamDclVisitor.accept(node)) {
ParamDclVisitor visitor = new ParamDclVisitor(getScope(), definition, schema, wsdlVisitor, inputWrappingSequence, outputWrappingSequence, corbaOperation);
visitor.visit(node);
node = node.getNextSibling();
}
// <raises_expr>
if (node != null && node.getType() == IDLTokenTypes.LITERAL_raises) {
node = node.getFirstChild();
while (node != null) {
//
ScopedNameVisitor visitor = new ScopedNameVisitor(getScope(), definition, schema, wsdlVisitor);
visitor.setExceptionMode(true);
visitor.visit(node);
CorbaTypeImpl corbaType = visitor.getCorbaType();
XmlSchemaType schemaType = visitor.getSchemaType();
// REVISIT, schema type ends with Type for exceptions, so strip it to get the element name.
int pos = schemaType.getQName().getLocalPart().indexOf("Type");
QName elementQName = new QName(schemaType.getQName().getNamespaceURI(), schemaType.getQName().getLocalPart().substring(0, pos));
createFaultMessage(corbaType, operation, bindingOperation, elementQName);
node = node.getNextSibling();
visitor.setExceptionMode(false);
}
}
}
use of org.apache.ws.commons.schema.XmlSchemaType in project cxf by apache.
the class ArrayVisitor method visit.
public void visit(AST node) {
// <array_declarator> ::= <identifier> <fixed_array_size>+
// <fixed_array_size> ::= "[" <positive_int_const> "]"
AST firstSizeNode = node.getFirstChild();
AST nextSizeNode = firstSizeNode.getNextSibling();
final Types result;
// process all anonarrays, skip first array as it might not be anonymous
if (nextSizeNode != null) {
result = doAnonarray(nextSizeNode, getSchemaType(), getCorbaType());
} else {
result = new Types();
result.setSchemaType(getSchemaType());
result.setCorbaType(getCorbaType());
result.setFullyQualifiedName(getFullyQualifiedName());
}
// process first array
Long size = Long.valueOf(firstSizeNode.toString());
final XmlSchemaType stype;
final CorbaType ctype;
if (identifierNode != null) {
Scope scopedName = getScope();
if (result.getSchemaType() != null) {
stype = generateSchemaArray(scopedName, size, result.getSchemaType(), result.getFullyQualifiedName());
} else {
stype = generateSchemaArray(scopedName, size, null, result.getFullyQualifiedName());
}
if (result.getCorbaType() != null) {
ctype = generateCorbaArray(scopedName, size, result.getCorbaType(), stype, getFullyQualifiedName());
} else {
ctype = generateCorbaArray(scopedName, size, null, stype, getFullyQualifiedName());
}
} else {
// anonymous array
Scope scopedName = TypesUtils.generateAnonymousScopedName(getScope(), schema);
if (result.getSchemaType() != null) {
stype = generateSchemaArray(scopedName, size, result.getSchemaType(), getFullyQualifiedName());
} else {
stype = generateSchemaArray(scopedName, size, null, getFullyQualifiedName());
}
if (result.getCorbaType() != null) {
ctype = generateCorbaAnonarray(scopedName.toString(), size, result.getCorbaType(), stype, getFullyQualifiedName());
} else {
ctype = generateCorbaAnonarray(scopedName.toString(), size, null, stype, getFullyQualifiedName());
}
}
// add corbaType
typeMap.getStructOrExceptionOrUnion().add(ctype);
setSchemaType(stype);
setCorbaType(ctype);
}
use of org.apache.ws.commons.schema.XmlSchemaType in project cxf by apache.
the class AttributeVisitor method generateWrappedDocElement.
/**
* Generate a wrapped doc style XmlSchemaElement containing one element.
*
* I.e.: generateWrappedDocElement(null, "foo", "bar");
* <xs:element name="foo">
* <xs:complexType>
* <xs:sequence>
* </xs:sequence>
* </xs:complexType>
* </xs:element>
*
* i.e.: generateWrappedDocElement(type, "foo", "bar");
* <xs:element name="foo">
* <xs:complexType>
* <xs:sequence>
* <xs:element name="bar" type="xs:short">
* </xs:element>
* </xs:sequence>
* </xs:complexType>
* </xs:element>
*
* @param typeNode is the type of the element wrapped in the sequence, no element is created if null.
* @param name is the name of the wrapping element.
* @param paramName is the name of the wrapping element.
* @return the wrapping element.
*/
private XmlSchemaElement generateWrappedDocElement(AST typeNode, String name, String paramName) {
XmlSchemaElement element = new XmlSchemaElement(schema, false);
if (typeNode != null) {
ParamTypeSpecVisitor visitor = new ParamTypeSpecVisitor(getScope(), definition, schema, wsdlVisitor);
visitor.visit(typeNode);
XmlSchemaType stype = visitor.getSchemaType();
Scope fqName = visitor.getFullyQualifiedName();
if (stype != null) {
element.setSchemaTypeName(stype.getQName());
if (stype.getQName().equals(ReferenceConstants.WSADDRESSING_TYPE)) {
element.setNillable(true);
}
} else {
wsdlVisitor.getDeferredActions().add(fqName, new AttributeDeferredAction(element));
}
element.setName(paramName);
}
XmlSchemaSequence sequence = new XmlSchemaSequence();
if (typeNode != null) {
sequence.getItems().add(element);
}
XmlSchemaComplexType complex = new XmlSchemaComplexType(schema, false);
complex.setParticle(sequence);
QName qName = new QName(definition.getTargetNamespace(), name);
XmlSchemaElement result = new XmlSchemaElement(schema, true);
result.setSchemaType(complex);
if (duplicateTypeTrackerMap.containsKey(qName.toString())) {
result.setName(getScope().toString() + "." + name);
qName = new QName(definition.getTargetNamespace(), getScope().toString() + "." + name);
} else {
result.setName(name);
}
duplicateTypeTrackerMap.put(qName.toString(), name);
return result;
}
Aggregations