use of org.apache.ws.commons.schema.XmlSchemaType in project cxf by apache.
the class WSDLToCorbaBinding method convertFaultToCorbaType.
private CorbaType convertFaultToCorbaType(XmlSchema xmlSchema, Fault fault) throws Exception {
org.apache.cxf.binding.corba.wsdl.Exception corbaex = null;
Iterator<Part> parts = CastUtils.cast(fault.getMessage().getParts().values().iterator());
if (!parts.hasNext()) {
String msgStr = "Fault " + fault.getMessage().getQName().getLocalPart() + " UNSUPPORTED_FAULT.";
org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message(msgStr, LOG);
throw new Exception(msg.toString());
}
Part part = parts.next();
XmlSchemaType schemaType = helper.lookUpType(part);
if (schemaType != null) {
QName name = schemaType.getQName();
if (name == null) {
name = part.getElementName();
}
if (!helper.isSchemaTypeException(schemaType)) {
corbaex = new org.apache.cxf.binding.corba.wsdl.Exception();
String faultName = fault.getMessage().getQName().getLocalPart();
int pos = faultName.indexOf("_exception.");
if (pos != -1) {
faultName = faultName.substring(pos + 11);
faultName = faultName + "Exception";
}
QName faultMsgName = helper.createQNameCorbaNamespace(faultName);
corbaex.setName(faultName);
corbaex.setQName(faultMsgName);
CorbaType corbaTypeImpl = helper.convertSchemaToCorbaType(schemaType, name, null, null, false);
if (corbaTypeImpl != null) {
MemberType member = new MemberType();
member.setName(corbaTypeImpl.getQName().getLocalPart());
member.setIdltype(corbaTypeImpl.getQName());
if (corbaTypeImpl.isSetQualified() && corbaTypeImpl.isQualified()) {
member.setQualified(true);
}
corbaex.getMember().add(member);
}
} else {
corbaex = createCorbaException(name, schemaType);
}
}
if (schemaType == null) {
String msgStr = "Fault " + fault.getMessage().getQName().getLocalPart() + " INCORRECT_FAULT_MSG.";
org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message(msgStr, LOG);
throw new Exception(msg.toString());
}
if (corbaex == null) {
String msgStr = "Fault " + fault.getMessage().getQName().getLocalPart() + " UNSUPPORTED_FAULT.";
org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message(msgStr, LOG);
throw new Exception(msg.toString());
}
// Set the repository ID for Exception
// add to CorbaTypeMapping
String repoId = WSDLToCorbaHelper.REPO_STRING + corbaex.getName().replace('.', '/') + WSDLToCorbaHelper.IDL_VERSION;
corbaex.setRepositoryID(repoId);
CorbaType corbaTypeImpl = corbaex;
if (!helper.isDuplicate(corbaTypeImpl)) {
CorbaType dup = helper.isDuplicateException(corbaTypeImpl);
if (dup != null) {
typeMappingType.getStructOrExceptionOrUnion().remove(dup);
typeMappingType.getStructOrExceptionOrUnion().add(corbaTypeImpl);
} else {
typeMappingType.getStructOrExceptionOrUnion().add(corbaTypeImpl);
}
}
return corbaex;
}
use of org.apache.ws.commons.schema.XmlSchemaType in project cxf by apache.
the class SequenceVisitor method visit.
public void visit(AST seq) {
// <sequence_type> ::= "sequence" "<" <simple_type_spec> "," <positive_int_const> ">"
// | "sequence" "<" <simple_type_spec> ">"
AST simpleTypeSpecNode = seq.getFirstChild();
// REVISIT: TypesUtils.getPrimitiveCorbaTypeNameNode should be renamed
// to something more suitable and should be made more general.
AST boundNode = TypesUtils.getCorbaTypeNameNode(simpleTypeSpecNode);
// if so, replace the symbol name with defined const
if (boundNode != null) {
String constValue = TypesUtils.getConstValueByName(boundNode, typeMap);
if (constValue != null) {
boundNode.setText(constValue);
}
}
SimpleTypeSpecVisitor visitor = new SimpleTypeSpecVisitor(new Scope(getScope(), identifierNode), definition, schema, wsdlVisitor, null);
visitor.visit(simpleTypeSpecNode);
XmlSchemaType stype = visitor.getSchemaType();
CorbaType ctype = visitor.getCorbaType();
Scope fullyQualifiedName = visitor.getFullyQualifiedName();
long bound = -1;
if (boundNode != null) {
bound = Long.parseLong(boundNode.toString());
}
final Scope scopedName;
if (identifierNode == null) {
// anonymous type
scopedName = TypesUtils.generateAnonymousScopedName(getScope(), schema);
} else {
scopedName = new Scope(getScope(), identifierNode);
}
final XmlSchemaType schemaType;
//
if (stype != null) {
if (!stype.getQName().equals(Constants.XSD_UNSIGNEDBYTE)) {
schemaType = generateSchemaType(stype, scopedName, bound, fullyQualifiedName);
} else {
schemaType = wsdlVisitor.getSequenceOctetType();
}
} else {
schemaType = generateSchemaType(null, scopedName, bound, fullyQualifiedName);
}
final CorbaType corbaType;
if (identifierNode == null) {
corbaType = generateCorbaAnonsequence(ctype, schemaType, scopedName, bound, fullyQualifiedName);
} else {
corbaType = generateCorbaSequence(ctype, schemaType, scopedName, bound, fullyQualifiedName);
}
setSchemaType(schemaType);
setCorbaType(corbaType);
setFullyQualifiedName(fullyQualifiedName);
}
use of org.apache.ws.commons.schema.XmlSchemaType in project cxf by apache.
the class StructVisitor method processForwardStructActions.
// Process any actions that were defered for a forward declared struct
private void processForwardStructActions(Scope structScope) {
if (wsdlVisitor.getDeferredActions() != null) {
DeferredActionCollection deferredActions = wsdlVisitor.getDeferredActions();
List<DeferredAction> list = deferredActions.getActions(structScope);
if ((list != null) && !list.isEmpty()) {
XmlSchemaType stype = getSchemaType();
CorbaType ctype = getCorbaType();
Iterator<DeferredAction> iterator = list.iterator();
while (iterator.hasNext()) {
SchemaDeferredAction action = (SchemaDeferredAction) iterator.next();
action.execute(stype, ctype);
}
iterator = list.iterator();
while (iterator.hasNext()) {
iterator.next();
iterator.remove();
}
}
}
}
use of org.apache.ws.commons.schema.XmlSchemaType in project cxf by apache.
the class ScopedNameVisitor method findSchemaTypeInGlobalScope.
private static boolean findSchemaTypeInGlobalScope(Scope scope, Definition defn, XmlSchema currentSchema, AST node, WSDLASTVisitor wsdlVisitor, VisitorTypeHolder holder) {
XmlSchemaCollection schemas = wsdlVisitor.getSchemas();
TypeMappingType typeMap = wsdlVisitor.getTypeMap();
ModuleToNSMapper mapper = wsdlVisitor.getModuleToNSMapper();
WSDLSchemaManager manager = wsdlVisitor.getManager();
Scope scopedName = new Scope(scope, node);
String name = node.toString();
if (isFullyScopedName(node)) {
scopedName = getFullyScopedName(new Scope(), node);
name = scopedName.toString();
}
boolean result = findNonSchemaType(name, wsdlVisitor, holder);
if (!result) {
XmlSchema xmlSchema = currentSchema;
QName qname = null;
String tns = mapper.map(scopedName.getParent());
if (tns != null) {
xmlSchema = manager.getXmlSchema(tns);
if (xmlSchema != null) {
qname = new QName(xmlSchema.getTargetNamespace(), scopedName.tail());
}
} else {
qname = new QName(xmlSchema.getTargetNamespace(), name);
}
XmlSchemaType stype = null;
if (qname != null) {
// Exceptions are treated as a special case as above
if (exceptionMode) {
qname = new QName(xmlSchema.getTargetNamespace(), qname.getLocalPart() + "Type");
}
stype = xmlSchema.getTypeByName(qname);
if (stype == null) {
stype = schemas.getTypeByQName(qname);
}
}
if (stype != null) {
result = true;
if (holder != null) {
holder.setSchemaType(stype);
holder.setCorbaType(getCorbaSchemaType(xmlSchema, typeMap, stype, scopedName));
// add a xmlschema import
if (!currentSchema.getTargetNamespace().equals(xmlSchema.getTargetNamespace())) {
String importFile = wsdlVisitor.getOutputDir() + System.getProperty("file.separator") + scopedName.getParent().toString("_");
manager.addXmlSchemaImport(currentSchema, xmlSchema, importFile);
}
}
}
}
return result;
}
use of org.apache.ws.commons.schema.XmlSchemaType in project cxf by apache.
the class ExceptionVisitor method visit.
public void visit(AST node) {
// <exception_dcl> ::= "exception" <identifier> "{" <member>* "}"
// <member> ::= <type_spec> <declarators> ";"
// <type_spec> visited by TypesVisitor
// Following should be visited by a separate visitor
// <declarators> ::= <declarator> { "," <declarator> }*
// <declarator> ::= <simple_declarator>
// | <complex_declarator>
// <simple_declarator> ::= <identifier>
// <complex_declarator> ::= <array_declarator>
// <array_declarator> ::= <identifier> <fixed_array_size>+
// <fixed_array_size> ::= "[" <positive_int_const> "]"
AST identifierNode = node.getFirstChild();
Scope exceptionScope = new Scope(getScope(), identifierNode);
// xmlschema:exception
Scope scopedName = new Scope(getScope(), identifierNode);
String exceptionName = mapper.mapToQName(scopedName);
XmlSchemaElement element = new XmlSchemaElement(schema, true);
element.setName(mapper.mapToQName(scopedName));
String exceptionTypeName = exceptionName + TYPE_SUFFIX;
XmlSchemaComplexType complexType = new XmlSchemaComplexType(schema, true);
complexType.setName(exceptionTypeName);
// complexType.setQName(new QName(schema.getTargetNamespace(), exceptionTypeName));
XmlSchemaSequence sequence = new XmlSchemaSequence();
complexType.setParticle(sequence);
element.setSchemaTypeName(complexType.getQName());
// corba:exception
org.apache.cxf.binding.corba.wsdl.Exception exception = new org.apache.cxf.binding.corba.wsdl.Exception();
exception.setQName(new QName(typeMap.getTargetNamespace(), exceptionName));
exception.setType(complexType.getQName());
exception.setRepositoryID(scopedName.toIDLRepositoryID());
// exception members
AST memberTypeNode = identifierNode.getNextSibling();
while (memberTypeNode != null) {
AST memberNode = TypesUtils.getCorbaTypeNameNode(memberTypeNode);
TypesVisitor visitor = new TypesVisitor(exceptionScope, definition, schema, wsdlVisitor, null);
visitor.visit(memberTypeNode);
XmlSchemaType stype = visitor.getSchemaType();
CorbaType ctype = visitor.getCorbaType();
Scope fullyQualifiedName = visitor.getFullyQualifiedName();
// needed for anonymous arrays in exceptions
if (ArrayVisitor.accept(memberNode)) {
Scope anonScope = new Scope(exceptionScope, TypesUtils.getCorbaTypeNameNode(memberTypeNode));
ArrayVisitor arrayVisitor = new ArrayVisitor(anonScope, definition, schema, wsdlVisitor, null, fullyQualifiedName);
arrayVisitor.setSchemaType(stype);
arrayVisitor.setCorbaType(ctype);
arrayVisitor.visit(memberNode);
stype = arrayVisitor.getSchemaType();
ctype = arrayVisitor.getCorbaType();
}
XmlSchemaElement member = createElementType(memberNode, stype, fullyQualifiedName);
sequence.getItems().add(member);
MemberType memberType = createMemberType(memberNode, ctype, fullyQualifiedName);
exception.getMember().add(memberType);
memberTypeNode = memberNode.getNextSibling();
}
// add exception to corba typemap
typeMap.getStructOrExceptionOrUnion().add(exception);
setSchemaType(complexType);
setCorbaType(exception);
createFaultMessage(element.getQName());
}
Aggregations