You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2015/01/20 21:02:04 UTC

svn commit: r1653356 - /felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/DuplexReferenceMethods.java

Author: cziegeler
Date: Tue Jan 20 20:02:03 2015
New Revision: 1653356

URL: http://svn.apache.org/r1653356
Log:
FELIX-4768 : [RFC190/212] Reference can specify both method and field

Added:
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/DuplexReferenceMethods.java   (with props)

Added: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/DuplexReferenceMethods.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/DuplexReferenceMethods.java?rev=1653356&view=auto
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/DuplexReferenceMethods.java (added)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/DuplexReferenceMethods.java Tue Jan 20 20:02:03 2015
@@ -0,0 +1,120 @@
+/*
+ * 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.felix.scr.impl.helper;
+
+import org.apache.felix.scr.impl.manager.ComponentContextImpl;
+import org.apache.felix.scr.impl.manager.RefPair;
+import org.osgi.framework.BundleContext;
+
+public class DuplexReferenceMethods implements ReferenceMethods
+{
+    /** First is field methods. */
+    private final ReferenceMethods first;
+
+    /** Second is method methods. */
+    private final ReferenceMethods second;
+
+    public DuplexReferenceMethods(final ReferenceMethods first, final ReferenceMethods second)
+    {
+        this.first = first;
+        this.second = second;
+    }
+
+    public ReferenceMethod getBind()
+    {
+        return new DuplexReferenceMethod(first.getBind(), second.getBind());
+    }
+
+    public ReferenceMethod getUnbind()
+    {
+        return new DuplexReferenceMethod(first.getUnbind(), second.getUnbind());
+    }
+
+    public ReferenceMethod getUpdated()
+    {
+        return new DuplexReferenceMethod(first.getUpdated(), second.getUpdated());
+    }
+
+    public InitReferenceMethod getInit()
+    {
+        return new InitReferenceMethod()
+        {
+
+            public boolean init(Object componentInstance, SimpleLogger logger)
+            {
+                final InitReferenceMethod i1 = first.getInit();
+                if ( i1 != null )
+                {
+                    if ( !i1.init(componentInstance, logger))
+                    {
+                        return false;
+                    }
+                }
+                final InitReferenceMethod i2 = second.getInit();
+                if ( i2 != null )
+                {
+                    if ( !i2.init(componentInstance, logger))
+                    {
+                        return false;
+                    }
+                }
+                return true;
+            }
+        };
+    }
+
+    private static final class DuplexReferenceMethod implements ReferenceMethod
+    {
+
+        private final ReferenceMethod first;
+
+        private final ReferenceMethod second;
+
+        public DuplexReferenceMethod(final ReferenceMethod first, final ReferenceMethod second)
+        {
+            this.first = first;
+            this.second = second;
+        }
+
+        public MethodResult invoke(Object componentInstance,
+                BindParameters rawParameter,
+                MethodResult methodCallFailureResult, SimpleLogger logger)
+        {
+            if ( first.invoke(componentInstance, rawParameter, methodCallFailureResult, logger) != null )
+            {
+                return second.invoke(componentInstance, rawParameter, methodCallFailureResult, logger);
+            }
+            return null;
+        }
+
+        public <S, T> boolean getServiceObject(ComponentContextImpl<S> key,
+                RefPair<S, T> refPair, BundleContext context,
+                SimpleLogger logger)
+        {
+            // only if both return true, we return true
+            boolean result = first.getServiceObject(key, refPair, context, logger);
+            if ( result )
+            {
+                result = second.getServiceObject(key, refPair, context, logger);
+            }
+            return result;
+        }
+
+    }
+}

Propchange: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/DuplexReferenceMethods.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/DuplexReferenceMethods.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url