Modified: tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java?rev=750178&r1=743057&r2=750178&view=diff ============================================================================== --- tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java (original) +++ tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java Wed Mar 4 21:58:05 2009 @@ -42,17 +42,16 @@ import org.apache.tuscany.sca.assembly.Property; import org.apache.tuscany.sca.assembly.Reference; import org.apache.tuscany.sca.assembly.Service; -import org.apache.tuscany.sca.assembly.builder.impl.ProblemImpl; import org.apache.tuscany.sca.assembly.xml.Constants; -import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; -import org.apache.tuscany.sca.contribution.osgi.BundleReference; +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.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.resolver.ClassReference; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; -import org.apache.tuscany.sca.contribution.service.ContributionReadException; -import org.apache.tuscany.sca.contribution.service.ContributionResolveException; -import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.databinding.impl.SimpleTypeMapperImpl; +import org.apache.tuscany.sca.implementation.osgi.OSGiImplementation; import org.apache.tuscany.sca.implementation.osgi.impl.OSGiImplementationImpl; import org.apache.tuscany.sca.interfacedef.Interface; import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; @@ -62,6 +61,7 @@ import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.monitor.Problem; import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.apache.tuscany.sca.monitor.impl.ProblemImpl; import org.osgi.framework.Bundle; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -76,35 +76,35 @@ * * @version $Rev$ $Date$ */ -public class OSGiImplementationProcessor implements StAXArtifactProcessor<OSGiImplementationImpl> { - - public static final QName IMPLEMENTATION_OSGI = new QName(Constants.SCA10_TUSCANY_NS, "implementation.osgi"); - - private static final String BUNDLE_SYMBOLICNAME= "bundleSymbolicName"; - private static final String BUNDLE_VERSION = "bundleVersion"; - private static final String CLASSES = "classes"; - private static final String IMPORTS = "imports"; - - private static final QName PROPERTIES_QNAME = new QName(Constants.SCA10_TUSCANY_NS, "properties"); - private static final QName PROPERTY_QNAME = new QName(Constants.SCA10_TUSCANY_NS, "property"); - +public class OSGiImplementationProcessor implements StAXArtifactProcessor<OSGiImplementation> { + + public static final QName IMPLEMENTATION_OSGI = new QName(Constants.SCA10_TUSCANY_NS, "implementation.osgi"); + + private static final String BUNDLE_SYMBOLICNAME = "bundleSymbolicName"; + private static final String BUNDLE_VERSION = "bundleVersion"; + private static final String CLASSES = "classes"; + private static final String IMPORTS = "imports"; + + private static final QName PROPERTIES_QNAME = new QName(Constants.SCA10_TUSCANY_NS, "properties"); + private static final QName PROPERTY_QNAME = new QName(Constants.SCA10_TUSCANY_NS, "property"); + private JavaInterfaceFactory javaInterfaceFactory; private AssemblyFactory assemblyFactory; - private ModelFactoryExtensionPoint modelFactories; + private FactoryExtensionPoint modelFactories; private Monitor monitor; - + private static final DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); static { domFactory.setNamespaceAware(true); } - public OSGiImplementationProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) { - this.monitor = monitor; + public OSGiImplementationProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { + this.monitor = monitor; this.modelFactories = modelFactories; this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); this.javaInterfaceFactory = modelFactories.getFactory(JavaInterfaceFactory.class); } - + /** * Report a exception. * @@ -113,12 +113,14 @@ * @param model */ private void error(String message, Object model, Exception ex) { - if (monitor != null) { - Problem problem = new ProblemImpl(this.getClass().getName(), "impl-osgi-validation-messages", Severity.ERROR, model, message, ex); - monitor.problem(problem); - } + if (monitor != null) { + Problem problem = + new ProblemImpl(this.getClass().getName(), "impl-osgi-validation-messages", Severity.ERROR, model, + message, ex); + monitor.problem(problem); + } } - + /** * Report a error. * @@ -127,31 +129,33 @@ * @param model */ private void error(String message, Object model, Object... messageParameters) { - if (monitor != null) { - Problem problem = new ProblemImpl(this.getClass().getName(), "impl-osgi-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); - monitor.problem(problem); - } + if (monitor != null) { + Problem problem = + new ProblemImpl(this.getClass().getName(), "impl-osgi-validation-messages", Severity.ERROR, model, + message, (Object[])messageParameters); + monitor.problem(problem); + } } - + public QName getArtifactType() { return IMPLEMENTATION_OSGI; } - public Class<OSGiImplementationImpl> getModelType() { - return OSGiImplementationImpl.class; + public Class<OSGiImplementation> getModelType() { + return OSGiImplementation.class; } private String[] tokenize(String str) { StringTokenizer tokenizer = new StringTokenizer(str); String[] tokens = new String[tokenizer.countTokens()]; - for (int i= 0; i < tokens.length; i++) { + for (int i = 0; i < tokens.length; i++) { tokens[i] = tokenizer.nextToken(); } - + return tokens; } - - public OSGiImplementationImpl read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + + public OSGiImplementation read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { assert IMPLEMENTATION_OSGI.equals(reader.getName()); String bundleSymbolicName = reader.getAttributeValue(null, BUNDLE_SYMBOLICNAME); @@ -169,23 +173,20 @@ else classList = new String[0]; - Hashtable<String, List<ComponentProperty>> refProperties = - new Hashtable<String, List<ComponentProperty>>(); - Hashtable<String, List<ComponentProperty>> serviceProperties = - new Hashtable<String, List<ComponentProperty>>(); - Hashtable<String, List<ComponentProperty>> refCallbackProperties = - new Hashtable<String, List<ComponentProperty>>(); - Hashtable<String, List<ComponentProperty>> serviceCallbackProperties = - new Hashtable<String, List<ComponentProperty>>(); - + Hashtable<String, List<ComponentProperty>> refProperties = new Hashtable<String, List<ComponentProperty>>(); + Hashtable<String, List<ComponentProperty>> serviceProperties = new Hashtable<String, List<ComponentProperty>>(); + Hashtable<String, List<ComponentProperty>> refCallbackProperties = + new Hashtable<String, List<ComponentProperty>>(); + Hashtable<String, List<ComponentProperty>> serviceCallbackProperties = + new Hashtable<String, List<ComponentProperty>>(); + while (reader.hasNext()) { - + int next = reader.next(); if (next == END_ELEMENT && IMPLEMENTATION_OSGI.equals(reader.getName())) { break; - } - else if (next == START_ELEMENT && PROPERTIES_QNAME.equals(reader.getName())) { - + } else if (next == START_ELEMENT && PROPERTIES_QNAME.equals(reader.getName())) { + // FIXME: This is temporary code which allows reference and service properties used // for filtering OSGi services to be specified in <implementation.osgi/> // This should really be provided in the component type file since these @@ -205,54 +206,50 @@ else if (serviceCallbackName != null) serviceCallbackProperties.put(serviceCallbackName, props); else { - error("PropertyShouldSpecifySR", reader); + error("PropertyShouldSpecifySR", reader); //throw new ContributionReadException("Properties in implementation.osgi should specify service or reference"); } } } - - OSGiImplementationImpl implementation = new OSGiImplementationImpl( - modelFactories, - bundleSymbolicName, - bundleVersion, - importList, - classList, - refProperties, - serviceProperties); + + OSGiImplementationImpl implementation = + new OSGiImplementationImpl(modelFactories, bundleSymbolicName, bundleVersion, importList, classList, + refProperties, serviceProperties); implementation.setCallbackProperties(refCallbackProperties, serviceCallbackProperties); - + implementation.setUnresolved(true); - + return implementation; - + } - - public void resolve(OSGiImplementationImpl impl, ModelResolver resolver) throws ContributionResolveException { - + public void resolve(OSGiImplementation impl, ModelResolver resolver) throws ContributionResolveException { + try { - - if (impl == null || !impl.isUnresolved()) - return; - - impl.setUnresolved(false); - - BundleReference bundleReference = new BundleReference(impl.getBundleSymbolicName(), impl.getBundleVersion()); + + if (impl == null || !impl.isUnresolved()) + return; + + impl.setUnresolved(false); + + BundleReference bundleReference = + new BundleReference(impl.getBundleSymbolicName(), impl.getBundleVersion()); BundleReference resolvedBundle = resolver.resolveModel(BundleReference.class, bundleReference); Bundle bundle = (Bundle)resolvedBundle.getBundle(); if (bundle != null) { - impl.setOSGiBundle(bundle); + impl.setOSGiBundle(bundle); } else { - error("CouldNotLocateOSGiBundle", impl, impl.getBundleSymbolicName()); + error("CouldNotLocateOSGiBundle", impl, impl.getBundleSymbolicName()); //throw new ContributionResolveException("Could not locate OSGi bundle " + - //impl.getBundleSymbolicName()); - return; + //impl.getBundleSymbolicName()); + return; } - + String bundleName = resolvedBundle.getBundleRelativePath(); - String ctURI = bundleName.endsWith(".jar") || bundleName.endsWith(".JAR")? - bundleName.substring(0, bundleName.lastIndexOf(".")) : bundleName; + String ctURI = + bundleName.endsWith(".jar") || bundleName.endsWith(".JAR") ? bundleName.substring(0, bundleName + .lastIndexOf(".")) : bundleName; ctURI = ctURI.replaceAll("\\.", "/"); ctURI = ctURI + ".componentType"; @@ -261,34 +258,35 @@ componentType.setUnresolved(true); componentType = resolver.resolveModel(ComponentType.class, componentType); if (componentType.isUnresolved()) { - error("MissingComponentTypeFile", impl, ctURI); + error("MissingComponentTypeFile", impl, ctURI); //throw new ContributionResolveException("missing .componentType side file " + ctURI); - return; + return; } - + List<Service> services = componentType.getServices(); for (Service service : services) { Interface interfaze = service.getInterfaceContract().getInterface(); if (interfaze instanceof JavaInterface) { JavaInterface javaInterface = (JavaInterface)interfaze; if (javaInterface.getJavaClass() == null) { - + javaInterface.setJavaClass(getJavaClass(resolver, javaInterface.getName())); } Class<?> callback = null; if (service.getInterfaceContract().getCallbackInterface() instanceof JavaInterface) { - JavaInterface callbackInterface = (JavaInterface)service.getInterfaceContract().getCallbackInterface(); + JavaInterface callbackInterface = + (JavaInterface)service.getInterfaceContract().getCallbackInterface(); if (callbackInterface.getJavaClass() == null) { callbackInterface.setJavaClass(getJavaClass(resolver, callbackInterface.getName())); } callback = callbackInterface.getJavaClass(); } - + Service serv = createService(service, javaInterface.getJavaClass(), callback); impl.getServices().add(serv); } } - + List<Reference> references = componentType.getReferences(); for (Reference reference : references) { Interface interfaze = reference.getInterfaceContract().getInterface(); @@ -299,79 +297,78 @@ } Reference ref = createReference(reference, javaInterface.getJavaClass()); impl.getReferences().add(ref); - } - else + } else impl.getReferences().add(reference); } - + List<Property> properties = componentType.getProperties(); for (Property property : properties) { impl.getProperties().add(property); } impl.setConstrainingType(componentType.getConstrainingType()); - + } catch (InvalidInterfaceException e) { - ContributionResolveException ce = new ContributionResolveException(e); - error("ContributionResolveException", resolver, ce); + ContributionResolveException ce = new ContributionResolveException(e); + error("ContributionResolveException", resolver, ce); //throw ce; } - + } - private Class getJavaClass(ModelResolver resolver, String className) { ClassReference ref = new ClassReference(className); ref = resolver.resolveModel(ClassReference.class, ref); return ref.getJavaClass(); } - - private Service createService(Service serv, Class<?> interfaze, Class<?> callbackInterfaze) throws InvalidInterfaceException { + + private Service createService(Service serv, Class<?> interfaze, Class<?> callbackInterfaze) + throws InvalidInterfaceException { Service service = assemblyFactory.createService(); JavaInterfaceContract interfaceContract = javaInterfaceFactory.createJavaInterfaceContract(); service.setInterfaceContract(interfaceContract); - - + // create a relative URI service.setName(serv.getName()); JavaInterface callInterface = javaInterfaceFactory.createJavaInterface(interfaze); service.getInterfaceContract().setInterface(callInterface); - + if (callbackInterfaze != null) { JavaInterface callbackInterface = javaInterfaceFactory.createJavaInterface(callbackInterfaze); service.getInterfaceContract().setCallbackInterface(callbackInterface); - } - else if (callInterface.getCallbackClass() != null) { - JavaInterface callbackInterface = javaInterfaceFactory.createJavaInterface(callInterface.getCallbackClass()); + } else if (callInterface.getCallbackClass() != null) { + JavaInterface callbackInterface = + javaInterfaceFactory.createJavaInterface(callInterface.getCallbackClass()); service.getInterfaceContract().setCallbackInterface(callbackInterface); } return service; } - + private Reference createReference(Reference ref, Class<?> clazz) throws InvalidInterfaceException { org.apache.tuscany.sca.assembly.Reference reference = assemblyFactory.createReference(); JavaInterfaceContract interfaceContract = javaInterfaceFactory.createJavaInterfaceContract(); reference.setInterfaceContract(interfaceContract); - + reference.setName(ref.getName()); reference.setMultiplicity(ref.getMultiplicity()); JavaInterface callInterface = javaInterfaceFactory.createJavaInterface(clazz); reference.getInterfaceContract().setInterface(callInterface); if (callInterface.getCallbackClass() != null) { - JavaInterface callbackInterface = javaInterfaceFactory.createJavaInterface(callInterface.getCallbackClass()); + JavaInterface callbackInterface = + javaInterfaceFactory.createJavaInterface(callInterface.getCallbackClass()); reference.getInterfaceContract().setCallbackInterface(callbackInterface); } - + return reference; } - public void write(OSGiImplementationImpl model, XMLStreamWriter outputSource) throws ContributionWriteException, XMLStreamException { - + public void write(OSGiImplementation model, XMLStreamWriter outputSource) throws ContributionWriteException, + XMLStreamException { + //FIXME Implement this method } - - + private QName getQNameValue(XMLStreamReader reader, String value) { if (value != null) { int index = value.indexOf(':'); @@ -386,7 +383,7 @@ return null; } } - + private void declareNamespace(Element element, String prefix, String ns) { String qname = null; if ("".equals(prefix)) { @@ -414,11 +411,11 @@ element.setAttributeNodeNS(attr); } } - + private Element createElement(Document document, QName name) { String prefix = name.getPrefix(); - String qname = (prefix != null && prefix.length() > 0) ? prefix + ":" + name.getLocalPart() : name - .getLocalPart(); + String qname = + (prefix != null && prefix.length() > 0) ? prefix + ":" + name.getLocalPart() : name.getLocalPart(); return document.createElementNS(name.getNamespaceURI(), qname); } @@ -473,17 +470,17 @@ } } } - - private Document readPropertyValue(XMLStreamReader reader, QName type) - throws XMLStreamException, ParserConfigurationException { - + + private Document readPropertyValue(XMLStreamReader reader, QName type) throws XMLStreamException, + ParserConfigurationException { + Document doc = domFactory.newDocumentBuilder().newDocument(); // root element has no namespace and local name "value" Element root = doc.createElementNS(null, "value"); if (type != null) { org.w3c.dom.Attr xsi = doc.createAttributeNS(XMLNS_ATTRIBUTE_NS_URI, "xmlns:xsi"); - xsi.setValue(W3C_XML_SCHEMA_INSTANCE_NS_URI); + xsi.setValue(W3C_XML_SCHEMA_INSTANCE_NS_URI); root.setAttributeNodeNS(xsi); String prefix = type.getPrefix(); @@ -502,49 +499,47 @@ loadElement(reader, root); return doc; } - - private void readProperty(ComponentProperty prop, XMLStreamReader reader) - throws XMLStreamException, ContributionReadException { - - + + private void readProperty(ComponentProperty prop, XMLStreamReader reader) throws XMLStreamException, + ContributionReadException { + prop.setName(reader.getAttributeValue(null, "name")); String xsdType = reader.getAttributeValue(null, "type"); - if (xsdType != null) + if (xsdType != null) prop.setXSDType(getQNameValue(reader, xsdType)); else prop.setXSDType(SimpleTypeMapperImpl.XSD_STRING); - + try { Document value = readPropertyValue(reader, prop.getXSDType()); prop.setValue(value); } catch (ParserConfigurationException e) { - ContributionReadException ce = new ContributionReadException(e); - error("ContributionReadException", reader, ce); + ContributionReadException ce = new ContributionReadException(e); + error("ContributionReadException", reader, ce); throw ce; } } - - private List<ComponentProperty> readProperties(XMLStreamReader reader) - throws XMLStreamException, ContributionReadException { - + + private List<ComponentProperty> readProperties(XMLStreamReader reader) throws XMLStreamException, + ContributionReadException { + List<ComponentProperty> properties = new ArrayList<ComponentProperty>(); - + while (reader.hasNext()) { - + int next = reader.next(); if (next == END_ELEMENT && PROPERTIES_QNAME.equals(reader.getName())) { break; - } - else if (next == START_ELEMENT && PROPERTY_QNAME.equals(reader.getName())) { - + } else if (next == START_ELEMENT && PROPERTY_QNAME.equals(reader.getName())) { + ComponentProperty componentProperty = assemblyFactory.createComponentProperty(); readProperty(componentProperty, reader); properties.add(componentProperty); } } - + return properties; } - + }
Modified: tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiPropertyTestCase.java URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiPropertyTestCase.java?rev=750178&r1=743057&r2=750178&view=diff ============================================================================== --- tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiPropertyTestCase.java (original) +++ tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiPropertyTestCase.java Wed Mar 4 21:58:05 2009 @@ -23,7 +23,6 @@ import org.apache.tuscany.sca.implementation.osgi.test.OSGiTestInterface; import org.apache.tuscany.sca.implementation.osgi.test.OSGiTestWithPropertyImpl; - /** * * Test the execution of an OSGi implementation type @@ -31,19 +30,17 @@ * @version $Rev$ $Date$ */ public class OSGiPropertyTestCase extends OSGiTestCase { - + @Override protected void setUp() throws Exception { - + className = OSGiTestWithPropertyImpl.class.getName(); compositeName = "osgiproptest.composite"; - - OSGiTestBundles.createBundle("target/test-classes/OSGiTestService.jar", - OSGiTestInterface.class, - OSGiTestWithPropertyImpl.class); - + + OSGiTestBundles.createBundle("target/test-classes/OSGiTestService.jar", + OSGiTestInterface.class, + OSGiTestWithPropertyImpl.class); + } - - } Modified: tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTestCase.java URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTestCase.java?rev=750178&r1=743057&r2=750178&view=diff ============================================================================== --- tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTestCase.java (original) +++ tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTestCase.java Wed Mar 4 21:58:05 2009 @@ -23,12 +23,9 @@ import junit.framework.TestCase; -import org.apache.tuscany.sca.host.embedded.SCADomain; import org.apache.tuscany.sca.implementation.osgi.test.OSGiTestBundles; import org.apache.tuscany.sca.implementation.osgi.test.OSGiTestImpl; import org.apache.tuscany.sca.implementation.osgi.test.OSGiTestInterface; -import org.apache.tuscany.sca.osgi.runtime.OSGiRuntime; - /** * @@ -37,38 +34,39 @@ * @version $Rev$ $Date$ */ public class OSGiTestCase extends TestCase { - + protected String className; protected String compositeName; - + protected void setUp() throws Exception { className = OSGiTestImpl.class.getName(); compositeName = "osgitest.composite"; - OSGiTestBundles.createBundle("target/test-classes/OSGiTestService.jar", OSGiTestInterface.class, OSGiTestImpl.class); - + OSGiTestBundles.createBundle("target/test-classes/OSGiTestService.jar", + OSGiTestInterface.class, + OSGiTestImpl.class); + } - - + @Override protected void tearDown() throws Exception { OSGiRuntime.stop(); } - + public void testOSGiComponent() throws Exception { - + SCADomain scaDomain = SCADomain.newInstance(compositeName); OSGiTestInterface testService = scaDomain.getService(OSGiTestInterface.class, "OSGiTestServiceComponent"); - assert(testService != null); - - assert(testService instanceof Proxy); - + assert (testService != null); + + assert (testService instanceof Proxy); + String str = testService.testService(); - + assertEquals(className, str); scaDomain.close(); - + } } Modified: tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestBundles.java URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestBundles.java?rev=750178&r1=743057&r2=750178&view=diff ============================================================================== --- tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestBundles.java (original) +++ tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestBundles.java Wed Mar 4 21:58:05 2009 @@ -28,7 +28,6 @@ import java.util.jar.Manifest; import java.util.zip.ZipEntry; - /** * * Utility class to create OSGi bundles @@ -41,22 +40,31 @@ int index = name.lastIndexOf('.'); return index == -1 ? "" : name.substring(0, index); } - - public static void createBundle(String jarName, - Class<?> interfaceClass, Class<?> implClass) throws Exception { + + public static void createBundle(String jarName, Class<?> interfaceClass, Class<?> implClass) throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); String EOL = System.getProperty("line.separator"); - + String packageName = getPackageName(interfaceClass); String bundleName = interfaceClass.getName(); - String manifestStr = "Manifest-Version: 1.0" + EOL - + "Bundle-ManifestVersion: 2" + EOL + "Bundle-Name: " - + bundleName + EOL + "Bundle-SymbolicName: " + bundleName + EOL - + "Bundle-Version: " + "1.0.0" + EOL - + "Bundle-Localization: plugin" + EOL; + String manifestStr = + "Manifest-Version: 1.0" + EOL + + "Bundle-ManifestVersion: 2" + + EOL + + "Bundle-Name: " + + bundleName + + EOL + + "Bundle-SymbolicName: " + + bundleName + + EOL + + "Bundle-Version: " + + "1.0.0" + + EOL + + "Bundle-Localization: plugin" + + EOL; StringBuilder manifestBuf = new StringBuilder(); manifestBuf.append(manifestStr); @@ -67,16 +75,12 @@ ByteArrayInputStream manifestStream = new ByteArrayInputStream(manifestBuf.toString().getBytes()); Manifest manifest = new Manifest(); manifest.read(manifestStream); - JarOutputStream jarOut = new JarOutputStream(out, manifest); - String interfaceClassName = interfaceClass.getName().replaceAll("\\.", - "/") - + ".class"; + String interfaceClassName = interfaceClass.getName().replaceAll("\\.", "/") + ".class"; - URL url = interfaceClass.getClassLoader().getResource( - interfaceClassName); + URL url = interfaceClass.getClassLoader().getResource(interfaceClassName); String path = url.getPath(); ZipEntry ze = new ZipEntry(interfaceClassName); @@ -86,10 +90,8 @@ byte[] fileContents = new byte[file.available()]; file.read(fileContents); jarOut.write(fileContents); - - String implClassName = implClass.getName().replaceAll("\\.", - "/") - + ".class"; + + String implClassName = implClass.getName().replaceAll("\\.", "/") + ".class"; url = implClass.getClassLoader().getResource(implClassName); path = url.getPath(); @@ -111,6 +113,5 @@ fileOut.write(out.toByteArray()); fileOut.close(); - } } Modified: tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestImpl.java URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestImpl.java?rev=750178&r1=743057&r2=750178&view=diff ============================================================================== --- tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestImpl.java (original) +++ tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestImpl.java Wed Mar 4 21:58:05 2009 @@ -31,21 +31,20 @@ * @version $Rev$ $Date$ */ public class OSGiTestImpl implements OSGiTestInterface, BundleActivator { - + public String testService() { - + return OSGiTestImpl.class.getName(); - + } public void start(BundleContext bc) throws Exception { - + bc.registerService(OSGiTestInterface.class.getName(), this, new Hashtable<String, Object>()); - + } public void stop(BundleContext bc) throws Exception { } - } Modified: tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestInterface.java URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestInterface.java?rev=750178&r1=743057&r2=750178&view=diff ============================================================================== --- tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestInterface.java (original) +++ tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestInterface.java Wed Mar 4 21:58:05 2009 @@ -27,6 +27,6 @@ */ public interface OSGiTestInterface { - String testService() throws Exception ; + String testService() throws Exception; } Modified: tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestWithPropertyImpl.java URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestWithPropertyImpl.java?rev=750178&r1=743057&r2=750178&view=diff ============================================================================== --- tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestWithPropertyImpl.java (original) +++ tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestWithPropertyImpl.java Wed Mar 4 21:58:05 2009 @@ -21,9 +21,9 @@ import java.util.Hashtable; +import org.oasisopen.sca.annotation.Property; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; -import org.oasisopen.sca.annotation.Property; /** * @@ -32,35 +32,34 @@ * @version $Rev$ $Date$ */ public class OSGiTestWithPropertyImpl implements OSGiTestInterface, BundleActivator { - + @Property public double exchangeRate; - + private String currency; - + @Property public void setCurrency(String currency) { this.currency = currency; } - + public String testService() throws Exception { - + if (exchangeRate != 2.0) throw new Exception("Property exchangeRate not set correctly, expected 2.0, got " + exchangeRate); if (!"USD".equals(currency)) throw new Exception("Property currency not set correctly, expected USD, got " + currency); return OSGiTestWithPropertyImpl.class.getName(); - + } public void start(BundleContext bc) throws Exception { - + bc.registerService(OSGiTestInterface.class.getName(), this, new Hashtable<String, Object>()); - + } public void stop(BundleContext bc) throws Exception { } - } Modified: tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiReadImplTestCase.java URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiReadImplTestCase.java?rev=750178&r1=743057&r2=750178&view=diff ============================================================================== --- tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiReadImplTestCase.java (original) +++ tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiReadImplTestCase.java Wed Mar 4 21:58:05 2009 @@ -33,7 +33,6 @@ import org.apache.tuscany.sca.assembly.SCABindingFactory; import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; import org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl; -import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; @@ -46,8 +45,6 @@ import org.apache.tuscany.sca.implementation.osgi.test.OSGiTestImpl; import org.apache.tuscany.sca.implementation.osgi.test.OSGiTestInterface; import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; -import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl; -import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory; /** * Test reading OSGi implementations. @@ -64,18 +61,23 @@ public void setUp() throws Exception { DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); inputFactory = XMLInputFactory.newInstance(); - StAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(extensionPoints); + StAXArtifactProcessorExtensionPoint staxProcessors = + new DefaultStAXArtifactProcessorExtensionPoint(extensionPoints); staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null); - + ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); AssemblyFactory assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); SCABindingFactory scaBindingFactory = modelFactories.getFactory(SCABindingFactory.class); UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); InterfaceContractMapper mapper = utilities.getUtility(InterfaceContractMapper.class); - IntentAttachPointTypeFactory attachPointTypeFactory = modelFactories.getFactory(IntentAttachPointTypeFactory.class); - compositeBuilder = new CompositeBuilderImpl(assemblyFactory, scaBindingFactory, attachPointTypeFactory, mapper, null); - - OSGiTestBundles.createBundle("target/test-classes/OSGiTestService.jar", OSGiTestInterface.class, OSGiTestImpl.class); + IntentAttachPointTypeFactory attachPointTypeFactory = + modelFactories.getFactory(IntentAttachPointTypeFactory.class); + compositeBuilder = + new CompositeBuilderImpl(assemblyFactory, scaBindingFactory, attachPointTypeFactory, mapper, null); + + OSGiTestBundles.createBundle("target/test-classes/OSGiTestService.jar", + OSGiTestInterface.class, + OSGiTestImpl.class); } @@ -93,7 +95,7 @@ XMLStreamReader reader = inputFactory.createXMLStreamReader(is); Composite composite = (Composite)staxProcessor.read(reader); assertNotNull(composite); - + is = getClass().getClassLoader().getResourceAsStream("OSGiTestService.componentType"); reader = inputFactory.createXMLStreamReader(is); ComponentType componentType = (ComponentType)staxProcessor.read(reader); @@ -101,7 +103,7 @@ ModelResolver resolver = new TestModelResolver(getClass().getClassLoader()); staxProcessor.resolve(componentType, resolver); resolver.addModel(componentType); - + staxProcessor.resolve(composite, resolver); compositeBuilder.build(composite); @@ -109,12 +111,12 @@ public void testReadOSGiImplementation() throws Exception { - String str = "<?xml version=\"1.0\" encoding=\"ASCII\"?>" + - "<implementation.osgi xmlns=\"http://tuscany.apache.org/xmlns/sca/1.0\" targetNamespace=\"http://osgi\" " + - "bundleSymbolicName=\"OSGiTestService\" " + - "bundleVersion=\"2.0.0\" " + - "imports=\"import1.jar import2.jar\"" + - "/>"; + String str = + "<?xml version=\"1.0\" encoding=\"ASCII\"?>" + "<implementation.osgi xmlns=\"http://tuscany.apache.org/xmlns/sca/1.0\" targetNamespace=\"http://osgi\" " + + "bundleSymbolicName=\"OSGiTestService\" " + + "bundleVersion=\"2.0.0\" " + + "imports=\"import1.jar import2.jar\"" + + "/>"; ByteArrayInputStream is = new ByteArrayInputStream(str.getBytes()); XMLStreamReader reader = inputFactory.createXMLStreamReader(is); Modified: tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/TestModelResolver.java URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/TestModelResolver.java?rev=750178&r1=743057&r2=750178&view=diff ============================================================================== --- tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/TestModelResolver.java (original) +++ tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/TestModelResolver.java Wed Mar 4 21:58:05 2009 @@ -30,7 +30,6 @@ import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.implementation.osgi.impl.OSGiImplementationImpl; - /** * A default implementation of an artifact resolver, based on a map. * @@ -38,11 +37,11 @@ */ public class TestModelResolver implements ModelResolver { private static final long serialVersionUID = -7826976465762296634L; - + private Map<Object, Object> map = new HashMap<Object, Object>(); - + private WeakReference<ClassLoader> classLoader; - + public TestModelResolver(ClassLoader classLoader) { this.classLoader = new WeakReference<ClassLoader>(classLoader); } @@ -50,12 +49,12 @@ public <T> T resolveModel(Class<T> modelClass, T unresolved) { Object resolved = map.get(unresolved); if (resolved != null) { - + if (unresolved instanceof OSGiImplementationImpl && !(resolved instanceof OSGiImplementationImpl)) { - + OSGiImplementationImpl impl = ((OSGiImplementationImpl)unresolved); ComponentType componentType = (ComponentType)resolved; - + List<Property> properties = componentType.getProperties(); for (Property property : properties) { impl.getProperties().add(property); @@ -63,44 +62,43 @@ impl.setUnresolved(false); return unresolved; } - - + // Return the resolved object return modelClass.cast(resolved); - + } else if (unresolved instanceof ClassReference) { - + // Load a class on demand ClassReference classReference = (ClassReference)unresolved; Class clazz; try { clazz = Class.forName(classReference.getClassName(), true, classLoader.get()); } catch (ClassNotFoundException e) { - + // Return the unresolved object return unresolved; } - + // Store a new ClassReference wrapping the loaded class resolved = new ClassReference(clazz); map.put(resolved, resolved); - + // Return the resolved ClassReference return modelClass.cast(resolved); - + } else { - + // Return the unresolved object return unresolved; } } - + public void addModel(Object resolved) { map.put(resolved, resolved); } - + public Object removeModel(Object resolved) { return map.remove(resolved); } - + } Modified: tuscany/java/sca/modules/implementation-osgi/src/test/resources/OSGiTestService.componentType URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-osgi/src/test/resources/OSGiTestService.componentType?rev=750178&r1=743057&r2=750178&view=diff ============================================================================== --- tuscany/java/sca/modules/implementation-osgi/src/test/resources/OSGiTestService.componentType (original) +++ tuscany/java/sca/modules/implementation-osgi/src/test/resources/OSGiTestService.componentType Wed Mar 4 21:58:05 2009 @@ -17,7 +17,7 @@ * specific language governing permissions and limitations * under the License. --> -<componentType xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> +<componentType xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200712" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <service name="OSGiTestService"> <interface.java interface="org.apache.tuscany.sca.implementation.osgi.test.OSGiTestInterface"/> </service> Modified: tuscany/java/sca/modules/implementation-osgi/src/test/resources/osgiproptest.composite URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-osgi/src/test/resources/osgiproptest.composite?rev=750178&r1=743057&r2=750178&view=diff ============================================================================== --- tuscany/java/sca/modules/implementation-osgi/src/test/resources/osgiproptest.composite (original) +++ tuscany/java/sca/modules/implementation-osgi/src/test/resources/osgiproptest.composite Wed Mar 4 21:58:05 2009 @@ -1,37 +1,24 @@ <?xml version="1.0" encoding="UTF-8"?> -<!-- - * 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. ---> -<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" - xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0" - xmlns:xsd="http://www.w3.org/2001/XMLSchema" - name="OSGiTestComposite"> + <!-- + * 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. + --> +<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200712" xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1" + xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="OSGiTestComposite"> <component name="OSGiTestServiceComponent"> - <tuscany:implementation.osgi - bundle="OSGiTestService" - bundleSymbolicName="org.apache.tuscany.sca.implementation.osgi.test.OSGiTestInterface" - classes="org.apache.tuscany.sca.implementation.osgi.test.OSGiTestWithPropertyImpl" - /> - - <property name="currency" type="xsd:string" >USD</property> - <property name="exchangeRate" type="xsd:double" >2.0</property> - + <tuscany:implementation.osgi bundle="OSGiTestService" + bundleSymbolicName="org.apache.tuscany.sca.implementation.osgi.test.OSGiTestInterface" /> + + <property name="currency" type="xsd:string">USD</property> + <property name="exchangeRate" type="xsd:double">2.0</property> + </component> </composite> Modified: tuscany/java/sca/modules/implementation-osgi/src/test/resources/osgitest.composite URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-osgi/src/test/resources/osgitest.composite?rev=750178&r1=743057&r2=750178&view=diff ============================================================================== --- tuscany/java/sca/modules/implementation-osgi/src/test/resources/osgitest.composite (original) +++ tuscany/java/sca/modules/implementation-osgi/src/test/resources/osgitest.composite Wed Mar 4 21:58:05 2009 @@ -17,8 +17,8 @@ * specific language governing permissions and limitations * under the License. --> -<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" - xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0" +<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200712" + xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="OSGiTestComposite">
