Search in sources :

Example 1 with Const

use of org.apache.cxf.binding.corba.wsdl.Const in project cxf by apache.

the class ConstVisitor method visit.

public void visit(AST constNode) {
    // <const_dcl> ::= "const" <const_type> <identifier> "=" <const_exp>
    // <const_type> ::= <integer_type>
    // | <char_type>
    // | <wide_char_type>
    // | <boolean_type>
    // | <floating_pt_type>
    // | <string_type>
    // | <wide_string_type>
    // | <fixed_pt_const_type>
    // | <scoped_name>
    // | <octet_type>
    AST constTypeNode = constNode.getFirstChild();
    AST constNameNode = TypesUtils.getCorbaTypeNameNode(constTypeNode);
    AST constValueNode = constNameNode.getNextSibling();
    // build value string
    StringBuilder constValue = new StringBuilder();
    if (constValueNode.toString() != null) {
        constValue.append(constValueNode.toString());
    }
    constValueNode = constValueNode.getFirstChild();
    if (constValue.length() == 1) {
        // might be a control char
        byte ch = (byte) constValue.charAt(0);
        if (ch >= 0 && ch <= 31) {
            // ascii code between 0 and 31 is invisible control code
            constValue.deleteCharAt(0);
            constValue.append("\\" + Integer.toOctalString(ch));
        }
    }
    while (constValueNode != null) {
        constValue.append(constValueNode.toString());
        constValueNode = constValueNode.getFirstChild();
    }
    QName constQName = new QName(typeMap.getTargetNamespace(), new Scope(getScope(), constNameNode).toString());
    Visitor visitor = null;
    if (PrimitiveTypesVisitor.accept(constTypeNode)) {
        visitor = new PrimitiveTypesVisitor(getScope(), definition, schema, schemas);
    } else if (StringVisitor.accept(constTypeNode)) {
        // string_type_spec
        // wstring_type_spec
        visitor = new StringVisitor(getScope(), definition, schema, wsdlVisitor, constTypeNode);
    } else if (FixedPtConstVisitor.accept(constTypeNode)) {
        visitor = new FixedPtConstVisitor(getScope(), definition, schema, schemas);
    } else if (ScopedNameVisitor.accept(getScope(), definition, schema, constTypeNode, wsdlVisitor)) {
        visitor = new ScopedNameVisitor(getScope(), definition, schema, wsdlVisitor);
    }
    if (visitor == null) {
        throw new RuntimeException("can't resolve type for const " + constNameNode.getText());
    }
    visitor.visit(constTypeNode);
    XmlSchemaType constSchemaType = visitor.getSchemaType();
    CorbaTypeImpl constCorbaType = visitor.getCorbaType();
    // corba:const
    Const corbaConst = new Const();
    corbaConst.setQName(constQName);
    corbaConst.setValue(constValue.toString());
    corbaConst.setType(constSchemaType.getQName());
    corbaConst.setIdltype(constCorbaType.getQName());
    typeMap.getStructOrExceptionOrUnion().add(corbaConst);
}
Also used : AST(antlr.collections.AST) QName(javax.xml.namespace.QName) CorbaTypeImpl(org.apache.cxf.binding.corba.wsdl.CorbaTypeImpl) Const(org.apache.cxf.binding.corba.wsdl.Const) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType)

Example 2 with Const

use of org.apache.cxf.binding.corba.wsdl.Const in project cxf by apache.

the class WSDLToIDLAction method createType.

