You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by jw...@apache.org on 2012/04/24 17:50:32 UTC

svn commit: r1329807 [3/3] - in /aries/trunk/subsystem: subsystem-core/src/main/java/org/apache/aries/subsystem/core/ subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/ subsystem-core/src/main/java/org/apache/felix/resolver/ subsyst...

Added: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/felix/resolver/WireImpl.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/felix/resolver/WireImpl.java?rev=1329807&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/felix/resolver/WireImpl.java (added)
+++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/felix/resolver/WireImpl.java Tue Apr 24 15:50:31 2012
@@ -0,0 +1,70 @@
+/*
+ * 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.resolver;
+
+import org.osgi.resource.Capability;
+import org.osgi.resource.Requirement;
+import org.osgi.resource.Resource;
+import org.osgi.resource.Wire;
+
+class WireImpl implements Wire
+{
+    private final Resource m_requirer;
+    private final Requirement m_req;
+    private final Resource m_provider;
+    private final Capability m_cap;
+
+    public WireImpl(
+        Resource requirer, Requirement req,
+        Resource provider, Capability cap)
+    {
+        m_requirer = requirer;
+        m_req = req;
+        m_provider = provider;
+        m_cap = cap;
+    }
+
+    public Resource getRequirer()
+    {
+        return m_requirer;
+    }
+
+    public Requirement getRequirement()
+    {
+        return m_req;
+    }
+
+    public Resource getProvider()
+    {
+        return m_provider;
+    }
+
+    public Capability getCapability()
+    {
+        return m_cap;
+    }
+
+    @Override
+    public String toString()
+    {
+        return m_req
+            + " -> "
+            + "[" + m_provider + "]";
+    }
+}
\ No newline at end of file

Added: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/felix/resolver/WrappedCapability.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/felix/resolver/WrappedCapability.java?rev=1329807&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/felix/resolver/WrappedCapability.java (added)
+++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/felix/resolver/WrappedCapability.java Tue Apr 24 15:50:31 2012
@@ -0,0 +1,114 @@
+/*
+ * Copyright (c) OSGi Alliance (2012). All Rights Reserved.
+ *
+ * Licensed 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.resolver;
+
+import java.util.Map;
+import org.osgi.framework.namespace.PackageNamespace;
+import org.osgi.resource.Capability;
+import org.osgi.resource.Resource;
+import org.osgi.service.resolver.HostedCapability;
+
+public class WrappedCapability implements HostedCapability
+{
+    private final Resource m_host;
+    private final Capability m_cap;
+
+    public WrappedCapability(Resource host, Capability cap)
+    {
+        m_host = host;
+        m_cap = cap;
+    }
+
+    @Override
+    public boolean equals(Object obj)
+    {
+        if (obj == null)
+        {
+            return false;
+        }
+        if (getClass() != obj.getClass())
+        {
+            return false;
+        }
+        final WrappedCapability other = (WrappedCapability) obj;
+        if (m_host != other.m_host && (m_host == null || !m_host.equals(other.m_host)))
+        {
+            return false;
+        }
+        if (m_cap != other.m_cap && (m_cap == null || !m_cap.equals(other.m_cap)))
+        {
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    public int hashCode()
+    {
+        int hash = 7;
+        hash = 37 * hash + (m_host != null ? m_host.hashCode() : 0);
+        hash = 37 * hash + (m_cap != null ? m_cap.hashCode() : 0);
+        return hash;
+    }
+
+    public Capability getDeclaredCapability()
+    {
+        return m_cap;
+    }
+
+    public Resource getResource()
+    {
+        return m_host;
+    }
+
+    public String getNamespace()
+    {
+        return m_cap.getNamespace();
+    }
+
+    public Map<String, String> getDirectives()
+    {
+        return m_cap.getDirectives();
+    }
+
+    public Map<String, Object> getAttributes()
+    {
+        return m_cap.getAttributes();
+    }
+
+// TODO: RFC-112 - Need impl-specific type.
+//    public List<String> getUses()
+//    {
+//        return m_cap.getUses();
+//    }
+
+    @Override
+    public String toString()
+    {
+        if (m_host == null)
+        {
+            return getAttributes().toString();
+        }
+        if (getNamespace().equals(PackageNamespace.PACKAGE_NAMESPACE))
+        {
+            return "[" + m_host + "] "
+                + getNamespace()
+                + "; "
+                + getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE);
+        }
+        return "[" + m_host + "] " + getNamespace() + "; " + getAttributes();
+    }
+}
\ No newline at end of file

Added: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/felix/resolver/WrappedRequirement.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/felix/resolver/WrappedRequirement.java?rev=1329807&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/felix/resolver/WrappedRequirement.java (added)
+++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/felix/resolver/WrappedRequirement.java Tue Apr 24 15:50:31 2012
@@ -0,0 +1,102 @@
+/*
+ * 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.resolver;
+
+import java.util.Map;
+import org.osgi.resource.Namespace;
+import org.osgi.resource.Requirement;
+import org.osgi.resource.Resource;
+
+public class WrappedRequirement implements Requirement
+{
+    private final Resource m_host;
+    private final Requirement m_req;
+
+    public WrappedRequirement(Resource host, Requirement req)
+    {
+        m_host = host;
+        m_req = req;
+    }
+
+    @Override
+    public boolean equals(Object obj)
+    {
+        if (obj == null)
+        {
+            return false;
+        }
+        if (getClass() != obj.getClass())
+        {
+            return false;
+        }
+        final WrappedRequirement other = (WrappedRequirement) obj;
+        if (m_host != other.m_host && (m_host == null || !m_host.equals(other.m_host)))
+        {
+            return false;
+        }
+        if (m_req != other.m_req && (m_req == null || !m_req.equals(other.m_req)))
+        {
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    public int hashCode()
+    {
+        int hash = 7;
+        hash = 37 * hash + (m_host != null ? m_host.hashCode() : 0);
+        hash = 37 * hash + (m_req != null ? m_req.hashCode() : 0);
+        return hash;
+    }
+
+    public Requirement getDeclaredRequirement()
+    {
+        return m_req;
+    }
+
+    public Resource getResource()
+    {
+        return m_host;
+    }
+
+    public String getNamespace()
+    {
+        return m_req.getNamespace();
+    }
+
+    public Map<String, String> getDirectives()
+    {
+        return m_req.getDirectives();
+    }
+
+    public Map<String, Object> getAttributes()
+    {
+        return m_req.getAttributes();
+    }
+
+    @Override
+    public String toString()
+    {
+        return "[" + m_host + "] "
+            + getNamespace()
+            + "; "
+            + getDirectives().get(Namespace.REQUIREMENT_FILTER_DIRECTIVE);
+    }
+}
\ No newline at end of file

Added: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/felix/resolver/WrappedResource.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/felix/resolver/WrappedResource.java?rev=1329807&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/felix/resolver/WrappedResource.java (added)
+++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/felix/resolver/WrappedResource.java Tue Apr 24 15:50:31 2012
@@ -0,0 +1,127 @@
+/*
+ * 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.resolver;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import org.osgi.framework.namespace.ExecutionEnvironmentNamespace;
+import org.osgi.framework.namespace.HostNamespace;
+import org.osgi.framework.namespace.IdentityNamespace;
+import org.osgi.resource.Capability;
+import org.osgi.resource.Requirement;
+import org.osgi.resource.Resource;
+
+class WrappedResource implements Resource
+{
+    private final Resource m_host;
+    private final List<Resource> m_fragments;
+    private List<Capability> m_cachedCapabilities = null;
+    private List<Requirement> m_cachedRequirements = null;
+
+    public WrappedResource(Resource host, List<Resource> fragments)
+    {
+        m_host = host;
+        m_fragments = fragments;
+    }
+
+    public Resource getDeclaredResource()
+    {
+        return m_host;
+    }
+
+    public List<Resource> getFragments()
+    {
+        return m_fragments;
+    }
+
+    public List<Capability> getCapabilities(String namespace)
+    {
+        if (m_cachedCapabilities == null)
+        {
+            List<Capability> caps = new ArrayList<Capability>();
+
+            // Wrap host capabilities.
+            for (Capability cap : m_host.getCapabilities(null))
+            {
+                caps.add(new WrappedCapability(this, cap));
+            }
+
+            // Wrap fragment capabilities.
+            if (m_fragments != null)
+            {
+                for (Resource fragment : m_fragments)
+                {
+                    for (Capability cap : fragment.getCapabilities(null))
+                    {
+                        // Filter out identity capabilities, since they
+                        // are not part of the fragment payload.
+                        if (!cap.getNamespace()
+                            .equals(IdentityNamespace.IDENTITY_NAMESPACE))
+                        {
+                            caps.add(new WrappedCapability(this,  cap));
+                        }
+                    }
+                }
+            }
+            m_cachedCapabilities = Collections.unmodifiableList(caps);
+        }
+        return m_cachedCapabilities;
+    }
+
+    public List<Requirement> getRequirements(String namespace)
+    {
+        if (m_cachedRequirements == null)
+        {
+            List<Requirement> reqs = new ArrayList<Requirement>();
+
+            // Wrap host requirements.
+            for (Requirement req : m_host.getRequirements(null))
+            {
+                reqs.add(new WrappedRequirement(this, req));
+            }
+
+            // Wrap fragment requirements.
+            if (m_fragments != null)
+            {
+                for (Resource fragment : m_fragments)
+                {
+                    for (Requirement req : fragment.getRequirements(null))
+                    {
+                        // Filter out host and execution environment requirements,
+                        // since they are not part of the fragment payload.
+                        if (!req.getNamespace().equals(HostNamespace.HOST_NAMESPACE)
+                            && !req.getNamespace().equals(
+                                ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE))
+                        {
+                            reqs.add(new WrappedRequirement(this, req));
+                        }
+                    }
+                }
+            }
+            m_cachedRequirements = Collections.unmodifiableList(reqs);
+        }
+        return m_cachedRequirements;
+    }
+
+    public String toString()
+    {
+        return m_host.toString();
+    }
+}
\ No newline at end of file