Author: thomas.diesler(a)jboss.com
Date: 2009-12-19 06:35:39 -0500 (Sat, 19 Dec 2009)
New Revision: 98017
Added:
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleValidator.java
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleValidatorR3.java
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleValidatorR4.java
Modified:
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiSystemState.java
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiBundleCapability.java
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiPackageCapability.java
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/metadata/OSGiMetaData.java
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/metadata/internal/AbstractOSGiMetaData.java
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/resolver/internal/ResolverBundleImpl.java
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BasicResolverImpl.java
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/util/CaseInsensitiveDictionary.java
Log:
Implement bundle header localization.
Differenciate R3/R4 bundle validation.
Fix CaseInsensitiveDictionary
Modified:
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java
===================================================================
---
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java 2009-12-19
04:03:09 UTC (rev 98016)
+++
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java 2009-12-19
11:35:39 UTC (rev 98017)
@@ -22,15 +22,23 @@
package org.jboss.osgi.framework.bundle;
import java.io.File;
+import java.io.IOException;
import java.io.InputStream;
+import java.net.URL;
import java.security.Permission;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Dictionary;
+import java.util.Enumeration;
import java.util.HashSet;
+import java.util.Hashtable;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
+import java.util.MissingResourceException;
+import java.util.PropertyResourceBundle;
+import java.util.ResourceBundle;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
@@ -41,6 +49,7 @@
import org.jboss.osgi.framework.plugins.BundleStoragePlugin;
import org.jboss.osgi.framework.plugins.FrameworkEventsPlugin;
import org.jboss.osgi.framework.plugins.LifecycleInterceptorServicePlugin;
+import org.jboss.osgi.framework.util.CaseInsensitiveDictionary;
import org.jboss.osgi.spi.NotImplementedException;
import org.jboss.osgi.spi.util.ConstantsHelper;
import org.jboss.virtual.VirtualFile;
@@ -50,6 +59,7 @@
import org.osgi.framework.BundleEvent;
import org.osgi.framework.BundleException;
import org.osgi.framework.BundleListener;
+import org.osgi.framework.Constants;
import org.osgi.framework.Filter;
import org.osgi.framework.FrameworkListener;
import org.osgi.framework.FrameworkUtil;
@@ -100,16 +110,16 @@
public String getSymbolicName()
{
- String symbolicName = getOSGiMetaData().getBundleSymbolicName();
+ String symbolicName = getMetaData().getBundleSymbolicName();
if (symbolicName == null)
symbolicName = "anonymous-bundle" + getBundleId();
-
+
return symbolicName;
}
public Version getVersion()
{
- String versionstr = getOSGiMetaData().getBundleVersion();
+ String versionstr = getMetaData().getBundleVersion();
try
{
return Version.parseVersion(versionstr);
@@ -200,11 +210,13 @@
*
* @return the osgiMetaData.
*/
- public abstract OSGiMetaData getOSGiMetaData();
+ public abstract OSGiMetaData getMetaData();
@SuppressWarnings("rawtypes")
public Dictionary getHeaders()
{
+ // If the specified locale is null then the locale returned
+ // by java.util.Locale.getDefault is used.
return getHeaders(null);
}
@@ -212,9 +224,98 @@
public Dictionary getHeaders(String locale)
{
checkAdminPermission(AdminPermission.METADATA);
- return getOSGiMetaData().getHeaders(locale);
+
+ // Get the raw (unlocalized) manifest headers
+ Dictionary<String, String> rawHeaders = getMetaData().getHeaders();
+
+ // If the specified locale is the empty string, this method will return the
+ // raw (unlocalized) manifest headers including any leading "%"
+ if ("".equals(locale))
+ return rawHeaders;
+
+ // If the specified locale is null then the locale
+ // returned by java.util.Locale.getDefault is used
+ if (locale == null)
+ locale = Locale.getDefault().toString();
+
+ // Get the localization base name
+ String baseName = rawHeaders.get(Constants.BUNDLE_LOCALIZATION);
+ if (baseName == null)
+ baseName = Constants.BUNDLE_LOCALIZATION_DEFAULT_BASENAME;
+
+ // The Framework searches for localization entries by appending suffixes to
+ // the localization base name according to a specified locale and finally
+ // appending the .properties suffix. If a translation is not found, the locale
+ // must be made more generic by first removing the variant, then the country
+ // and finally the language until an entry is found that contains a valid
+ // translation.
+ String entryPath = baseName + "_" + locale + ".properties";
+ URL entryURL = getEntryInternal(entryPath);
+ while (entryURL == null)
+ {
+ if (entryPath.equals(baseName + ".properties"))
+ break;
+
+ int lastIndex = locale.lastIndexOf('_');
+ if (lastIndex > 0)
+ {
+ locale = locale.substring(0, lastIndex);
+ entryPath = baseName + "_" + locale + ".properties";
+ }
+ else
+ {
+ entryPath = baseName + ".properties";
+ }
+
+ // The bundle's class loader is not used to search for localization entries.
Only
+ // the contents of the bundle and its attached fragments are searched.
+ entryURL = getEntryInternal(entryPath);
+ }
+
+ // Read the resource bundle
+ ResourceBundle resBundle = null;
+ if (entryURL != null)
+ {
+ try
+ {
+ resBundle = new PropertyResourceBundle(entryURL.openStream());
+ }
+ catch (IOException ex)
+ {
+ throw new IllegalStateException("Cannot read resouce bundle: " +
entryURL, ex);
+ }
+ }
+
+ Dictionary<String, String> locHeaders = new Hashtable<String,
String>();
+ Enumeration<String> e = rawHeaders.keys();
+ while (e.hasMoreElements())
+ {
+ String key = e.nextElement();
+ String value = rawHeaders.get(key);
+ if (value.startsWith("%"))
+ value = value.substring(1);
+
+ if (resBundle != null)
+ {
+ try
+ {
+ value = resBundle.getString(value);
+ }
+ catch (MissingResourceException ex)
+ {
+ // ignore
+ }
+ }
+
+ locHeaders.put(key, value);
+ }
+
+ return new CaseInsensitiveDictionary(locHeaders);
}
+ // Get the entry without checking permissions and bundle state.
+ abstract URL getEntryInternal(String path);
+
public String getProperty(String key)
{
checkValidBundleContext();
Modified:
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
===================================================================
---
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java 2009-12-19
04:03:09 UTC (rev 98016)
+++
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java 2009-12-19
11:35:39 UTC (rev 98017)
@@ -35,7 +35,6 @@
import java.util.Collection;
import java.util.Collections;
import java.util.Dictionary;
-import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
@@ -81,7 +80,7 @@
import org.jboss.osgi.deployment.deployer.DeploymentFactory;
import org.jboss.osgi.framework.deployers.OSGiBundleActivatorDeployer;
import org.jboss.osgi.framework.metadata.OSGiMetaData;
-import org.jboss.osgi.framework.metadata.PackageAttribute;
+import org.jboss.osgi.framework.metadata.ParameterizedAttribute;
import org.jboss.osgi.framework.metadata.internal.AbstractOSGiMetaData;
import org.jboss.osgi.framework.plugins.AutoInstallPlugin;
import org.jboss.osgi.framework.plugins.BundleStoragePlugin;
@@ -91,6 +90,7 @@
import org.jboss.osgi.framework.plugins.ResolverPlugin;
import org.jboss.osgi.framework.plugins.ServicePlugin;
import org.jboss.osgi.framework.util.NoFilter;
+import org.jboss.osgi.spi.NotImplementedException;
import org.jboss.osgi.spi.util.BundleInfo;
import org.jboss.virtual.VFS;
import org.jboss.virtual.VFSUtils;
@@ -804,7 +804,7 @@
{
// If the specified InputStream is null, the Framework must create the InputStream
from which to read the updated bundle by interpreting,
// in an implementation dependent manner, this bundle's Bundle-UpdateLocation
Manifest header, if present, or this bundle's original location.
- URL updateURL = bundleState.getOSGiMetaData().getBundleUpdateLocation();
+ URL updateURL = bundleState.getMetaData().getBundleUpdateLocation();
if (in == null)
{
try
@@ -1031,62 +1031,22 @@
*
* @param bundleState the bundle state
*/
- @SuppressWarnings("deprecation")
private void validateBundle(AbstractBundleState bundleState)
{
- OSGiMetaData metaData = bundleState.getOSGiMetaData();
+ OSGiMetaData metaData = bundleState.getMetaData();
if (metaData == null)
return;
- int manifestVersion = metaData.getBundleManifestVersion();
- if (manifestVersion > 2)
- throw new IllegalStateException("Unsupported manifest version " +
manifestVersion + " for " + bundleState);
+ ParameterizedAttribute fragmentHost = metaData.getFragmentHost();
+ if (fragmentHost != null)
+ throw new NotImplementedException("Fragments not implemented: " +
fragmentHost);
+
+ // Delegate to the validator for the appropriate revision
+ OSGiBundleValidator validator = new OSGiBundleValidatorR3(this);
+ if(metaData.getBundleManifestVersion() > 1)
+ validator = new OSGiBundleValidatorR4(this);
- String symbolicName = bundleState.getSymbolicName();
- for (AbstractBundleState bundle : getBundles())
- {
- OSGiMetaData other = bundle.getOSGiMetaData();
- if (symbolicName.equals(other.getBundleSymbolicName()))
- {
- if (other.isSingleton() && metaData.isSingleton())
- throw new IllegalStateException("Cannot install singleton " +
bundleState + " another singleton is already installed: " +
bundle.getLocation());
- if (other.getBundleVersion().equals(metaData.getBundleVersion()))
- throw new IllegalStateException("Cannot install " + bundleState
+ " a bundle with that name and version is already installed: "
- + bundle.getLocation());
- }
- }
-
- List<PackageAttribute> importPackages = metaData.getImportPackages();
- if (importPackages != null && importPackages.isEmpty() == false)
- {
- Set<String> packages = new HashSet<String>();
- for (PackageAttribute packageAttribute : importPackages)
- {
- String packageName = packageAttribute.getAttribute();
- if (packages.contains(packageName))
- throw new IllegalStateException("Duplicate import of package " +
packageName + " for " + bundleState);
- packages.add(packageName);
-
- if (packageName.startsWith("java."))
- throw new IllegalStateException("Not allowed to import java.* for
" + bundleState);
-
- String version =
packageAttribute.getAttributeValue(Constants.VERSION_ATTRIBUTE, String.class);
- String specificationVersion =
packageAttribute.getAttributeValue(Constants.PACKAGE_SPECIFICATION_VERSION,
String.class);
- if (version != null && specificationVersion != null &&
version.equals(specificationVersion) == false)
- throw new IllegalStateException(packageName + " version and
specification version should be the same for " + bundleState);
- }
- }
-
- List<PackageAttribute> exportPackages = metaData.getExportPackages();
- if (exportPackages != null && exportPackages.isEmpty() == false)
- {
- for (PackageAttribute packageAttribute : exportPackages)
- {
- String packageName = packageAttribute.getAttribute();
- if (packageName.startsWith("java."))
- throw new IllegalStateException("Not allowed to export java.* for
" + bundleState);
- }
- }
+ validator.validateBundle(bundleState);
}
/**
Modified:
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java
===================================================================
---
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java 2009-12-19
04:03:09 UTC (rev 98016)
+++
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java 2009-12-19
11:35:39 UTC (rev 98017)
@@ -87,7 +87,7 @@
}
@Override
- public OSGiMetaData getOSGiMetaData()
+ public OSGiMetaData getMetaData()
{
DeploymentUnit unit = getDeploymentUnit();
OSGiMetaData metadata = unit.getAttachment(OSGiMetaData.class);
@@ -151,6 +151,13 @@
if (noAdminPermission(AdminPermission.RESOURCE))
return null;
+ return getEntryInternal(path);
+ }
+
+ // Get the entry without checking permissions and bundle state.
+ @Override
+ URL getEntryInternal(String path)
+ {
DeploymentUnit unit = getDeploymentUnit();
if (unit instanceof VFSDeploymentUnit)
{
@@ -158,6 +165,7 @@
if (path.startsWith("/"))
path = path.substring(1);
+
return vfsDeploymentUnit.getResourceLoader().getResource(path);
}
return null;
@@ -313,7 +321,7 @@
// The BundleActivator.start(org.osgi.framework.BundleContext) method of this
bundle's BundleActivator, if one is specified, is called.
try
{
- OSGiMetaData metaData = getOSGiMetaData();
+ OSGiMetaData metaData = getMetaData();
if (metaData == null)
throw new IllegalStateException("Cannot obtain OSGi meta data");
Added:
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleValidator.java
===================================================================
---
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleValidator.java
(rev 0)
+++
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleValidator.java 2009-12-19
11:35:39 UTC (rev 98017)
@@ -0,0 +1,37 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+package org.jboss.osgi.framework.bundle;
+
+
+/**
+ * A bundle validator.
+ *
+ * @author Thomas.Diesler(a)jboss.com
+ * @since 19-Dec-2009
+ */
+public interface OSGiBundleValidator
+{
+ /**
+ * Validate the bundle
+ */
+ void validateBundle(AbstractBundleState bundleState);
+}
Added:
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleValidatorR3.java
===================================================================
---
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleValidatorR3.java
(rev 0)
+++
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleValidatorR3.java 2009-12-19
11:35:39 UTC (rev 98017)
@@ -0,0 +1,45 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+package org.jboss.osgi.framework.bundle;
+
+import org.jboss.osgi.framework.metadata.OSGiMetaData;
+
+/**
+ * A bundle validator for OSGi R3.
+ *
+ * @author Thomas.Diesler(a)jboss.com
+ * @since 19-Dec-2009
+ */
+public class OSGiBundleValidatorR3 implements OSGiBundleValidator
+{
+ public OSGiBundleValidatorR3(OSGiBundleManager bundleManager)
+ {
+ }
+
+ public void validateBundle(AbstractBundleState bundleState)
+ {
+ OSGiMetaData metaData = bundleState.getMetaData();
+ int manifestVersion = metaData.getBundleManifestVersion();
+ if (manifestVersion != 1)
+ throw new IllegalStateException("Unsupported manifest version " +
manifestVersion + " for " + bundleState);
+ }
+}
Added:
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleValidatorR4.java
===================================================================
---
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleValidatorR4.java
(rev 0)
+++
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleValidatorR4.java 2009-12-19
11:35:39 UTC (rev 98017)
@@ -0,0 +1,130 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+package org.jboss.osgi.framework.bundle;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.jboss.osgi.framework.metadata.OSGiMetaData;
+import org.jboss.osgi.framework.metadata.PackageAttribute;
+import org.osgi.framework.Constants;
+
+/**
+ * OSGiBundleManager.
+ *
+ * @author Thomas.Diesler(a)jboss.com
+ * @version $Revision: 1.1 $
+ */
+public class OSGiBundleValidatorR4 implements OSGiBundleValidator
+{
+ private OSGiBundleManager bundleManager;
+
+ public OSGiBundleValidatorR4(OSGiBundleManager bundleManager)
+ {
+ this.bundleManager = bundleManager;
+ }
+
+
+ /**
+ * Validate the bundle
+ *
+ * @param bundleState the bundle state
+ */
+ @SuppressWarnings("deprecation")
+ public void validateBundle(AbstractBundleState bundleState)
+ {
+ OSGiMetaData metaData = bundleState.getMetaData();
+
+ // Missing Bundle-SymbolicName
+ String symbolicName = bundleState.getSymbolicName();
+ if (symbolicName == null)
+ throw new IllegalStateException("Missing Bundle-SymbolicName in: " +
bundleState);
+
+ // Bundle-ManifestVersion value not equal to 2, unless the Framework specifically
recognizes the semantics of a later release.
+ int manifestVersion = metaData.getBundleManifestVersion();
+ if (manifestVersion > 2)
+ throw new IllegalStateException("Unsupported manifest version " +
manifestVersion + " for " + bundleState);
+
+ // [TODO] Duplicate attribute or duplicate directive (except in the Bundle-Native
code clause).
+
+ // Multiple imports of a given package.
+ List<PackageAttribute> importPackages = metaData.getImportPackages();
+ if (importPackages != null && importPackages.isEmpty() == false)
+ {
+ Set<String> packages = new HashSet<String>();
+ for (PackageAttribute packageAttribute : importPackages)
+ {
+ String packageName = packageAttribute.getAttribute();
+ if (packages.contains(packageName))
+ throw new IllegalStateException("Duplicate import of package " +
packageName + " for " + bundleState);
+ packages.add(packageName);
+
+ if (packageName.startsWith("java."))
+ throw new IllegalStateException("Not allowed to import java.* for
" + bundleState);
+
+ String version =
packageAttribute.getAttributeValue(Constants.VERSION_ATTRIBUTE, String.class);
+ String specificationVersion =
packageAttribute.getAttributeValue(Constants.PACKAGE_SPECIFICATION_VERSION,
String.class);
+ if (version != null && specificationVersion != null &&
version.equals(specificationVersion) == false)
+ throw new IllegalStateException(packageName + " version and
specification version should be the same for " + bundleState);
+ }
+ }
+
+ // Export or import of java.*.
+ List<PackageAttribute> exportPackages = metaData.getExportPackages();
+ if (exportPackages != null && exportPackages.isEmpty() == false)
+ {
+ for (PackageAttribute packageAttribute : exportPackages)
+ {
+ String packageName = packageAttribute.getAttribute();
+ if (packageName.startsWith("java."))
+ throw new IllegalStateException("Not allowed to export java.* for
" + bundleState);
+ }
+ }
+
+ // [TODO] Export-Package with a mandatory attribute that is not defined.
+
+ // Installing a bundle that has the same symbolic name and version as an already
installed bundle.
+ for (AbstractBundleState bundle : bundleManager.getBundles())
+ {
+ OSGiMetaData other = bundle.getMetaData();
+ if (symbolicName.equals(other.getBundleSymbolicName()))
+ {
+ if (other.isSingleton() && metaData.isSingleton())
+ throw new IllegalStateException("Cannot install singleton " +
bundleState + " another singleton is already installed: " +
bundle.getLocation());
+ if (other.getBundleVersion().equals(metaData.getBundleVersion()))
+ throw new IllegalStateException("Cannot install " + bundleState
+ " a bundle with that name and version is already installed: "
+ + bundle.getLocation());
+ }
+ }
+
+ // [TODO] Updating a bundle to a bundle that has the same symbolic name and version
as another installed bundle.
+
+ // [TODO] Any syntactic error (for example, improperly formatted version or bundle
symbolic name, unrecognized directive value, etc.).
+
+ // [TODO] Specification-version and version specified together (for the same
package(s)) but with different values.
+
+ // [TODO] The manifest lists a OSGI-INF/permission.perm file but no such file is
present.
+
+ // [TODO] Requiring the same bundle symbolic name more than once
+ }
+}
Modified:
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java
===================================================================
---
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java 2009-12-19
04:03:09 UTC (rev 98016)
+++
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java 2009-12-19
11:35:39 UTC (rev 98017)
@@ -516,7 +516,7 @@
return result.toArray(new String[result.size()]);
}
- @SuppressWarnings({ "unchecked", "rawtypes" })
+ @SuppressWarnings("rawtypes")
public void setProperties(Dictionary properties)
{
checkUnregistered();
@@ -673,7 +673,7 @@
if (used.add(using)) // add so we don't do duplicate work
{
int count = ct.getUsedByCount(this, using);
- while(count > 0)
+ while (count > 0)
{
using.ungetContext(this); // ungetService will cleanup service
cache
count--;
Modified:
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiSystemState.java
===================================================================
---
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiSystemState.java 2009-12-19
04:03:09 UTC (rev 98016)
+++
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiSystemState.java 2009-12-19
11:35:39 UTC (rev 98017)
@@ -66,7 +66,7 @@
}
@Override
- public OSGiMetaData getOSGiMetaData()
+ public OSGiMetaData getMetaData()
{
return osgiMetaData;
}
@@ -134,6 +134,13 @@
public URL getEntry(String path)
{
+ return getEntryInternal(path);
+ }
+
+ // Get the entry without checking permissions and bundle state.
+ @Override
+ URL getEntryInternal(String path)
+ {
log.warn("[JBOSGI-138] getEntry(" + path + ")");
return null;
}
Modified:
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiBundleCapability.java
===================================================================
---
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiBundleCapability.java 2009-12-19
04:03:09 UTC (rev 98016)
+++
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiBundleCapability.java 2009-12-19
11:35:39 UTC (rev 98017)
@@ -90,7 +90,7 @@
*/
public OSGiMetaData getMetaData()
{
- return bundleState.getOSGiMetaData();
+ return bundleState.getMetaData();
}
@Override
Modified:
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiPackageCapability.java
===================================================================
---
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiPackageCapability.java 2009-12-19
04:03:09 UTC (rev 98016)
+++
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiPackageCapability.java 2009-12-19
11:35:39 UTC (rev 98017)
@@ -191,7 +191,7 @@
if (reqVersionRange.isInRange(capVersion) == false)
return false;
- OSGiMetaData metaData = bundleState.getOSGiMetaData();
+ OSGiMetaData metaData = bundleState.getMetaData();
PackageAttribute capParameters = exportPackage;
PackageAttribute reqParameters = packageRequirement.getPackageMetaData();
Modified:
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/metadata/OSGiMetaData.java
===================================================================
---
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/metadata/OSGiMetaData.java 2009-12-19
04:03:09 UTC (rev 98016)
+++
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/metadata/OSGiMetaData.java 2009-12-19
11:35:39 UTC (rev 98017)
@@ -31,16 +31,16 @@
* OSGi specific manifest meta data.
*
* @author <a href="mailto:ales.justin@jboss.com">Ales Justin</a>
+ * @author Thomas.Diesler(a)jboss.com
*/
public interface OSGiMetaData extends ManifestMetaData
{
/**
- * Get the headers
+ * Get the headers in raw unlocalized format.
*
- * @param locale the locale to use
* @return the headers
*/
- Dictionary<String, String> getHeaders(String locale);
+ Dictionary<String, String> getHeaders();
/**
* Extension point to read custom manifest headers.
Modified:
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/metadata/internal/AbstractOSGiMetaData.java
===================================================================
---
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/metadata/internal/AbstractOSGiMetaData.java 2009-12-19
04:03:09 UTC (rev 98016)
+++
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/metadata/internal/AbstractOSGiMetaData.java 2009-12-19
11:35:39 UTC (rev 98017)
@@ -30,6 +30,7 @@
import static
org.jboss.osgi.framework.metadata.internal.ValueCreatorUtil.STRING_LIST_VC;
import static org.jboss.osgi.framework.metadata.internal.ValueCreatorUtil.STRING_VC;
import static org.jboss.osgi.framework.metadata.internal.ValueCreatorUtil.URL_VC;
+import static org.osgi.framework.Constants.BUNDLE_ACTIVATIONPOLICY;
import static org.osgi.framework.Constants.BUNDLE_ACTIVATOR;
import static org.osgi.framework.Constants.BUNDLE_CATEGORY;
import static org.osgi.framework.Constants.BUNDLE_CLASSPATH;
@@ -69,6 +70,7 @@
import
org.jboss.osgi.framework.metadata.internal.AbstractVersionRange.OSGiVersionToOSGiVersionComparator;
import
org.jboss.osgi.framework.metadata.internal.AbstractVersionRange.OSGiVersionToStringComparator;
import
org.jboss.osgi.framework.metadata.internal.AbstractVersionRange.OSGiVersionToVersionComparator;
+import org.jboss.osgi.framework.util.CaseInsensitiveDictionary;
import org.osgi.framework.Constants;
import org.osgi.framework.Version;
@@ -92,7 +94,7 @@
protected transient Map<String, Object> cachedAttributes = new
ConcurrentHashMap<String, Object>();
protected transient ParameterizedAttribute parameters;
-
+
public AbstractOSGiMetaData()
{
}
@@ -103,14 +105,14 @@
}
@SuppressWarnings({ "unchecked", "rawtypes" })
- public Dictionary<String, String> getHeaders(String locale)
+ public Dictionary<String, String> getHeaders()
{
- // TODO localisation
- Map<Name, String> attributes = (Map) getManifest().getMainAttributes();
- Hashtable<String, String> result = new Hashtable<String, String>();
+ Map<Name, String> attributes = (Map)getManifest().getMainAttributes();
+ Dictionary<String, String> result = new Hashtable<String, String>();
for (Entry<Name, String> entry : attributes.entrySet())
result.put(entry.getKey().toString(), entry.getValue());
- return result;
+
+ return new CaseInsensitiveDictionary(result);
}
public String getHeader(String key)
@@ -120,7 +122,7 @@
public ActivationPolicyMetaData getBundleActivationPolicy()
{
- return get("Bundle-ActivationPolicy", ACTIVATION_POLICY_VC);
+ return get(BUNDLE_ACTIVATIONPOLICY, ACTIVATION_POLICY_VC);
}
public String getBundleActivator()
@@ -150,7 +152,7 @@
public int getBundleManifestVersion()
{
- return get(BUNDLE_MANIFESTVERSION, INTEGER_VC, 2);
+ return get(BUNDLE_MANIFESTVERSION, INTEGER_VC, 1);
}
public String getBundleName()
@@ -171,11 +173,11 @@
public String getBundleSymbolicName()
{
String symbolicName = null;
-
+
ParameterizedAttribute parameters = parseSymbolicName();
if (parameters != null)
symbolicName = parameters.getAttribute();
-
+
return symbolicName;
}
@@ -183,7 +185,7 @@
{
return parseSymbolicName();
}
-
+
public URL getBundleUpdateLocation()
{
return get(BUNDLE_UPDATELOCATION, URL_VC);
@@ -191,7 +193,7 @@
public String getBundleVersion()
{
- return get(BUNDLE_VERSION, STRING_VC , "0.0.0");
+ return get(BUNDLE_VERSION, STRING_VC, "0.0.0");
}
public List<PackageAttribute> getDynamicImports()
Modified:
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/resolver/internal/ResolverBundleImpl.java
===================================================================
---
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/resolver/internal/ResolverBundleImpl.java 2009-12-19
04:03:09 UTC (rev 98016)
+++
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/resolver/internal/ResolverBundleImpl.java 2009-12-19
11:35:39 UTC (rev 98017)
@@ -43,7 +43,7 @@
{
super(bundle);
- this.metaData = OSGiBundleState.assertBundleState(bundle).getOSGiMetaData();
+ this.metaData = OSGiBundleState.assertBundleState(bundle).getMetaData();
// Initialize exported packages
List<PackageAttribute> exportPackages = metaData.getExportPackages();
Modified:
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BasicResolverImpl.java
===================================================================
---
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BasicResolverImpl.java 2009-12-19
04:03:09 UTC (rev 98016)
+++
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BasicResolverImpl.java 2009-12-19
11:35:39 UTC (rev 98017)
@@ -405,7 +405,7 @@
// The Require-Bundle header specifies that all exported packages from
// another bundle must be imported, effectively requiring the public interface
// of another bundle
- OSGiMetaData osgiMetaData = bundle.getOSGiMetaData();
+ OSGiMetaData osgiMetaData = bundle.getMetaData();
List<ParameterizedAttribute> requireBundles =
osgiMetaData.getRequireBundles();
if (requireBundles != null)
{
Modified:
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/util/CaseInsensitiveDictionary.java
===================================================================
---
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/util/CaseInsensitiveDictionary.java 2009-12-19
04:03:09 UTC (rev 98016)
+++
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/util/CaseInsensitiveDictionary.java 2009-12-19
11:35:39 UTC (rev 98017)
@@ -36,8 +36,11 @@
* @author <a href="adrian(a)jboss.com">Adrian Brock</a>
* @version $Revision: 1.1 $
*/
-public class CaseInsensitiveDictionary extends Dictionary<String, Object>
+@SuppressWarnings("rawtypes")
+public class CaseInsensitiveDictionary extends Hashtable
{
+ private static final long serialVersionUID = 5802491129524016545L;
+
/** The delegate dictionary */
private Dictionary<String, Object> delegate;
@@ -49,11 +52,12 @@
*
* @param delegate the delegate
*/
- public CaseInsensitiveDictionary(Dictionary<String, Object> delegate)
+ @SuppressWarnings("unchecked")
+ public CaseInsensitiveDictionary(Dictionary delegate)
{
if (delegate == null)
throw new IllegalArgumentException("Null delegaqte");
-
+
this.delegate = new Hashtable<String, Object>(delegate.size());
this.originalKeys = Collections.synchronizedSet(new HashSet<String>());
Enumeration<String> e = delegate.keys();
@@ -62,32 +66,32 @@
String key = e.nextElement();
if (get(key) != null)
throw new IllegalArgumentException("Properties contain duplicates with
varying case for key=" + key + " : " + delegate);
-
+
this.delegate.put(key.toLowerCase(), delegate.get(key));
originalKeys.add(key);
}
}
-
+
public Enumeration<Object> elements()
{
return delegate.elements();
}
- @SuppressWarnings({ "unchecked", "rawtypes" })
+ @SuppressWarnings("unchecked")
public synchronized boolean equals(Object obj)
{
if (obj == this)
return true;
if (obj == null || obj instanceof Dictionary == false)
return false;
-
- Dictionary<String, Object> other = (Dictionary) obj;
-
+
+ Dictionary<String, Object> other = (Dictionary)obj;
+
if (size() != other.size())
return false;
if (isEmpty())
return true;
-
+
for (String key : originalKeys)
{
if (get(key).equals(other.get(key)))
@@ -99,7 +103,7 @@
public Object get(Object key)
{
if (key instanceof String)
- key = ((String) key).toLowerCase();
+ key = ((String)key).toLowerCase();
return delegate.get(key);
}
@@ -119,7 +123,7 @@
return Iterators.toEnumeration(originalKeys.iterator());
}
- public Object put(String key, Object value)
+ public Object put(Object key, Object value)
{
throw new UnsupportedOperationException("immutable");
}