protected IdlType createType(QName idlType, String[] name, CorbaType corbaType) throws Exception {
    if (idlType.getLocalPart().equals("CORBA.Object")) {
        return IdlInterface.create(null, "Object");
    }
    CorbaType corbaTypeImpl = corbaType;
    if (corbaTypeImpl == null) {
        corbaTypeImpl = getCorbaType(idlType);
    }
    if (corbaTypeImpl == null) {
        String msgStr = "Type " + idlType.getLocalPart() + " not found.";
        org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message(msgStr, LOG);
        throw new Exception(msg.toString());
    }
    IdlScopeBase scope = root;
    StringBuilder dotScopedName = new StringBuilder("");
    for (int i = 0; i < name.length - 1; ++i) {
        dotScopedName.append(name[i]);
        // name array.
        if ("CORBA".equals(dotScopedName.toString()) && name.length == 2 && i == 0 && name[1].equals("Object")) {
            break;
        }
        IdlDefn idlDef = scope.lookup(name[i]);
        if (idlDef == null) {
            // Before creating module, check to see if a Corba type
            // represent this name aleady exists.
            // For example if type is a.b.c and we are about to create
            // module b, look to see if a.b
            // is an interface that needs to be processed
            QName qname = new QName(corbaTypeImpl.getType().getNamespaceURI(), dotScopedName.toString());
            // Check to see if CORBAType exists. If so, create type for it
            // otherwise
            // create module for this scope
            CorbaType possibleCorbaType = getCorbaType(qname);
            if (possibleCorbaType != null) {
                idlDef = findType(qname);
            }
            if (idlDef == null) {
                idlDef = IdlModule.create(scope, name[i]);
                scope.addToScope(idlDef);
            }
        }
        dotScopedName.append(".");
        scope = (IdlScopeBase) idlDef;
    }
    IdlType result = null;
    String local = name[name.length - 1];
    if (corbaTypeImpl instanceof Enum) {
        result = createEnum((Enum) corbaTypeImpl, scope, local);
    } else if (corbaTypeImpl instanceof Sequence) {
        result = createSequence((Sequence) corbaTypeImpl, scope, local);
    } else if (corbaTypeImpl instanceof Anonsequence) {
        result = createAnonSequence((Anonsequence) corbaTypeImpl, scope, local);
    } else if (corbaTypeImpl instanceof org.apache.cxf.binding.corba.wsdl.Exception) {
        result = createIdlException((org.apache.cxf.binding.corba.wsdl.Exception) corbaTypeImpl, scope, local);
    } else if (corbaTypeImpl instanceof Struct) {
        result = createStruct((Struct) corbaTypeImpl, scope, local);
    } else if (corbaTypeImpl instanceof Union) {
        result = createUnion((Union) corbaTypeImpl, scope, local);
    } else if (corbaTypeImpl instanceof Alias) {
        result = createTypedef((Alias) corbaTypeImpl, scope, local);
    } else if (corbaTypeImpl instanceof Array) {
        result = createArray((Array) corbaTypeImpl, scope, local);
    } else if (corbaTypeImpl instanceof Anonarray) {
        result = createAnonArray((Anonarray) corbaTypeImpl, scope, local);
    } else if (corbaTypeImpl instanceof Fixed) {
        result = createFixed((Fixed) corbaTypeImpl, scope, local);
    } else if (corbaTypeImpl instanceof Anonfixed) {
        result = createAnonFixed((Anonfixed) corbaTypeImpl, scope, local);
    } else if (corbaTypeImpl instanceof Const) {
        result = createConst((Const) corbaTypeImpl, scope, local);
    } else {
        result = checkAnon(corbaTypeImpl, scope, local);
    }
    if (result == null && corbaTypeImpl instanceof org.apache.cxf.binding.corba.wsdl.Object) {
        result = createInterface((org.apache.cxf.binding.corba.wsdl.Object) corbaTypeImpl, scope, local);
    }
    return result;
}
Also used : IdlEnum(org.apache.cxf.tools.corba.common.idltypes.IdlEnum) Enum(org.apache.cxf.binding.corba.wsdl.Enum) IdlString(org.apache.cxf.tools.corba.common.idltypes.IdlString) IdlType(org.apache.cxf.tools.corba.common.idltypes.IdlType) Union(org.apache.cxf.binding.corba.wsdl.Union) IdlUnion(org.apache.cxf.tools.corba.common.idltypes.IdlUnion) IdlStruct(org.apache.cxf.tools.corba.common.idltypes.IdlStruct) Struct(org.apache.cxf.binding.corba.wsdl.Struct) Anonarray(org.apache.cxf.binding.corba.wsdl.Anonarray) IdlFixed(org.apache.cxf.tools.corba.common.idltypes.IdlFixed) IdlAnonFixed(org.apache.cxf.tools.corba.common.idltypes.IdlAnonFixed) Fixed(org.apache.cxf.binding.corba.wsdl.Fixed) QName(javax.xml.namespace.QName) IdlDefn(org.apache.cxf.tools.corba.common.idltypes.IdlDefn) Const(org.apache.cxf.binding.corba.wsdl.Const) IdlConst(org.apache.cxf.tools.corba.common.idltypes.IdlConst) IdlScopeBase(org.apache.cxf.tools.corba.common.idltypes.IdlScopeBase) IdlAnonSequence(org.apache.cxf.tools.corba.common.idltypes.IdlAnonSequence) Sequence(org.apache.cxf.binding.corba.wsdl.Sequence) IdlSequence(org.apache.cxf.tools.corba.common.idltypes.IdlSequence) IdlException(org.apache.cxf.tools.corba.common.idltypes.IdlException) IdlAnonArray(org.apache.cxf.tools.corba.common.idltypes.IdlAnonArray) Array(org.apache.cxf.binding.corba.wsdl.Array) IdlArray(org.apache.cxf.tools.corba.common.idltypes.IdlArray) Anonfixed(org.apache.cxf.binding.corba.wsdl.Anonfixed) CorbaType(org.apache.cxf.binding.corba.wsdl.CorbaType) Alias(org.apache.cxf.binding.corba.wsdl.Alias) Anonsequence(org.apache.cxf.binding.corba.wsdl.Anonsequence)

