Package org.apache.yoko.tools.processors.idl

Source Code of org.apache.yoko.tools.processors.idl.StructVisitor

/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.yoko.tools.processors.idl;

import javax.xml.namespace.QName;

import antlr.collections.AST;

import org.apache.schemas.yoko.bindings.corba.MemberType;
import org.apache.schemas.yoko.bindings.corba.Struct;
import org.apache.schemas.yoko.bindings.corba.TypeMappingType;

import org.apache.ws.commons.schema.XmlSchema;
import org.apache.ws.commons.schema.XmlSchemaCollection;
import org.apache.ws.commons.schema.XmlSchemaComplexType;
import org.apache.ws.commons.schema.XmlSchemaElement;
import org.apache.ws.commons.schema.XmlSchemaSequence;
import org.apache.ws.commons.schema.XmlSchemaType;

import org.apache.yoko.wsdl.CorbaTypeImpl;

public class StructVisitor extends VisitorBase {
   
    public StructVisitor(Scope scope,
                         XmlSchemaCollection xmlSchemas,
                         XmlSchema xmlSchema,
                         TypeMappingType typeMappingType) {
        super(scope, xmlSchemas, xmlSchema, typeMappingType);
    }

    public static boolean accept(AST node) {
        if (node.getType() == IDLTokenTypes.LITERAL_struct) {
            return true;
        }
        return false;
    }
   
    public void visit(AST node) {
        // <struct_type> ::= "struct" <identifier> "{" <member_list> "}"
        // <member_list> ::= <member>+
        // <member> ::= <type_spec> <declarators> ";"

       
        AST identifierNode = node.getFirstChild();
        Scope structScope = new Scope(getScope(), identifierNode);       

        // xmlschema:struct
        XmlSchemaComplexType complexType = new XmlSchemaComplexType(schema);
        complexType.setName(structScope.toString());
        XmlSchemaSequence sequence = new XmlSchemaSequence();
        complexType.setParticle(sequence);

       
        // corba:struct
        Struct struct = new Struct();
        struct.setQName(new QName(typeMap.getTargetNamespace(), structScope.toString()));
        struct.setType(complexType.getQName());
        struct.setRepositoryID(structScope.toIDLRepositoryID());

       
        // struct members
        AST memberTypeNode = identifierNode.getNextSibling();
        while (memberTypeNode != null) {
            AST memberNode = TypesUtils.getCorbaTypeNameNode(memberTypeNode);
           
            XmlSchemaType schemaType = null;
            CorbaTypeImpl corbaType = null;
            try {
                TypesVisitor visitor = new TypesVisitor(structScope,
                                                        schemas,
                                                        schema,
                                                        typeMap,
                                                        null);
                visitor.visit(memberTypeNode);
               
                schemaType = visitor.getSchemaType();
                corbaType = visitor.getCorbaType();
               
            } catch (Exception ex) {
                System.out.println(ex.getMessage());
                System.exit(1);
            }

            // needed for anonymous arrays in structs
            if (ArrayVisitor.accept(memberNode)) {
                Scope anonScope = new Scope(structScope,
                                            TypesUtils.getCorbaTypeNameNode(memberTypeNode));
                ArrayVisitor arrayVisitor = new ArrayVisitor(anonScope,
                                                             schemas,
                                                             schema,
                                                             typeMap,
                                                             schemaType,
                                                             corbaType,
                                                             null);
                arrayVisitor.visit(memberNode);
                schemaType = arrayVisitor.getSchemaType();
                corbaType = arrayVisitor.getCorbaType();
            }
           
            // xmlschema:member
            XmlSchemaElement member = new XmlSchemaElement();
            String memberName = memberNode.toString();
            member.setName(memberName);
            member.setSchemaType(schemaType);
            member.setSchemaTypeName(schemaType.getQName());

            sequence.getItems().add(member);

           
            // corba:member
            MemberType memberType = new MemberType();
            memberType.setName(memberName);
            memberType.setIdltype(corbaType.getQName());
            struct.getMember().add(memberType);

            memberTypeNode = memberNode.getNextSibling();
        }

        // add schemaType
        schema.getItems().add(complexType);
        schema.addType(complexType);

        // add corbaType
        typeMap.getStructOrExceptionOrUnion().add(struct);
       
        // REVISIT: are there assignment needed?
        setSchemaType(complexType);
        setCorbaType(struct);
    }
   
}
TOP

Related Classes of org.apache.yoko.tools.processors.idl.StructVisitor

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.