Separate ServiceDescription as interfaces

git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@751863 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
rfeng 2009-03-09 22:01:43 +00:00
parent ab419e5683
commit b92698dff1
6 changed files with 148 additions and 20 deletions

View file

@ -0,0 +1,45 @@
/*
* 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;
import java.util.List;
import java.util.Map;
import javax.xml.namespace.QName;
/**
* The OSGi RFC 119 description of a remote OSGi service
*/
public interface ServiceDescription {
String REMOTE_SERVICE_FOLDER = "OSGI-INF/remote-service";
String SD_NS = "http://www.osgi.org/xmlns/sd/v1.0.0";
QName SERVICE_DESCRIPTIONS_QNAME = new QName(SD_NS, "service-descriptions");
QName SERVICE_DESCRIPTION_QNAME = new QName(SD_NS, "service-description");
String REMOTE_SERVICE_HEADER = "Remote-Service";
String PROP_SERVICE_INTENTS = "service.intents";
String PROP_REQUIRES_INTENTS = "osgi.remote.requires.intents";
String PROP_CONFIGURATION_TYPE = "osgi.remote.configuration.type";
String CONFIGURATION_TYPE_SCA = "sca";
String PROP_CONFIGURATION_SCA_BINDINGS = "osgi.remote.configuration.sca.bindings";
List<String> getInterfaces();
Map<String, Object> getProperties();
}

View file

@ -0,0 +1,29 @@
/*
* 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;
import java.util.List;
/**
* OSGi RFC 119 service descriptions
*/
public interface ServiceDescriptions extends List<ServiceDescription> {
}

View file

@ -17,29 +17,22 @@
* under the License.
*/
package org.apache.tuscany.sca.implementation.osgi.xml;
package org.apache.tuscany.sca.implementation.osgi.impl;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.xml.namespace.QName;
import org.apache.tuscany.sca.implementation.osgi.ServiceDescription;
/**
* The OSGi RFC 119 description of a remote OSGi service
*/
public class ServiceDescription {
public final static String REMOTE_SERVICE_FOLDER = "OSGI-INF/remote-service";
public final static String SD_NS = "http://www.osgi.org/xmlns/sd/v1.0.0";
public final static QName SERVICE_DESCRIPTIONS_QNAME = new QName(SD_NS, "service-descriptions");
public final static QName SERVICE_DESCRIPTION_QNAME = new QName(SD_NS, "service-description");
public final static String REMOTE_SERVICE_HEADER = "Remote-Service";
public final static String PROP_SERVICE_INTENTS = "service.intents";
public final static String PROP_REQUIRES_INTENTS = "osgi.remote.requires.intents";
public final static String PROP_CONFIGURATION_TYPE = "osgi.remote.configuration.type";
public final static String CONFIGURATION_TYPE_SCA = "sca";
public final static String PROP_CONFIGURATION_SCA_BINDINGS = "osgi.remote.configuration.sca.bindings";
public class ServiceDescriptionImpl implements ServiceDescription {
public ServiceDescriptionImpl() {
super();
}
private List<String> interfaces = new ArrayList<String>();
private Map<String, Object> properties = new HashMap<String, Object>();

View file

@ -0,0 +1,36 @@
/*
* 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.impl;
import java.util.ArrayList;
import org.apache.tuscany.sca.implementation.osgi.ServiceDescription;
import org.apache.tuscany.sca.implementation.osgi.ServiceDescriptions;
/**
*
*/
public class ServiceDescriptionsImpl extends ArrayList<ServiceDescription> implements ServiceDescriptions {
private static final long serialVersionUID = 6205649013621747968L;
public ServiceDescriptionsImpl() {
super();
}
}

View file

@ -19,13 +19,20 @@
package org.apache.tuscany.sca.implementation.osgi.xml;
import java.util.ArrayList;
import java.util.List;
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.ContributionResolveException;
import org.apache.tuscany.sca.contribution.processor.ContributionWriteException;
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
import org.apache.tuscany.sca.implementation.osgi.ServiceDescription;
import org.apache.tuscany.sca.implementation.osgi.ServiceDescriptions;
import org.apache.tuscany.sca.implementation.osgi.impl.ServiceDescriptionImpl;
import org.apache.tuscany.sca.implementation.osgi.impl.ServiceDescriptionsImpl;
/*
<?xml version="1.0" encoding="UTF-8"?>
@ -48,18 +55,18 @@ import javax.xml.stream.XMLStreamReader;
</service-description>
</service-descriptions>
*/
public class ServiceDescriptionsProcessor {
public class ServiceDescriptionsProcessor implements StAXArtifactProcessor<ServiceDescriptions> {
public List<ServiceDescription> read(XMLStreamReader reader) throws XMLStreamException {
public ServiceDescriptions read(XMLStreamReader reader) throws XMLStreamException {
int event = reader.getEventType();
List<ServiceDescription> sds = new ArrayList<ServiceDescription>();
ServiceDescriptions sds = new ServiceDescriptionsImpl();
ServiceDescription sd = null;
while (true) {
switch (event) {
case XMLStreamConstants.START_ELEMENT:
QName name = reader.getName();
if (ServiceDescription.SERVICE_DESCRIPTION_QNAME.equals(name)) {
sd = new ServiceDescription();
sd = new ServiceDescriptionImpl();
sds.add(sd);
} else if ("provide".equals(name.getLocalPart())) {
String interfaceName = reader.getAttributeValue(null, "interface");
@ -118,4 +125,21 @@ public class ServiceDescriptionsProcessor {
}
}
}
public QName getArtifactType() {
return ServiceDescription.SERVICE_DESCRIPTIONS_QNAME;
}
public void write(ServiceDescriptions model, XMLStreamWriter writer) throws ContributionWriteException,
XMLStreamException {
// TODO: To be implemented
}
public Class<ServiceDescriptions> getModelType() {
return ServiceDescriptions.class;
}
public void resolve(ServiceDescriptions model, ModelResolver resolver) throws ContributionResolveException {
// TODO: To be implemented
}
}

View file

@ -25,6 +25,7 @@ import java.util.List;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamReader;
import org.apache.tuscany.sca.implementation.osgi.ServiceDescription;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;