/*
* 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.tuscany.sca.implementation.osgi.xml;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.StringTokenizer;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor;
import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
import org.apache.tuscany.sca.contribution.processor.ContributionResolveException;
import org.apache.tuscany.sca.contribution.processor.ContributionWriteException;
import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.core.FactoryExtensionPoint;
import org.apache.tuscany.sca.implementation.osgi.ServiceDescription;
import org.apache.tuscany.sca.implementation.osgi.ServiceDescriptions;
import org.apache.tuscany.sca.implementation.osgi.ServiceDescriptionsFactory;
import org.osgi.framework.Constants;
/*
SOAPHTTP1029www.acme.com
*/
public class ServiceDescriptionsProcessor extends BaseStAXArtifactProcessor implements
StAXArtifactProcessor {
private ServiceDescriptionsFactory factory;
private StAXArtifactProcessor processor;
public ServiceDescriptionsProcessor(ExtensionPointRegistry registry, StAXArtifactProcessor processor) {
this.processor = processor;
FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class);
this.factory = modelFactories.getFactory(ServiceDescriptionsFactory.class);
}
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 are both present");
}
propertyValue = new ArrayList