You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2008/09/01 17:08:10 UTC
svn commit: r690991 [12/20] - in /cxf/sandbox/dosgi: ./ discovery/
discovery/local/ discovery/local/src/ discovery/local/src/main/
discovery/local/src/main/java/ discovery/local/src/main/java/org/
discovery/local/src/main/java/org/apache/ discovery/loc...
Propchange: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4SearchPolicyCore.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4Wire.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4Wire.java?rev=690991&view=auto
==============================================================================
--- cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4Wire.java (added)
+++ cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4Wire.java Mon Sep 1 08:08:01 2008
@@ -0,0 +1,184 @@
+/*
+ * 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.framework.searchpolicy;
+
+import java.net.URL;
+import java.util.Enumeration;
+
+import org.apache.felix.framework.util.Util;
+import org.apache.felix.framework.util.manifestparser.Capability;
+import org.apache.felix.moduleloader.*;
+
+public class R4Wire implements IWire
+{
+ private IModule m_importer = null;
+ private IRequirement m_requirement = null;
+ private IModule m_exporter = null;
+ private ICapability m_capability = null;
+
+ public R4Wire(IModule importer, IRequirement requirement,
+ IModule exporter, ICapability capability)
+ {
+ m_importer = importer;
+ m_requirement = requirement;
+ m_exporter = exporter;
+ m_capability = capability;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.felix.framework.searchpolicy.IWire#getImporter()
+ */
+ public IModule getImporter()
+ {
+ return m_importer;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.felix.framework.searchpolicy.IWire#getRequirement()
+ */
+ public IRequirement getRequirement()
+ {
+ return m_requirement;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.felix.framework.searchpolicy.IWire#getExporter()
+ */
+ public IModule getExporter()
+ {
+ return m_exporter;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.felix.framework.searchpolicy.IWire#getCapability()
+ */
+ public ICapability getCapability()
+ {
+ return m_capability;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.felix.framework.searchpolicy.IWire#getClass(java.lang.String)
+ */
+ public Class getClass(String name) throws ClassNotFoundException
+ {
+ Class clazz = null;
+
+ // Get the package of the target class.
+ String pkgName = Util.getClassPackage(name);
+
+ // Only check when the package of the target class is
+ // the same as the package for the wire.
+ if (m_capability.getNamespace().equals(ICapability.PACKAGE_NAMESPACE) &&
+ m_capability.getProperties().get(ICapability.PACKAGE_PROPERTY).equals(pkgName))
+ {
+ // Before delegating to the exporting module to satisfy
+ // the class load, we must check the include/exclude filters
+ // from the target package to make sure that the class is
+ // actually visible. However, if the exporting module is the
+ // same as the requesting module, then filtering is not
+ // performed since a module has complete access to itself.
+ if ((m_exporter == m_importer) ||
+ (m_capability.getNamespace().equals(ICapability.PACKAGE_NAMESPACE) &&
+ ((Capability) m_capability).isIncluded(name)))
+ {
+ clazz = m_exporter.getContentLoader().getClass(name);
+ }
+
+ // If no class was found, then we must throw an exception
+ // since the exporter for this package did not contain the
+ // requested class.
+ if (clazz == null)
+ {
+ throw new ClassNotFoundException(name);
+ }
+ }
+
+ return clazz;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.felix.framework.searchpolicy.IWire#getResource(java.lang.String)
+ */
+ public URL getResource(String name) throws ResourceNotFoundException
+ {
+ URL url = null;
+
+ // Get the package of the target class.
+ String pkgName = Util.getResourcePackage(name);
+
+ // Only check when the package of the target resource is
+ // the same as the package for the wire.
+ if (m_capability.getNamespace().equals(ICapability.PACKAGE_NAMESPACE) &&
+ m_capability.getProperties().get(ICapability.PACKAGE_PROPERTY).equals(pkgName))
+ {
+ url = m_exporter.getContentLoader().getResource(name);
+
+ // If no resource was found, then we must throw an exception
+ // since the exporter for this package did not contain the
+ // requested class.
+ if (url == null)
+ {
+ throw new ResourceNotFoundException(name);
+ }
+ }
+
+ return url;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.felix.framework.searchpolicy.IWire#getResources(java.lang.String)
+ */
+ public Enumeration getResources(String name) throws ResourceNotFoundException
+ {
+ Enumeration urls = null;
+
+ // Get the package of the target class.
+ String pkgName = Util.getResourcePackage(name);
+
+ // Only check when the package of the target resource is
+ // the same as the package for the wire.
+ if (m_capability.getNamespace().equals(ICapability.PACKAGE_NAMESPACE) &&
+ m_capability.getProperties().get(ICapability.PACKAGE_PROPERTY).equals(pkgName))
+ {
+ urls = m_exporter.getContentLoader().getResources(name);
+
+ // If no resource was found, then we must throw an exception
+ // since the exporter for this package did not contain the
+ // requested class.
+ if (urls == null)
+ {
+ throw new ResourceNotFoundException(name);
+ }
+ }
+
+ return urls;
+ }
+
+ public String toString()
+ {
+ if (m_capability.getNamespace().equals(ICapability.PACKAGE_NAMESPACE))
+ {
+ return m_importer + " -> "
+ + m_capability.getProperties().get(ICapability.PACKAGE_PROPERTY)
+ + " -> " + m_exporter;
+ }
+ return m_importer + " -> " + m_capability + " -> " + m_exporter;
+ }
+}
\ No newline at end of file
Propchange: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4Wire.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4Wire.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4WireModule.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4WireModule.java?rev=690991&view=auto
==============================================================================
--- cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4WireModule.java (added)
+++ cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4WireModule.java Mon Sep 1 08:08:01 2008
@@ -0,0 +1,181 @@
+/*
+ * 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.framework.searchpolicy;
+
+import java.net.URL;
+import java.util.*;
+
+import org.apache.felix.framework.searchpolicy.R4SearchPolicyCore.ResolvedPackage;
+import org.apache.felix.framework.searchpolicy.R4SearchPolicyCore.PackageSource;
+import org.apache.felix.framework.util.CompoundEnumeration;
+import org.apache.felix.framework.util.Util;
+import org.apache.felix.framework.util.manifestparser.Capability;
+import org.apache.felix.moduleloader.*;
+
+public class R4WireModule implements IWire
+{
+ private IModule m_importer = null;
+ private IRequirement m_requirement = null;
+ private IModule m_exporter = null;
+ private ICapability m_capability = null;
+ private Map m_pkgMap = null;
+
+ public R4WireModule(IModule importer, IRequirement requirement,
+ IModule exporter, ICapability capability, Map pkgMap)
+ {
+ m_importer = importer;
+ m_requirement = requirement;
+ m_exporter = exporter;
+ m_capability = capability;
+ m_pkgMap = pkgMap;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.felix.framework.searchpolicy.IWire#getImporter()
+ */
+ public IModule getImporter()
+ {
+ return m_importer;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.felix.framework.searchpolicy.IWire#getRequirement()
+ */
+ public IRequirement getRequirement()
+ {
+ return m_requirement;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.felix.framework.searchpolicy.IWire#getExporter()
+ */
+ public IModule getExporter()
+ {
+ return m_exporter;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.felix.framework.searchpolicy.IWire#getCapability()
+ */
+ public ICapability getCapability()
+ {
+ return m_capability;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.felix.framework.searchpolicy.IWire#getClass(java.lang.String)
+ */
+ public Class getClass(String name) throws ClassNotFoundException
+ {
+ // Get the package of the target class.
+ String pkgName = Util.getClassPackage(name);
+
+ ResolvedPackage rp = (ResolvedPackage) m_pkgMap.get(pkgName);
+ if (rp != null)
+ {
+ for (int srcIdx = 0; srcIdx < rp.m_sourceList.size(); srcIdx++)
+ {
+ PackageSource ps = (PackageSource) rp.m_sourceList.get(srcIdx);
+ if ((ps.m_module == m_importer) ||
+ ((ps.m_capability instanceof Capability) &&
+ ((Capability) ps.m_capability).isIncluded(name)))
+ {
+ Class clazz = ps.m_module.getContentLoader().getClass(name);
+ if (clazz != null)
+ {
+ return clazz;
+ }
+ }
+ }
+ }
+
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.felix.framework.searchpolicy.IWire#getResource(java.lang.String)
+ */
+ public URL getResource(String name) throws ResourceNotFoundException
+ {
+ // Get the package of the target class.
+ String pkgName = Util.getResourcePackage(name);
+
+ ResolvedPackage rp = (ResolvedPackage) m_pkgMap.get(pkgName);
+ if (rp != null)
+ {
+ for (int srcIdx = 0; srcIdx < rp.m_sourceList.size(); srcIdx++)
+ {
+ PackageSource ps = (PackageSource) rp.m_sourceList.get(srcIdx);
+ URL url = ps.m_module.getContentLoader().getResource(name);
+ if (url != null)
+ {
+ return url;
+ }
+ }
+
+ // Don't throw ResourceNotFoundException because module
+ // dependencies support split packages.
+ }
+
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.felix.framework.searchpolicy.IWire#getResources(java.lang.String)
+ */
+ public Enumeration getResources(String name) throws ResourceNotFoundException
+ {
+ // List to hold all enumerations from all package sources.
+ List enums = new ArrayList();
+
+ // Get the package of the target class.
+ String pkgName = Util.getResourcePackage(name);
+
+ // See if we have a resolved package for the resource's package.
+ // If so, loop through all package sources and aggregate any
+ // matching resource enumerations.
+ ResolvedPackage rp = (ResolvedPackage) m_pkgMap.get(pkgName);
+ if (rp != null)
+ {
+ for (int srcIdx = 0; srcIdx < rp.m_sourceList.size(); srcIdx++)
+ {
+ PackageSource ps = (PackageSource) rp.m_sourceList.get(srcIdx);
+ Enumeration urls = ps.m_module.getContentLoader().getResources(name);
+ if (urls != null)
+ {
+ enums.add(urls);
+ }
+ }
+
+ // Don't throw ResourceNotFoundException because module
+ // dependencies support split packages.
+ }
+
+ return (enums.size() == 0)
+ ? null
+ : new CompoundEnumeration(
+ (Enumeration[]) enums.toArray(new Enumeration[enums.size()]));
+
+ }
+
+ public String toString()
+ {
+ return m_importer + " -> " + m_capability + " -> " + m_exporter;
+ }
+}
\ No newline at end of file
Propchange: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4WireModule.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/searchpolicy/R4WireModule.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/searchpolicy/ResolveException.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/searchpolicy/ResolveException.java?rev=690991&view=auto
==============================================================================
--- cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/searchpolicy/ResolveException.java (added)
+++ cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/searchpolicy/ResolveException.java Mon Sep 1 08:08:01 2008
@@ -0,0 +1,62 @@
+/*
+ * 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.framework.searchpolicy;
+
+import org.apache.felix.moduleloader.IModule;
+import org.apache.felix.moduleloader.IRequirement;
+
+/**
+ * <p>
+ * This exception is thrown if a module cannot be resolved. The module
+ * that failed to be resolved is recorded, along with the failed import target
+ * identifier and version number. If the error was a result of a propagation
+ * conflict, then the propagation error flag is set.
+ * </p>
+ * @see org.apache.felix.moduleloader.search.ImportSearchPolicy#validate(org.apache.felix.moduleloader.Module)
+**/
+public class ResolveException extends Exception
+{
+ private IModule m_module = null;
+ private IRequirement m_req = null;
+
+ /**
+ * Constructs an exception with the specified message, module,
+ * import identifier, import version number, and propagation flag.
+ **/
+ public ResolveException(String msg, IModule module, IRequirement req)
+ {
+ super(msg);
+ m_module = module;
+ m_req = req;
+ }
+
+ /**
+ * Returns the module that was being resolved.
+ * @return the module that was being resolved.
+ **/
+ public IModule getModule()
+ {
+ return m_module;
+ }
+
+ public IRequirement getRequirement()
+ {
+ return m_req;
+ }
+}
\ No newline at end of file
Propchange: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/searchpolicy/ResolveException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/searchpolicy/ResolveException.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/searchpolicy/ResolveListener.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/searchpolicy/ResolveListener.java?rev=690991&view=auto
==============================================================================
--- cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/searchpolicy/ResolveListener.java (added)
+++ cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/searchpolicy/ResolveListener.java Mon Sep 1 08:08:01 2008
@@ -0,0 +1,48 @@
+/*
+ * 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.framework.searchpolicy;
+
+import java.util.EventListener;
+
+import org.apache.felix.moduleloader.ModuleEvent;
+
+/**
+ * <p>
+ * This is an event listener interface for listening to resolution
+ * events that are generated by the <tt>R4SearchPolicy</tt>. Events
+ * are fired when a module is resolved and when it is unresolved.
+ * </p>
+ * @see org.apache.felix.framework.searchpolicy.R4SearchPolicyCore
+**/
+public interface ResolveListener extends EventListener
+{
+ /**
+ * This is an event callback method that indicates that
+ * a module was resolved.
+ * @param event the module event containing the event data.
+ **/
+ public void moduleResolved(ModuleEvent event);
+
+ /**
+ * This is an event callback method that indicates that
+ * a module was unresolved.
+ * @param event the module event containing the event data.
+ **/
+ public void moduleUnresolved(ModuleEvent event);
+}
\ No newline at end of file
Propchange: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/searchpolicy/ResolveListener.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/searchpolicy/ResolveListener.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/searchpolicy/URLPolicyImpl.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/searchpolicy/URLPolicyImpl.java?rev=690991&view=auto
==============================================================================
--- cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/searchpolicy/URLPolicyImpl.java (added)
+++ cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/searchpolicy/URLPolicyImpl.java Mon Sep 1 08:08:01 2008
@@ -0,0 +1,69 @@
+/*
+ * 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.framework.searchpolicy;
+
+import java.net.*;
+
+import org.apache.felix.framework.Logger;
+import org.apache.felix.framework.util.FelixConstants;
+import org.apache.felix.framework.util.SecureAction;
+import org.apache.felix.moduleloader.IModule;
+import org.apache.felix.moduleloader.IURLPolicy;
+
+public class URLPolicyImpl implements IURLPolicy
+{
+ private Logger m_logger = null;
+ private URLStreamHandler m_streamHandler = null;
+ private IModule m_module = null;
+ private static SecureAction m_secureAction = new SecureAction();
+
+// TODO: ML - IT SUCKS HAVING A URL POLICY OBJECT PER MODULE!
+ public URLPolicyImpl(Logger logger, URLStreamHandler streamHandler, IModule module)
+ {
+ m_logger = logger;
+ m_streamHandler = streamHandler;
+ m_module = module;
+ }
+
+ public URL createURL(int port, String path)
+ {
+ // Add a slash if there is one already, otherwise
+ // the is no slash separating the host from the file
+ // in the resulting URL.
+ if (!path.startsWith("/"))
+ {
+ path = "/" + path;
+ }
+
+ try
+ {
+ return m_secureAction.createURL(
+ FelixConstants.BUNDLE_URL_PROTOCOL,
+ m_module.getId(), port, path, m_streamHandler);
+ }
+ catch (MalformedURLException ex)
+ {
+ m_logger.log(
+ Logger.LOG_ERROR,
+ "Unable to create resource URL.",
+ ex);
+ }
+ return null;
+ }
+}
\ No newline at end of file
Propchange: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/searchpolicy/URLPolicyImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/searchpolicy/URLPolicyImpl.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/CompoundEnumeration.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/CompoundEnumeration.java?rev=690991&view=auto
==============================================================================
--- cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/CompoundEnumeration.java (added)
+++ cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/CompoundEnumeration.java Mon Sep 1 08:08:01 2008
@@ -0,0 +1,109 @@
+/*
+ * 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.framework.util;
+
+import java.util.Enumeration;
+import java.util.NoSuchElementException;
+
+public class CompoundEnumeration implements Enumeration
+{
+ private Enumeration[] m_enums = null;
+ private int index = 0;
+
+ public CompoundEnumeration(Enumeration[] enums)
+ {
+ m_enums = enums;
+ }
+
+ public boolean hasMoreElements()
+ {
+ // if the current enum is null that means this enum is finished
+ if (currentEnumeration() == null)
+ {
+ // No next enum
+ return false;
+ }
+ // If the current enum has more elements, lets go
+ return currentEnumeration().hasMoreElements();
+ }
+
+ private Enumeration findNextEnumeration(boolean moveCursor)
+ {
+ return findNextEnumeration(index, moveCursor);
+ }
+
+ private Enumeration findNextEnumeration(int cursor, boolean moveCursor)
+ {
+ // next place in the array
+ int next = cursor + 1;
+ // If the cursor is still in the array
+ if (next < m_enums.length)
+ {
+
+ // If there is something in that place
+ // AND the enum is not empty
+ if (m_enums[next] != null &&
+ m_enums[next].hasMoreElements())
+ {
+ // OK
+ if (moveCursor)
+ {
+ index = next;
+ }
+ return m_enums[next];
+ }
+ // Try next element
+ return findNextEnumeration(next, moveCursor);
+ }
+ // No more elements available
+ return null;
+ }
+
+ public Object nextElement()
+ {
+ // ask for the next element of the current enum.
+ if (currentEnumeration() != null)
+ {
+ return currentEnumeration().nextElement();
+ }
+
+ // no more elements in this Enum
+ // We must throw a NoSuchElementException
+ throw new NoSuchElementException("No more elements");
+ }
+
+ private Enumeration currentEnumeration()
+ {
+ if (m_enums != null)
+ {
+ if (index < m_enums.length)
+ {
+ Enumeration e = m_enums[index];
+ if (e == null || !e.hasMoreElements())
+ {
+ // the current enum is null or empty
+ // we probably want to switch to the next one
+ e = findNextEnumeration(true);
+ }
+ return e;
+ }
+ }
+ return null;
+ }
+}
\ No newline at end of file
Propchange: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/CompoundEnumeration.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/CompoundEnumeration.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/EventDispatcher.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/EventDispatcher.java?rev=690991&view=auto
==============================================================================
--- cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/EventDispatcher.java (added)
+++ cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/EventDispatcher.java Mon Sep 1 08:08:01 2008
@@ -0,0 +1,874 @@
+/*
+ * 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.framework.util;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.ArrayList;
+import java.util.EventListener;
+import java.util.EventObject;
+
+import org.apache.felix.framework.Logger;
+import org.osgi.framework.AllServiceListener;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.BundleListener;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Filter;
+import org.osgi.framework.FrameworkEvent;
+import org.osgi.framework.FrameworkListener;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServicePermission;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.SynchronousBundleListener;
+import org.osgi.framework.hooks.service.ListenerHook;
+
+public class EventDispatcher
+{
+ private static final int LISTENER_BUNDLE_OFFSET = 0;
+ private static final int LISTENER_CLASS_OFFSET = 1;
+ private static final int LISTENER_OBJECT_OFFSET = 2;
+ private static final int LISTENER_FILTER_OFFSET = 3;
+ private static final int LISTENER_SECURITY_OFFSET = 4;
+ private static final int LISTENER_ARRAY_INCREMENT = 5;
+
+ // Framework instance for this dispatcher.
+ private Logger m_logger = null;
+
+ // Representation of an empty listener list.
+ private static final Object[] m_emptyList = new Object[0];
+
+ private Object[] m_frameworkListeners = m_emptyList;
+ private Object[] m_bundleListeners = m_emptyList;
+ private Object[] m_syncBundleListeners = m_emptyList;
+ private Object[] m_serviceListeners = m_emptyList;
+
+ // A single thread is used to deliver events for all dispatchers.
+ private static Thread m_thread = null;
+ private static String m_threadLock = new String("thread lock");
+ private static int m_references = 0;
+ private static volatile boolean m_stopping = false;
+
+ // List of requests.
+ private static final ArrayList m_requestList = new ArrayList();
+ // Pooled requests to avoid memory allocation.
+ private static final ArrayList m_requestPool = new ArrayList();
+
+ private EventDispatcher(Logger logger)
+ {
+ m_logger = logger;
+ }
+
+ public static EventDispatcher start(Logger logger)
+ {
+ EventDispatcher eventDispatcher = new EventDispatcher(logger);
+
+ synchronized (m_threadLock)
+ {
+ // Start event dispatching thread if necessary.
+ if (m_thread == null || !m_thread.isAlive())
+ {
+ m_stopping = false;
+
+ m_thread = new Thread(new Runnable() {
+ public void run()
+ {
+ try
+ {
+ EventDispatcher.run();
+ }
+ finally
+ {
+ // Ensure we update state even if stopped by external cause
+ // e.g. an Applet VM forceably killing threads
+ synchronized (m_threadLock)
+ {
+ m_thread = null;
+ m_stopping = false;
+ m_references = 0;
+ m_threadLock.notifyAll();
+ }
+ }
+ }
+ }, "FelixDispatchQueue");
+ m_thread.start();
+ }
+
+ // reference counting and flags
+ m_references++;
+ }
+
+ return eventDispatcher;
+ }
+
+ public static void shutdown()
+ {
+ synchronized (m_threadLock)
+ {
+ // Return if already dead or stopping.
+ if (m_thread == null || m_stopping)
+ {
+ return;
+ }
+
+ // decrement use counter, don't continue if there are users
+ m_references--;
+ if (m_references > 0)
+ {
+ return;
+ }
+
+ m_stopping = true;
+ }
+
+ // Signal dispatch thread.
+ synchronized (m_requestList)
+ {
+ m_requestList.notify();
+ }
+
+ // Use separate lock for shutdown to prevent any chance of nested lock deadlock
+ synchronized (m_threadLock)
+ {
+ while (m_thread != null)
+ {
+ try
+ {
+ m_threadLock.wait();
+ }
+ catch (InterruptedException ex)
+ {
+ }
+ }
+ }
+ }
+
+ public ListenerHook.Listener[] wrapAllServiceListeners() {
+ Object[] listeners = null;
+ synchronized (this)
+ {
+ listeners = m_serviceListeners;
+ }
+ ListenerHook.Listener[] existingListeners =
+ new ListenerHook.Listener[listeners.length/LISTENER_ARRAY_INCREMENT];
+ for (int i = 0, j = 0; i < listeners.length; i += LISTENER_ARRAY_INCREMENT, j++)
+ {
+ existingListeners[j] = wrapListener(listeners, i);
+ }
+ return existingListeners;
+ }
+
+ private static ListenerHook.Listener wrapListener(Object[] listeners, int offset) {
+
+ Filter filter = ((Filter)listeners[offset + LISTENER_FILTER_OFFSET]);
+
+ return new ListenerHook.Listener(
+ ((Bundle)listeners[offset + LISTENER_BUNDLE_OFFSET]).getBundleContext(),
+ (ServiceListener)listeners[offset + LISTENER_OBJECT_OFFSET],
+ filter == null ? null : filter.toString());
+ }
+
+ public void addListener(Bundle bundle, Class clazz, EventListener l, Filter filter)
+ {
+ // Verify the listener.
+ if (l == null)
+ {
+ throw new IllegalArgumentException("Listener is null");
+ }
+ else if (!clazz.isInstance(l))
+ {
+ throw new IllegalArgumentException(
+ "Listener not of type " + clazz.getName());
+ }
+
+ // See if we can simply update the listener, if so then
+ // return immediately.
+ if (updateListener(bundle, clazz, l, filter))
+ {
+ return;
+ }
+
+ // Lock the object to add the listener.
+ synchronized (this)
+ {
+ Object[] listeners = null;
+ Object acc = null;
+
+ if (clazz == FrameworkListener.class)
+ {
+ listeners = m_frameworkListeners;
+ }
+ else if (clazz == BundleListener.class)
+ {
+ if (SynchronousBundleListener.class.isInstance(l))
+ {
+ listeners = m_syncBundleListeners;
+ }
+ else
+ {
+ listeners = m_bundleListeners;
+ }
+ }
+ else if (clazz == ServiceListener.class)
+ {
+ // Remember security context for filtering service events.
+ Object sm = System.getSecurityManager();
+ if (sm != null)
+ {
+ acc = ((SecurityManager) sm).getSecurityContext();
+ }
+
+ listeners = m_serviceListeners;
+ }
+ else
+ {
+ throw new IllegalArgumentException("Unknown listener: " + l.getClass());
+ }
+
+ // If we have no listeners, then just add the new listener.
+ if (listeners == m_emptyList)
+ {
+ listeners = new Object[LISTENER_ARRAY_INCREMENT];
+ listeners[LISTENER_BUNDLE_OFFSET] = bundle;
+ listeners[LISTENER_CLASS_OFFSET] = clazz;
+ listeners[LISTENER_OBJECT_OFFSET] = l;
+ listeners[LISTENER_FILTER_OFFSET] = filter;
+ listeners[LISTENER_SECURITY_OFFSET] = acc;
+ }
+ // Otherwise, we need to do some array copying.
+ // Notice, the old array is always valid, so if
+ // the dispatch thread is in the middle of a dispatch,
+ // then it has a reference to the old listener array
+ // and is not affected by the new value.
+ else
+ {
+ Object[] newList = new Object[listeners.length + LISTENER_ARRAY_INCREMENT];
+ System.arraycopy(listeners, 0, newList, 0, listeners.length);
+ newList[listeners.length + LISTENER_BUNDLE_OFFSET] = bundle;
+ newList[listeners.length + LISTENER_CLASS_OFFSET] = clazz;
+ newList[listeners.length + LISTENER_OBJECT_OFFSET] = l;
+ newList[listeners.length + LISTENER_FILTER_OFFSET] = filter;
+ newList[listeners.length + LISTENER_SECURITY_OFFSET] = acc;
+ listeners = newList;
+ }
+
+ if (clazz == FrameworkListener.class)
+ {
+ m_frameworkListeners = listeners;
+ }
+ else if (clazz == BundleListener.class)
+ {
+ if (SynchronousBundleListener.class.isInstance(l))
+ {
+ m_syncBundleListeners = listeners;
+ }
+ else
+ {
+ m_bundleListeners = listeners;
+ }
+ }
+ else if (clazz == ServiceListener.class)
+ {
+ m_serviceListeners = listeners;
+ }
+ }
+ }
+
+ // returning ListenerHook.Listener is the only way to pick a filter value for the
+ // service listener being removed. m_serviceListeners array can hold ListenerHook.Listener ?
+ public ListenerHook.Listener removeListener(Bundle bundle, Class clazz, EventListener l)
+ {
+ ListenerHook.Listener listener = null;
+ // Verify listener.
+ if (l == null)
+ {
+ throw new IllegalArgumentException("Listener is null");
+ }
+ else if (!clazz.isInstance(l))
+ {
+ throw new IllegalArgumentException(
+ "Listener not of type " + clazz.getName());
+ }
+
+ // Lock the object to remove the listener.
+ synchronized (this)
+ {
+ Object[] listeners = null;
+
+ if (clazz == FrameworkListener.class)
+ {
+ listeners = m_frameworkListeners;
+ }
+ else if (clazz == BundleListener.class)
+ {
+ if (SynchronousBundleListener.class.isInstance(l))
+ {
+ listeners = m_syncBundleListeners;
+ }
+ else
+ {
+ listeners = m_bundleListeners;
+ }
+ }
+ else if (clazz == ServiceListener.class)
+ {
+ listeners = m_serviceListeners;
+ }
+ else
+ {
+ throw new IllegalArgumentException("Unknown listener: " + l.getClass());
+ }
+
+ // Try to find the instance in our list.
+ int idx = -1;
+ for (int i = 0; i < listeners.length; i += LISTENER_ARRAY_INCREMENT)
+ {
+ if (listeners[i + LISTENER_BUNDLE_OFFSET].equals(bundle) &&
+ (listeners[i + LISTENER_CLASS_OFFSET] == clazz) &&
+ (listeners[i + LISTENER_OBJECT_OFFSET] == l))
+ {
+ if (ServiceListener.class == clazz) {
+ listener = wrapListener(listeners, i);
+ }
+ idx = i;
+ break;
+ }
+ }
+
+ // If we have the instance, then remove it.
+ if (idx >= 0)
+ {
+ // If this is the last listener, then point to empty list.
+ if ((listeners.length - LISTENER_ARRAY_INCREMENT) == 0)
+ {
+ listeners = m_emptyList;
+ }
+ // Otherwise, we need to do some array copying.
+ // Notice, the old array is always valid, so if
+ // the dispatch thread is in the middle of a dispatch,
+ // then it has a reference to the old listener array
+ // and is not affected by the new value.
+ else
+ {
+ Object[] newList = new Object[listeners.length - LISTENER_ARRAY_INCREMENT];
+ System.arraycopy(listeners, 0, newList, 0, idx);
+ if (idx < newList.length)
+ {
+ System.arraycopy(
+ listeners, idx + LISTENER_ARRAY_INCREMENT,
+ newList, idx, newList.length - idx);
+ }
+ listeners = newList;
+ }
+ }
+
+ if (clazz == FrameworkListener.class)
+ {
+ m_frameworkListeners = listeners;
+ }
+ else if (clazz == BundleListener.class)
+ {
+ if (SynchronousBundleListener.class.isInstance(l))
+ {
+ m_syncBundleListeners = listeners;
+ }
+ else
+ {
+ m_bundleListeners = listeners;
+ }
+ }
+ else if (clazz == ServiceListener.class)
+ {
+ m_serviceListeners = listeners;
+ }
+ }
+ return listener;
+ }
+
+ public void removeListeners(Bundle bundle)
+ {
+ if (bundle == null)
+ {
+ return;
+ }
+
+ synchronized (this)
+ {
+ // Remove all framework listeners associated with the specified bundle.
+ Object[] listeners = m_frameworkListeners;
+ for (int i = listeners.length - LISTENER_ARRAY_INCREMENT;
+ i >= 0;
+ i -= LISTENER_ARRAY_INCREMENT)
+ {
+ // Check if the bundle associated with the current listener
+ // is the same as the specified bundle, if so remove the listener.
+ Bundle registeredBundle = (Bundle) listeners[i + LISTENER_BUNDLE_OFFSET];
+ if (bundle.equals(registeredBundle))
+ {
+ Class clazz = (Class) listeners[i + LISTENER_CLASS_OFFSET];
+ EventListener l = (EventListener) listeners[i + LISTENER_OBJECT_OFFSET];
+ removeListener(bundle, clazz, l);
+ }
+ }
+
+ // Remove all bundle listeners associated with the specified bundle.
+ listeners = m_bundleListeners;
+ for (int i = listeners.length - LISTENER_ARRAY_INCREMENT;
+ i >= 0;
+ i -= LISTENER_ARRAY_INCREMENT)
+ {
+ // Check if the bundle associated with the current listener
+ // is the same as the specified bundle, if so remove the listener.
+ Bundle registeredBundle = (Bundle) listeners[i + LISTENER_BUNDLE_OFFSET];
+ if (bundle.equals(registeredBundle))
+ {
+ Class clazz = (Class) listeners[i + LISTENER_CLASS_OFFSET];
+ EventListener l = (EventListener) listeners[i + LISTENER_OBJECT_OFFSET];
+ removeListener(bundle, clazz, l);
+ }
+ }
+
+ // Remove all synchronous bundle listeners associated with
+ // the specified bundle.
+ listeners = m_syncBundleListeners;
+ for (int i = listeners.length - LISTENER_ARRAY_INCREMENT;
+ i >= 0;
+ i -= LISTENER_ARRAY_INCREMENT)
+ {
+ // Check if the bundle associated with the current listener
+ // is the same as the specified bundle, if so remove the listener.
+ Bundle registeredBundle = (Bundle) listeners[i + LISTENER_BUNDLE_OFFSET];
+ if (bundle.equals(registeredBundle))
+ {
+ Class clazz = (Class) listeners[i + LISTENER_CLASS_OFFSET];
+ EventListener l = (EventListener) listeners[i + LISTENER_OBJECT_OFFSET];
+ removeListener(bundle, clazz, l);
+ }
+ }
+
+ // Remove all service listeners associated with the specified bundle.
+ listeners = m_serviceListeners;
+ for (int i = listeners.length - LISTENER_ARRAY_INCREMENT;
+ i >= 0;
+ i -= LISTENER_ARRAY_INCREMENT)
+ {
+ // Check if the bundle associated with the current listener
+ // is the same as the specified bundle, if so remove the listener.
+ Bundle registeredBundle = (Bundle) listeners[i + LISTENER_BUNDLE_OFFSET];
+ if (bundle.equals(registeredBundle))
+ {
+ Class clazz = (Class) listeners[i + LISTENER_CLASS_OFFSET];
+ EventListener l = (EventListener) listeners[i + LISTENER_OBJECT_OFFSET];
+ removeListener(bundle, clazz, l);
+ }
+ }
+ }
+ }
+
+ public boolean updateListener(Bundle bundle, Class clazz, EventListener l, Filter filter)
+ {
+ synchronized (this)
+ {
+ Object[] listeners = null;
+
+ if (clazz == FrameworkListener.class)
+ {
+ listeners = m_frameworkListeners;
+ }
+ else if (clazz == BundleListener.class)
+ {
+ if (SynchronousBundleListener.class.isInstance(l))
+ {
+ listeners = m_syncBundleListeners;
+ }
+ else
+ {
+ listeners = m_bundleListeners;
+ }
+ }
+ else if (clazz == ServiceListener.class)
+ {
+ listeners = m_serviceListeners;
+ }
+
+ // See if the listener is already registered, if so then
+ // handle it according to the spec.
+ for (int i = 0; i < listeners.length; i += LISTENER_ARRAY_INCREMENT)
+ {
+ if (listeners[i + LISTENER_BUNDLE_OFFSET].equals(bundle) &&
+ (listeners[i + LISTENER_CLASS_OFFSET] == clazz) &&
+ (listeners[i + LISTENER_OBJECT_OFFSET] == l))
+ {
+ if (clazz == FrameworkListener.class)
+ {
+ // The spec says to ignore this case.
+ }
+ else if (clazz == BundleListener.class)
+ {
+ // The spec says to ignore this case.
+ }
+ else if (clazz == ServiceListener.class)
+ {
+ // The spec says to update the filter in this case.
+ listeners[i + LISTENER_FILTER_OFFSET] = filter;
+ }
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ public void fireFrameworkEvent(FrameworkEvent event)
+ {
+ // Take a snapshot of the listener array.
+ Object[] listeners = null;
+ synchronized (this)
+ {
+ listeners = m_frameworkListeners;
+ }
+
+ // Fire all framework listeners on a separate thread.
+ fireEventAsynchronously(m_logger, Request.FRAMEWORK_EVENT, listeners, event);
+ }
+
+ public void fireBundleEvent(BundleEvent event)
+ {
+ // Take a snapshot of the listener array.
+ Object[] listeners = null;
+ Object[] syncListeners = null;
+ synchronized (this)
+ {
+ listeners = m_bundleListeners;
+ syncListeners = m_syncBundleListeners;
+ }
+
+ // Fire synchronous bundle listeners immediately on the calling thread.
+ fireEventImmediately(m_logger, Request.BUNDLE_EVENT, syncListeners, event);
+
+ // The spec says that asynchronous bundle listeners do not get events
+ // of types STARTING or STOPPING.
+ if ((event.getType() != BundleEvent.STARTING) &&
+ (event.getType() != BundleEvent.STOPPING))
+ {
+ // Fire asynchronous bundle listeners on a separate thread.
+ fireEventAsynchronously(m_logger, Request.BUNDLE_EVENT, listeners, event);
+ }
+ }
+
+ public void fireServiceEvent(ServiceEvent event)
+ {
+ // Take a snapshot of the listener array.
+ Object[] listeners = null;
+ synchronized (this)
+ {
+ listeners = m_serviceListeners;
+ }
+
+ // Fire all service events immediately on the calling thread.
+ fireEventImmediately(m_logger, Request.SERVICE_EVENT, listeners, event);
+ }
+
+ private void fireEventAsynchronously(
+ Logger logger, int type, Object[] listeners, EventObject event)
+ {
+ //TODO: should possibly check this within thread lock, seems to be ok though without
+ // If dispatch thread is stopped, then ignore dispatch request.
+ if (m_stopping || m_thread == null)
+ {
+ return;
+ }
+
+ // First get a request from the pool or create one if necessary.
+ Request req = null;
+ synchronized (m_requestPool)
+ {
+ if (m_requestPool.size() > 0)
+ {
+ req = (Request) m_requestPool.remove(0);
+ }
+ else
+ {
+ req = new Request();
+ }
+ }
+
+ // Initialize dispatch request.
+ req.m_logger = logger;
+ req.m_type = type;
+ req.m_listeners = listeners;
+ req.m_event = event;
+
+ // Lock the request list.
+ synchronized (m_requestList)
+ {
+ // Add our request to the list.
+ m_requestList.add(req);
+ // Notify the dispatch thread that there is work to do.
+ m_requestList.notify();
+ }
+ }
+
+ private static void fireEventImmediately(
+ Logger logger, int type, Object[] listeners, EventObject event)
+ {
+ if (listeners.length > 0)
+ {
+ // Notify appropriate listeners.
+ for (int i = listeners.length - LISTENER_ARRAY_INCREMENT;
+ i >= 0;
+ i -= LISTENER_ARRAY_INCREMENT)
+ {
+ Bundle bundle = (Bundle) listeners[i + LISTENER_BUNDLE_OFFSET];
+ EventListener l = (EventListener) listeners[i + LISTENER_OBJECT_OFFSET];
+ Filter filter = (Filter) listeners[i + LISTENER_FILTER_OFFSET];
+ Object acc = listeners[i + LISTENER_SECURITY_OFFSET];
+ try
+ {
+ if (type == Request.FRAMEWORK_EVENT)
+ {
+ invokeFrameworkListenerCallback(bundle, l, event);
+ }
+ else if (type == Request.BUNDLE_EVENT)
+ {
+ invokeBundleListenerCallback(bundle, l, event);
+ }
+ else if (type == Request.SERVICE_EVENT)
+ {
+ invokeServiceListenerCallback(bundle, l, filter, acc, event);
+ }
+ }
+ catch (Throwable th)
+ {
+ logger.log(
+ Logger.LOG_ERROR,
+ "EventDispatcher: Error during dispatch.", th);
+ }
+ }
+ }
+ }
+
+ private static void invokeFrameworkListenerCallback(
+ Bundle bundle, final EventListener l, final EventObject event)
+ {
+ // The spec says only active bundles receive asynchronous events,
+ // but we will include starting bundles too otherwise
+ // it is impossible to see everything.
+ if ((bundle.getState() == Bundle.STARTING) ||
+ (bundle.getState() == Bundle.ACTIVE))
+ {
+ if (System.getSecurityManager() != null)
+ {
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run()
+ {
+ ((FrameworkListener) l).frameworkEvent((FrameworkEvent) event);
+ return null;
+ }
+ });
+ }
+ else
+ {
+ ((FrameworkListener) l).frameworkEvent((FrameworkEvent) event);
+ }
+ }
+ }
+
+ private static void invokeBundleListenerCallback(
+ Bundle bundle, final EventListener l, final EventObject event)
+ {
+ // A bundle listener is either synchronous or asynchronous.
+ // If the bundle listener is synchronous, then deliver the
+ // event to bundles with a state of STARTING, STOPPING, or
+ // ACTIVE. If the listener is asynchronous, then deliver the
+ // event only to bundles that are STARTING or ACTIVE.
+ if (((SynchronousBundleListener.class.isAssignableFrom(l.getClass())) &&
+ ((bundle.getState() == Bundle.STARTING) ||
+ (bundle.getState() == Bundle.STOPPING) ||
+ (bundle.getState() == Bundle.ACTIVE)))
+ ||
+ ((bundle.getState() == Bundle.STARTING) ||
+ (bundle.getState() == Bundle.ACTIVE)))
+ {
+ if (System.getSecurityManager() != null)
+ {
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run()
+ {
+ ((BundleListener) l).bundleChanged((BundleEvent) event);
+ return null;
+ }
+ });
+ }
+ else
+ {
+ ((BundleListener) l).bundleChanged((BundleEvent) event);
+ }
+ }
+ }
+
+ private static void invokeServiceListenerCallback(
+ Bundle bundle, final EventListener l, Filter filter, Object acc, final EventObject event)
+ {
+ // Service events should be delivered to STARTING,
+ // STOPPING, and ACTIVE bundles.
+ if ((bundle.getState() != Bundle.STARTING) &&
+ (bundle.getState() != Bundle.STOPPING) &&
+ (bundle.getState() != Bundle.ACTIVE))
+ {
+ return;
+ }
+
+ // Check that the bundle has permission to get at least
+ // one of the service interfaces; the objectClass property
+ // of the service stores its service interfaces.
+ ServiceReference ref = ((ServiceEvent) event).getServiceReference();
+ String[] objectClass = (String[]) ref.getProperty(Constants.OBJECTCLASS);
+
+ // On the safe side, if there is no objectClass property
+ // then ignore event altogether.
+ if (objectClass != null)
+ {
+ boolean hasPermission = false;
+
+ Object sm = System.getSecurityManager();
+ if ((acc != null) && (sm != null))
+ {
+ for (int i = 0;
+ !hasPermission && (i < objectClass.length);
+ i++)
+ {
+ try
+ {
+ ServicePermission perm =
+ new ServicePermission(
+ objectClass[i], ServicePermission.GET);
+ ((SecurityManager) sm).checkPermission(perm, acc);
+ hasPermission = true;
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+ }
+ else
+ {
+ hasPermission = true;
+ }
+
+ if (hasPermission)
+ {
+ // Dispatch according to the filter.
+ if ((filter == null) || filter.match(((ServiceEvent) event).getServiceReference()))
+ {
+ if ((l instanceof AllServiceListener) ||
+ Util.isServiceAssignable(bundle, ((ServiceEvent) event).getServiceReference()))
+ {
+ if (System.getSecurityManager() != null)
+ {
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run()
+ {
+ ((ServiceListener) l).serviceChanged((ServiceEvent) event);
+ return null;
+ }
+ });
+ }
+ else
+ {
+ {
+ ((ServiceListener) l).serviceChanged((ServiceEvent) event);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * This is the dispatching thread's main loop.
+ **/
+ private static void run()
+ {
+ Request req = null;
+ while (true)
+ {
+ // Lock the request list so we can try to get a
+ // dispatch request from it.
+ synchronized (m_requestList)
+ {
+ // Wait while there are no requests to dispatch. If the
+ // dispatcher thread is supposed to stop, then let the
+ // dispatcher thread exit the loop and stop.
+ while ((m_requestList.size() == 0) && !m_stopping)
+ {
+ // Wait until some signals us for work.
+ try
+ {
+ m_requestList.wait();
+ }
+ catch (InterruptedException ex)
+ {
+ // Not much we can do here except for keep waiting.
+ }
+ }
+
+ // If there are no events to dispatch and shutdown
+ // has been called then exit, otherwise dispatch event.
+ if ((m_requestList.size() == 0) && (m_stopping))
+ {
+ return;
+ }
+
+ // Get the dispatch request.
+ req = (Request) m_requestList.remove(0);
+ }
+
+ // Deliver event outside of synchronized block
+ // so that we don't block other requests from being
+ // queued during event processing.
+ fireEventImmediately(req.m_logger, req.m_type, req.m_listeners, req.m_event);
+
+ // Put dispatch request in cache.
+ synchronized (m_requestPool)
+ {
+ req.m_logger = null;
+ req.m_type = -1;
+ req.m_listeners = null;
+ req.m_event = null;
+ m_requestPool.add(req);
+ }
+ }
+ }
+
+ private static class Request
+ {
+ public static final int FRAMEWORK_EVENT = 0;
+ public static final int BUNDLE_EVENT = 1;
+ public static final int SERVICE_EVENT = 2;
+
+ public Logger m_logger = null;
+ public int m_type = -1;
+ public Object[] m_listeners = null;
+ public EventObject m_event = null;
+ }
+}
Propchange: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/EventDispatcher.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/EventDispatcher.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/FelixConstants.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/FelixConstants.java?rev=690991&view=auto
==============================================================================
--- cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/FelixConstants.java (added)
+++ cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/FelixConstants.java Mon Sep 1 08:08:01 2008
@@ -0,0 +1,63 @@
+/*
+ * 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.framework.util;
+
+public interface FelixConstants extends org.osgi.framework.Constants
+{
+ public static final String SYSTEM_BUNDLE_SYMBOLICNAME = "org.apache.felix.framework";
+ // Framework constants and values.
+ public static final String FRAMEWORK_VERSION_VALUE = "1.3";
+ public static final String FRAMEWORK_VENDOR_VALUE = "Apache Software Foundation";
+
+ // Framework constants and values.
+ public static final String FELIX_VERSION_PROPERTY = "felix.version";
+
+ // Miscellaneous manifest constants.
+ public static final String DIRECTIVE_SEPARATOR = ":=";
+ public static final String ATTRIBUTE_SEPARATOR = "=";
+ public static final String CLASS_PATH_SEPARATOR = ",";
+ public static final String CLASS_PATH_DOT = ".";
+ public static final String PACKAGE_SEPARATOR = ";";
+ public static final String VERSION_SEGMENT_SEPARATOR = ".";
+ public static final int VERSION_SEGMENT_COUNT = 3;
+ public static final String BUNDLE_NATIVECODE_OPTIONAL = "*";
+
+ // Miscellaneous OSGi constants.
+ public static final String BUNDLE_URL_PROTOCOL = "bundle";
+
+ // Miscellaneous framework configuration property names.
+ public static final String LOG_LEVEL_PROP = "felix.log.level";
+ public static final String EMBEDDED_EXECUTION_PROP = "felix.embedded.execution";
+ public static final String STRICT_OSGI_PROP = "felix.strict.osgi";
+ public static final String FRAMEWORK_STARTLEVEL_PROP
+ = "felix.startlevel.framework";
+ public static final String BUNDLE_STARTLEVEL_PROP
+ = "felix.startlevel.bundle";
+ public static final String SERVICE_URLHANDLERS_PROP = "felix.service.urlhandlers";
+
+ // Start level-related constants.
+ public static final int FRAMEWORK_INACTIVE_STARTLEVEL = 0;
+ public static final int FRAMEWORK_DEFAULT_STARTLEVEL = 1;
+ public static final int SYSTEMBUNDLE_DEFAULT_STARTLEVEL = 0;
+ public static final int BUNDLE_DEFAULT_STARTLEVEL = 1;
+
+ // Miscellaneous properties values.
+ public static final String FAKE_URL_PROTOCOL_VALUE = "location:";
+ public static final String FELIX_EXTENSION_ACTIVATOR = "Felix-Activator";
+}
\ No newline at end of file
Propchange: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/FelixConstants.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/FelixConstants.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/IteratorToEnumeration.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/IteratorToEnumeration.java?rev=690991&view=auto
==============================================================================
--- cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/IteratorToEnumeration.java (added)
+++ cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/IteratorToEnumeration.java Mon Sep 1 08:08:01 2008
@@ -0,0 +1,46 @@
+/*
+ * 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.framework.util;
+
+import java.util.Enumeration;
+import java.util.Iterator;
+
+public class IteratorToEnumeration implements Enumeration
+{
+ private final Iterator m_iter;
+
+ public IteratorToEnumeration(Iterator iter)
+ {
+ m_iter = iter;
+ }
+
+ public boolean hasMoreElements()
+ {
+ if (m_iter == null)
+ return false;
+ return m_iter.hasNext();
+ }
+
+ public Object nextElement()
+ {
+ if (m_iter == null)
+ return null;
+ return m_iter.next();
+ }
+}
Propchange: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/IteratorToEnumeration.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/IteratorToEnumeration.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/JarFileX.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/JarFileX.java?rev=690991&view=auto
==============================================================================
--- cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/JarFileX.java (added)
+++ cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/JarFileX.java Mon Sep 1 08:08:01 2008
@@ -0,0 +1,88 @@
+/*
+ * 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.framework.util;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.zip.ZipEntry;
+
+/**
+ * The purpose of this class is to fix an apparent bug in the JVM in versions
+ * 1.4.2 and lower where directory entries in ZIP/JAR files are not correctly
+ * identified.
+**/
+public class JarFileX extends JarFile
+{
+ public JarFileX(File file) throws IOException
+ {
+ super(file);
+ }
+
+ public JarFileX(File file, boolean verify) throws IOException
+ {
+ super(file, verify);
+ }
+
+ public JarFileX(File file, boolean verify, int mode) throws IOException
+ {
+ super(file, verify, mode);
+ }
+
+ public JarFileX(String name) throws IOException
+ {
+ super(name);
+ }
+
+ public JarFileX(String name, boolean verify) throws IOException
+ {
+ super(name, verify);
+ }
+
+ public ZipEntry getEntry(String name)
+ {
+ ZipEntry entry = super.getEntry(name);
+ if ((entry != null) && (entry.getSize() == 0) && !entry.isDirectory())
+ {
+ ZipEntry dirEntry = super.getEntry(name + '/');
+ if (dirEntry != null)
+ {
+ entry = dirEntry;
+ }
+ }
+ return entry;
+ }
+
+ public JarEntry getJarEntry(String name)
+ {
+ JarEntry entry = super.getJarEntry(name);
+ if ((entry != null) && (entry.getSize() == 0) && !entry.isDirectory())
+ {
+ JarEntry dirEntry = super.getJarEntry(name + '/');
+ if (dirEntry != null)
+ {
+ entry = dirEntry;
+ }
+ }
+ return entry;
+ }
+
+
+}
Propchange: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/JarFileX.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/JarFileX.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/MapToDictionary.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/MapToDictionary.java?rev=690991&view=auto
==============================================================================
--- cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/MapToDictionary.java (added)
+++ cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/MapToDictionary.java Mon Sep 1 08:08:01 2008
@@ -0,0 +1,83 @@
+/*
+ * 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.framework.util;
+
+import java.util.*;
+
+
+/**
+ * This is a simple class that implements a <tt>Dictionary</tt>
+ * from a <tt>Map</tt>. The resulting dictionary is immutable.
+**/
+public class MapToDictionary extends Dictionary
+{
+ /**
+ * Map source.
+ **/
+ private Map m_map = null;
+
+ public MapToDictionary(Map map)
+ {
+ if (map == null)
+ {
+ throw new IllegalArgumentException("Source map cannot be null.");
+ }
+ m_map = map;
+ }
+
+ public Enumeration elements()
+ {
+ return new IteratorToEnumeration(m_map.values().iterator());
+ }
+
+ public Object get(Object key)
+ {
+ return m_map.get(key);
+ }
+
+ public boolean isEmpty()
+ {
+ return m_map.isEmpty();
+ }
+
+ public Enumeration keys()
+ {
+ return new IteratorToEnumeration(m_map.keySet().iterator());
+ }
+
+ public Object put(Object key, Object value)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public Object remove(Object key)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public int size()
+ {
+ return m_map.size();
+ }
+
+ public String toString()
+ {
+ return m_map.toString();
+ }
+}
\ No newline at end of file
Propchange: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/MapToDictionary.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/MapToDictionary.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/ObjectInputStreamX.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/ObjectInputStreamX.java?rev=690991&view=auto
==============================================================================
--- cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/ObjectInputStreamX.java (added)
+++ cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/ObjectInputStreamX.java Mon Sep 1 08:08:01 2008
@@ -0,0 +1,56 @@
+/*
+ * 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.framework.util;
+
+import java.io.*;
+
+import org.apache.felix.moduleloader.IModule;
+
+/**
+ * The ObjectInputStreamX class is a simple extension to the ObjectInputStream
+ * class. The purpose of ObjectInputStreamX is to allow objects to be deserialized
+ * when their classes are not in the CLASSPATH (e.g., in a JAR file).
+ */
+public class ObjectInputStreamX extends ObjectInputStream
+{
+ private IModule m_module = null;
+
+ /**
+ * Construct an ObjectInputStreamX for the specified InputStream and the specified
+ * ClassLoader.
+ * @param in the input stream to read.
+ * @param loader the class loader used to resolve classes.
+ */
+ public ObjectInputStreamX(InputStream in, IModule module)
+ throws IOException, StreamCorruptedException
+ {
+ super(in);
+ m_module = module;
+ }
+
+ /**
+ * By overloading this method, the ObjectInputStreamX can resolve a class
+ * from the class loader that was passed into it at construction time.
+ */
+ protected Class resolveClass(ObjectStreamClass v)
+ throws IOException, ClassNotFoundException
+ {
+ return m_module.getClass(v.getName());
+ }
+}
\ No newline at end of file
Propchange: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/ObjectInputStreamX.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/ObjectInputStreamX.java
------------------------------------------------------------------------------
svn:keywords = Rev Date