[jboss-cvs] JBossAS SVN: r70062 - in projects/microcontainer/trunk/osgi-int: src/main/org/jboss/osgi/plugins/facade and 6 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Feb 25 09:08:50 EST 2008
Author: johnbailey
Date: 2008-02-25 09:08:49 -0500 (Mon, 25 Feb 2008)
New Revision: 70062
Added:
projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/BundleHeaders.java
projects/microcontainer/trunk/osgi-int/src/resources/tests/OSGI-INF/
projects/microcontainer/trunk/osgi-int/src/resources/tests/OSGI-INF/l10n/
projects/microcontainer/trunk/osgi-int/src/resources/tests/OSGI-INF/l10n/bundle.properties
projects/microcontainer/trunk/osgi-int/src/resources/tests/OSGI-INF/l10n/bundle_en_US.properties
projects/microcontainer/trunk/osgi-int/src/resources/tests/org/jboss/test/bundle/metadata/LocalizedManifest.mf
projects/microcontainer/trunk/osgi-int/src/tests/org/jboss/test/bundle/BundleHeaderTestCase.java
projects/microcontainer/trunk/osgi-int/src/tests/org/jboss/test/bundle/BundleImplTestCase.java
Modified:
projects/microcontainer/trunk/osgi-int/.classpath
projects/microcontainer/trunk/osgi-int/pom.xml
projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/BundleImpl.java
projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/ValueCreatorUtil.java
projects/microcontainer/trunk/osgi-int/src/tests/org/jboss/test/bundle/BundleTestSuite.java
Log:
Modified: projects/microcontainer/trunk/osgi-int/.classpath
===================================================================
--- projects/microcontainer/trunk/osgi-int/.classpath 2008-02-25 13:31:43 UTC (rev 70061)
+++ projects/microcontainer/trunk/osgi-int/.classpath 2008-02-25 14:08:49 UTC (rev 70062)
@@ -1,45 +1,47 @@
-<classpath>
- <classpathentry kind="src" path="src/main"/>
- <classpathentry kind="src" path="src/resources/tests" output="target/tests-classes" excluding="**/*.java"/>
- <classpathentry kind="src" path="src/tests" output="target/tests-classes"/>
- <classpathentry kind="src" path="target/generated-sources/javacc"/>
- <classpathentry kind="output" path="target/classes"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
- <classpathentry kind="var" path="M2_REPO/apache-xerces/xml-apis/2.7.1/xml-apis-2.7.1.jar"/>
- <classpathentry kind="var" path="M2_REPO/jboss/jboss-logging-spi/2.0.3.GA/jboss-logging-spi-2.0.3.GA.jar" sourcepath="M2_REPO/jboss/jboss-logging-spi/2.0.3.GA/jboss-logging-spi-2.0.3.GA-sources.jar"/>
- <classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar" sourcepath="M2_REPO/junit/junit/3.8.1/junit-3.8.1-sources.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/jboss/jboss-common-core/2.2.3.GA/jboss-common-core-2.2.3.GA.jar"/>
- <classpathentry kind="var" path="M2_REPO/apache-httpclient/commons-httpclient/2.0.2/commons-httpclient-2.0.2.jar"/>
- <classpathentry kind="var" path="M2_REPO/apache-slide/webdavlib/2.0/webdavlib-2.0.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/jboss/jboss-test/1.0.4.GA/jboss-test-1.0.4.GA.jar" sourcepath="M2_REPO/org/jboss/jboss-test/1.0.4.GA/jboss-test-1.0.4.GA-sources.jar"/>
- <classpathentry kind="var" path="M2_REPO/ant/ant/1.6.5/ant-1.6.5.jar" sourcepath="M2_REPO/ant/ant/1.6.5/ant-1.6.5-sources.jar"/>
- <classpathentry kind="var" path="M2_REPO/ant/ant-junit/1.6.5/ant-junit-1.6.5.jar"/>
- <classpathentry kind="var" path="M2_REPO/jboss/jboss-common-logging-log4j/2.0.4.GA/jboss-common-logging-log4j-2.0.4.GA.jar" sourcepath="M2_REPO/jboss/jboss-common-logging-log4j/2.0.4.GA/jboss-common-logging-log4j-2.0.4.GA-sources.jar"/>
- <classpathentry kind="var" path="M2_REPO/log4j/log4j/1.2.14/log4j-1.2.14.jar" sourcepath="M2_REPO/log4j/log4j/1.2.14/log4j-1.2.14-sources.jar"/>
- <classpathentry kind="var" path="M2_REPO/jboss/profiler/jvmti/jboss-profiler-jvmti/1.0.0.CR5/jboss-profiler-jvmti-1.0.0.CR5.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/jboss/jboss-vfs/2.0.0.Beta7/jboss-vfs-2.0.0.Beta7.jar"/>
- <classpathentry kind="var" path="M2_REPO/jboss/jboss-common-logging-spi/2.0.4.GA/jboss-common-logging-spi-2.0.4.GA.jar" sourcepath="M2_REPO/jboss/jboss-common-logging-spi/2.0.4.GA/jboss-common-logging-spi-2.0.4.GA-sources.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/jboss/jbossxb/2.0.0.CR5/jbossxb-2.0.0.CR5.jar"/>
- <classpathentry kind="src" path="/jboss-container"/>
- <classpathentry kind="var" path="M2_REPO/org/jboss/javassist/3.6.0.GA/javassist-3.6.0.GA.jar" sourcepath="M2_REPO/org/jboss/javassist/3.6.0.GA/javassist-3.6.0.GA-sources.jar"/>
- <classpathentry kind="var" path="M2_REPO/apache-xerces/xercesImpl/2.7.1/xercesImpl-2.7.1.jar"/>
- <classpathentry kind="var" path="M2_REPO/javax/xml/bind/jaxb-api/2.0/jaxb-api-2.0.jar"/>
- <classpathentry kind="var" path="M2_REPO/javax/xml/bind/jsr173_api/1.0/jsr173_api-1.0.jar"/>
- <classpathentry kind="var" path="M2_REPO/javax/activation/activation/1.0.2/activation-1.0.2.jar"/>
- <classpathentry kind="var" path="M2_REPO/wutka-dtdparser/dtdparser121/1.2.1/dtdparser121-1.2.1.jar"/>
- <classpathentry kind="var" path="M2_REPO/sun-jaxb/jaxb-api/2.0.5/jaxb-api-2.0.5.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/jboss/aop/jboss-aop/2.0.0.CR3/jboss-aop-2.0.0.CR3.jar"/>
- <classpathentry kind="var" path="M2_REPO/qdox/qdox/1.6/qdox-1.6.jar" sourcepath="M2_REPO/qdox/qdox/1.6/qdox-1.6-sources.jar"/>
- <classpathentry kind="var" path="M2_REPO/trove/trove/2.1.1/trove-2.1.1.jar"/>
- <classpathentry kind="src" path="/jboss-dependency"/>
- <classpathentry kind="src" path="/jboss-deployers-core-spi"/>
- <classpathentry kind="src" path="/jboss-deployers-spi"/>
- <classpathentry kind="src" path="/jboss-deployers-structure-spi"/>
- <classpathentry kind="src" path="/jboss-deployers-client-spi"/>
- <classpathentry kind="src" path="/jboss-managed"/>
- <classpathentry kind="src" path="/jboss-metatype"/>
- <classpathentry kind="src" path="/jboss-deployers-core"/>
- <classpathentry kind="src" path="/jboss-deployers-vfs-spi"/>
- <classpathentry kind="src" path="/jboss-kernel"/>
- <classpathentry kind="var" path="M2_REPO/org/osgi/osgi_R4_core/1.0/osgi_R4_core-1.0.jar"/>
-</classpath>
\ No newline at end of file
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src/main"/>
+ <classpathentry excluding="**/*.java" kind="src" output="target/tests-classes" path="src/resources/tests"/>
+ <classpathentry kind="src" output="target/tests-classes" path="src/tests"/>
+ <classpathentry kind="src" path="target/generated-sources/javacc"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="var" path="M2_REPO/apache-xerces/xml-apis/2.7.1/xml-apis-2.7.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/jboss/jboss-logging-spi/2.0.3.GA/jboss-logging-spi-2.0.3.GA.jar" sourcepath="M2_REPO/jboss/jboss-logging-spi/2.0.3.GA/jboss-logging-spi-2.0.3.GA-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar" sourcepath="M2_REPO/junit/junit/3.8.1/junit-3.8.1-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/jboss/jboss-common-core/2.2.3.GA/jboss-common-core-2.2.3.GA.jar"/>
+ <classpathentry kind="var" path="M2_REPO/apache-httpclient/commons-httpclient/2.0.2/commons-httpclient-2.0.2.jar"/>
+ <classpathentry kind="var" path="M2_REPO/apache-slide/webdavlib/2.0/webdavlib-2.0.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/jboss/jboss-test/1.0.4.GA/jboss-test-1.0.4.GA.jar" sourcepath="M2_REPO/org/jboss/jboss-test/1.0.4.GA/jboss-test-1.0.4.GA-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/ant/ant/1.6.5/ant-1.6.5.jar" sourcepath="M2_REPO/ant/ant/1.6.5/ant-1.6.5-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/ant/ant-junit/1.6.5/ant-junit-1.6.5.jar"/>
+ <classpathentry kind="var" path="M2_REPO/jboss/jboss-common-logging-log4j/2.0.4.GA/jboss-common-logging-log4j-2.0.4.GA.jar" sourcepath="M2_REPO/jboss/jboss-common-logging-log4j/2.0.4.GA/jboss-common-logging-log4j-2.0.4.GA-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/log4j/log4j/1.2.14/log4j-1.2.14.jar" sourcepath="M2_REPO/log4j/log4j/1.2.14/log4j-1.2.14-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/jboss/profiler/jvmti/jboss-profiler-jvmti/1.0.0.CR5/jboss-profiler-jvmti-1.0.0.CR5.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/jboss/jboss-vfs/2.0.0.Beta7/jboss-vfs-2.0.0.Beta7.jar"/>
+ <classpathentry kind="var" path="M2_REPO/jboss/jboss-common-logging-spi/2.0.4.GA/jboss-common-logging-spi-2.0.4.GA.jar" sourcepath="M2_REPO/jboss/jboss-common-logging-spi/2.0.4.GA/jboss-common-logging-spi-2.0.4.GA-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/jboss/jbossxb/2.0.0.CR5/jbossxb-2.0.0.CR5.jar"/>
+ <classpathentry kind="src" path="/jboss-container"/>
+ <classpathentry kind="var" path="M2_REPO/org/jboss/javassist/3.6.0.GA/javassist-3.6.0.GA.jar" sourcepath="M2_REPO/org/jboss/javassist/3.6.0.GA/javassist-3.6.0.GA-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/apache-xerces/xercesImpl/2.7.1/xercesImpl-2.7.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/javax/xml/bind/jaxb-api/2.0/jaxb-api-2.0.jar"/>
+ <classpathentry kind="var" path="M2_REPO/javax/xml/bind/jsr173_api/1.0/jsr173_api-1.0.jar"/>
+ <classpathentry kind="var" path="M2_REPO/javax/activation/activation/1.0.2/activation-1.0.2.jar"/>
+ <classpathentry kind="var" path="M2_REPO/wutka-dtdparser/dtdparser121/1.2.1/dtdparser121-1.2.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/sun-jaxb/jaxb-api/2.0.5/jaxb-api-2.0.5.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/jboss/aop/jboss-aop/2.0.0.CR3/jboss-aop-2.0.0.CR3.jar"/>
+ <classpathentry kind="var" path="M2_REPO/qdox/qdox/1.6/qdox-1.6.jar" sourcepath="M2_REPO/qdox/qdox/1.6/qdox-1.6-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/trove/trove/2.1.1/trove-2.1.1.jar"/>
+ <classpathentry kind="src" path="/jboss-dependency"/>
+ <classpathentry kind="src" path="/jboss-deployers-core-spi"/>
+ <classpathentry kind="src" path="/jboss-deployers-spi"/>
+ <classpathentry kind="src" path="/jboss-deployers-structure-spi"/>
+ <classpathentry kind="src" path="/jboss-deployers-client-spi"/>
+ <classpathentry kind="src" path="/jboss-managed"/>
+ <classpathentry kind="src" path="/jboss-metatype"/>
+ <classpathentry kind="src" path="/jboss-deployers-core"/>
+ <classpathentry kind="src" path="/jboss-deployers-vfs-spi"/>
+ <classpathentry kind="src" path="/jboss-kernel"/>
+ <classpathentry kind="var" path="M2_REPO/org/osgi/osgi_R4_core/1.0/osgi_R4_core-1.0.jar"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/jboss-deployers-impl"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
Modified: projects/microcontainer/trunk/osgi-int/pom.xml
===================================================================
--- projects/microcontainer/trunk/osgi-int/pom.xml 2008-02-25 13:31:43 UTC (rev 70061)
+++ projects/microcontainer/trunk/osgi-int/pom.xml 2008-02-25 14:08:49 UTC (rev 70062)
@@ -81,6 +81,10 @@
<artifactId>jboss-kernel</artifactId>
</dependency>
<dependency>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-deployers-impl</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.jboss</groupId>
<artifactId>jboss-vfs</artifactId>
</dependency>
Added: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/BundleHeaders.java
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/BundleHeaders.java (rev 0)
+++ projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/BundleHeaders.java 2008-02-25 14:08:49 UTC (rev 70062)
@@ -0,0 +1,264 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.plugins.facade;
+
+import static org.jboss.osgi.plugins.metadata.ValueCreatorUtil.PACKAGE_LIST_VC;
+import static org.jboss.osgi.plugins.metadata.ValueCreatorUtil.PARAM_ATTRIB_VC;
+import static org.jboss.osgi.plugins.metadata.ValueCreatorUtil.PATH_ATTRIB_LIST_VC;
+import static org.jboss.osgi.plugins.metadata.ValueCreatorUtil.QNAME_ATTRIB_LIST_VC;
+import static org.jboss.osgi.plugins.metadata.ValueCreatorUtil.STRING_LIST_VC;
+import static org.jboss.osgi.plugins.metadata.ValueCreatorUtil.STRING_VC;
+import static org.jboss.osgi.plugins.metadata.ValueCreatorUtil.URL_VC;
+import static org.jboss.osgi.plugins.metadata.ValueCreatorUtil.VERSION_VC;
+import static org.osgi.framework.Constants.BUNDLE_ACTIVATOR;
+import static org.osgi.framework.Constants.BUNDLE_CLASSPATH;
+import static org.osgi.framework.Constants.BUNDLE_DESCRIPTION;
+import static org.osgi.framework.Constants.BUNDLE_LOCALIZATION;
+import static org.osgi.framework.Constants.BUNDLE_MANIFESTVERSION;
+import static org.osgi.framework.Constants.BUNDLE_NAME;
+import static org.osgi.framework.Constants.BUNDLE_NATIVECODE;
+import static org.osgi.framework.Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT;
+import static org.osgi.framework.Constants.BUNDLE_SYMBOLICNAME;
+import static org.osgi.framework.Constants.BUNDLE_UPDATELOCATION;
+import static org.osgi.framework.Constants.BUNDLE_VERSION;
+import static org.osgi.framework.Constants.DYNAMICIMPORT_PACKAGE;
+import static org.osgi.framework.Constants.EXPORT_PACKAGE;
+import static org.osgi.framework.Constants.FRAGMENT_HOST;
+import static org.osgi.framework.Constants.IMPORT_PACKAGE;
+import static org.osgi.framework.Constants.REQUIRE_BUNDLE;
+
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Locale;
+import java.util.Map;
+import java.util.ResourceBundle;
+import java.util.Map.Entry;
+
+import org.jboss.osgi.plugins.metadata.ValueCreator;
+import org.jboss.osgi.spi.metadata.OSGiMetaData;
+import org.osgi.framework.Constants;
+
+/**
+ *
+ * Container for Bundle headers providing localization for Manifest headers.
+ *
+ * @author <a href="baileyje at gmail.com">John Bailey</a>
+ * @version $Revision: 1.1 $
+ */
+public class BundleHeaders
+{
+ private static final String LOACAIZED_HEADER_IDENTIFIER = "%";
+
+ private final OSGiMetaData metaData;
+
+ @SuppressWarnings("unchecked")
+ private static final Map<String, ValueCreator> valueCreators = new HashMap<String, ValueCreator>();
+
+ private Map<String, Object> nonLocalizedHeaders;
+
+ private Map<String, Map<String, Object>> localizedHeaderMap = new HashMap<String, Map<String, Object>>();
+
+ private boolean scannedForLocalized;
+
+ private boolean localized;
+
+ static
+ {
+ valueCreators.put(BUNDLE_ACTIVATOR, STRING_VC);
+ valueCreators.put(BUNDLE_CLASSPATH, STRING_LIST_VC);
+ valueCreators.put(BUNDLE_DESCRIPTION, STRING_VC);
+ valueCreators.put(BUNDLE_LOCALIZATION, STRING_VC);
+ valueCreators.put(BUNDLE_NAME, STRING_VC);
+ valueCreators.put(BUNDLE_NATIVECODE, PATH_ATTRIB_LIST_VC);
+ valueCreators.put(BUNDLE_REQUIREDEXECUTIONENVIRONMENT, STRING_LIST_VC);
+ valueCreators.put(BUNDLE_SYMBOLICNAME, STRING_VC);
+ valueCreators.put(BUNDLE_UPDATELOCATION, URL_VC);
+ valueCreators.put(BUNDLE_VERSION, VERSION_VC);
+ valueCreators.put(DYNAMICIMPORT_PACKAGE, PACKAGE_LIST_VC);
+ valueCreators.put(EXPORT_PACKAGE, PACKAGE_LIST_VC);
+ valueCreators.put(FRAGMENT_HOST, PARAM_ATTRIB_VC);
+ valueCreators.put(IMPORT_PACKAGE, PACKAGE_LIST_VC);
+ valueCreators.put(REQUIRE_BUNDLE, QNAME_ATTRIB_LIST_VC);
+ }
+
+ public BundleHeaders(OSGiMetaData metaData)
+ {
+ this.metaData = metaData;
+ }
+
+ private Map<String, Object> getNonLocalizedHeaders()
+ {
+ if (nonLocalizedHeaders == null)
+ {
+ nonLocalizedHeaders = new HashMap<String, Object>();
+ if (metaData != null)
+ {
+ if (metaData.getBundleActivator() != null)
+ {
+ nonLocalizedHeaders.put(BUNDLE_ACTIVATOR, metaData.getBundleActivator());
+ }
+ if (metaData.getBundleClassPath() != null)
+ {
+ nonLocalizedHeaders.put(BUNDLE_CLASSPATH, metaData.getBundleClassPath());
+ }
+ if (metaData.getBundleDescription() != null)
+ {
+ nonLocalizedHeaders.put(BUNDLE_DESCRIPTION, metaData.getBundleDescription());
+ }
+ if (metaData.getBundleLocalization() != null)
+ {
+ nonLocalizedHeaders.put(BUNDLE_LOCALIZATION, metaData.getBundleLocalization());
+ }
+ if (metaData.getBundleManifestVersion() > 0)
+ {
+ nonLocalizedHeaders.put(BUNDLE_MANIFESTVERSION, metaData.getBundleManifestVersion());
+ }
+ if (metaData.getBundleName() != null)
+ {
+ nonLocalizedHeaders.put(BUNDLE_NAME, metaData.getBundleName());
+ }
+ if (metaData.getBundleSymbolicName() != null)
+ {
+ nonLocalizedHeaders.put(BUNDLE_SYMBOLICNAME, metaData.getBundleSymbolicName());
+ }
+ if (metaData.getBundleUpdateLocation() != null)
+ {
+ nonLocalizedHeaders.put(BUNDLE_UPDATELOCATION, metaData.getBundleUpdateLocation());
+ }
+ if (metaData.getBundleVersion() != null)
+ {
+ nonLocalizedHeaders.put(BUNDLE_VERSION, metaData.getBundleVersion());
+ }
+ if (metaData.getBundleNativeCode() != null)
+ {
+ nonLocalizedHeaders.put(BUNDLE_NATIVECODE, metaData.getBundleNativeCode());
+ }
+ if (metaData.getDynamicImports() != null)
+ {
+ nonLocalizedHeaders.put(DYNAMICIMPORT_PACKAGE, metaData.getDynamicImports());
+ }
+ if (metaData.getExportPackages() != null)
+ {
+ nonLocalizedHeaders.put(EXPORT_PACKAGE, metaData.getExportPackages());
+ }
+ if (metaData.getFragmentHost() != null)
+ {
+ nonLocalizedHeaders.put(FRAGMENT_HOST, metaData.getFragmentHost());
+ }
+ if (metaData.getImportPackages() != null)
+ {
+ nonLocalizedHeaders.put(IMPORT_PACKAGE, metaData.getImportPackages());
+ }
+ if (metaData.getRequireBundles() != null)
+ {
+ nonLocalizedHeaders.put(REQUIRE_BUNDLE, metaData.getRequireBundles());
+ }
+ if (metaData.getRequiredExecutionEnvironment() != null)
+ {
+ nonLocalizedHeaders.put(BUNDLE_REQUIREDEXECUTIONENVIRONMENT, metaData.getRequiredExecutionEnvironment());
+ }
+ }
+ }
+ return nonLocalizedHeaders;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Dictionary getHeaders(String locale)
+ {
+ // TODO - Check permissions (METADATA)
+ Map<String, Object> localizedHeaders = localizedHeaderMap.get(locale);
+ if (localizedHeaders == null)
+ {
+ if (localizedHeadersFound(getNonLocalizedHeaders()))
+ {
+ localizedHeaders = new HashMap<String, Object>(getNonLocalizedHeaders());
+
+ String bundleLocaleBase = (String) getNonLocalizedHeaders().get(Constants.BUNDLE_LOCALIZATION);
+ if (bundleLocaleBase == null)
+ {
+ bundleLocaleBase = Constants.BUNDLE_LOCALIZATION_DEFAULT_BASENAME;
+ }
+ ResourceBundle resourceBundle = ResourceBundle.getBundle(bundleLocaleBase, convertToLocale(locale));
+ for (Entry<String, Object> header : localizedHeaders.entrySet())
+ {
+ if (metaData.getMainAttribute(header.getKey()).startsWith(LOACAIZED_HEADER_IDENTIFIER))
+ {
+ String localizedValue = resourceBundle.getString(header.getKey());
+ if (localizedValue != null)
+ {
+ ValueCreator valueCreator = valueCreators.get(header.getKey());
+ if (valueCreator == null)
+ {
+ valueCreator = STRING_VC;
+ }
+ header.setValue(valueCreator.createValue(localizedValue));
+ }
+ }
+ }
+ localizedHeaderMap.put(locale, localizedHeaders);
+ }
+ else
+ {
+ localizedHeaders = getNonLocalizedHeaders();
+ localizedHeaderMap.put(locale, getNonLocalizedHeaders());
+ }
+ }
+ return new Hashtable(localizedHeaders);
+ }
+
+ private boolean localizedHeadersFound(Map<String, Object> headers)
+ {
+ if (scannedForLocalized == false)
+ {
+ for (String headerName : headers.keySet())
+ {
+ // Need the raw value.....
+ if (metaData.getMainAttribute(headerName).startsWith(LOACAIZED_HEADER_IDENTIFIER))
+ {
+ localized = true;
+ break;
+ }
+ }
+ scannedForLocalized = true;
+ }
+ return localized;
+ }
+
+ private Locale convertToLocale(String localeString)
+ {
+ Locale locale = null;
+ String[] parts = localeString.split("_");
+ switch (parts.length)
+ {
+ case 1 :
+ locale = new Locale(parts[0]);
+ break;
+ case 2 :
+ locale = new Locale(parts[0], parts[1]);
+ break;
+ case 3 :
+ locale = new Locale(parts[0], parts[1], parts[2]);
+ }
+ return locale;
+ }
+}
Property changes on: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/BundleHeaders.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/BundleImpl.java
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/BundleImpl.java 2008-02-25 13:31:43 UTC (rev 70061)
+++ projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/BundleImpl.java 2008-02-25 14:08:49 UTC (rev 70062)
@@ -1,46 +1,61 @@
/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt 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.
-*/
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.plugins.facade;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
+import java.security.Permission;
import java.util.Dictionary;
import java.util.Enumeration;
+import java.util.Locale;
+import java.util.Set;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.deployers.plugins.deployers.DeploymentControllerContext;
+import org.jboss.deployers.spi.DeploymentState;
+import org.jboss.deployers.structure.spi.DeploymentContext;
import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.osgi.spi.metadata.OSGiMetaData;
+import org.osgi.framework.AdminPermission;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
import org.osgi.framework.ServiceReference;
/**
* Bundle implementation on top of existing DeploymentContext.
- *
+ *
* @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ * @author <a href="mailto:baileyje at gmail.com">John Bailey</a>
*/
public class BundleImpl implements Bundle
{
protected DeploymentUnit unit;
+ protected BundleHeaders bundleHeaders;
+
+ private long lastModified = -1;
+
public BundleImpl(DeploymentUnit unit)
{
this.unit = unit;
@@ -48,111 +63,256 @@
public int getState()
{
- return 0; //To change body of implemented methods use File | Settings | File Templates.
+ int bundleState = Bundle.UNINSTALLED;
+ if (getControllerContext() != null)
+ {
+ ControllerState controllerState = getControllerContext().getState();
+ if (ControllerState.ERROR.equals(controllerState))
+ {
+ bundleState = Bundle.INSTALLED; // Seems strange, but see javadoc
+ }
+ else if (ControllerState.NOT_INSTALLED.equals(controllerState))
+ {
+ bundleState = Bundle.UNINSTALLED;
+ }
+ else if (ControllerState.PRE_INSTALL.equals(controllerState)
+ || ControllerState.DESCRIBED.equals(controllerState))
+ {
+ bundleState = Bundle.INSTALLED;
+ }
+ else if (ControllerState.INSTANTIATED.equals(controllerState)
+ || ControllerState.CONFIGURED.equals(controllerState) || ControllerState.CREATE.equals(controllerState))
+ {
+ bundleState = Bundle.RESOLVED;
+ }
+ else if (ControllerState.START.equals(controllerState))
+ {
+ bundleState = Bundle.STARTING;
+ }
+ else if (ControllerState.INSTALLED.equals(controllerState))
+ {
+ bundleState = Bundle.ACTIVE;
+ }
+ }
+ return bundleState;
}
public void start() throws BundleException
{
- //To change body of implemented methods use File | Settings | File Templates.
+ checkPermission(AdminPermission.EXECUTE);
+
+ DeploymentControllerContext deploymentControllerContext = getControllerContext();
+ DeploymentContext deploymentContext = deploymentControllerContext.getDeploymentContext();
+
+ try
+ {
+ deploymentControllerContext.getController().change(getControllerContext(), ControllerState.INSTALLED);
+ }
+ catch (Throwable t)
+ {
+ deploymentContext.setState(DeploymentState.ERROR);
+ deploymentContext.setProblem(t);
+ }
+
}
public void stop() throws BundleException
{
- //To change body of implemented methods use File | Settings | File Templates.
+ checkPermission(AdminPermission.EXECUTE);
}
public void update() throws BundleException
{
- //To change body of implemented methods use File | Settings | File Templates.
+ checkPermission(AdminPermission.LIFECYCLE);
}
public void update(InputStream inputStream) throws BundleException
{
- //To change body of implemented methods use File | Settings | File Templates.
+ checkPermission(AdminPermission.LIFECYCLE);
}
public void uninstall() throws BundleException
{
- //To change body of implemented methods use File | Settings | File Templates.
+ checkPermission(AdminPermission.LIFECYCLE);
}
- @SuppressWarnings("unchecked")
- public Dictionary getHeaders()
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
public long getBundleId()
{
- return 0; //To change body of implemented methods use File | Settings | File Templates.
+ checkPermission(AdminPermission.METADATA);
+ return 1L;
}
public String getLocation()
{
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ checkPermission(AdminPermission.METADATA);
+ return null;
}
public ServiceReference[] getRegisteredServices()
{
- return new ServiceReference[0]; //To change body of implemented methods use File | Settings | File Templates.
+ return new ServiceReference[0];
}
public ServiceReference[] getServicesInUse()
{
- return new ServiceReference[0]; //To change body of implemented methods use File | Settings | File Templates.
+ return new ServiceReference[0];
}
- public boolean hasPermission(Object object)
+ public boolean hasPermission(Object permission)
{
- return false; //To change body of implemented methods use File | Settings | File Templates.
+ if (permission instanceof Permission)
+ {
+ try
+ {
+ // TODO check if bundle implies the permission
+ }
+ catch (SecurityException se)
+ {
+ return false;
+ }
+ }
+ return true;
}
- public URL getResource(String string)
+ @SuppressWarnings("unchecked")
+ public Dictionary getHeaders()
{
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ return getHeaders(Locale.getDefault().toString());
}
@SuppressWarnings("unchecked")
- public Dictionary getHeaders(String string)
+ public Dictionary getHeaders(String locale)
{
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ checkPermission(AdminPermission.METADATA);
+ return getBundleHeaders().getHeaders(locale);
}
public String getSymbolicName()
{
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ if (getOSGIMetaData() != null)
+ {
+ return getOSGIMetaData().getBundleSymbolicName();
+ }
+ return null;
}
- public Class<?> loadClass(String string) throws ClassNotFoundException
+ public Class<?> loadClass(String name) throws ClassNotFoundException
{
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ checkPermission(AdminPermission.CLASS);
+ if (getControllerContext() != null)
+ {
+ // Verify ControllerState required to load CL resources
+ if (ControllerState.INSTANTIATED.equals(getControllerContext().getState()))
+ {
+ return getClassLoader().loadClass(name);
+ }
+ }
+ return null;
}
+ public URL getResource(String name)
+ {
+ checkPermission(AdminPermission.RESOURCE);
+
+ if (getControllerContext() != null)
+ {
+ // Verify ControllerState required to load CL resources
+ if (ControllerState.INSTANTIATED.equals(getControllerContext().getState()))
+ {
+ return getClassLoader().getResource(name);
+ }
+ }
+ return null;
+ }
+
@SuppressWarnings("unchecked")
- public Enumeration getResources(String string) throws IOException
+ public Enumeration getResources(String name) throws IOException
{
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ checkPermission(AdminPermission.RESOURCE);
+
+ if (getControllerContext() != null)
+ {
+ // Verify ControllerState required to load CL resources
+ if (ControllerState.INSTANTIATED.equals(getControllerContext().getState()))
+ {
+ return getClassLoader().getResources(name);
+ }
+ }
+ return null;
}
@SuppressWarnings("unchecked")
public Enumeration getEntryPaths(String string)
{
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ checkPermission(AdminPermission.RESOURCE);
+ return null;
}
public URL getEntry(String string)
{
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ checkPermission(AdminPermission.RESOURCE);
+ return null;
}
public long getLastModified()
{
- return 0; //To change body of implemented methods use File | Settings | File Templates.
+ // TODO - Get a better scheme for this.. This should be set at INSTALL, UPDATE, UNSTALL
+ if (lastModified == -1)
+ {
+ lastModified = System.currentTimeMillis();
+ }
+ return lastModified;
}
@SuppressWarnings("unchecked")
public Enumeration findEntries(String string, String string1, boolean b)
{
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ checkPermission(AdminPermission.RESOURCE);
+
+ return null;
}
+
+ private DeploymentControllerContext getControllerContext()
+ {
+ return unit.getAttachment(ControllerContext.class.getName(), DeploymentControllerContext.class);
+ }
+
+ private OSGiMetaData getOSGIMetaData()
+ {
+ OSGiMetaData metaData = null;
+ Set<? extends OSGiMetaData> metaDatas = unit.getAllMetaData(OSGiMetaData.class);
+ if (metaDatas != null && metaDatas.isEmpty() == false)
+ {
+ metaData = (OSGiMetaData) metaDatas.iterator().next();
+ }
+ return metaData;
+ }
+
+ private BundleHeaders getBundleHeaders()
+ {
+ if (bundleHeaders == null)
+ {
+ bundleHeaders = new BundleHeaders(getOSGIMetaData());
+ }
+ return bundleHeaders;
+ }
+
+ private ClassLoader getClassLoader()
+ {
+ ClassLoader classLoader = null;
+ if (getControllerContext() != null)
+ {
+ classLoader = getControllerContext().getDeploymentContext().getClassLoader();
+ }
+ return classLoader;
+ }
+
+ private void checkPermission(String adminPermission)
+ {
+ if (System.getSecurityManager() != null)
+ {
+ System.getSecurityManager().checkPermission(new AdminPermission(this, adminPermission));
+ }
+ }
+
}
Modified: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/ValueCreatorUtil.java
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/ValueCreatorUtil.java 2008-02-25 13:31:43 UTC (rev 70061)
+++ projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/metadata/ValueCreatorUtil.java 2008-02-25 14:08:49 UTC (rev 70062)
@@ -28,13 +28,13 @@
*/
public class ValueCreatorUtil
{
- static StringValueCreator STRING_VC = new StringValueCreator();
- static IntegerValueCreator INTEGER_VC = new IntegerValueCreator();
- static BooleanValueCreator BOOLEAN_VC = new BooleanValueCreator();
- static VersionValueCreator VERSION_VC = new VersionValueCreator();
- static VersionRangeValueCreator VERSION_RANGE_VC = new VersionRangeValueCreator();
- static URLValueCreator URL_VC = new URLValueCreator();
- static StringListValueCreator STRING_LIST_VC = new StringListValueCreator();
+ public static StringValueCreator STRING_VC = new StringValueCreator();
+ public static IntegerValueCreator INTEGER_VC = new IntegerValueCreator();
+ public static BooleanValueCreator BOOLEAN_VC = new BooleanValueCreator();
+ public static VersionValueCreator VERSION_VC = new VersionValueCreator();
+ public static VersionRangeValueCreator VERSION_RANGE_VC = new VersionRangeValueCreator();
+ public static URLValueCreator URL_VC = new URLValueCreator();
+ public static StringListValueCreator STRING_LIST_VC = new StringListValueCreator();
public static ParameterizedAttributeValueCreator PARAM_ATTRIB_VC = new ParameterizedAttributeValueCreator();
public static ParameterizedAttributeListValueCreator QNAME_ATTRIB_LIST_VC = new QNameAttributeListValueCreator();
public static ParameterizedAttributeListValueCreator PATH_ATTRIB_LIST_VC = new PathAttributeListValueCreator();
Added: projects/microcontainer/trunk/osgi-int/src/resources/tests/OSGI-INF/l10n/bundle.properties
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/resources/tests/OSGI-INF/l10n/bundle.properties (rev 0)
+++ projects/microcontainer/trunk/osgi-int/src/resources/tests/OSGI-INF/l10n/bundle.properties 2008-02-25 14:08:49 UTC (rev 70062)
@@ -0,0 +1 @@
+Bundle-SymbolicName=DefaultSymbolicName
\ No newline at end of file
Property changes on: projects/microcontainer/trunk/osgi-int/src/resources/tests/OSGI-INF/l10n/bundle.properties
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: projects/microcontainer/trunk/osgi-int/src/resources/tests/OSGI-INF/l10n/bundle_en_US.properties
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/resources/tests/OSGI-INF/l10n/bundle_en_US.properties (rev 0)
+++ projects/microcontainer/trunk/osgi-int/src/resources/tests/OSGI-INF/l10n/bundle_en_US.properties 2008-02-25 14:08:49 UTC (rev 70062)
@@ -0,0 +1 @@
+Bundle-Description=Description with Locale( en_US )
\ No newline at end of file
Property changes on: projects/microcontainer/trunk/osgi-int/src/resources/tests/OSGI-INF/l10n/bundle_en_US.properties
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: projects/microcontainer/trunk/osgi-int/src/resources/tests/org/jboss/test/bundle/metadata/LocalizedManifest.mf
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/resources/tests/org/jboss/test/bundle/metadata/LocalizedManifest.mf (rev 0)
+++ projects/microcontainer/trunk/osgi-int/src/resources/tests/org/jboss/test/bundle/metadata/LocalizedManifest.mf 2008-02-25 14:08:49 UTC (rev 70062)
@@ -0,0 +1,16 @@
+Manifest-Version: 1.0
+Ant-Version: Apache Ant 1.6.5
+Created-By: Ales Justin
+Implementation-Title: JBoss OSGi tests
+Implementation-Version: 2.0.0.beta2
+Implementation-Vendor: jboss.org
+Bundle-Activator: org.jboss.test.bundle.metadata.BundleActivator
+Bundle-ClassPath: test.jar,mc.jar,seam.jar
+Bundle-Description: %TestHeadersManifest
+Bundle-Localization: OSGI-INF/l10n/bundle
+Bundle-ManifestVersion: 2
+Bundle-Name: TestBundle
+Bundle-SymbolicName: %UniqueName
+Bundle-UpdateLocation: file://test.jar
+Bundle-Version: 1.2.3.GA
+Bundle-RequiredExecutionEnvironment: ena,dva,tri
Added: projects/microcontainer/trunk/osgi-int/src/tests/org/jboss/test/bundle/BundleHeaderTestCase.java
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/tests/org/jboss/test/bundle/BundleHeaderTestCase.java (rev 0)
+++ projects/microcontainer/trunk/osgi-int/src/tests/org/jboss/test/bundle/BundleHeaderTestCase.java 2008-02-25 14:08:49 UTC (rev 70062)
@@ -0,0 +1,97 @@
+package org.jboss.test.bundle;
+
+import static org.osgi.framework.Constants.BUNDLE_ACTIVATOR;
+import static org.osgi.framework.Constants.BUNDLE_CLASSPATH;
+import static org.osgi.framework.Constants.BUNDLE_DESCRIPTION;
+import static org.osgi.framework.Constants.BUNDLE_LOCALIZATION;
+import static org.osgi.framework.Constants.BUNDLE_MANIFESTVERSION;
+import static org.osgi.framework.Constants.BUNDLE_NAME;
+import static org.osgi.framework.Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT;
+import static org.osgi.framework.Constants.BUNDLE_SYMBOLICNAME;
+import static org.osgi.framework.Constants.BUNDLE_UPDATELOCATION;
+import static org.osgi.framework.Constants.BUNDLE_VERSION;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.Arrays;
+import java.util.Dictionary;
+import java.util.List;
+import java.util.Locale;
+
+import junit.framework.Test;
+
+import org.jboss.osgi.plugins.facade.BundleHeaders;
+import org.jboss.osgi.plugins.metadata.AbstractOSGiMetaData;
+import org.jboss.osgi.spi.metadata.OSGiMetaData;
+import org.jboss.test.bundle.metadata.AbstractManifestTestCase;
+import org.osgi.framework.Version;
+
+public class BundleHeaderTestCase extends AbstractManifestTestCase
+{
+
+ public BundleHeaderTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(BundleHeaderTestCase.class);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testGetHeadersNoLocalization() throws Exception
+ {
+ Dictionary<String, Object> headers = getBundleHeaders(
+ getMetaData("/org/jboss/test/bundle/metadata/SimpleManifest.mf"))
+ .getHeaders(Locale.getDefault().toString());
+ assertNotNull(headers);
+ assertEquals(headers.get(BUNDLE_ACTIVATOR), "org.jboss.test.bundle.metadata.BundleActivator");
+ List<String> classpath = Arrays.asList("test.jar", "mc.jar", "seam.jar");
+ assertEquals(classpath, headers.get(BUNDLE_CLASSPATH));
+ assertEquals("TestHeadersManifest", headers.get(BUNDLE_DESCRIPTION));
+ assertEquals("OSGI-INF/l10n/bundle", headers.get(BUNDLE_LOCALIZATION));
+ assertEquals(2, headers.get(BUNDLE_MANIFESTVERSION));
+ assertEquals("TestBundle", headers.get(BUNDLE_NAME));
+ assertEquals("UniqueName", headers.get(BUNDLE_SYMBOLICNAME));
+ URL url = new URL("file://test.jar");
+ assertEquals(url, headers.get(BUNDLE_UPDATELOCATION));
+ Version version = new Version("1.2.3.GA");
+ assertEquals(version, headers.get(BUNDLE_VERSION));
+ List<String> env = Arrays.asList("ena", "dva", "tri");
+ assertEquals(env, headers.get(BUNDLE_REQUIREDEXECUTIONENVIRONMENT));
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testGetHeadersWithDefaultLocalization() throws Exception
+ {
+ Dictionary<String, Object> headers = getBundleHeaders(
+ getMetaData("/org/jboss/test/bundle/metadata/LocalizedManifest.mf")).getHeaders(
+ new Locale("en", "US").toString());
+ assertNotNull(headers);
+ assertEquals(headers.get(BUNDLE_ACTIVATOR), "org.jboss.test.bundle.metadata.BundleActivator");
+ List<String> classpath = Arrays.asList("test.jar", "mc.jar", "seam.jar");
+ assertEquals(classpath, headers.get(BUNDLE_CLASSPATH));
+ assertEquals("Description with Locale( en_US )", headers.get(BUNDLE_DESCRIPTION));
+ assertEquals("OSGI-INF/l10n/bundle", headers.get(BUNDLE_LOCALIZATION));
+ assertEquals(2, headers.get(BUNDLE_MANIFESTVERSION));
+ assertEquals("TestBundle", headers.get(BUNDLE_NAME));
+ assertEquals("DefaultSymbolicName", headers.get(BUNDLE_SYMBOLICNAME));
+ URL url = new URL("file://test.jar");
+ assertEquals(url, headers.get(BUNDLE_UPDATELOCATION));
+ Version version = new Version("1.2.3.GA");
+ assertEquals(version, headers.get(BUNDLE_VERSION));
+ List<String> env = Arrays.asList("ena", "dva", "tri");
+ assertEquals(env, headers.get(BUNDLE_REQUIREDEXECUTIONENVIRONMENT));
+ }
+
+ private OSGiMetaData getMetaData(String manifestPath) throws IOException
+ {
+ return new AbstractOSGiMetaData(getManifest(manifestPath));
+ }
+
+ private BundleHeaders getBundleHeaders(OSGiMetaData metaData)
+ {
+ return new BundleHeaders(metaData);
+ }
+}
Property changes on: projects/microcontainer/trunk/osgi-int/src/tests/org/jboss/test/bundle/BundleHeaderTestCase.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: projects/microcontainer/trunk/osgi-int/src/tests/org/jboss/test/bundle/BundleImplTestCase.java
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/tests/org/jboss/test/bundle/BundleImplTestCase.java (rev 0)
+++ projects/microcontainer/trunk/osgi-int/src/tests/org/jboss/test/bundle/BundleImplTestCase.java 2008-02-25 14:08:49 UTC (rev 70062)
@@ -0,0 +1,110 @@
+package org.jboss.test.bundle;
+
+import java.util.jar.Manifest;
+
+import junit.framework.Test;
+
+import org.jboss.dependency.plugins.AbstractController;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.deployers.plugins.deployers.DeployersImpl;
+import org.jboss.deployers.plugins.deployers.DeploymentControllerContext;
+import org.jboss.deployers.structure.spi.DeploymentContext;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.structure.spi.helpers.AbstractDeploymentContext;
+import org.jboss.deployers.structure.spi.helpers.AbstractDeploymentUnit;
+import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap;
+import org.jboss.osgi.plugins.facade.BundleImpl;
+import org.jboss.osgi.plugins.metadata.AbstractOSGiMetaData;
+import org.jboss.osgi.spi.metadata.OSGiMetaData;
+import org.jboss.test.bundle.metadata.AbstractManifestTestCase;
+import org.osgi.framework.Bundle;
+
+public class BundleImplTestCase extends AbstractManifestTestCase
+{
+ private OSGiMetaData metaData;
+ private Bundle bundle;
+ private DeploymentUnit deploymentUnit;
+ private ControllerContext controllerContext;
+
+ public BundleImplTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(BundleImplTestCase.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ BasicBootstrap bootstrap = new BasicBootstrap();
+ bootstrap.run();
+
+ DeploymentContext deploymentContext = new AbstractDeploymentContext("deployment", "/");
+ deploymentUnit = new AbstractDeploymentUnit(deploymentContext);
+ controllerContext = new DeploymentControllerContext(deploymentContext, new DeployersImpl((AbstractController) bootstrap.getKernel().getController()));
+ deploymentUnit.addAttachment(ControllerContext.class.getName(), controllerContext);
+ bundle = new BundleImpl(deploymentUnit);
+
+ Manifest manifest = getManifest("/org/jboss/test/bundle/metadata/SimpleManifest.mf");
+ metaData = new AbstractOSGiMetaData(manifest);
+ deploymentUnit.addAttachment(OSGiMetaData.class, metaData);
+
+ try
+ {
+ bootstrap.getKernel().getController().install(controllerContext);
+ }
+ catch (Throwable e)
+ {
+ throw new Exception(e);
+ }
+ }
+
+ public void testGetBundleState() throws Exception
+ {
+ controllerContext.setState(ControllerState.ERROR);
+ assertEquals(Bundle.INSTALLED, bundle.getState());
+
+ controllerContext.setState(ControllerState.NOT_INSTALLED);
+ assertEquals(Bundle.UNINSTALLED, bundle.getState());
+
+ controllerContext.setState(ControllerState.PRE_INSTALL);
+ assertEquals(Bundle.INSTALLED, bundle.getState());
+
+ controllerContext.setState(ControllerState.DESCRIBED);
+ assertEquals(Bundle.INSTALLED, bundle.getState());
+
+ controllerContext.setState(ControllerState.INSTANTIATED);
+ assertEquals(Bundle.RESOLVED, bundle.getState());
+
+ controllerContext.setState(ControllerState.CONFIGURED);
+ assertEquals(Bundle.RESOLVED, bundle.getState());
+
+ controllerContext.setState(ControllerState.CREATE);
+ assertEquals(Bundle.RESOLVED, bundle.getState());
+
+ controllerContext.setState(ControllerState.START);
+ assertEquals(Bundle.STARTING, bundle.getState());
+
+ controllerContext.setState(ControllerState.INSTALLED);
+ assertEquals(Bundle.ACTIVE, bundle.getState());
+ }
+
+ public void testGetSymbolicName() throws Exception
+ {
+ assertEquals("UniqueName", bundle.getSymbolicName());
+ }
+
+ public void testStartBundle() throws Exception
+ {
+ assertEquals(Bundle.UNINSTALLED, bundle.getState());
+ bundle.start();
+ assertEquals(Bundle.ACTIVE, bundle.getState());
+ }
+
+}
Property changes on: projects/microcontainer/trunk/osgi-int/src/tests/org/jboss/test/bundle/BundleImplTestCase.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: projects/microcontainer/trunk/osgi-int/src/tests/org/jboss/test/bundle/BundleTestSuite.java
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/tests/org/jboss/test/bundle/BundleTestSuite.java 2008-02-25 13:31:43 UTC (rev 70061)
+++ projects/microcontainer/trunk/osgi-int/src/tests/org/jboss/test/bundle/BundleTestSuite.java 2008-02-25 14:08:49 UTC (rev 70062)
@@ -42,6 +42,8 @@
{
TestSuite suite = new TestSuite("Bundle Tests");
+ suite.addTest(BundleImplTestCase.suite());
+ suite.addTest(BundleHeaderTestCase.suite());
suite.addTest(MetaDataTestSuite.suite());
return suite;
More information about the jboss-cvs-commits
mailing list