public InterfaceContract read()

in modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/InterfaceContractProcessor.java [110:248]


    public InterfaceContract read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException {
        
        TuscanyInterfaceContractImpl interfaceContract = new TuscanyInterfaceContractImpl();
        
        try {
            InterfaceImpl iface = null;
            QName name = null;
            Operation operation = null;
            List<DataType> inputs = null;
            List<DataType> outputs = null;
            List<DataType> faults = null;
            XMLType logicalXMLType = null;
            
            Iof iof = Iof.UNSET;
            CharacterTarget characterTarget = CharacterTarget.UNSET;
            
            boolean logicalCollection = false;            
          
            DataType dataType = null;
            
            while (reader.hasNext()) {
                int event = reader.getEventType();
                
                switch (event) {
                    case START_ELEMENT:
                        name = reader.getName();
                        if (INTERFACE_CONTRACT_QNAME.equals(name)){
                        } else if (INTERFACE_QNAME.equals(name)){
                            iface = new InterfaceImpl();
                            interfaceContract.setInterface(iface);
                            iface.setRemotable(getBoolean(reader, "isRemotable"));
                        } else if (CALLBACK_INTERFACE_QNAME.equals(name)){
                            iface = new InterfaceImpl();
                            interfaceContract.setCallbackInterface(iface);
                            iface.setRemotable(getBoolean(reader, "isRemotable"));
                        } else if (OPERATION_QNAME.equals(name)) {
                            operation = new OperationImpl();
                            iface.getOperations().add(operation);
                            
                            operation.setName(getString(reader, "name"));
                            operation.setDynamic(getBoolean(reader, "isDynamic"));
                            operation.setNonBlocking(getBoolean(reader, "isNonBlocking"));
                            operation.setInputWrapperStyle(getBoolean(reader, "isInputWrapperStyle"));
                            operation.setOutputWrapperStyle(getBoolean(reader, "isOutputWrapperStyle"));
                            
                            inputs = new ArrayList<DataType>();
                            DataType inputType = new DataTypeImpl<List<DataType>>(null, null);
                            inputType.setLogical(inputs);
                            operation.setInputType(inputType);
                            
                            outputs = new ArrayList<DataType>();
                            DataType outputType = new DataTypeImpl<List<DataType>>(null, null);
                            outputType.setLogical(outputs);
                            operation.setOutputType(outputType);
                            
                            faults = new ArrayList<DataType>();
                            operation.setFaultTypes(faults);
                        } else if (INPUT_QNAME.equals(name)) {
                            iof = Iof.INPUT;
                        } else if (OUTPUT_QNAME.equals(name)) {
                            iof = Iof.OUTPUT;
                        } else if (FAULT_QNAME.equals(name)) {
                            iof = Iof.FAULT;
                        } else if (DATATYPE_QNAME.equals(name)){
                            DataType newDataType = new DataTypeImpl<XMLType>(null, null);
                            newDataType.setDataBinding(getString(reader, "dataBinding"));
                            if (logicalCollection) {
                                dataType.setLogical(newDataType);
                                dataType = newDataType;
                            } else if (iof == Iof.INPUT) {
                                inputs.add(newDataType);
                                dataType = newDataType;
                            } else if (iof == Iof.OUTPUT){
                                outputs.add(newDataType);
                                dataType = newDataType;
                            } else if (iof == Iof.FAULT){
                                faults.add(newDataType);
                                dataType = newDataType;
                            } 
                        } else if (GENERIC_QNAME.equals(name)){
                            characterTarget = CharacterTarget.GENERIC;
                        } else if (PHYSICAL_QNAME.equals(name)){
                            characterTarget = CharacterTarget.PHYSICAL;
                        } else if (LOGICAL_COLLECTION_QNAME.equals(name)){
                            logicalCollection = true;
                        } else if (LOGICAL_XMLTYPE_QNAME.equals(name)){
                            characterTarget = CharacterTarget.XMLTYPE;
                            logicalXMLType = new XMLType(null, null);
                            dataType.setLogical(logicalXMLType);
                        } else if (LOGICAL_TYPE_QNAME.equals(name)){
                            // is this ever used?
                        } else if (XMLTYPE_QNAME.equals(name)){
                            // is this ever used?
                        } else {
                            System.out.println("Unexpected element " + name);
                        }
                        break;
                    case XMLStreamConstants.CHARACTERS:
                        if (characterTarget == CharacterTarget.GENERIC){
                            String generic = reader.getText();
                            // Not sure what to do with this as we may not have the actual type
                        } else if (characterTarget == CharacterTarget.PHYSICAL){
                            String physical = reader.getText();
                            // Not sure what to do with this as we may not have the actual type
                        } else if (characterTarget == CharacterTarget.XMLTYPE) {
                            String xmlType = reader.getText();
                            if (!xmlType.equals(NO_TYPE)){
                                int splitPoint = xmlType.indexOf("}");
                                String namespace = xmlType.substring(1, splitPoint);
                                String localname = xmlType.substring(splitPoint + 1);
                                QName typeName = new QName(namespace, localname);
                                logicalXMLType.setTypeName(typeName);
                            }
                        }
                        characterTarget = CharacterTarget.UNSET;
                        break;
                    case END_ELEMENT:
                        name = reader.getName();
                        if (INPUT_QNAME.equals(name) ||
                            OUTPUT_QNAME.equals(name) ||
                            FAULT_QNAME.equals(name)) {
                            iof = Iof.UNSET;
                        } else if (LOGICAL_COLLECTION_QNAME.equals(name)) {
                            logicalCollection = false;
                        }
                }
    
                // Read the next element
                if (reader.hasNext()) {
                    reader.next();
                }
            }
        } catch (XMLStreamException e) {
            ContributionReadException ex = new ContributionReadException(e);
            //error(monitor, "XMLStreamException", reader, ex);
        }                    
        
        return interfaceContract;
    }