use of org.apache.ws.commons.schema.XmlSchemaSimpleType in project cxf by apache.
the class WSDLToCorbaHelper method convertSchemaToCorbaType.
public CorbaType convertSchemaToCorbaType(XmlSchemaType stype, QName defaultName, XmlSchemaType parent, XmlSchemaAnnotation annotation, boolean anonymous) throws Exception {
CorbaType corbaTypeImpl = null;
if (!isAddressingNamespace(stype.getQName())) {
// need to determine if its a primitive type.
if (stype instanceof XmlSchemaComplexType) {
corbaTypeImpl = processComplexType((XmlSchemaComplexType) stype, defaultName, annotation, anonymous);
} else if (stype instanceof XmlSchemaSimpleType) {
corbaTypeImpl = processSimpleType((XmlSchemaSimpleType) stype, defaultName, anonymous);
} else if (xmlSchemaList.getElementByQName(stype.getQName()) != null) {
XmlSchemaElement el = xmlSchemaList.getElementByQName(stype.getQName());
// REVISIT, passing ns uri because of a bug in XmlSchema (Bug: WSCOMMONS-69)
corbaTypeImpl = processElementType(el, defaultName, stype.getQName().getNamespaceURI());
} else {
throw new Exception("Couldn't convert schema " + stype.getQName() + " to corba type");
}
}
if (corbaTypeImpl != null && !isDuplicate(corbaTypeImpl)) {
typeMappingType.getStructOrExceptionOrUnion().add(corbaTypeImpl);
}
return corbaTypeImpl;
}
use of org.apache.ws.commons.schema.XmlSchemaSimpleType in project cxf by apache.
the class DeclaratorVisitor method duplicateXmlSchemaSimpleType.
private XmlSchemaSimpleType duplicateXmlSchemaSimpleType(Scope newScope) {
XmlSchemaSimpleType oldSimpleType = (XmlSchemaSimpleType) getSchemaType();
XmlSchemaSimpleType simpleType = new XmlSchemaSimpleType(schema, oldSimpleType.isTopLevel());
simpleType.setContent(oldSimpleType.getContent());
simpleType.setName(newScope.toString());
return simpleType;
}
use of org.apache.ws.commons.schema.XmlSchemaSimpleType in project cxf by apache.
the class EnumVisitor method visit.
public void visit(AST enumNode) {
// <enum_type> ::= "enum" <identifier> "{" <enumerator> {"," <enumerator>}* "}"
// <enumerator> ::= <identifier>
AST enumNameNode = enumNode.getFirstChild();
Scope enumNameScope = new Scope(getScope(), enumNameNode);
// xmlschema:enum
XmlSchemaSimpleType enumSchemaSimpleType = new XmlSchemaSimpleType(schema, true);
enumSchemaSimpleType.setName(mapper.mapToQName(enumNameScope));
XmlSchemaSimpleTypeRestriction enumSchemaSimpleTypeRestriction = new XmlSchemaSimpleTypeRestriction();
enumSchemaSimpleTypeRestriction.setBaseTypeName(Constants.XSD_STRING);
// XmlSchemaSimpleTypeContent xmlSchemaSimpleTypeContent = enumSchemaSimpleTypeRestriction;
enumSchemaSimpleType.setContent(enumSchemaSimpleTypeRestriction);
// corba:enum
Enum corbaEnum = new Enum();
corbaEnum.setQName(new QName(typeMap.getTargetNamespace(), enumNameScope.toString()));
corbaEnum.setRepositoryID(enumNameScope.toIDLRepositoryID());
corbaEnum.setType(enumSchemaSimpleType.getQName());
AST node = enumNameNode.getNextSibling();
while (node != null) {
// xmlschema:enumeration
XmlSchemaEnumerationFacet enumeration = new XmlSchemaEnumerationFacet();
enumeration.setValue(node.toString());
enumSchemaSimpleTypeRestriction.getFacets().add(enumeration);
// corba:enumerator
Enumerator enumerator = new Enumerator();
enumerator.setValue(node.toString());
corbaEnum.getEnumerator().add(enumerator);
node = node.getNextSibling();
}
// add corbaType
typeMap.getStructOrExceptionOrUnion().add(corbaEnum);
// REVISIT: are there assignments needed?
setSchemaType(enumSchemaSimpleType);
setCorbaType(corbaEnum);
}
use of org.apache.ws.commons.schema.XmlSchemaSimpleType in project cxf by apache.
the class FixedVisitor method visit.
public void visit(AST fixedNode) {
// "typedef" <type_declarator>
// <type_declarator> ::= <type_spec> <declarators>
// <type_spec> ::= <simple_type_spec>
// | <constr_type_spec>
// <simple_type_spec> ::= <base_type_spec>
// | <template_type_spec>
// | <scoped_name>
// <base_type_spec> ::= ... omitted (integer, char, octect, etc)
// <template_type_spec> ::= <sequence_type>
// | <string_type>
// | <wstring_type>
// | <fixed_pt_type>
// <constr_type_spec> ::= <struct_type>
// | <union_type>
// | <enum_type>
// <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 digitsNode = fixedNode.getFirstChild();
AST scaleNode = digitsNode.getNextSibling();
Scope scopedName = null;
if (identifierNode == null) {
scopedName = TypesUtils.generateAnonymousScopedName(getScope(), schema);
} else {
scopedName = new Scope(getScope(), identifierNode);
}
// validate digits and scale
Long digits = Long.valueOf(digitsNode.toString());
Long scale = Long.valueOf(scaleNode.toString());
if (digits < 1 || digits > 31) {
// throw IllegalIDLException();
System.out.println("Digits cannot be greater than 31");
return;
}
if (scale.compareTo(digits) > 0) {
// throw IllegalIDLException();
System.out.println("Scale cannot be greater than digits");
return;
}
// xmlschema:fixed
XmlSchemaSimpleType fixedSimpleType = new XmlSchemaSimpleType(schema, true);
XmlSchemaSimpleTypeRestriction fixedRestriction = new XmlSchemaSimpleTypeRestriction();
fixedRestriction.setBaseTypeName(Constants.XSD_DECIMAL);
XmlSchemaTotalDigitsFacet fixedTotalDigits = new XmlSchemaTotalDigitsFacet();
fixedTotalDigits.setValue(digitsNode.toString());
XmlSchemaFractionDigitsFacet fixedFractionDigits = new XmlSchemaFractionDigitsFacet();
fixedFractionDigits.setValue(scaleNode.toString());
fixedFractionDigits.setFixed(true);
fixedRestriction.getFacets().add(fixedTotalDigits);
fixedRestriction.getFacets().add(fixedFractionDigits);
fixedSimpleType.setName(mapper.mapToQName(scopedName));
fixedSimpleType.setContent(fixedRestriction);
// add xmlschema:fixed
setSchemaType(fixedSimpleType);
CorbaType type = null;
if (identifierNode != null) {
// corba:fixed
Fixed corbaFixed = new Fixed();
corbaFixed.setQName(new QName(typeMap.getTargetNamespace(), scopedName.toString()));
corbaFixed.setDigits(digits);
corbaFixed.setScale(scale);
corbaFixed.setRepositoryID(scopedName.toIDLRepositoryID());
// corbaFixed.setType(Constants.XSD_DECIMAL);
corbaFixed.setType(fixedSimpleType.getQName());
type = corbaFixed;
} else {
// corba:anonfixed
Anonfixed corbaFixed = new Anonfixed();
corbaFixed.setQName(new QName(typeMap.getTargetNamespace(), scopedName.toString()));
corbaFixed.setDigits(digits);
corbaFixed.setScale(scale);
// corbaFixed.setType(Constants.XSD_DECIMAL);
corbaFixed.setType(fixedSimpleType.getQName());
typeMap.getStructOrExceptionOrUnion().add(corbaFixed);
type = corbaFixed;
}
// add corba:fixed
setCorbaType(type);
}
use of org.apache.ws.commons.schema.XmlSchemaSimpleType 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);
}
}
Aggregations