public void visit(AST node) {
// <scoped_name> ::= <identifier>
// | :: <identifier>
// | <scoped_name> "::" <identifier>
XmlSchemaType stype = null;
CorbaTypeImpl ctype = null;
if (PrimitiveTypesVisitor.accept(node)) {
// primitive type
PrimitiveTypesVisitor primitiveVisitor = new PrimitiveTypesVisitor(null, schemas);
primitiveVisitor.visit(node);
stype = primitiveVisitor.getSchemaType();
ctype = primitiveVisitor.getCorbaType();
} else {
// declared type
Scope currentScope = getScope();
while (stype == null
&& currentScope != currentScope.getParent()) {
// A name can be used in an unqualified form within a particular scope;
// it will be resolved by successvely searching farther out in enclosing
// scopes, while taking into consideration inheritance relationships
// among interfaces.
// INHERITANCE NOT IMPLEMENTED YET
Scope scopedName = new Scope(currentScope, node);
QName schemaQName = new QName(schema.getTargetNamespace(), scopedName.toString());
stype = schema.getTypeByName(schemaQName);
currentScope = currentScope.getParent();
}
if (stype == null) {
// Global scope is our last chance to resolve the node
QName schemaQName = new QName(schema.getTargetNamespace(), node.toString());
stype = schema.getTypeByName(schemaQName);
}
// handle special case of simple string alias
// a plain xsd:string has no corresponding XmlSchemaType in the XmlSchema
// so the previous findType() method would return null.
// As a temporary workaround, we query the typeMap for a corba:string with
// same name. If the string is there, then it had been previously properly
// declared and we can use it here.
if (stype == null) {
QName corbaQName = null;
currentScope = getScope();
while (ctype == null
&& currentScope != currentScope.getParent()) {
Scope scopedName = new Scope(currentScope, node);
corbaQName = new QName(typeMap.getTargetNamespace(), scopedName.toString());
ctype = findCorbaType(typeMap, corbaQName);
currentScope = currentScope.getParent();
}
if (ctype == null) {
corbaQName = new QName(typeMap.getTargetNamespace(), node.toString());
ctype = findCorbaType(typeMap, corbaQName);
}
if (ctype != null && ctype.getType() == Constants.XSD_STRING) {
stype = schemas.getTypeByQName(Constants.XSD_STRING);
ctype = new CorbaTypeImpl();
ctype.setName(CorbaConstants.NT_CORBA_STRING.getLocalPart());
ctype.setQName(CorbaConstants.NT_CORBA_STRING);
ctype.setType(Constants.XSD_STRING);
} else {
throw new RuntimeException("[ScopedNameVisitor: Corba type "
+ corbaQName.toString()
+ " not found in typeMap]");
}
} else {
ctype = findCorbaType(typeMap, stype.getQName());
}
}
setSchemaType(stype);
setCorbaType(ctype);