tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rf...@apache.org
Subject svn commit: r450953 - in /incubator/tuscany/java/sca/kernel: core/src/main/java/org/apache/tuscany/core/wire/jdk/ spi/src/main/java/org/apache/tuscany/spi/component/ spi/src/main/java/org/apache/tuscany/spi/extension/ spi/src/test/java/org/apache/tusca...
Date Thu, 28 Sep 2006 18:12:32 GMT
Author: rfeng
Date: Thu Sep 28 11:12:31 2006
New Revision: 450953

URL: http://svn.apache.org/viewvc?view=rev&rev=450953
Log:
Improve exception handling for the following two cases:

1) locateService(name): name is not found in children of a composite
2) reference name (for exmaple "ref") in component is not found in the component type (for
example, using a wrong setter such as setRef1 with @Reference)

Added:
    incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ReferenceNotFoundException.java
  (with props)
Modified:
    incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKWireService.java
    incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/CompositeComponentExtension.java
    incubator/tuscany/java/sca/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/CompositeComponentExtensionTestCase.java

Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKWireService.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKWireService.java?view=diff&rev=450953&r1=450952&r2=450953
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKWireService.java
(original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKWireService.java
Thu Sep 28 11:12:31 2006
@@ -18,24 +18,28 @@
  */
 package org.apache.tuscany.core.wire.jdk;
 
+import static org.apache.tuscany.spi.idl.java.JavaIDLUtils.findMethod;
+
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
 import java.util.HashMap;
 import java.util.Map;
 
-import org.osoa.sca.annotations.Constructor;
-import org.osoa.sca.annotations.Init;
-import org.osoa.sca.annotations.Scope;
-
+import org.apache.tuscany.core.implementation.composite.CompositeReference;
+import org.apache.tuscany.core.implementation.composite.CompositeService;
+import org.apache.tuscany.core.wire.InboundInvocationChainImpl;
+import org.apache.tuscany.core.wire.InboundWireImpl;
+import org.apache.tuscany.core.wire.InvokerInterceptor;
+import org.apache.tuscany.core.wire.OutboundInvocationChainImpl;
+import org.apache.tuscany.core.wire.OutboundWireImpl;
 import org.apache.tuscany.spi.QualifiedName;
 import org.apache.tuscany.spi.annotation.Autowire;
 import org.apache.tuscany.spi.component.Component;
 import org.apache.tuscany.spi.component.CompositeComponent;
 import org.apache.tuscany.spi.component.Reference;
+import org.apache.tuscany.spi.component.ReferenceNotFoundException;
 import org.apache.tuscany.spi.component.Service;
 import org.apache.tuscany.spi.component.WorkContext;
-import static org.apache.tuscany.spi.idl.java.JavaIDLUtils.findMethod;
-import org.apache.tuscany.spi.model.BoundServiceDefinition;
 import org.apache.tuscany.spi.model.ComponentDefinition;
 import org.apache.tuscany.spi.model.ComponentType;
 import org.apache.tuscany.spi.model.CompositeComponentType;
@@ -54,14 +58,9 @@
 import org.apache.tuscany.spi.wire.RuntimeWire;
 import org.apache.tuscany.spi.wire.WireInvocationHandler;
 import org.apache.tuscany.spi.wire.WireService;
-
-import org.apache.tuscany.core.implementation.composite.CompositeReference;
-import org.apache.tuscany.core.implementation.composite.CompositeService;
-import org.apache.tuscany.core.wire.InboundInvocationChainImpl;
-import org.apache.tuscany.core.wire.InboundWireImpl;
-import org.apache.tuscany.core.wire.InvokerInterceptor;
-import org.apache.tuscany.core.wire.OutboundInvocationChainImpl;
-import org.apache.tuscany.core.wire.OutboundWireImpl;
+import org.osoa.sca.annotations.Constructor;
+import org.osoa.sca.annotations.Init;
+import org.osoa.sca.annotations.Scope;
 
 /**
  * @version $$Rev$$ $$Date$$
@@ -170,6 +169,13 @@
         for (ReferenceTarget referenceTarget : definition.getReferenceTargets().values())
{
             Map<String, ? extends ReferenceDefinition> references = componentType.getReferences();
             ReferenceDefinition mappedReference = references.get(referenceTarget.getReferenceName());
+            if (mappedReference == null) {
+                String refName = referenceTarget.getReferenceName();
+                ReferenceNotFoundException e = new ReferenceNotFoundException(refName);
+                e.addContextName(refName);
+                e.addContextName(definition.getName());
+                throw e;
+            }
             OutboundWire wire = createWire(referenceTarget, mappedReference);
             wire.setContainer(component);
             component.addOutboundWire(wire);

Added: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ReferenceNotFoundException.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ReferenceNotFoundException.java?view=auto&rev=450953
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ReferenceNotFoundException.java
(added)
+++ incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ReferenceNotFoundException.java
Thu Sep 28 11:12:31 2006
@@ -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.spi.component;
+
+import org.apache.tuscany.spi.CoreRuntimeException;
+
+/**
+ * Thrown when a component reference is not defined in the compoenent type
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public class ReferenceNotFoundException extends CoreRuntimeException {
+    private static final long serialVersionUID = 737170534780079573L;
+
+    public ReferenceNotFoundException() {
+    }
+
+    public ReferenceNotFoundException(String message) {
+        super(message);
+    }
+
+    public ReferenceNotFoundException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public ReferenceNotFoundException(Throwable cause) {
+        super(cause);
+    }
+}

Propchange: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ReferenceNotFoundException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ReferenceNotFoundException.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/CompositeComponentExtension.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/CompositeComponentExtension.java?view=diff&rev=450953&r1=450952&r2=450953
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/CompositeComponentExtension.java
(original)
+++ incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/CompositeComponentExtension.java
Thu Sep 28 11:12:31 2006
@@ -137,7 +137,13 @@
     }
 
     public <T> T locateService(Class<T> serviceInterface, String name) {
-        return serviceInterface.cast(children.get(name).getServiceInstance());
+        SCAObject context = children.get(name);
+        if (context == null) {
+            TargetNotFoundException e = new TargetNotFoundException(name);
+            e.addContextName(getName());
+            throw e;
+        }
+        return serviceInterface.cast(context.getServiceInstance());
     }
 
     public List<Reference> getReferences() {

Modified: incubator/tuscany/java/sca/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/CompositeComponentExtensionTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/CompositeComponentExtensionTestCase.java?view=diff&rev=450953&r1=450952&r2=450953
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/CompositeComponentExtensionTestCase.java
(original)
+++ incubator/tuscany/java/sca/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/CompositeComponentExtensionTestCase.java
Thu Sep 28 11:12:31 2006
@@ -116,6 +116,18 @@
             // expected
         }
     }
+    
+    public void testTargetNotFound() {
+        Composite composite = new Composite();
+        composite.register(getReference("foo"));
+        composite.start();
+        try {
+            composite.locateService(Foo.class, "foo1");
+            fail();
+        } catch (TargetNotFoundException e) {
+            // expected
+        }
+    }    
 
     public void testReferencesServices() {
         Composite composite = new Composite();



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org


Mime
View raw message