Package org.apache.tuscany.sca.implementation.osgi

Examples of org.apache.tuscany.sca.implementation.osgi.ServiceDescription


    public ServiceDescriptions read(XMLStreamReader reader, ProcessorContext context) throws XMLStreamException,
        ContributionReadException {
        int event = reader.getEventType();
        ServiceDescriptions sds = null;
        ServiceDescription sd = null;
        String propertyName = null;
        String propertyType = "String";
        Object propertyValue = null;
        String propertyLiteral = null;
        boolean xml = false;
        boolean multiValued = false;
        while (true) {
            switch (event) {
                case XMLStreamConstants.START_ELEMENT:
                    QName name = reader.getName();
                    if (ServiceDescriptions.SERVICE_DESCRIPTIONS_QNAME.equals(name)) {
                        sds = factory.createServiceDescriptions();
                    } else if (ServiceDescriptions.SERVICE_DESCRIPTION_QNAME.equals(name)) {
                        sd = factory.createServiceDescription();
                        sds.add(sd);
                    } else if ("property".equals(name.getLocalPart())) {
                        multiValued = false;
                        propertyName = reader.getAttributeValue(null, "name");
                        propertyType = reader.getAttributeValue(null, "value-type");
                        if (propertyType == null) {
                            propertyType = "String";
                        }
                        propertyLiteral = reader.getAttributeValue(null, "value");
                        //                        if (propertyLiteral == null) {
                        //                            propertyLiteral = reader.getElementText();
                        //                        }
                        if (propertyLiteral != null) {
                            propertyLiteral = propertyLiteral.trim();
                            propertyValue = getPropertyValue(reader, propertyName, propertyLiteral, propertyType);
                        }
                    } else if ("list".equals(name.getLocalPart())) {
                        if (propertyValue != null) {
                            throw new IllegalArgumentException("@value and <list> are both present");
                        }
                        propertyValue = new ArrayList<Object>();
                        multiValued = true;
                    } else if ("array".equals(name.getLocalPart())) {
                        if (propertyValue != null) {
                            throw new IllegalArgumentException("@value and <array> are both present");
                        }
                        propertyValue = new ArrayList<Object>();
                        multiValued = true;
                    } else if ("set".equals(name.getLocalPart())) {
                        if (propertyValue != null) {
                            throw new IllegalArgumentException("@value and <set> are both present");
                        }
                        propertyValue = new HashSet<Object>();
                        multiValued = true;
                    } else if ("xml".equals(name.getLocalPart())) {
                        xml = true;
                    } else if ("value".equals(name.getLocalPart())) {
                        propertyLiteral = reader.getElementText();
                        if (propertyLiteral != null) {
                            propertyLiteral = propertyLiteral.trim();
                            Object value = getPropertyValue(reader, propertyName, propertyLiteral, propertyType);
                            if (multiValued && (propertyValue instanceof Collection)) {
                                ((Collection)propertyValue).add(value);
                            } else if (propertyValue == null) {
                                propertyValue = value;
                            }
                        }
                    } else {
                        // FIXME: [rfeng] The rsa spec says the XML should be saved as String
                        Object value = processor.read(reader, context);
                        if (xml) {
                            if (multiValued && (propertyValue instanceof Collection)) {
                                ((Collection)propertyValue).add(value);
                            } else if (propertyValue == null) {
                                propertyValue = value;
                            }
                        }
                    }
                    break;
                case XMLStreamConstants.END_ELEMENT:
                    name = reader.getName();
                    if (ServiceDescriptions.SERVICE_DESCRIPTION_QNAME.equals(name)) {
                        // Reset the sd
                        sd = null;
                    } else if (ServiceDescriptions.PROPERTY_QNAME.equals(name)) {
                        if (sd != null && propertyName != null) {
                            if (propertyValue == null) {
                                throw new IllegalArgumentException("No value is defined for " + propertyName);
                            }
                            sd.getProperties().put(propertyName, propertyValue);
                        }
                        propertyName = null;
                        propertyType = "String";
                        propertyValue = null;
                        multiValued = false;
View Full Code Here


    }

    public ServiceDescriptions read(XMLStreamReader reader) throws XMLStreamException {
        int event = reader.getEventType();
        ServiceDescriptions sds = factory.createServiceDescriptions();
        ServiceDescription sd = null;
        while (true) {
            switch (event) {
                case XMLStreamConstants.START_ELEMENT:
                    QName name = reader.getName();
                    if (ServiceDescriptions.SERVICE_DESCRIPTION_QNAME.equals(name)) {
                        sd = factory.createServiceDescription();
                        sds.add(sd);
                    } else if ("provide".equals(name.getLocalPart())) {
                        String interfaceName = reader.getAttributeValue(null, "interface");
                        if (interfaceName != null) {
                            sd.getInterfaces().add(interfaceName);
                        }
                    } else if ("property".equals(name.getLocalPart())) {
                        String propName = reader.getAttributeValue(null, "name");
                        String propValue = reader.getAttributeValue(null, "value");
                        String propType = reader.getAttributeValue(null, "type");
                        if (propType == null) {
                            propType = "String";
                        }
                        if (propValue == null) {
                            propValue = reader.getElementText();
                        }
                        if (propValue != null) {
                            propValue = propValue.trim();
                        }
                        Object prop = propValue;
                        if ("Integer".equals(propType)) {
                            prop = Integer.valueOf(propValue);
                        } else if ("Long".equals(propType)) {
                            prop = Long.valueOf(propValue);
                        } else if ("Float".equals(propType)) {
                            prop = Float.valueOf(propValue);
                        } else if ("Double".equals(propType)) {
                            prop = Double.valueOf(propValue);
                        } else if ("Short".equals(propType)) {
                            prop = Short.valueOf(propValue);
                        } else if ("Character".equals(propType)) {
                            prop = propValue.charAt(0);
                        } else if ("Byte".equals(propType)) {
                            prop = Byte.valueOf(propValue);
                        } else if ("Boolean".equals(propType)) {
                            prop = Boolean.valueOf(propValue);
                        }
                        sd.getProperties().put(propName, prop);
                    }
                    break;
                case XMLStreamConstants.END_ELEMENT:
                    name = reader.getName();
                    if (ServiceDescriptions.SERVICE_DESCRIPTION_QNAME.equals(name)) {
View Full Code Here

TOP

Related Classes of org.apache.tuscany.sca.implementation.osgi.ServiceDescription

Copyright © 2018 www.massapicom. 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.