You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by js...@apache.org on 2008/09/29 02:55:58 UTC
svn commit: r699935 - in /tuscany/branches/sca-equinox/modules:
core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextImpl.java
sca-api/src/main/java/org/osoa/sca/ComponentContext.java
Author: jsdelfino
Date: Sun Sep 28 17:55:58 2008
New Revision: 699935
URL: http://svn.apache.org/viewvc?rev=699935&view=rev
Log:
Pulled from trunk. TUSCANY-2281 provide a api to allow service references to be retrieved for references where the multiplicity >1. Thanks to Daniel Stucky for the patch.
Modified:
tuscany/branches/sca-equinox/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextImpl.java
tuscany/branches/sca-equinox/modules/sca-api/src/main/java/org/osoa/sca/ComponentContext.java
Modified: tuscany/branches/sca-equinox/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextImpl.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-equinox/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextImpl.java?rev=699935&r1=699934&r2=699935&view=diff
==============================================================================
--- tuscany/branches/sca-equinox/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextImpl.java (original)
+++ tuscany/branches/sca-equinox/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextImpl.java Sun Sep 28 17:55:58 2008
@@ -21,6 +21,8 @@
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
+import java.util.Collection;
+import java.util.ArrayList;
import org.apache.tuscany.sca.assembly.AssemblyFactory;
import org.apache.tuscany.sca.assembly.Binding;
@@ -107,6 +109,14 @@
try {
for (ComponentReference ref : component.getReferences()) {
if (referenceName.equals(ref.getName())) {
+ /* ******************** Contribution for issue TUSCANY-2281 ******************** */
+ Multiplicity multiplicity = ref.getMultiplicity();
+ if( multiplicity == Multiplicity.ZERO_N || multiplicity == Multiplicity.ONE_N)
+ {
+ throw new IllegalArgumentException("Reference " + referenceName + " has multiplicity " + multiplicity);
+ }
+ /* ******************** Contribution for issue TUSCANY-2281 ******************** */
+
return getServiceReference(businessInterface, (RuntimeComponentReference)ref, null);
}
}
@@ -400,4 +410,43 @@
public void write(RuntimeComponentReference reference, Writer writer) throws IOException {
compositeActivator.getComponentContextHelper().write(component, reference, writer);
}
+
+ /* ******************** Contribution for issue TUSCANY-2281 ******************** */
+
+ /**
+ * @see ComponentContext#getServices(Class<B>, String)
+ */
+ public <B> Collection<B> getServices(Class<B> businessInterface, String referenceName) {
+ ArrayList<B> services = new ArrayList<B>();
+ Collection<ServiceReference<B>> serviceRefs = getServiceReferences(businessInterface, referenceName);
+ for (ServiceReference<B> serviceRef : serviceRefs) {
+ services.add(serviceRef.getService());
+ }
+ return services;
+ }
+
+ /**
+ * @see ComponentContext#getServiceReferences(Class<B>, String)
+ */
+ public <B> Collection<ServiceReference<B>> getServiceReferences(Class<B> businessInterface, String referenceName) {
+ try {
+ for (ComponentReference ref : component.getReferences()) {
+ if (referenceName.equals(ref.getName())) {
+ ArrayList<ServiceReference<B>> serviceRefs = new ArrayList<ServiceReference<B>>();
+ for(Binding binding : ref.getBindings())
+ {
+ serviceRefs.add( getServiceReference(businessInterface, (RuntimeComponentReference) ref, binding) );
+ }
+ return serviceRefs;
+ }
+ }
+ throw new ServiceRuntimeException("Reference not found: " + referenceName);
+ } catch (ServiceRuntimeException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new ServiceRuntimeException(e.getMessage(), e);
+ }
+ }
+ /* ******************** Contribution for issue TUSCANY-2281 ******************** */
+
}
Modified: tuscany/branches/sca-equinox/modules/sca-api/src/main/java/org/osoa/sca/ComponentContext.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-equinox/modules/sca-api/src/main/java/org/osoa/sca/ComponentContext.java?rev=699935&r1=699934&r2=699935&view=diff
==============================================================================
--- tuscany/branches/sca-equinox/modules/sca-api/src/main/java/org/osoa/sca/ComponentContext.java (original)
+++ tuscany/branches/sca-equinox/modules/sca-api/src/main/java/org/osoa/sca/ComponentContext.java Sun Sep 28 17:55:58 2008
@@ -18,6 +18,8 @@
*/
package org.osoa.sca;
+import java.util.Collection;
+
/**
* Interface providing programmatic access to a component's SCA context as an alternative to injection.
* It provides access to reference and property values for the component and provides a mechanism for
@@ -106,4 +108,26 @@
* @return the SCA request context; may be null
*/
RequestContext getRequestContext();
+
+
+ /* ******************** Contribution for issue TUSCANY-2281 ******************** */
+
+ /**
+ * Returns a Collection of typed service proxies for a business interface type and a reference name.
+ * @param businessInterface the interface that will be used to invoke the service
+ * @param referenceName the name of the reference
+ * @param <B> the Java type of the business interface for the reference
+ * @return a Collection of objects that implements the business interface
+ */
+ <B> Collection<B> getServices(Class<B> businessInterface, String referenceName);
+
+
+ /**
+ * Returns a Collection of typed service reference for a business interface type and a reference name.
+ * @param businessInterface the interface that will be used to invoke the service
+ * @param referenceName the name of the reference
+ * @param <B> the Java type of the business interface for the reference
+ * @return a Collection of objects that implements the business interface
+ */
+ <B> Collection<ServiceReference<B>> getServiceReferences(Class<B> businessInterface, String referenceName);
}