Example 3 with Const

use of org.apache.cxf.binding.corba.wsdl.Const in project cxf by apache.

the class TypesUtils method getConstValueByName.

public static String getConstValueByName(AST node, TypeMappingType typeMap) {
    List<CorbaType> types = typeMap.getStructOrExceptionOrUnion();
    for (Iterator<CorbaType> it = types.iterator(); it.hasNext(); ) {
        CorbaType corbaType = it.next();
        if (corbaType instanceof Const) {
            Const corbaConst = (Const) corbaType;
            String name = corbaConst.getQName().getLocalPart();
            if (name.endsWith(node.getText())) {
                return corbaConst.getValue();
            }
        }
    }
    return null;
}
Also used : CorbaType(org.apache.cxf.binding.corba.wsdl.CorbaType) Const(org.apache.cxf.binding.corba.wsdl.Const)

Aggregations

Const (org.apache.cxf.binding.corba.wsdl.Const)3 QName (javax.xml.namespace.QName)2 CorbaType (org.apache.cxf.binding.corba.wsdl.CorbaType)2 AST (antlr.collections.AST)1 Alias (org.apache.cxf.binding.corba.wsdl.Alias)1 Anonarray (org.apache.cxf.binding.corba.wsdl.Anonarray)1 Anonfixed (org.apache.cxf.binding.corba.wsdl.Anonfixed)1 Anonsequence (org.apache.cxf.binding.corba.wsdl.Anonsequence)1 Array (org.apache.cxf.binding.corba.wsdl.Array)1 CorbaTypeImpl (org.apache.cxf.binding.corba.wsdl.CorbaTypeImpl)1 Enum (org.apache.cxf.binding.corba.wsdl.Enum)1 Fixed (org.apache.cxf.binding.corba.wsdl.Fixed)1 Sequence (org.apache.cxf.binding.corba.wsdl.Sequence)1 Struct (org.apache.cxf.binding.corba.wsdl.Struct)1 Union (org.apache.cxf.binding.corba.wsdl.Union)1 IdlAnonArray (org.apache.cxf.tools.corba.common.idltypes.IdlAnonArray)1 IdlAnonFixed (org.apache.cxf.tools.corba.common.idltypes.IdlAnonFixed)1 IdlAnonSequence (org.apache.cxf.tools.corba.common.idltypes.IdlAnonSequence)1 IdlArray (org.apache.cxf.tools.corba.common.idltypes.IdlArray)1 IdlConst (org.apache.cxf.tools.corba.common.idltypes.IdlConst)1