[jboss-cvs] JBossAS SVN: r92424 - in projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int: src/main/java/org/jboss/osgi/plugins and 63 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Aug 17 09:47:09 EDT 2009
Author: adrian at jboss.org
Date: 2009-08-17 09:47:07 -0400 (Mon, 17 Aug 2009)
New Revision: 92424
Added:
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/bundle/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/bundle/OSGiBundleActivatorDeployer.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/bundle/OSGiBundleClassLoadingDeployer.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/bundle/OSGiBundleStateDeployer.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/bundle/OSGiManifestParsingDeployer.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/bundle/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleContextWrapper.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleState.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleWrapper.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiServiceReferenceWrapper.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiServiceRegistrationWrapper.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiServiceState.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiSystemBundle.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/bundle/VFSEntryPathsEnumeration.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/bundle/VFSFindEntriesEnumeration.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/FilterImpl.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/NoFilter.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/model/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/model/AndOperation.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/model/ApproximateOperation.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/model/CompareOperation.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/model/EqualsOperation.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/model/GreaterThanOperation.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/model/LessThanOperation.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/model/NotOperation.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/model/Operation.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/model/OrOperation.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/model/PresentOperation.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/model/SubStringOperation.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/parser/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/parser/FilterParser.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/property/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/property/DictionaryToPropertySource.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/property/PropertySource.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/property/ServiceReferenceToPropertySource.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/framework/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/framework/AdminPermission.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/framework/FrameworkUtil.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/util/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/util/CaseInsensitiveDictionary.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/OSGiClassLoaderSystem.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/OSGiTestCase.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/OSGiTestDelegate.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/OSGiTestSuite.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/bundle/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/bundle/BundleTestSuite.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/bundle/test/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/bundle/test/BundleContextUnitTestCase.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/bundle/test/BundleEntriesUnitTestCase.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/bundle/test/BundleUnitTestCase.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/bundle/test/SystemBundleUnitTestCase.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/filter/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/filter/FilterTestSuite.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/filter/test/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/filter/test/AbstractFilterTest.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/filter/test/BundleContextFilterUnitTestCase.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/filter/test/FrameworkUtilFilterUnitTestCase.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/service/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/service/ServiceTestSuite.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/service/support/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/service/support/BrokenServiceFactory.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/service/support/SimpleServiceFactory.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/service/support/a/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/service/support/a/A.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/service/support/b/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/service/support/b/B.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/service/test/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/service/test/GetServiceReferencesUnitTestCase.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/service/test/GetUnGetServiceUnitTestCase.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/service/test/RegisterServiceUnitTestCase.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/service/test/ServiceReferenceUnitTestCase.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/service/test/ServiceRegistrationUnitTestCase.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/smoke/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/smoke/SmokeTestSuite.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/smoke/support/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/smoke/support/a/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/smoke/support/a/A.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/smoke/support/a/b/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/smoke/support/a/b/B.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/smoke/support/c/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/smoke/support/c/C.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/smoke/test/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/smoke/test/OSGiSmokeTestCase.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/entries/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/entries/entries-simple/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/entries/entries-simple/META-INF/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/entries/entries-simple/META-INF/MANIFEST.MF
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/entries/entries-simple/entry1.xml
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/entries/entries-simple/org/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/entries/entries-simple/org/jboss/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/entries/entries-simple/org/jboss/test/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/entries/entries-simple/org/jboss/test/osgi/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/entries/entries-simple/org/jboss/test/osgi/bundle/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/entries/entries-simple/org/jboss/test/osgi/bundle/entries/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/entries/entries-simple/org/jboss/test/osgi/bundle/entries/entry1.xml
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/entries/entries-simple/org/jboss/test/osgi/bundle/entries/entry2.xml
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/entries/entries-simple/org/jboss/test/osgi/bundle/entries/notxml.suffix
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/entries/entries-simple/org/jboss/test/osgi/bundle/entries/sub/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/entries/entries-simple/org/jboss/test/osgi/bundle/entries/sub/entry1.xml
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/entries/entries-simple/org/jboss/test/osgi/bundle/entries/sub/entry2.xml
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/entries/entries-simple/root-no-suffix
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/entries/entries-simple/root.xml
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/service/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/service/service-bundle1/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/service/service-bundle1/META-INF/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/service/service-bundle1/META-INF/MANIFEST.MF
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/service/service-bundle2/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/service/service-bundle2/META-INF/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/service/service-bundle2/META-INF/MANIFEST.MF
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/simple/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/simple/simple-bundle1/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/simple/simple-bundle1/META-INF/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/simple/simple-bundle1/META-INF/MANIFEST.MF
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/simple/simple-bundle2/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/simple/simple-bundle2/META-INF/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/simple/simple-bundle2/META-INF/MANIFEST.MF
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/smoke/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/smoke/smoke-assembled/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/smoke/smoke-assembled/META-INF/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/smoke/smoke-assembled/META-INF/MANIFEST.MF
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/smoke/smoke-assembled/id
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/smoke/smoke-no-manifest/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/smoke/smoke-no-manifest/id
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/smoke/smoke-non-osgi-manifest/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/smoke/smoke-non-osgi-manifest/META-INF/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/smoke/smoke-non-osgi-manifest/META-INF/MANIFEST.MF
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/smoke/smoke-non-osgi-manifest/id
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/smoke/smoke-osgi-manifest/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/smoke/smoke-osgi-manifest/META-INF/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/smoke/smoke-osgi-manifest/META-INF/MANIFEST.MF
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/smoke/smoke-osgi-manifest/id
Removed:
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/dependency/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/BundleActivatorDeployer.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/OSGiDeclarativeDeployer.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/OSGiMetaData2ClassLoadingMetaDataDeployer.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/OSGiMetaDataDeployer.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/OSGiMetaDataDeploymentVisitor.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/OSGiServiceDeployer.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/OSGiStructure.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/SecurityActions.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/ServiceDeploymentDeployer.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/AbstractBundleEvent.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/AbstractDelegateListener.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/AbstractFrameworkEvent.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/AbstractServiceEvent.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/BundleContextImpl.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/BundleEventAdapter.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/BundleImpl.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/BundleListenerImpl.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/BundleState.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/EventAdapter.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/FilterImpl.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/FrameworkEventAdapter.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/FrameworkListenerImpl.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/InternalOSGiFacadeException.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/NumberUtil.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/OSGiKernelEventFilter.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/OSGiUtils.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/ServiceEventAdapter.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/ServiceFactoryProxy.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/ServiceListenerImpl.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/ServiceReferenceImpl.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/ServiceRegistrationImpl.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/asynch/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/helpers/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/registry/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/version/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/OSGiAllTestSuite.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/OSGiTestCase.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/OSGiTestDelegate.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/bundle/BundleTestSuite.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/bundle/deployers/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/bundle/facade/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/bundle/helper/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/bundle/support/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundle/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/log4j.xml
Modified:
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/.classpath
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/.project
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/pom.xml
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployment/xml/OSGiSchemaBindingHelper.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployment/xml/ReferenceHandler.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployment/xml/ServiceHandler.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/metadata/AbstractOSGiMetaData.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/metadata/AbstractReferenceMetaData.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/metadata/AbstractServiceMetaData.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/metadata/AbstractVersionRange.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/metadata/OSGiParameters.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/spi/metadata/OSGiMetaData.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/bundle/metadata/HeaderValuesTestCase.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bootstrap/bootstrap.xml
Log:
[JBOSGI-5] - Updated prototype of core OSGi implemented on top of JBoss deployers/classloading
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/.classpath
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/.classpath 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/.classpath 2009-08-17 13:47:07 UTC (rev 92424)
@@ -1,9 +1,9 @@
-<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
+ <classpathentry kind="src" output="target/classes" path="target/generated-sources/javacc"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/.project
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/.project 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/.project 2009-08-17 13:47:07 UTC (rev 92424)
@@ -1,23 +1,17 @@
-<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
- <name>jboss-osgi-microcontainer-facade</name>
- <comment>JBoss OSGi Integration</comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.maven.ide.eclipse.maven2Builder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.maven.ide.eclipse.maven2Nature</nature>
- <nature>org.eclipse.jdt.core.javanature</nature>
- </natures>
-</projectDescription>
+ <name>jboss-osgi-runtime-microcontainer-facade</name>
+ <comment>JBossOSGi</comment>
+ <projects/>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ </buildCommand>
+ <buildCommand>
+ <name>org.maven.ide.eclipse.maven2Builder</name>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.maven.ide.eclipse.maven2Nature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
\ No newline at end of file
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/pom.xml
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/pom.xml 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/pom.xml 2009-08-17 13:47:07 UTC (rev 92424)
@@ -8,12 +8,17 @@
<parent>
<groupId>org.jboss.osgi</groupId>
<artifactId>jboss-osgi-runtime-microcontainer-parent</artifactId>
- <version>1.0.0-SNAPSHOT</version>
+ <version>1.0.0.Beta2</version>
</parent>
<!-- Properties -->
<properties>
- <version.jboss.test>1.0.5.GA</version.jboss.test>
+ <version.jboss.aop>2.1.0.CR3</version.jboss.aop>
+ <version.jboss.deployers>2.0.8-SNAPSHOT</version.jboss.deployers>
+ <version.jboss.microcontainer>2.0.6.GA</version.jboss.microcontainer>
+ <version.jboss.test>1.1.4.GA</version.jboss.test>
+ <version.junit>4.6</version.junit>
+ <version.jboss.logging.log4j>2.1.0.GA</version.jboss.logging.log4j>
</properties>
<dependencies>
@@ -21,14 +26,22 @@
<dependency>
<groupId>org.jboss.microcontainer</groupId>
<artifactId>jboss-kernel</artifactId>
+ <version>${version.jboss.microcontainer}</version>
</dependency>
<dependency>
<groupId>org.jboss.deployers</groupId>
+ <artifactId>jboss-deployers-impl</artifactId>
+ <version>${version.jboss.deployers}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.deployers</groupId>
<artifactId>jboss-deployers-vfs-spi</artifactId>
+ <version>${version.jboss.deployers}</version>
</dependency>
<dependency>
<groupId>org.jboss.deployers</groupId>
<artifactId>jboss-deployers-vfs</artifactId>
+ <version>${version.jboss.deployers}</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
@@ -41,6 +54,7 @@
<dependency>
<groupId>org.jboss.aop</groupId>
<artifactId>jboss-aop</artifactId>
+ <version>${version.jboss.aop}</version>
<exclusions>
<exclusion>
<groupId>ant</groupId>
@@ -83,7 +97,7 @@
<!-- Test dependencies -->
<dependency>
- <groupId>org.jboss</groupId>
+ <groupId>org.jboss.test</groupId>
<artifactId>jboss-test</artifactId>
<version>${version.jboss.test}</version>
<scope>test</scope>
@@ -99,10 +113,17 @@
</exclusions>
</dependency>
<dependency>
- <groupId>org.jboss.deployers</groupId>
- <artifactId>jboss-deployers-impl</artifactId>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${version.junit}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.jboss.logging</groupId>
+ <artifactId>jboss-logging-log4j</artifactId>
+ <version>${version.jboss.logging.log4j}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
@@ -110,7 +131,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>javacc-maven-plugin</artifactId>
- <version>2.1</version>
+ <version>2.4</version>
<executions>
<execution>
<phase>generate-sources</phase>
Deleted: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/BundleActivatorDeployer.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/BundleActivatorDeployer.java 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/BundleActivatorDeployer.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -1,93 +0,0 @@
-/*
-* 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.deployers;
-
-import org.jboss.beans.metadata.plugins.builder.BeanMetaDataBuilderFactory;
-import org.jboss.beans.metadata.spi.BeanMetaData;
-import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
-import org.jboss.deployers.spi.DeploymentException;
-import org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployerWithInput;
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.kernel.spi.dependency.KernelController;
-import org.jboss.osgi.plugins.facade.BundleContextImpl;
-import org.jboss.osgi.spi.metadata.OSGiMetaData;
-import org.osgi.framework.BundleContext;
-
-/**
- * Create OSGi meta data from manifest.
- *
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
- */
-public class BundleActivatorDeployer extends AbstractRealDeployerWithInput<OSGiMetaData>
-{
- private final KernelController controller;
-
- public BundleActivatorDeployer(KernelController controller)
- {
- super(OSGiMetaData.class);
- if (controller == null)
- throw new IllegalArgumentException("Null controller");
- this.controller = controller;
- setDeploymentVisitor(new BundleActivatorDeploymentVisitor());
- }
-
- protected String createBundleActivatorBeanName(OSGiMetaData metaData)
- {
- return metaData.getBundleSymbolicName() + "Activator";
- }
-
- private class BundleActivatorDeploymentVisitor extends OSGiMetaDataDeploymentVisitor
- {
- public void deploy(DeploymentUnit unit, OSGiMetaData deployment) throws DeploymentException
- {
- String bundleActivator = deployment.getBundleActivator();
- if (bundleActivator != null)
- {
- String name = createBundleActivatorBeanName(deployment);
- // todo - get deployment context in non-depricated way
- BundleContext bundleContext = new BundleContextImpl(unit);
- BeanMetaDataBuilder builder = BeanMetaDataBuilderFactory.createBuilder(name, bundleActivator)
- .addStartParameter(BundleContext.class.getName(), bundleContext)
- .addStopParameter(BundleContext.class.getName(), bundleContext);
- BeanMetaData beanMetaData = builder.getBeanMetaData();
- try
- {
- controller.install(beanMetaData);
- }
- catch (Throwable throwable)
- {
- throw DeploymentException.rethrowAsDeploymentException("Unable to install BundleActivator.", throwable);
- }
- }
- }
-
- public void undeploy(DeploymentUnit unit, OSGiMetaData deployment)
- {
- String bundleActivator = deployment.getBundleActivator();
- if (bundleActivator != null)
- {
- String name = createBundleActivatorBeanName(deployment);
- controller.uninstall(name);
- }
- }
- }
-}
Deleted: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/OSGiDeclarativeDeployer.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/OSGiDeclarativeDeployer.java 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/OSGiDeclarativeDeployer.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -1,47 +0,0 @@
-/*
-* 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.deployers;
-
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.deployers.vfs.spi.deployer.SchemaResolverDeployer;
-import org.jboss.osgi.spi.metadata.ServiceDeployment;
-import org.jboss.virtual.VirtualFile;
-
-/**
- * OSGi declarative components deployer
- *
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
- */
-public class OSGiDeclarativeDeployer extends SchemaResolverDeployer<ServiceDeployment>
-{
- public OSGiDeclarativeDeployer()
- {
- super(ServiceDeployment.class);
- setSuffix("-osgi.xml");
- }
-
- protected void init(DeploymentUnit unit, ServiceDeployment metaData, VirtualFile file) throws Exception
- {
- String name = file.toURI().toString();
- metaData.setName(name);
- }
-}
Deleted: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/OSGiMetaData2ClassLoadingMetaDataDeployer.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/OSGiMetaData2ClassLoadingMetaDataDeployer.java 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/OSGiMetaData2ClassLoadingMetaDataDeployer.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -1,120 +0,0 @@
-/*
-* 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.deployers;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.jboss.classloading.spi.metadata.Capability;
-import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
-import org.jboss.classloading.spi.metadata.ClassLoadingMetaDataFactory;
-import org.jboss.classloading.spi.metadata.Requirement;
-import org.jboss.classloading.spi.version.VersionComparatorRegistry;
-import org.jboss.deployers.spi.DeploymentException;
-import org.jboss.deployers.spi.deployer.DeploymentStages;
-import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.osgi.plugins.version.OSGiVersionComparator;
-import org.jboss.osgi.plugins.version.OSGiVersionToStringComparator;
-import org.jboss.osgi.plugins.version.OSGiVersionToVersionComparator;
-import org.jboss.osgi.spi.metadata.OSGiMetaData;
-import org.jboss.osgi.spi.metadata.PackageAttribute;
-import org.jboss.osgi.spi.metadata.VersionRange;
-import org.jboss.reflect.spi.PackageInfo;
-import org.osgi.framework.Version;
-
-/**
- * Create ClassLoading metadat from OSGi metadata.
- *
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
- */
-public class OSGiMetaData2ClassLoadingMetaDataDeployer extends AbstractSimpleRealDeployer<OSGiMetaData>
-{
- public OSGiMetaData2ClassLoadingMetaDataDeployer()
- {
- super(OSGiMetaData.class);
- setOutput(ClassLoadingMetaData.class);
- setStage(DeploymentStages.DESCRIBE);
- }
-
- /**
- * Add OSGi Version impl to VersionComparatorRegistry.
- */
- public void create()
- {
- VersionComparatorRegistry registry = VersionComparatorRegistry.getInstance();
- registry.registerVersionComparator(Version.class, OSGiVersionComparator.INSTANCE);
- registry.registerVersionComparator(Version.class, String.class, OSGiVersionToStringComparator.INSTANCE);
- registry.registerVersionComparator(Version.class, org.jboss.classloading.spi.version.Version.class, OSGiVersionToVersionComparator.INSTANCE);
- }
-
- /**
- * Remove OSGi Version impl from VersionComparatorRegistry.
- */
- public void destroy()
- {
- VersionComparatorRegistry registry = VersionComparatorRegistry.getInstance();
- registry.removeVersionComparator(Version.class);
- registry.removeVersionComparator(Version.class, String.class);
- registry.removeVersionComparator(Version.class, org.jboss.classloading.spi.version.Version.class);
- }
-
- public void deploy(DeploymentUnit unit, OSGiMetaData deployment) throws DeploymentException
- {
- ClassLoadingMetaData clmd = new ClassLoadingMetaData();
- clmd.setName(unit.getSimpleName());
- Version bundleVersion = deployment.getBundleVersion();
- if (bundleVersion != null)
- clmd.setVersion(bundleVersion);
- clmd.setDomain(deployment.getHeader("Domain-Name"));
- ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
- List<PackageAttribute> exports = deployment.getExportPackages();
- if (exports != null && exports.isEmpty() == false)
- {
- List<Capability> capabilities = new ArrayList<Capability>(exports.size());
- for (PackageAttribute pa : exports)
- {
- PackageInfo pi = pa.getPackageInfo();
- VersionRange vr = pa.getVersion();
- capabilities.add(factory.createPackage(pi.getName(), vr.getFloor()));
- }
- clmd.setCapabilities(capabilities);
- }
- List<PackageAttribute> imports = deployment.getImportPackages();
- if (imports != null && imports.isEmpty() == false)
- {
- List<Requirement> requirements = new ArrayList<Requirement>(imports.size());
- for (PackageAttribute pa : imports)
- {
- PackageInfo pi = pa.getPackageInfo();
- VersionRange vr = pa.getVersion();
- org.jboss.classloading.spi.version.VersionRange versionRange = new org.jboss.classloading.spi.version.VersionRange(vr.getFloor(), vr.getCeiling());
- requirements.add(factory.createRequirePackage(pi.getName(), versionRange));
- }
- clmd.setRequirements(requirements);
- }
- clmd.setImportAll(imports == null || imports.isEmpty());
-
- // put to attacmhents
- unit.addAttachment(ClassLoadingMetaData.class, clmd);
- }
-}
\ No newline at end of file
Deleted: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/OSGiMetaDataDeployer.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/OSGiMetaDataDeployer.java 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/OSGiMetaDataDeployer.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -1,46 +0,0 @@
-/*
-* 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.deployers;
-
-import java.util.jar.Manifest;
-
-import org.jboss.deployers.vfs.spi.deployer.ManifestDeployer;
-import org.jboss.osgi.plugins.metadata.AbstractOSGiMetaData;
-import org.jboss.osgi.spi.metadata.OSGiMetaData;
-
-/**
- * Create OSGi meta data from manifest.
- *
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
- */
-public class OSGiMetaDataDeployer extends ManifestDeployer<OSGiMetaData>
-{
- public OSGiMetaDataDeployer()
- {
- super(OSGiMetaData.class);
- }
-
- protected OSGiMetaData createMetaData(Manifest manifest) throws Exception
- {
- return new AbstractOSGiMetaData(manifest);
- }
-}
Deleted: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/OSGiMetaDataDeploymentVisitor.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/OSGiMetaDataDeploymentVisitor.java 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/OSGiMetaDataDeploymentVisitor.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -1,40 +0,0 @@
-/*
-* 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.deployers;
-
-import org.jboss.deployers.spi.deployer.helpers.DeploymentVisitor;
-import org.jboss.osgi.spi.metadata.OSGiMetaData;
-
-/**
- * OSGi meta data deployment visitor.
- * Used with real OSGi deployer.
- *
- * @see BundleActivatorDeployer
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
- */
-public abstract class OSGiMetaDataDeploymentVisitor implements DeploymentVisitor<OSGiMetaData>
-{
- public Class<OSGiMetaData> getVisitorType()
- {
- return OSGiMetaData.class;
- }
-}
Deleted: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/OSGiServiceDeployer.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/OSGiServiceDeployer.java 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/OSGiServiceDeployer.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -1,73 +0,0 @@
-/*
-* 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.deployers;
-
-import org.jboss.dependency.spi.ControllerContext;
-import org.jboss.deployers.spi.DeploymentException;
-import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.kernel.Kernel;
-import org.jboss.kernel.spi.dependency.KernelController;
-import org.jboss.osgi.plugins.dependency.OSGiServiceReferenceContext;
-import org.jboss.osgi.plugins.facade.BundleContextImpl;
-import org.jboss.osgi.spi.metadata.ServiceMetaData;
-import org.osgi.framework.BundleContext;
-
-/**
- * Create OSGi meta data from manifest.
- *
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
- */
-public class OSGiServiceDeployer extends AbstractSimpleRealDeployer<ServiceMetaData>
-{
- /** The kernel controller */
- private final KernelController controller;
-
- public OSGiServiceDeployer(Kernel kernel)
- {
- super(ServiceMetaData.class);
- if (kernel == null)
- throw new IllegalArgumentException("Null kernel");
- controller = kernel.getController();
- setComponentsOnly(true);
- }
-
- public void deploy(DeploymentUnit unit, ServiceMetaData deployment) throws DeploymentException
- {
- // todo - get deployment context in non-depricated way
- BundleContext bundleContext = new BundleContextImpl(unit);
- ControllerContext context = new OSGiServiceReferenceContext(deployment, bundleContext);
- try
- {
- controller.install(context);
- }
- catch (Throwable t)
- {
- throw DeploymentException.rethrowAsDeploymentException("Error deploying: " + deployment.getId(), t);
- }
- }
-
- public void undeploy(DeploymentUnit unit, ServiceMetaData deployment)
- {
- controller.uninstall(deployment.getId());
- }
-}
Deleted: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/OSGiStructure.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/OSGiStructure.java 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/OSGiStructure.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -1,46 +0,0 @@
-/*
-* 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.deployers;
-
-import org.jboss.deployers.spi.DeploymentException;
-import org.jboss.deployers.vfs.plugins.structure.AbstractVFSStructureDeployer;
-import org.jboss.deployers.vfs.spi.structure.StructureContext;
-
-/**
- * OSGi structure deployer.
- * Reads manifest for OSGi classpath.
- *
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
- */
-public class OSGiStructure extends AbstractVFSStructureDeployer
-{
- public OSGiStructure()
- {
- /* one after jar */
- setRelativeOrder(10001);
- }
-
- public boolean determineStructure(StructureContext context) throws DeploymentException
- {
- return false;
- }
-}
Deleted: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/SecurityActions.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/SecurityActions.java 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/SecurityActions.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -1,90 +0,0 @@
-/*
-* 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.deployers;
-
-import java.io.IOException;
-import java.lang.reflect.UndeclaredThrowableException;
-import java.security.AccessController;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
-
-import org.jboss.virtual.VirtualFile;
-
-/**
- * @author Scott.Stark at jboss.org
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
- */
-public class SecurityActions
-{
- /**
- * Actions for File access
- */
- interface FileActions
- {
- FileActions PRIVILEGED = new FileActions()
- {
- public Boolean isLeaf(final VirtualFile f) throws IOException
- {
- try
- {
- return AccessController.doPrivileged(new PrivilegedExceptionAction<Boolean>()
- {
- public Boolean run() throws Exception
- {
- return f.isLeaf();
- }
- });
- }
- catch(PrivilegedActionException e)
- {
- Exception ex = e.getException();
- if( ex instanceof IOException )
- throw (IOException) ex;
- else if( ex instanceof RuntimeException )
- throw (RuntimeException) ex;
- else
- throw new UndeclaredThrowableException(ex);
- }
- }
- };
-
- FileActions NON_PRIVILEGED = new FileActions()
- {
- public Boolean isLeaf(VirtualFile f) throws IOException
- {
- return f.isLeaf();
- }
-
- };
-
- public Boolean isLeaf(VirtualFile f) throws IOException;
- }
-
- static boolean isLeaf(VirtualFile f) throws IOException
- {
- SecurityManager sm = System.getSecurityManager();
- if( sm != null )
- return FileActions.PRIVILEGED.isLeaf(f);
- else
- return FileActions.NON_PRIVILEGED.isLeaf(f);
- }
-}
Deleted: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/ServiceDeploymentDeployer.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/ServiceDeploymentDeployer.java 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/ServiceDeploymentDeployer.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -1,103 +0,0 @@
-/*
-* 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.deployers;
-
-import java.util.List;
-
-import org.jboss.deployers.spi.DeploymentException;
-import org.jboss.deployers.spi.deployer.helpers.AbstractComponentDeployer;
-import org.jboss.deployers.spi.deployer.helpers.DeploymentVisitor;
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.osgi.spi.metadata.ServiceDeployment;
-import org.jboss.osgi.spi.metadata.ServiceMetaData;
-
-/**
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
- */
-public class ServiceDeploymentDeployer extends AbstractComponentDeployer<ServiceDeployment, ServiceMetaData>
-{
- /**
- * Create a new ServiceDeploymentDeployer.
- */
- public ServiceDeploymentDeployer()
- {
- setDeploymentVisitor(new ServiceDeploymentVisitor());
- setComponentVisitor(new ServiceMetaDataVisitor());
- }
-
- protected static void addServiceComponent(DeploymentUnit unit, ServiceMetaData service)
- {
- DeploymentUnit component = unit.addComponent(service.getId());
- component.addAttachment(ServiceMetaData.class.getName(), service);
- }
-
- protected static void removeServiceComponent(DeploymentUnit unit, ServiceMetaData service)
- {
- unit.removeComponent(service.getId());
- }
-
- /**
- * ServiceDeploymentVisitor.
- */
- private static class ServiceDeploymentVisitor implements DeploymentVisitor<ServiceDeployment>
- {
- public Class<ServiceDeployment> getVisitorType()
- {
- return ServiceDeployment.class;
- }
-
- public void deploy(DeploymentUnit unit, ServiceDeployment deployment) throws DeploymentException
- {
- List<ServiceMetaData> services = deployment.getServices();
- for (ServiceMetaData service : services)
- addServiceComponent(unit, service);
- }
-
- public void undeploy(DeploymentUnit unit, ServiceDeployment deployment)
- {
- List<ServiceMetaData> services = deployment.getServices();
- for (ServiceMetaData service : services)
- removeServiceComponent(unit, service);
- }
- }
-
- /**
- * ServiceMetaDataVisitor.
- */
- private static class ServiceMetaDataVisitor implements DeploymentVisitor<ServiceMetaData>
- {
- public Class<ServiceMetaData> getVisitorType()
- {
- return ServiceMetaData.class;
- }
-
- public void deploy(DeploymentUnit unit, ServiceMetaData deployment) throws DeploymentException
- {
- addServiceComponent(unit, deployment);
- }
-
- public void undeploy(DeploymentUnit unit, ServiceMetaData deployment)
- {
- removeServiceComponent(unit, deployment);
- }
- }
-}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/bundle/OSGiBundleActivatorDeployer.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/bundle/OSGiBundleActivatorDeployer.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/bundle/OSGiBundleActivatorDeployer.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,70 @@
+/*
+* 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.plugins.deployers.bundle;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.osgi.plugins.facade.bundle.OSGiBundleState;
+
+/**
+ * OSGiBundleActivatorDeployer.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class OSGiBundleActivatorDeployer extends AbstractSimpleRealDeployer<OSGiBundleState>
+{
+ /**
+ * Create a new BundleStateDeployer.
+ */
+ public OSGiBundleActivatorDeployer()
+ {
+ super(OSGiBundleState.class);
+ }
+
+ @Override
+ public void deploy(DeploymentUnit unit, OSGiBundleState deployment) throws DeploymentException
+ {
+ try
+ {
+ deployment.startInternal();
+ }
+ catch (Throwable t)
+ {
+ throw DeploymentException.rethrowAsDeploymentException("Error starting bundle: " + deployment, t);
+ }
+ }
+
+ @Override
+ public void undeploy(DeploymentUnit unit, OSGiBundleState deployment)
+ {
+ try
+ {
+ deployment.stopInternal();
+ }
+ catch (Throwable t)
+ {
+ log.warn("Error stopping bundle: " + deployment, t);
+ }
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/bundle/OSGiBundleClassLoadingDeployer.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/bundle/OSGiBundleClassLoadingDeployer.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/bundle/OSGiBundleClassLoadingDeployer.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,98 @@
+/*
+* 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.plugins.deployers.bundle;
+
+import java.util.List;
+
+import org.jboss.classloading.plugins.metadata.ModuleCapability;
+import org.jboss.classloading.plugins.metadata.PackageCapability;
+import org.jboss.classloading.plugins.metadata.PackageRequirement;
+import org.jboss.classloading.spi.metadata.Capability;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentStages;
+import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.osgi.spi.metadata.OSGiMetaData;
+import org.jboss.osgi.spi.metadata.PackageAttribute;
+
+/**
+ * OSGiBundleClassLoadingDeployer.<p>
+ *
+ * This deployer maps osgi metadata into our classloading metadata.
+ *
+ * todo versions and attributes
+ * todo require-bundle, dynamic-imports, etc.
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class OSGiBundleClassLoadingDeployer extends AbstractSimpleRealDeployer<OSGiMetaData>
+{
+ /**
+ * Create a new OSGiBundleClassLoadingDeployer.
+ */
+ public OSGiBundleClassLoadingDeployer()
+ {
+ super(OSGiMetaData.class);
+ setTopLevelOnly(true);
+ setOutput(ClassLoadingMetaData.class);
+ setStage(DeploymentStages.POST_PARSE);
+ }
+
+ @Override
+ public void deploy(DeploymentUnit unit, OSGiMetaData deployment) throws DeploymentException
+ {
+ if (unit.isAttachmentPresent(ClassLoadingMetaData.class))
+ return;
+
+ ClassLoadingMetaData classLoadingMetaData = new ClassLoadingMetaData();
+ classLoadingMetaData.setName(deployment.getBundleSymbolicName());
+ classLoadingMetaData.setVersion(deployment.getBundleVersion());
+
+ Capability capability = new ModuleCapability(deployment.getBundleSymbolicName(), deployment.getBundleVersion());
+ classLoadingMetaData.getCapabilities().addCapability(capability);
+
+ List<PackageAttribute> exported = deployment.getExportPackages();
+ if (exported != null && exported.isEmpty() == false)
+ {
+ for (PackageAttribute packageAttribute : exported)
+ {
+ String packageName = packageAttribute.getPackageInfo().getName();
+ capability = new PackageCapability(packageName);
+ classLoadingMetaData.getCapabilities().addCapability(capability);
+ }
+ }
+
+ List<PackageAttribute> imported = deployment.getImportPackages();
+ if (imported != null && imported.isEmpty() == false)
+ {
+ for (PackageAttribute packageAttribute : imported)
+ {
+ String packageName = packageAttribute.getPackageInfo().getName();
+ PackageRequirement requirement = new PackageRequirement(packageName);
+ classLoadingMetaData.getRequirements().addRequirement(requirement);
+ }
+ }
+
+ unit.addAttachment(ClassLoadingMetaData.class, classLoadingMetaData);
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/bundle/OSGiBundleStateDeployer.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/bundle/OSGiBundleStateDeployer.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/bundle/OSGiBundleStateDeployer.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,76 @@
+/*
+* 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.plugins.deployers.bundle;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentStages;
+import org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.osgi.plugins.facade.bundle.OSGiBundleManager;
+import org.jboss.osgi.plugins.facade.bundle.OSGiBundleState;
+
+/**
+ * OSGiBundleStateDeployer.<p>
+ *
+ * This deployer creates a bundle state object for all top level deployments
+ * regardless of whether they are OSGi deployments or not.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class OSGiBundleStateDeployer extends AbstractRealDeployer
+{
+ /** The bundle manager */
+ private OSGiBundleManager bundleManager;
+
+ /**
+ * Create a new BundleStateDeployer.
+ *
+ * @param bundleManager the bundleManager
+ * @throws IllegalArgumentException for a null bundle manager
+ */
+ public OSGiBundleStateDeployer(OSGiBundleManager bundleManager)
+ {
+ if (bundleManager == null)
+ throw new IllegalArgumentException("Null bundle manager");
+ this.bundleManager = bundleManager;
+
+ setOutput(OSGiBundleState.class);
+ setStage(DeploymentStages.POST_PARSE);
+ setTopLevelOnly(true);
+ }
+
+ @Override
+ protected void internalDeploy(DeploymentUnit unit) throws DeploymentException
+ {
+ OSGiBundleState bundleState = bundleManager.addDeployment(unit);
+ unit.addAttachment(OSGiBundleState.class, bundleState);
+ }
+
+ @Override
+ protected void internalUndeploy(DeploymentUnit unit)
+ {
+ OSGiBundleState bundleState = unit.getAttachment(OSGiBundleState.class);
+ if (bundleState != null)
+ bundleManager.removeBundle(bundleState);
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/bundle/OSGiManifestParsingDeployer.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/bundle/OSGiManifestParsingDeployer.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployers/bundle/OSGiManifestParsingDeployer.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,58 @@
+/*
+* 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.plugins.deployers.bundle;
+
+import java.util.jar.Manifest;
+
+import org.jboss.deployers.vfs.spi.deployer.ManifestDeployer;
+import org.jboss.osgi.plugins.metadata.AbstractOSGiMetaData;
+import org.jboss.osgi.spi.metadata.OSGiMetaData;
+
+/**
+ * OSGiManifestParsingDeployer.<p>
+ *
+ * This deployer attaches OSGiMetaData to the deployment if it is a real OSGi bundle.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class OSGiManifestParsingDeployer extends ManifestDeployer<OSGiMetaData>
+{
+ /**
+ * Create a new OSGiManifestParsingDeployer.
+ */
+ public OSGiManifestParsingDeployer()
+ {
+ super(OSGiMetaData.class);
+ setTopLevelOnly(true); // REVIEW allow OSGi sub-deployments? Probably not?
+ }
+
+ @Override
+ protected OSGiMetaData createMetaData(Manifest manifest) throws Exception
+ {
+ // To be a true OSGi bundle it must have a bundle symbolic name in the manfiest
+ OSGiMetaData result = new AbstractOSGiMetaData(manifest);
+ if (result.getBundleSymbolicName() == null)
+ return null;
+ return result;
+ }
+}
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployment/xml/OSGiSchemaBindingHelper.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployment/xml/OSGiSchemaBindingHelper.java 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployment/xml/OSGiSchemaBindingHelper.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -28,7 +28,7 @@
*
* @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
*/
-// TODO - remove this --> move xml handling to jbossxb; JBOSGI-25
+// TDO - remove this --> move xml handling to jbossxb; JBOSGI-25
public class OSGiSchemaBindingHelper
{
public static void initServiceHandler(TypeBinding serviceType)
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployment/xml/ReferenceHandler.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployment/xml/ReferenceHandler.java 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployment/xml/ReferenceHandler.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -72,7 +72,7 @@
}
else if ("context-classloader".equals(localName))
{
- ClassLoaderMetaData clmd = null; // todo
+ ClassLoaderMetaData clmd = null; // tdo
referenceMetaData.setClassLoaderMetaData(clmd);
}
}
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployment/xml/ServiceHandler.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployment/xml/ServiceHandler.java 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/deployment/xml/ServiceHandler.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -69,7 +69,7 @@
}
else if ("context-classloader".equals(localName))
{
- ClassLoaderMetaData clmd = null; // todo
+ ClassLoaderMetaData clmd = null; // tdo
serviceMetaData.setClassLoaderMetaData(clmd);
}
}
Deleted: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/AbstractBundleEvent.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/AbstractBundleEvent.java 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/AbstractBundleEvent.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -1,45 +0,0 @@
-/*
-* 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 org.jboss.kernel.plugins.event.AbstractEvent;
-import org.osgi.framework.BundleEvent;
-
-/**
- * BundleEvent implementation on top of KernelEvent.
- *
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
- */
-public class AbstractBundleEvent extends AbstractEvent implements BundleEventAdapter
-{
- // todo - bundle event type, Bundle
- public AbstractBundleEvent(Object source, String type, long sequence, long timestamp, Object context)
- {
- super(source, type, sequence, timestamp, context);
- }
-
- public BundleEvent getEvent()
- {
- int bundleType = 0;
- return new BundleEvent(bundleType, null);
- }
-}
Deleted: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/AbstractDelegateListener.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/AbstractDelegateListener.java 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/AbstractDelegateListener.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -1,66 +0,0 @@
-/*
-* 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 org.jboss.kernel.spi.event.KernelEventListener;
-
-/**
- * Delegate implementation on top of existing KernelEventListener.
- *
- * @param <T> Listener type
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
- */
-public abstract class AbstractDelegateListener<T> implements KernelEventListener
-{
- protected T delegate;
-
- public AbstractDelegateListener(T delegate)
- {
- if (delegate == null)
- throw new IllegalArgumentException("Listener is null!");
- this.delegate = delegate;
- }
-
- /**
- * Common add / remove validate.
- */
- protected void validate()
- {
- }
-
- /**
- * Validate if we are allowed to add this listener
- */
- protected void addValidate()
- {
- validate();
- }
-
- /**
- * Validate if we ar eallowed to remove this listener
- */
- protected void removeValidate()
- {
- validate();
- }
-
-}
Deleted: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/AbstractFrameworkEvent.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/AbstractFrameworkEvent.java 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/AbstractFrameworkEvent.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -1,45 +0,0 @@
-/*
-* 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 org.jboss.kernel.plugins.event.AbstractEvent;
-import org.osgi.framework.FrameworkEvent;
-
-/**
- * BundleEvent implementation on top of KernelEvent.
- *
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
- */
-public class AbstractFrameworkEvent extends AbstractEvent implements FrameworkEventAdapter
-{
- // todo - framework event type, Bundle
- public AbstractFrameworkEvent(Object source, String type, long sequence, long timestamp, Object context)
- {
- super(source, type, sequence, timestamp, context);
- }
-
- public FrameworkEvent getEvent()
- {
- int frameworkType = 0;
- return new FrameworkEvent(frameworkType, null, null);
- }
-}
Deleted: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/AbstractServiceEvent.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/AbstractServiceEvent.java 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/AbstractServiceEvent.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -1,59 +0,0 @@
-/*
-* 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 org.jboss.kernel.plugins.event.AbstractEvent;
-import org.jboss.kernel.spi.registry.KernelRegistry;
-import org.osgi.framework.ServiceEvent;
-
-/**
- * ServiceEvent implementation on top of KernelEvent.
- *
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
- */
- at SuppressWarnings("deprecation")
-public class AbstractServiceEvent extends AbstractEvent implements ServiceEventAdapter
-{
- // todo - ServiceReference
- public AbstractServiceEvent(Object source, String type, long sequence, long timestamp, Object context)
- {
- super(source, type, sequence, timestamp, context);
- }
-
- public ServiceEvent getEvent()
- {
- int serviceType = 0;
- if (KernelRegistry.KERNEL_REGISTRY_REGISTERED.equals(type))
- {
- serviceType = ServiceEvent.REGISTERED;
- }
- else if (KernelRegistry.KERNEL_REGISTRY_MODIFIED.equals(type))
- {
- serviceType = ServiceEvent.MODIFIED;
- }
- else if (KernelRegistry.KERNEL_REGISTRY_UNREGISTERED.equals(type))
- {
- serviceType = ServiceEvent.UNREGISTERING;
- }
- return new ServiceEvent(serviceType, null);
- }
-}
Deleted: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/BundleContextImpl.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/BundleContextImpl.java 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/BundleContextImpl.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -1,468 +0,0 @@
-/*
-* 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.File;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Dictionary;
-import java.util.EventListener;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.jboss.beans.metadata.plugins.builder.BeanMetaDataBuilderFactory;
-import org.jboss.beans.metadata.spi.BeanMetaData;
-import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.kernel.spi.config.KernelConfigurator;
-import org.jboss.kernel.spi.dependency.KernelController;
-import org.jboss.kernel.spi.dependency.KernelControllerContext;
-import org.jboss.kernel.spi.event.KernelEvent;
-import org.jboss.kernel.spi.event.KernelEventEmitter;
-import org.jboss.kernel.spi.event.KernelEventFilter;
-import org.jboss.kernel.spi.event.KernelEventListener;
-import org.jboss.logging.Logger;
-import org.jboss.reflect.spi.ClassInfo;
-import org.jboss.util.id.GUID;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-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;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceFactory;
-import org.osgi.framework.ServiceListener;
-import org.osgi.framework.ServiceReference;
-import org.osgi.framework.ServiceRegistration;
-
-/**
- * Bundle context implementation on top of existing DeploymentContext.
- *
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
- */
-public class BundleContextImpl implements BundleContext, KernelEventEmitter
-{
- /** The log */
- private static final Logger log = Logger.getLogger(BundleContextImpl.class);
- /** The service reference comparator */
- private static Comparator<ServiceReference> serviceRefenceComparator = new ServiceReferenceComparator();
-
- protected DeploymentUnit context;
- protected Bundle bundle;
- protected KernelController controller; // todo - get it
- protected KernelEventEmitter emitterDelegate; // todo - get it
- protected KernelConfigurator configurator; // todo - get it
-
- protected Map<EventListener, AbstractDelegateListener<?>> listeners = Collections.synchronizedMap(new HashMap<EventListener, AbstractDelegateListener<?>>());
- protected Map<ServiceListener, KernelEventFilter> filters = Collections.synchronizedMap(new HashMap<ServiceListener, KernelEventFilter>());
-
- public BundleContextImpl(DeploymentUnit context)
- {
- this.context = context;
- }
-
- protected boolean isBundleContextValid()
- {
- return true;
- }
-
- protected void validateBundle() throws IllegalStateException
- {
- if (isBundleContextValid() == false)
- throw new IllegalStateException("BundleContext is no longer valid.");
- }
-
- protected ClassLoader getClassLoader()
- {
- return null;
- }
-
- public void registerListener(KernelEventListener listener, KernelEventFilter filter, Object handback) throws Throwable
- {
- emitterDelegate.registerListener(listener, filter, handback);
- }
-
- public void unregisterListener(KernelEventListener listener, KernelEventFilter filter, Object handback) throws Throwable
- {
- emitterDelegate.unregisterListener(listener, filter, handback);
- }
-
- public void fireKernelEvent(KernelEvent event)
- {
- emitterDelegate.fireKernelEvent(event);
- }
-
- // --------------- OSGi framework -----------------------
-
- public String getProperty(String string)
- {
- return null; // TODO
- }
-
- public Bundle getBundle()
- {
- if (bundle == null)
- {
- bundle = new BundleImpl(context);
- }
- return bundle;
- }
-
- public Bundle installBundle(String string) throws BundleException
- {
- throw new UnsupportedOperationException("not yet implemented");
- }
-
- public Bundle installBundle(String string, InputStream inputStream) throws BundleException
- {
- throw new UnsupportedOperationException("not yet implemented");
- }
-
- public Bundle getBundle(long id)
- {
- return null; // TODO
- }
-
- public Bundle[] getBundles()
- {
- return new Bundle[0]; // TODO
- }
-
- public void addServiceListener(ServiceListener serviceListener, String filter) throws InvalidSyntaxException
- {
- // todo - conditional add
- validateBundle();
- // remove the existing first
- if (listeners.containsKey(serviceListener))
- {
- removeServiceListener(serviceListener);
- }
- // create new one
- ServiceListenerImpl listener = new ServiceListenerImpl(serviceListener);
- listener.addValidate();
- OSGiKernelEventFilter eventFilter = null;
- if (filter != null)
- {
- eventFilter = new OSGiKernelEventFilter(filter);
- filters.put(serviceListener, eventFilter);
- }
- try
- {
- registerListener(listener, eventFilter, this);
- listeners.put(serviceListener, listener);
- }
- catch (Throwable throwable)
- {
- filters.remove(serviceListener);
- // todo - throw what?
- throw new IllegalArgumentException(throwable);
- }
- }
-
- public void addServiceListener(ServiceListener serviceListener)
- {
- try
- {
- addServiceListener(serviceListener, null);
- }
- catch (InvalidSyntaxException ignored)
- {
- }
- }
-
- public void removeServiceListener(ServiceListener serviceListener)
- {
- validateBundle();
- AbstractDelegateListener<?> listener = listeners.get(serviceListener);
- if (listener != null)
- {
- listener.removeValidate();
- KernelEventFilter filter = filters.get(serviceListener);
- try
- {
- unregisterListener(listener, filter, this);
- }
- catch (Throwable t)
- {
- log.warn("Exception while unregistering Service listener.", t);
- }
- finally
- {
- listeners.remove(serviceListener);
- if (filter != null)
- {
- filters.remove(serviceListener);
- }
- }
- }
- }
-
- public void addBundleListener(BundleListener bundleListener)
- {
- validateBundle();
- if (listeners.containsKey(bundleListener) == false)
- {
- BundleListenerImpl listener = new BundleListenerImpl(bundleListener);
- listener.addValidate();
- try
- {
- registerListener(listener, null, this);
- listeners.put(bundleListener, listener);
- }
- catch (Throwable t)
- {
- throw new IllegalArgumentException(t);
- }
- }
- }
-
- public void removeBundleListener(BundleListener bundleListener)
- {
- validateBundle();
- AbstractDelegateListener<?> listener = listeners.get(bundleListener);
- if (listener != null)
- {
- listener.removeValidate();
- try
- {
- unregisterListener(listener, null, this);
- }
- catch (Throwable t)
- {
- log.warn("Exception while unregistering Bundle listener.", t);
- }
- finally
- {
- listeners.remove(bundleListener);
- }
- }
- }
-
- public void addFrameworkListener(FrameworkListener frameworkListener)
- {
- validateBundle();
- if (listeners.containsKey(frameworkListener) == false)
- {
- FrameworkListenerImpl listener = new FrameworkListenerImpl(frameworkListener);
- listener.addValidate();
- try
- {
- registerListener(listener, null, this);
- listeners.put(frameworkListener, listener);
- }
- catch (Throwable t)
- {
- throw new IllegalArgumentException(t);
- }
- }
- }
-
- public void removeFrameworkListener(FrameworkListener frameworkListener)
- {
- validateBundle();
- AbstractDelegateListener<?> listener = listeners.get(frameworkListener);
- if (listener != null)
- {
- listener.removeValidate();
- try
- {
- unregisterListener(listener, null, this);
- }
- catch (Throwable t)
- {
- log.warn("Exception while unregistering Framework listener.", t);
- }
- finally
- {
- listeners.remove(frameworkListener);
- }
- }
- }
-
- @SuppressWarnings({"unchecked", "deprecation"})
- public ServiceRegistration registerService(String[] clazzes, Object service, Dictionary properties)
- {
- validateBundle();
- // todo - permissions
- if (service == null)
- throw new IllegalArgumentException("service is null!");
- if (clazzes == null)
- throw new Error("null clazzes parameter!"); // todo - what else?
-
- ClassInfo serviceInfo;
- ClassInfo[] infos = new ClassInfo[clazzes.length];
- Class<?>[] interfaces = new Class[clazzes.length];
- try
- {
- serviceInfo = configurator.getClassInfo(service.getClass());
- for(int i=0; i < clazzes.length; i++)
- {
- infos[i] = configurator.getClassInfo(clazzes[i], getClassLoader());
- interfaces[i] = infos[i].getType();
- }
- }
- catch (Throwable t)
- {
- throw new InternalOSGiFacadeException(t);
- }
- // check types
- boolean isServiceFactory = (service instanceof ServiceFactory);
- if (isServiceFactory == false)
- {
- for (ClassInfo info : infos)
- {
- if (info.isAssignableFrom(serviceInfo) == false)
- throw new IllegalArgumentException("service is not a ServiceFactory object and is not an instance of all the named classes in clazzes: " + info);
- }
- }
- // handle properties
- Map<String, Object> serviceMap = OSGiUtils.toMap(properties);
- Long serviceId = NumberUtil.nextLong();
- serviceMap.put(Constants.SERVICE_ID, serviceId);
- serviceMap.put(Constants.OBJECTCLASS, clazzes);
- if (isServiceFactory)
- {
- service = ServiceFactoryProxy.createProxy(service, interfaces);
- }
- BeanMetaDataBuilder builder = BeanMetaDataBuilderFactory.createBuilder(GUID.asString(), serviceInfo.getName());
- BeanMetaData metaData = builder.getBeanMetaData();
- KernelControllerContext context;
- try
- {
- context = controller.install(metaData, service);
- }
- catch (Throwable t)
- {
- throw new InternalOSGiFacadeException(t);
- }
- // todo - get underlying bundle --> ServiceReference
- return new ServiceRegistrationImpl(this, context, serviceId, serviceMap);
- }
-
- @SuppressWarnings("unchecked")
- public ServiceRegistration registerService(String clazz, Object service, Dictionary properties)
- {
- return registerService(new String[]{clazz}, service, properties);
- }
-
- public ServiceReference[] getAllServiceReferences(String clazz, String filter) throws InvalidSyntaxException
- {
- validateBundle();
- // todo - see spec API
- return null;
- }
-
- public ServiceReference[] getServiceReferences(String clazz, String filter) throws InvalidSyntaxException
- {
- ServiceReference[] references = getAllServiceReferences(clazz, filter);
- if (references != null && references.length > 0)
- {
- List<ServiceReference> list = new ArrayList<ServiceReference>();
- for(ServiceReference ref : references)
- {
- String[] clazzes = (String[])ref.getProperty(Constants.OBJECTCLASS);
- for (String refClass : clazzes)
- {
- if (ref.isAssignableTo(getBundle(), refClass))
- {
- list.add(ref);
- }
- }
- }
- Collections.sort(list, serviceRefenceComparator);
- return list.toArray(new ServiceReference[list.size()]);
- }
- else
- {
- return null;
- }
- }
-
- public ServiceReference getServiceReference(String clazz)
- {
- validateBundle();
- try
- {
- ServiceReference[] references = getServiceReferences(clazz, null);
- if (references != null && references.length > 0)
- {
- // watch for the order in getServiceReferences
- return references[0];
- }
- return null;
- }
- catch (InvalidSyntaxException e)
- {
- throw new InternalOSGiFacadeException("Should not be here, since filter was null!");
- }
- }
-
- public Object getService(ServiceReference reference)
- {
- validateBundle();
- return null;
- }
-
- public boolean ungetService(ServiceReference reference)
- {
- validateBundle();
- return false; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public File getDataFile(String filename)
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public Filter createFilter(String filter) throws InvalidSyntaxException
- {
- validateBundle();
- // todo - create our own impl?
- return FrameworkUtil.createFilter(filter);
- }
-
- /**
- * @see org.osgi.framework.BundleContext#getServiceReferences(String, String)
- */
- private static class ServiceReferenceComparator implements Comparator<ServiceReference>
- {
- public int compare(ServiceReference sr1, ServiceReference sr2)
- {
- int rank1 = OSGiUtils.getServiceRanking(sr1);
- int rank2 = OSGiUtils.getServiceRanking(sr2);
- if (rank1 == rank2)
- {
- long id1 = OSGiUtils.getServiceId(sr1);
- long id2 = OSGiUtils.getServiceId(sr2);
- return (int)(id1 - id2);
- }
- return rank2 - rank1;
- }
- }
-
-}
Deleted: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/BundleEventAdapter.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/BundleEventAdapter.java 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/BundleEventAdapter.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -1,33 +0,0 @@
-/*
-* 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 org.osgi.framework.BundleEvent;
-
-/**
- * BundleEvent contract.
- *
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
- */
-public interface BundleEventAdapter extends EventAdapter<BundleEvent>
-{
-}
Deleted: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/BundleImpl.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/BundleImpl.java 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/BundleImpl.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -1,372 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, 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 org.jboss.dependency.spi.ControllerContext;
-import org.jboss.deployers.client.spi.DeployerClient;
-import org.jboss.deployers.spi.DeploymentException;
-import org.jboss.deployers.spi.deployer.DeploymentStages;
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
-import org.jboss.logging.Logger;
-import org.jboss.osgi.plugins.facade.helpers.BundleEntryHelper;
-import org.jboss.osgi.plugins.facade.helpers.BundleHeaders;
-import org.jboss.osgi.plugins.facade.helpers.DeploymentStage2BundleStateMapper;
-import org.jboss.virtual.VirtualFile;
-import org.osgi.framework.AdminPermission;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-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
-{
- /** The log */
- private static final Logger log = Logger.getLogger(BundleImpl.class);
-
- protected DeploymentUnit unit;
-
- protected BundleHeaders bundleHeaders;
-
- private long lastModified = System.currentTimeMillis();
-
- /**
- * Create a new BundleImpl.
- *
- * @param unit the DeploymentUnit
- */
- public BundleImpl(DeploymentUnit unit)
- {
- this.unit = unit;
-
- }
-
- /**
- * Get Bundle state based on the current DeployentStage
- *
- * @return the Bundle's state
- */
- public int getState()
- {
- try
- {
- return DeploymentStage2BundleStateMapper.mapBundleState(unit.getMainDeployer().getDeploymentStage(unit.getName())).getState();
- }
- catch (DeploymentException e)
- {
- log.error("Unable to get DeploymentStage for DeploymentUnit " + unit.getName(), e);
- return Bundle.INSTALLED;
- }
- }
-
- /**
- * Start the Bundle
- */
- public void start() throws BundleException
- {
- checkPermission(AdminPermission.EXECUTE);
- try
- {
- DeployerClient main = unit.getMainDeployer();
- main.change(unit.getName(), DeploymentStages.INSTALLED);
- }
- catch (DeploymentException e)
- {
- throw new BundleException("Failed to start Bundle", e);
- }
- }
-
- public void stop() throws BundleException
- {
- checkPermission(AdminPermission.EXECUTE);
- try
- {
- DeployerClient main = unit.getMainDeployer();
- main.change(unit.getName(), DeploymentStages.DESCRIBE);
- }
- catch (DeploymentException e)
- {
- throw new BundleException("Failed to stop Bundle", e);
- }
- }
-
- public void update() throws BundleException
- {
- checkPermission(AdminPermission.LIFECYCLE);
- }
-
- public void update(InputStream inputStream) throws BundleException
- {
- checkPermission(AdminPermission.LIFECYCLE);
- }
-
- public void uninstall() throws BundleException
- {
- checkPermission(AdminPermission.LIFECYCLE);
- try
- {
- DeployerClient main = unit.getMainDeployer();
- main.change(unit.getName(), DeploymentStages.NOT_INSTALLED);
- }
- catch (DeploymentException e)
- {
- throw new BundleException("Failed to uninstall Bundle", e);
- }
- }
-
- public long getBundleId()
- {
- checkPermission(AdminPermission.METADATA);
- return unit.getName().hashCode();
- }
-
- public String getLocation()
- {
- checkPermission(AdminPermission.METADATA);
- if (unit instanceof VFSDeploymentUnit)
- {
- VFSDeploymentUnit vfsUnit = VFSDeploymentUnit.class.cast(unit);
- VirtualFile file = vfsUnit.getRoot();
- return file.getPathName();
- }
- return null; // TODO What if the DeploymentUnit is not VFS
- }
-
- public ServiceReference[] getRegisteredServices()
- {
- return new ServiceReference[0];
- }
-
- public ServiceReference[] getServicesInUse()
- {
- return new ServiceReference[0];
- }
-
- public boolean hasPermission(Object permission)
- {
- if (permission instanceof Permission)
- {
- try
- {
- // TODO check if bundle implies the permission
- }
- catch (SecurityException se)
- {
- return false;
- }
- }
- return true;
- }
-
- /**
- * Get the Bundle's headers
- *
- * @return the Bundle's headers
- */
- @SuppressWarnings("unchecked")
- public Dictionary getHeaders()
- {
- return getHeaders(Locale.getDefault().toString());
- }
-
- @SuppressWarnings("unchecked")
- public Dictionary getHeaders(String locale)
- {
- checkPermission(AdminPermission.METADATA);
- if (bundleHeaders == null)
- {
- bundleHeaders = new BundleHeaders(unit);
- }
- return bundleHeaders.toDictionary();
- }
-
- /**
- * Get the Bundle's symbolic name
- *
- * @return the Bundle's symbolic name
- */
- public String getSymbolicName()
- {
- return (String) getControllerContext().getName();
- }
-
- /**
- * Load class from Bundles classloader
- *
- * @param name a class name
- * @return the class
- * @throws ClassNotFoundException If the class can not be loaded by DeploymentUnit ClassLoader
- * @throws IllegalStateException If the DeploymentUnit classloader is not set
- */
- public Class<?> loadClass(String name) throws ClassNotFoundException
- {
- checkPermission(AdminPermission.CLASS);
- checkForUninstalledDeploymentUnit();
- return unit.getClassLoader().loadClass(name);
-
- }
-
- /**
- * Get resource from Bundle classloader
- *
- * @param name a resource name
- * @return URL URL to resource
- */
- public URL getResource(String name)
- {
- checkPermission(AdminPermission.RESOURCE);
- checkForUninstalledDeploymentUnit();
- return unit.getClassLoader().getResource(name); // TODO Should it propagate the IllegalStateException or trap and return null?
- }
-
- /**
- * Get resources from bundle classloader
- *
- * @param name a resource name
- * @return Enumeration of URLs to resources
- */
- public Enumeration getResources(String name) throws IOException
- {
- checkPermission(AdminPermission.RESOURCE);
- checkForUninstalledDeploymentUnit();
- return unit.getClassLoader().getResources(name); // TODO Should it propagate the IllegalStateException or trap and return null?
- }
-
- /**
- * Get paths to entries in Bundle for a given directory
- *
- * @param dirPath the dir path
- * @return Enumeration of URLs to entries in Bundle
- */
- public Enumeration getEntryPaths(String dirPath)
- {
- checkPermission(AdminPermission.RESOURCE);
- return BundleEntryHelper.getEntryPaths(unit, dirPath);
- }
-
- /**
- * Get an entry from the bundle
- *
- * @param path path to entry
- * @return URL to entry
- */
- public URL getEntry(String path)
- {
- checkPermission(AdminPermission.RESOURCE);
- return BundleEntryHelper.getEntry(unit, path);
- }
-
- public long getLastModified()
- {
- return lastModified;
- }
-
- /**
- * Search Bundle for entries
- *
- * @param path base path in Bundle
- * @param filePattern pattern used to select files
- * @param recurse should search recurse directories
- * @return Enumeration of URLs to matched entries
- */
- public Enumeration findEntries(String path, String filePattern, boolean recurse)
- {
- checkPermission(AdminPermission.RESOURCE);
- return BundleEntryHelper.findEntries(unit, path, filePattern, recurse);
- }
-
- /**
- * Returns the ControllerContext for the DeploymentUnit
- *
- * @return the ControllerContext
- */
- private ControllerContext getControllerContext()
- {
- return unit.getAttachment(ControllerContext.class.getName(), ControllerContext.class);
- }
-
- /**
- * Checks administrative permissions
- *
- * @param adminPermission the permission to check
- */
- private void checkPermission(String adminPermission)
- {
- if (System.getSecurityManager() != null)
- {
- System.getSecurityManager().checkPermission(new AdminPermission(this, adminPermission));
- }
- }
-
- /**
- * Checks to see if the DeploymentUnit has been uninstalled.
- *
- * @throws IllegalStateException If there is a problem determining the DeploymentUnitState
- */
- private void checkForUninstalledDeploymentUnit()
- {
- try
- {
- if (DeploymentStages.NOT_INSTALLED.equals(unit.getMainDeployer().getDeploymentStage(unit.getName())))
- {
- throw new IllegalStateException("Bundle has been uninstalled");
- }
- }
- catch (DeploymentException e)
- {
- throw new IllegalStateException("Failed to determine current DeploymentStage for Deployment: "
- + unit.getName(), e);
- }
- }
-
- public BundleContext getBundleContext()
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- public void start(int options) throws BundleException
- {
- // TODO Auto-generated method stub
-
- }
-
- public void stop(int options) throws BundleException
- {
- // TODO Auto-generated method stub
-
- }
-}
Deleted: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/BundleListenerImpl.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/BundleListenerImpl.java 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/BundleListenerImpl.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -1,72 +0,0 @@
-/*
-* 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 org.jboss.kernel.spi.event.KernelEvent;
-import org.osgi.framework.BundleListener;
-import org.osgi.framework.SynchronousBundleListener;
-
-/**
- * BundleListenerImpl implementation on top of KernelEventListener.
- * Handles both SynchronousBundleListener and simple BundleListener.
- *
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
- */
-public class BundleListenerImpl extends AbstractDelegateListener<BundleListener>
-{
- private boolean isSynchronous;
-
- public BundleListenerImpl(BundleListener delegate)
- {
- super(delegate);
- isSynchronous = (delegate instanceof SynchronousBundleListener);
- }
-
- /**
- * Is the listener synchronous.
- *
- * @return synchhronous
- */
- public boolean isSynchronous()
- {
- return isSynchronous;
- }
-
- protected void validate()
- {
- if (isSynchronous())
- {
- // todo - check appropriate AdminPermission[context bundle,LISTENER]
- }
- }
-
- // todo - synchrounous stuff
- public void onEvent(KernelEvent event, Object handback)
- {
- if (event instanceof BundleEventAdapter)
- {
- BundleEventAdapter adapter = (BundleEventAdapter)event;
- delegate.bundleChanged(adapter.getEvent());
- }
- }
-
-}
Deleted: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/BundleState.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/BundleState.java 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/BundleState.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -1,63 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, 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 org.osgi.framework.Bundle;
-
-/**
- * A BundleState enum to wrap the non-type-safe Bundle state constants
- *
- * @author <a href="baileyje at gmail.com">John Bailey</a>
- * @version $Revision$
- */
-public enum BundleState {
-
- UNINSTALLED(Bundle.UNINSTALLED),
- INSTALLED(Bundle.INSTALLED),
- RESOLVED(Bundle.RESOLVED),
- STARTING(Bundle.STARTING),
- STOPPING(Bundle.STOPPING),
- ACTIVE(Bundle.ACTIVE);
-
- private final int state;
-
- /**
- *
- * Create a new BundleState.
- *
- * @param state the state number
- */
- private BundleState(final int state)
- {
- this.state = state;
- }
-
- /**
- * Get Bundle state
- *
- * @return the state
- */
- public int getState()
- {
- return state;
- }
-}
Deleted: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/EventAdapter.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/EventAdapter.java 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/EventAdapter.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -1,33 +0,0 @@
-/*
-* 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;
-
-/**
- * Event adapter contract.
- *
- * @param <E> event type
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
- */
-public interface EventAdapter<E>
-{
- E getEvent();
-}
Deleted: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/FilterImpl.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/FilterImpl.java 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/FilterImpl.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -1,69 +0,0 @@
-/*
-* 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.util.Dictionary;
-
-import org.jboss.kernel.spi.event.KernelEvent;
-import org.jboss.kernel.spi.event.KernelEventFilter;
-import org.osgi.framework.Filter;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
-
-/**
- * OSGi Filter contract on top of KernelEventFilter.
- *
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
- */
-public class FilterImpl implements KernelEventFilter, Filter
-{
- protected String filter;
- protected OSGiKernelEventFilter eventFilter;
-
- public FilterImpl(String filter) throws InvalidSyntaxException
- {
- this.filter = filter;
- this.eventFilter = new OSGiKernelEventFilter(filter);
- }
-
- public boolean wantEvent(KernelEvent event, Object handback)
- {
- return eventFilter.wantEvent(event, handback);
- }
-
- public boolean match(ServiceReference serviceReference)
- {
- return false; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- @SuppressWarnings("unchecked")
- public boolean match(Dictionary dictionary)
- {
- return false; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- @SuppressWarnings("unchecked")
- public boolean matchCase(Dictionary dictionary)
- {
- return false; //To change body of implemented methods use File | Settings | File Templates.
- }
-}
Deleted: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/FrameworkEventAdapter.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/FrameworkEventAdapter.java 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/FrameworkEventAdapter.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -1,33 +0,0 @@
-/*
-* 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 org.osgi.framework.FrameworkEvent;
-
-/**
- * FrameworkEvent contract.
- *
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
- */
-public interface FrameworkEventAdapter extends EventAdapter<FrameworkEvent>
-{
-}
Deleted: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/FrameworkListenerImpl.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/FrameworkListenerImpl.java 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/FrameworkListenerImpl.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -1,47 +0,0 @@
-/*
-* 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 org.jboss.kernel.spi.event.KernelEvent;
-import org.osgi.framework.FrameworkListener;
-
-/**
- * FrameworkListener implementation on top of existing KernelEventListener.
- *
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
- */
-public class FrameworkListenerImpl extends AbstractDelegateListener<FrameworkListener>
-{
- public FrameworkListenerImpl(FrameworkListener delegate)
- {
- super(delegate);
- }
-
- public void onEvent(KernelEvent event, Object handback)
- {
- if (event instanceof FrameworkEventAdapter)
- {
- FrameworkEventAdapter adapter = (FrameworkEventAdapter)event;
- delegate.frameworkEvent(adapter.getEvent());
- }
- }
-}
Deleted: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/InternalOSGiFacadeException.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/InternalOSGiFacadeException.java 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/InternalOSGiFacadeException.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -1,54 +0,0 @@
-/*
-* 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;
-
-/**
- * Signaling internal exception - container, dependency, kernel related.
- *
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
- */
-public class InternalOSGiFacadeException extends RuntimeException
-{
- /** The serialVersionUID */
- private static final long serialVersionUID = 9213483035127929387L;
-
- public InternalOSGiFacadeException()
- {
- super();
- }
-
- public InternalOSGiFacadeException(String message)
- {
- super(message);
- }
-
- public InternalOSGiFacadeException(String message, Throwable cause)
- {
- super(message, cause);
- }
-
- public InternalOSGiFacadeException(Throwable cause)
- {
- super(cause);
- }
-
-}
Deleted: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/NumberUtil.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/NumberUtil.java 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/NumberUtil.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -1,50 +0,0 @@
-/*
-* 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.util.concurrent.atomic.AtomicLong;
-
-/**
- * Unique numbering util.
- * todo - should we do this more generic?
- *
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
- */
-public class NumberUtil
-{
- private static AtomicLong longOrder = new AtomicLong(Long.MIN_VALUE);
-
- private NumberUtil()
- {
- }
-
- /**
- * Return next long.
- *
- * @return unique Long number
- */
- public static Long nextLong()
- {
- return longOrder.getAndIncrement();
- }
-
-}
Deleted: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/OSGiKernelEventFilter.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/OSGiKernelEventFilter.java 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/OSGiKernelEventFilter.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -1,52 +0,0 @@
-/*
-* 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 org.jboss.kernel.spi.event.KernelEvent;
-import org.jboss.kernel.spi.event.KernelEventFilter;
-import org.osgi.framework.InvalidSyntaxException;
-
-/**
- * OSGi Filter contract on top of KernelEventFilter.
- *
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
- */
-public class OSGiKernelEventFilter implements KernelEventFilter
-{
- protected String filter;
-
- public OSGiKernelEventFilter(String filter) throws InvalidSyntaxException
- {
- this.filter = filter;
- validateFilterString();
- }
-
- protected void validateFilterString()
- {
- // todo
- }
-
- public boolean wantEvent(KernelEvent event, Object handback)
- {
- return false; //To change body of implemented methods use File | Settings | File Templates.
- }
-}
Deleted: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/OSGiUtils.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/OSGiUtils.java 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/OSGiUtils.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -1,99 +0,0 @@
-/*
-* 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.util.Dictionary;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
-
-/**
- * Helpful methods for handling specific OSGi cases.
- *
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
- */
-public abstract class OSGiUtils
-{
- /**
- * Transform from Dictionary to Map
- *
- * @param dictionary dictionary to transform
- * @return Map<String, Object>
- */
- @SuppressWarnings("unchecked")
- public static Map<String, Object> toMap(Dictionary dictionary)
- {
- Map<String, Object> map = new HashMap<String, Object>();
- if (dictionary != null && dictionary.size() > 0)
- {
- Enumeration keys = dictionary.keys();
- while(keys.hasMoreElements())
- {
- String key = keys.nextElement().toString();
- Object value = dictionary.get(key);
- map.put(key, value);
- }
- }
- return map;
- }
-
- /**
- * Get ServiceReference id.
- *
- * @param reference service reference to look for id
- * @return reference's id or error if no such property
- */
- public static Long getServiceId(ServiceReference reference)
- {
- Object value = reference.getProperty(Constants.SERVICE_RANKING);
- if (value == null || value instanceof Long == false)
- {
- throw new IllegalArgumentException("No such property: " + Constants.SERVICE_ID);
- }
- else
- {
- return (Long)value;
- }
- }
-
- /**
- * Get ServiceReference ranking.
- *
- * @param reference service reference to look for ranking
- * @return reference's ranking or 0 if no such property
- */
- public static Integer getServiceRanking(ServiceReference reference)
- {
- Object value = reference.getProperty(Constants.SERVICE_RANKING);
- if (value == null || value instanceof Integer == false)
- {
- return 0;
- }
- else
- {
- return (Integer)value;
- }
- }
-}
Deleted: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/ServiceEventAdapter.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/ServiceEventAdapter.java 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/ServiceEventAdapter.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -1,33 +0,0 @@
-/*
-* 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 org.osgi.framework.ServiceEvent;
-
-/**
- * ServiceEvent contract.
- *
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
- */
-public interface ServiceEventAdapter extends EventAdapter<ServiceEvent>
-{
-}
Deleted: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/ServiceFactoryProxy.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/ServiceFactoryProxy.java 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/ServiceFactoryProxy.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -1,124 +0,0 @@
-/*
-* 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.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import java.util.Arrays;
-
-import org.osgi.framework.ServiceFactory;
-
-/**
- * An implementation of InvocationHandler used to proxy of the ServiceFactory
- * interface for OSGi services.
- *
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
- */
-public class ServiceFactoryProxy implements InvocationHandler
-{
- public static final String GET_SERVICE = "getService";
- public static final String UNGET_SERVICE = "ungetService";
-
-/*
- private static final Logger log = Logger.getLogger(ServiceFactoryProxy.class);
-
- public static Method GET_SERVICE_METHOD;
- static
- {
- try
- {
- GET_SERVICE_METHOD = ServiceFactory.class.getMethod(GET_SERVICE, Bundle.class, ServiceRegistration.class);
- }
- catch (NoSuchMethodException e)
- {
- log.error("Unable to prepare getService method.", e);
- }
- }
-*/
- protected Object serviceFactory;
- protected Class<?>[] interfaces;
- protected Object service;
- protected Boolean checked;
-
- private ServiceFactoryProxy(Object serviceFactory, Class<?>[] interfaces)
- {
- this.serviceFactory = serviceFactory;
- this.interfaces = interfaces;
- }
-
- public static Object createProxy(Object serviceFactory, Class<?>[] interfaces)
- {
- int lenght = interfaces.length;
- Class<?>[] allIntefaces = new Class[lenght + 1];
- System.arraycopy(interfaces, 0, allIntefaces, 0, lenght);
- allIntefaces[lenght] = ServiceFactory.class;
- InvocationHandler handler = new ServiceFactoryProxy(serviceFactory, interfaces);
- return Proxy.newProxyInstance(ServiceFactory.class.getClassLoader(), allIntefaces, handler);
- }
-
- protected boolean checkInterfaces()
- {
- // already checked
- if (checked != null)
- return checked;
- // can be null
- if (service == null)
- return true;
-
- Class<?> serviceInterface = service.getClass();
- for(Class<?> exposedInterface : interfaces)
- {
- if (exposedInterface.isAssignableFrom(serviceInterface) == false)
- {
- return (checked = false);
- }
- }
- return (checked = true);
- }
-
- public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
- {
- String methodName = method.getName();
- if (GET_SERVICE.equals(methodName))
- {
- service = method.invoke(serviceFactory, args);
- if (checkInterfaces() == false)
- return null;
- return service;
- }
- else if (UNGET_SERVICE.equals(methodName))
- {
- service = null;
- checked = null;
- return method.invoke(serviceFactory, args);
- }
- else
- {
- if (service == null)
- throw new IllegalStateException("Service not yet created from ServiceFactory!"); // todo - or create it now?
- if (checkInterfaces() == false)
- throw new IllegalArgumentException("Illegal exposed interfaces: " + service + "; " + Arrays.asList(interfaces));
- return method.invoke(service, args);
- }
- }
-}
Deleted: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/ServiceListenerImpl.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/ServiceListenerImpl.java 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/ServiceListenerImpl.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -1,63 +0,0 @@
-/*
-* 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 org.jboss.kernel.spi.event.KernelEvent;
-import org.osgi.framework.AllServiceListener;
-import org.osgi.framework.ServiceListener;
-
-/**
- * ServiceListenerImpl implementation on top of existing KernelEventListener.
- * Handles both AllServiceListener and simple ServiceListener.
- *
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
- */
-public class ServiceListenerImpl extends AbstractDelegateListener<ServiceListener>
-{
- private boolean isAll;
-
- public ServiceListenerImpl(ServiceListener delegate)
- {
- super(delegate);
- isAll = (delegate instanceof AllServiceListener);
- }
-
- /**
- * Is AllServiceListener.
- *
- * @return is all service listener
- */
- public boolean isAll()
- {
- return isAll;
- }
-
- public void onEvent(KernelEvent event, Object handback)
- {
- // todo - all stuff, permissions
- if (event instanceof ServiceEventAdapter)
- {
- ServiceEventAdapter adapter = (ServiceEventAdapter)event;
- delegate.serviceChanged(adapter.getEvent());
- }
- }
-}
Deleted: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/ServiceReferenceImpl.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/ServiceReferenceImpl.java 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/ServiceReferenceImpl.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -1,64 +0,0 @@
-/*
-* 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 org.osgi.framework.Bundle;
-import org.osgi.framework.ServiceReference;
-
-/**
- * ServiceReference implementation.
- *
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
- */
-public class ServiceReferenceImpl implements ServiceReference
-{
- public Object getProperty(String string)
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public String[] getPropertyKeys()
- {
- return new String[0]; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public Bundle getBundle()
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public Bundle[] getUsingBundles()
- {
- return new Bundle[0]; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public boolean isAssignableTo(Bundle bundle, String string)
- {
- return false; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public int compareTo(Object reference)
- {
- // TODO Auto-generated method stub
- return 0;
- }
-}
Deleted: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/ServiceRegistrationImpl.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/ServiceRegistrationImpl.java 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/ServiceRegistrationImpl.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -1,112 +0,0 @@
-/*
-* 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.util.Dictionary;
-import java.util.Enumeration;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeSet;
-
-import org.jboss.kernel.spi.dependency.KernelControllerContext;
-import org.jboss.kernel.spi.event.KernelEvent;
-import org.jboss.kernel.spi.event.KernelEventEmitter;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
-import org.osgi.framework.ServiceRegistration;
-
-/**
- * ServiceRegistration implementation.
- *
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
- */
- at SuppressWarnings("deprecation")
-public class ServiceRegistrationImpl implements ServiceRegistration
-{
- protected KernelEventEmitter emitter;
- protected KernelControllerContext context;
- protected Long serviceId;
- protected Map<String, Object> properties;
-
- protected boolean isRegistered;
-
- public ServiceRegistrationImpl(KernelEventEmitter emitter, KernelControllerContext context, Long serviceId, Map<String, Object> properties)
- {
- this.emitter = emitter;
- this.context = context;
- this.serviceId = serviceId;
- this.properties = properties;
- init();
- }
- protected void init()
- {
- KernelEvent event = new AbstractServiceEvent(this, org.jboss.kernel.spi.registry.KernelRegistry.KERNEL_REGISTRY_REGISTERED, serviceId, System.currentTimeMillis(), emitter);
- emitter.fireKernelEvent(event);
- }
-
- protected void validateServiceRegistration()
- {
- if (isServiceRegistered() == false)
- throw new IllegalStateException("ServiceRegistration object has already been unregistered.");
- }
-
- protected boolean isServiceRegistered()
- {
- return isRegistered;
- }
-
- public ServiceReference getReference()
- {
- return null; // TODO
- }
-
- @SuppressWarnings("unchecked")
- public void setProperties(Dictionary properties)
- {
- validateServiceRegistration();
- if (properties != null && properties.size() > 0)
- {
- Set<String> names = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
- Enumeration keys = properties.keys();
- for(String key = (String)keys.nextElement(); keys.hasMoreElements();)
- {
- if (names.add(key) == false)
- throw new IllegalArgumentException("properties contains case variants of the same key name.");
-
- if (Constants.OBJECTCLASS.equals(key) == false && Constants.SERVICE_ID.equals(key) == false)
- {
- this.properties.put(key, properties.get(key));
- }
- }
- KernelEvent event = new AbstractServiceEvent(this, org.jboss.kernel.spi.registry.KernelRegistry.KERNEL_REGISTRY_MODIFIED, serviceId, System.currentTimeMillis(), emitter);
- emitter.fireKernelEvent(event);
- }
- }
-
- public void unregister()
- {
- validateServiceRegistration();
- isRegistered = false;
- KernelEvent event = new AbstractServiceEvent(this, org.jboss.kernel.spi.registry.KernelRegistry.KERNEL_REGISTRY_UNREGISTERED, serviceId, System.currentTimeMillis(), emitter);
- emitter.fireKernelEvent(event);
- }
-}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleContextWrapper.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleContextWrapper.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleContextWrapper.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,180 @@
+/*
+* 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.plugins.facade.bundle;
+
+import java.io.File;
+import java.io.InputStream;
+import java.util.Dictionary;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.BundleListener;
+import org.osgi.framework.Filter;
+import org.osgi.framework.FrameworkListener;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * OSGiBundleContextImpl.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class OSGiBundleContextWrapper implements BundleContext
+{
+ /** The bundle state */
+ private OSGiBundleState bundleState;
+
+ /**
+ * Create a new OSGiBundleContextWrapper.
+ *
+ * @param bundleState the bundle state
+ * @throws IllegalArgumentException for a null parameter
+ */
+ public OSGiBundleContextWrapper(OSGiBundleState bundleState)
+ {
+ if (bundleState == null)
+ throw new IllegalArgumentException("Null bundle state");
+ this.bundleState = bundleState;
+ }
+
+ public void addBundleListener(BundleListener listener)
+ {
+ bundleState.addBundleListener(listener);
+ }
+
+ public void addFrameworkListener(FrameworkListener listener)
+ {
+ bundleState.addFrameworkListener(listener);
+ }
+
+ public void addServiceListener(ServiceListener listener, String filter) throws InvalidSyntaxException
+ {
+ bundleState.addServiceListener(listener, filter);
+ }
+
+ public void addServiceListener(ServiceListener listener)
+ {
+ bundleState.addServiceListener(listener);
+ }
+
+ public Filter createFilter(String filter) throws InvalidSyntaxException
+ {
+ return bundleState.createFilter(filter);
+ }
+
+ public ServiceReference[] getAllServiceReferences(String clazz, String filter) throws InvalidSyntaxException
+ {
+ return bundleState.getAllServiceReferences(clazz, filter);
+ }
+
+ public Bundle getBundle()
+ {
+ return bundleState.getBundle();
+ }
+
+ public Bundle getBundle(long id)
+ {
+ return bundleState.getBundle(id);
+ }
+
+ public Bundle[] getBundles()
+ {
+ return bundleState.getBundles();
+ }
+
+ public File getDataFile(String filename)
+ {
+ return bundleState.getDataFile(filename);
+ }
+
+ public String getProperty(String key)
+ {
+ return bundleState.getProperty(key);
+ }
+
+ public Object getService(ServiceReference reference)
+ {
+ return bundleState.getService(reference);
+ }
+
+ public ServiceReference getServiceReference(String clazz)
+ {
+ return bundleState.getServiceReference(clazz);
+ }
+
+ public ServiceReference[] getServiceReferences(String clazz, String filter) throws InvalidSyntaxException
+ {
+ return bundleState.getServiceReferences(clazz, filter);
+ }
+
+ public Bundle installBundle(String location, InputStream input) throws BundleException
+ {
+ return bundleState.installBundle(location, input);
+ }
+
+ public Bundle installBundle(String location) throws BundleException
+ {
+ return bundleState.installBundle(location);
+ }
+
+ @SuppressWarnings("unchecked")
+ public ServiceRegistration registerService(String clazz, Object service, Dictionary properties)
+ {
+ return bundleState.registerService(clazz, service, properties);
+ }
+
+ @SuppressWarnings("unchecked")
+ public ServiceRegistration registerService(String[] clazzes, Object service, Dictionary properties)
+ {
+ return bundleState.registerService(clazzes, service, properties);
+ }
+
+ public void removeBundleListener(BundleListener listener)
+ {
+ bundleState.removeBundleListener(listener);
+ }
+
+ public void removeFrameworkListener(FrameworkListener listener)
+ {
+ bundleState.removeFrameworkListener(listener);
+ }
+
+ public void removeServiceListener(ServiceListener listener)
+ {
+ bundleState.removeServiceListener(listener);
+ }
+
+ @Override
+ public String toString()
+ {
+ return bundleState.toString();
+ }
+
+ public boolean ungetService(ServiceReference reference)
+ {
+ return bundleState.ungetService(reference);
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,795 @@
+/*
+* 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.plugins.facade.bundle;
+
+import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.Dictionary;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
+import java.util.jar.Attributes.Name;
+
+import org.jboss.deployers.client.spi.DeployerClient;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentStages;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.structure.spi.main.MainDeployerStructure;
+import org.jboss.deployers.vfs.spi.client.VFSDeployment;
+import org.jboss.deployers.vfs.spi.client.VFSDeploymentFactory;
+import org.jboss.logging.Logger;
+import org.jboss.osgi.plugins.filter.NoFilter;
+import org.jboss.osgi.plugins.metadata.AbstractOSGiMetaData;
+import org.jboss.osgi.spi.metadata.OSGiMetaData;
+import org.jboss.util.collection.ConcurrentSet;
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Filter;
+import org.osgi.framework.FrameworkEvent;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * OSGiBundleManager.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class OSGiBundleManager
+{
+ /** The log */
+ private static final Logger log = Logger.getLogger(OSGiBundleManager.class);
+
+ /** The framework version */
+ private static String OSGi_FRAMEWORK_VERSION = "r4v41"; // todo externalise
+
+ /** The framework vendor */
+ private static String OSGi_FRAMEWORK_VENDOR = "jboss.org"; // todo externalise
+
+ /** The framework language */
+ private static String OSGi_FRAMEWORK_LANGUAGE = Locale.getDefault().getISO3Language(); // REVIEW correct?
+
+ /** The os name */
+ private static String OSGi_FRAMEWORK_OS_NAME;
+
+ /** The os version */
+ private static String OSGi_FRAMEWORK_OS_VERSION;
+
+ /** The os version */
+ private static String OSGi_FRAMEWORK_PROCESSOR;
+
+ /** The bundles by id */
+ private Map<Long, OSGiBundleState> bundlesById = new ConcurrentHashMap<Long, OSGiBundleState>();
+
+ /** The registered services */
+ private Set<OSGiServiceState> registeredServices = new ConcurrentSet<OSGiServiceState>();
+
+ /** The main deployer */
+ private DeployerClient deployerClient;
+
+ /** The deployment structure */
+ private MainDeployerStructure deployerStructure;
+
+ /** The executor */
+ private Executor executor;
+
+ /** The system bundle */
+ private OSGiSystemBundle systemBundle;
+
+ static
+ {
+ AccessController.doPrivileged(new PrivilegedAction<Object>()
+ {
+ public Object run()
+ {
+ OSGi_FRAMEWORK_OS_NAME=System.getProperty("os.name");
+ OSGi_FRAMEWORK_OS_VERSION=System.getProperty("os.version");
+ OSGi_FRAMEWORK_PROCESSOR=System.getProperty("os.arch");
+
+ System.setProperty("org.osgi.vendor.framework", "org.jboss.osgi.plugins.framework");
+ return null;
+ }
+ });
+ }
+
+ /**
+ * Create a new OSGiBundleManager.
+ *
+ * @param deployerClient the deployer client
+ * @throws IllegalArgumentException for a null parameter
+ */
+ public OSGiBundleManager(DeployerClient deployerClient)
+ {
+ this(deployerClient, null);
+ }
+
+ /**
+ * Create a new OSGiBundleManager.
+ *
+ * @param deployerClient the deployer client
+ * @param executor the executor
+ * @throws IllegalArgumentException for a null parameter
+ */
+ public OSGiBundleManager(DeployerClient deployerClient, Executor executor)
+ {
+ if (deployerClient == null)
+ throw new IllegalArgumentException("Null deployerClient");
+ this.deployerClient = deployerClient;
+ if (deployerClient instanceof MainDeployerStructure == false)
+ throw new IllegalArgumentException("Deployer client does not implement " + MainDeployerStructure.class.getName());
+ deployerStructure = (MainDeployerStructure) deployerClient;
+ if (executor == null)
+ // TODO thread factory
+ executor = Executors.newFixedThreadPool(10);
+ this.executor = executor;
+
+ // todo populate metadata for system bundle
+ Manifest manifest = new Manifest();
+ Attributes attributes = manifest.getMainAttributes();
+ attributes.put(new Name(Constants.BUNDLE_NAME), Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
+ attributes.put(new Name(Constants.BUNDLE_SYMBOLICNAME), Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
+ OSGiMetaData systemMetaData = new AbstractOSGiMetaData(manifest);
+ this.systemBundle = new OSGiSystemBundle(systemMetaData);
+ addBundle(systemBundle);
+ // todo integrate lifecycle with the underlying framework for stopping/updating
+ startFramework();
+ }
+
+ /**
+ * Are we active
+ *
+ * @return true when the system is active
+ */
+ public boolean isActive()
+ {
+ // We are active if the system bundle is at least in the starting/stopping state
+ OSGiBundleState bundleState = getSystemBundle();
+ return bundleState.getState() >= Bundle.STARTING;
+ }
+
+ /**
+ * Install a bundle
+ *
+ * @param url the url of the bundle
+ * @return the bundle state
+ * @throws BundleException for any error
+ */
+ public OSGiBundleState install(URL url) throws BundleException
+ {
+ if (url == null)
+ throw new BundleException("Null url");
+
+ try
+ {
+ VirtualFile root = VFS.getRoot(url);
+ VFSDeployment deployment = VFSDeploymentFactory.getInstance().createVFSDeployment(root);
+ deployerClient.deploy(deployment);
+ try
+ {
+ DeploymentUnit unit = deployerStructure.getDeploymentUnit(deployment.getName());
+ OSGiBundleState bundleState = unit.getAttachment(OSGiBundleState.class);
+ if (bundleState == null)
+ throw new IllegalStateException("Unable to determine bundle state for " + deployment.getName());
+ return bundleState;
+ }
+ catch (Exception e)
+ {
+ deployerClient.undeploy(deployment);
+ throw e;
+ }
+ }
+ catch (Exception e)
+ {
+ throw new BundleException("Error installing bundle from location=" + url, e);
+ }
+ }
+
+ /**
+ * Install a bundle
+ *
+ * @param file the virtual file
+ * @return the bundle state
+ * @throws BundleException for any error
+ */
+ public OSGiBundleState install(VirtualFile file) throws BundleException
+ {
+ if (file == null)
+ throw new BundleException("Null file");
+
+ try
+ {
+ VFSDeployment deployment = VFSDeploymentFactory.getInstance().createVFSDeployment(file);
+ deployerClient.deploy(deployment);
+ try
+ {
+ DeploymentUnit unit = deployerStructure.getDeploymentUnit(deployment.getName());
+ OSGiBundleState bundleState = unit.getAttachment(OSGiBundleState.class);
+ if (bundleState == null)
+ throw new IllegalStateException("Unable to determine bundle state for " + deployment.getName());
+ return bundleState;
+ }
+ catch (Exception e)
+ {
+ deployerClient.undeploy(deployment);
+ throw e;
+ }
+ }
+ catch (Exception e)
+ {
+ throw new BundleException("Error installing bundle from location=" + file, e);
+ }
+ }
+
+ /**
+ * Uninstall a bundle
+ *
+ * @param bundle the bundle
+ * @throws BundleException for any error
+ */
+ public void uninstall(Bundle bundle) throws BundleException
+ {
+ long id = bundle.getBundleId();
+ OSGiBundleState state = getBundle(id);
+ if (state == null)
+ throw new BundleException(bundle + " not installed");
+ uninstall(state);
+ }
+
+ /**
+ * Uninstall a bundle
+ *
+ * @param bundleState the bundle state
+ * @throws BundleException for any error
+ */
+ public void uninstall(OSGiBundleState bundleState) throws BundleException
+ {
+ DeploymentUnit unit = bundleState.getDeploymentUnit();
+ try
+ {
+ deployerClient.undeploy(unit.getName());
+ bundleState.modified();
+ }
+ catch (DeploymentException e)
+ {
+ throw new BundleException("Unable to uninstall " + bundleState, e);
+ }
+ }
+
+ /**
+ * Add a deployment
+ *
+ * @param unit the deployment unit
+ * @return the bundle state
+ * @throws IllegalArgumentException for a null parameter
+ */
+ public OSGiBundleState addDeployment(DeploymentUnit unit)
+ {
+ if (unit == null)
+ throw new IllegalArgumentException("Null unit");
+
+ OSGiMetaData osgiMetaData = unit.getAttachment(OSGiMetaData.class);
+ if (osgiMetaData == null)
+ {
+ Manifest manifest = unit.getAttachment(Manifest.class);
+ // todo we need a mechanism to construct an OSGiMetaData from an easier factory
+ if (manifest == null)
+ manifest = new Manifest();
+ // todo populate some bundle information
+ Attributes attributes = manifest.getMainAttributes();
+ attributes.put(new Name(Constants.BUNDLE_NAME), unit.getName());
+ attributes.put(new Name(Constants.BUNDLE_SYMBOLICNAME), unit.getName());
+ osgiMetaData = new AbstractOSGiMetaData(manifest);
+ }
+ else
+ {
+ // todo look at manifest headers and persistent state for this
+ unit.setRequiredStage(DeploymentStages.DESCRIBE);
+ }
+ OSGiBundleState bundleState = new OSGiBundleState(osgiMetaData, unit);
+ addBundle(bundleState);
+ return bundleState;
+ }
+
+ /**
+ * Add a bundle
+ *
+ * @param bundleState the bundle state
+ * @throws IllegalArgumentException for a null bundle state
+ */
+ public void addBundle(OSGiBundleState bundleState)
+ {
+ if (bundleState == null)
+ throw new IllegalArgumentException("Null bundle state");
+ bundleState.setBundleManager(this);
+ bundlesById.put(bundleState.getBundleId(), bundleState);
+ log.debug("Added " + bundleState.getCanonicalName() + " id=" + bundleState.getBundleId());
+ }
+
+ /**
+ * Remove a bundle
+ *
+ * @param bundleState the bundle state
+ * @throws IllegalArgumentException for a null bundle state
+ */
+ public void removeBundle(OSGiBundleState bundleState)
+ {
+ if (bundleState == null)
+ throw new IllegalArgumentException("Null bundle state");
+ bundleState.uninstallInternal();
+ bundleState.setBundleManager(null);
+ long id = bundleState.getBundleId();
+ bundlesById.remove(id);
+ log.debug("Removed " + bundleState.getCanonicalName() + " id=" + id);
+ }
+
+ /**
+ * Get a bundle by id
+ *
+ * @param id the id of the bundle
+ * @return the bundle or null if there is no bundle with that id
+ */
+ public OSGiBundleState getBundle(long id)
+ {
+ return bundlesById.get(id);
+ }
+
+ /**
+ * Get the system bundle
+ *
+ * @return the system bundle
+ */
+ OSGiSystemBundle getSystemBundle()
+ {
+ return systemBundle;
+ }
+
+ /**
+ * Get a deployment
+ *
+ * @param id the id of the bundle
+ * @return the deployment or null if there is no bundle with that id
+ */
+ public DeploymentUnit getDeployment(long id)
+ {
+ OSGiBundleState bundleState = getBundle(id);
+ if (bundleState == null)
+ return null;
+ return bundleState.getDeploymentUnit();
+ }
+
+ /**
+ * Get all the bundles
+ *
+ * @return the bundles
+ */
+ public Collection<OSGiBundleState> getBundles()
+ {
+ return bundlesById.values();
+ }
+
+ /**
+ * Get a property
+ *
+ * @param key the property key
+ * @return the property
+ * @throws SecurityException if the caller doesn't have the relevant property permission
+ */
+ public static String getProperty(String key)
+ {
+ if (key == null)
+ return null;
+ if (Constants.FRAMEWORK_VERSION.equals(key))
+ return OSGi_FRAMEWORK_VERSION;
+ if (Constants.FRAMEWORK_VENDOR.equals(key))
+ return OSGi_FRAMEWORK_VENDOR;
+ if (Constants.FRAMEWORK_LANGUAGE.equals(key))
+ return OSGi_FRAMEWORK_LANGUAGE;
+ if (Constants.FRAMEWORK_OS_NAME.equals(key))
+ return OSGi_FRAMEWORK_OS_NAME;
+ if (Constants.FRAMEWORK_OS_VERSION.equals(key))
+ return OSGi_FRAMEWORK_OS_VERSION;
+ if (Constants.FRAMEWORK_PROCESSOR.equals(key))
+ return OSGi_FRAMEWORK_PROCESSOR;
+ return System.getProperty(key);
+ }
+
+ /**
+ * Resolve a bundle
+ *
+ * @param bundleState the bundle state
+ * @param errorOnFail whether to throw an error if it cannot be resolved
+ * @return true when resolved
+ */
+ public boolean resolve(OSGiBundleState bundleState, boolean errorOnFail)
+ {
+ try
+ {
+ // todo check actually changed state
+ deployerClient.change(bundleState.getDeploymentUnit().getName(), DeploymentStages.CLASSLOADER);
+ return true;
+ }
+ catch (DeploymentException e)
+ {
+ if (errorOnFail)
+ throw new IllegalStateException("Error resolving bundle: " + bundleState, e);
+ return false;
+ }
+ }
+
+ /**
+ * Start a bundle
+ *
+ * @param bundleState the bundle state
+ * @throws BundleException the bundle exception
+ */
+ public void start(OSGiBundleState bundleState) throws BundleException
+ {
+ try
+ {
+ // todo check actually changed state
+ deployerClient.change(bundleState.getDeploymentUnit().getName(), DeploymentStages.INSTALLED);
+ }
+ catch (DeploymentException e)
+ {
+ Throwable t = e.getCause();
+ if (t instanceof BundleException)
+ throw (BundleException) t;
+ throw new BundleException("Error starting " + bundleState, e);
+ }
+ }
+
+ /**
+ * Stop a bundle
+ *
+ * @param bundleState the bundle state
+ * @throws BundleException the bundle exception
+ */
+ public void stop(OSGiBundleState bundleState) throws BundleException
+ {
+ try
+ {
+ deployerClient.change(bundleState.getDeploymentUnit().getName(), DeploymentStages.CLASSLOADER);
+ }
+ catch (DeploymentException e)
+ {
+ Throwable t = e.getCause();
+ if (t instanceof BundleException)
+ throw (BundleException) t;
+ throw new BundleException("Error stopping " + bundleState, e);
+ }
+ }
+
+ /**
+ * Get services
+ *
+ * @param bundleState the referencing bundle
+ * @param clazz any class
+ * @param filter any filter
+ * @param checkAssignable whether to check isAssignable
+ * @return the services
+ */
+ Collection<OSGiServiceState> getServices(OSGiBundleState bundleState, String clazz, Filter filter, boolean checkAssignable)
+ {
+ if (filter == null)
+ filter = NoFilter.INSTANCE;
+
+ if (registeredServices.isEmpty())
+ return null;
+
+ // review: optimise this, e.g. index by class
+ // Use a sorted set to order services according to spec
+ Set<OSGiServiceState> result = new TreeSet<OSGiServiceState>(ServiceComparator.INSTANCE);
+ for (OSGiServiceState service : registeredServices)
+ {
+ // Check the state, filter and permission
+ if (service.isUnregistered() == false && filter.match(service) && service.hasPermission())
+ {
+ // Check any passed class matches
+ if (clazz == null || service.matchClass(bundleState, clazz))
+ {
+ // Check the assignability
+ if (checkAssignable == false || service.isAssignable(bundleState))
+ result.add(service);
+ }
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Get service reference
+ *
+ * @param bundleState the referencing bundle
+ * @param clazz any class
+ * @return the reference
+ */
+ ServiceReference getServiceReference(OSGiBundleState bundleState, String clazz)
+ {
+ Collection<OSGiServiceState> services = getServices(bundleState, clazz, null, true);
+ if (services == null || services.isEmpty())
+ return null;
+ OSGiServiceState service = services.iterator().next();
+ return service.getReferenceInternal();
+ }
+
+ /**
+ * Get service references
+ *
+ * @param bundleState the referencing bundle
+ * @param clazz any class
+ * @param filter any filter
+ * @param checkAssignable whether to check isAssignable
+ * @return the services
+ */
+ ServiceReference[] getServiceReferences(OSGiBundleState bundleState, String clazz, Filter filter, boolean checkAssignable)
+ {
+ Collection<OSGiServiceState> services = getServices(bundleState, clazz, filter, checkAssignable);
+ if (services == null || services.isEmpty())
+ return null;
+ ServiceReference[] result = new ServiceReference[services.size()];
+ int i = 0;
+ for (OSGiServiceState service : services)
+ result[i++] = service.getReferenceInternal();
+ return result;
+ }
+
+ /**
+ * Get service references
+ *
+ * @param bundleState the referencing bundle
+ * @param clazz any class
+ * @param filter any filter
+ * @param checkAssignable whether to check isAssignable
+ * @return the services
+ * @throws InvalidSyntaxException when the filter is invalid
+ */
+ ServiceReference[] getServiceReferences(OSGiBundleState bundleState, String clazz, String filter, boolean checkAssignable) throws InvalidSyntaxException
+ {
+ Filter f = NoFilter.INSTANCE;
+ if (filter != null)
+ f = FrameworkUtil.createFilter(filter);
+ return getServiceReferences(bundleState, clazz, f, checkAssignable);
+ }
+
+ /**
+ * Register a service
+ *
+ * @param bundleState the bundle
+ * @param clazzes the classes to implement
+ * @param service the service
+ * @param properties the properties
+ * @return the service state
+ */
+ @SuppressWarnings("unchecked")
+ OSGiServiceState registerService(OSGiBundleState bundleState, String[] clazzes, Object service, Dictionary properties)
+ {
+ OSGiServiceState result = new OSGiServiceState(bundleState, clazzes, service, properties);
+ result.internalRegister();
+ registeredServices.add(result);
+ bundleState.fireServiceEvent(ServiceEvent.REGISTERED, result);
+ log.debug("Registered service : " + result.toLongString());
+ return result;
+ }
+
+ /**
+ * Unregister a service
+ *
+ * @param serviceState the service state
+ */
+ void unregisterService(OSGiServiceState serviceState)
+ {
+ log.debug("Unregistering service: " + serviceState.toLongString());
+ serviceState.getBundleState().fireServiceEvent(ServiceEvent.UNREGISTERING, serviceState);
+ registeredServices.remove(serviceState);
+ serviceState.internalUnregister();
+ }
+
+ /**
+ * Get a service
+ *
+ * @param bundleState the bundle state
+ * @param reference the service reference
+ * @return the service
+ */
+ Object getService(OSGiBundleState bundleState, ServiceReference reference)
+ {
+ OSGiServiceReferenceWrapper serviceReference = (OSGiServiceReferenceWrapper) reference;
+ OSGiServiceState serviceState = serviceReference.getServiceState();
+ Object result = serviceState.getService();
+ if (result != null)
+ bundleState.addServiceInUse(serviceState);
+ return result;
+ }
+
+ /**
+ * Unget a service
+ *
+ * @param bundleState the bundle state
+ * @param reference the service reference
+ * @return true when the service is still in use by the bundle
+ */
+ boolean ungetService(OSGiBundleState bundleState, ServiceReference reference)
+ {
+ if (reference == null)
+ throw new IllegalArgumentException("Null reference");
+ OSGiServiceReferenceWrapper serviceReference = (OSGiServiceReferenceWrapper) reference;
+ OSGiServiceState serviceState = serviceReference.getServiceState();
+ return ungetService(bundleState, serviceState);
+ }
+
+ /**
+ * Unget a service
+ *
+ * @param bundleState the bundle state
+ * @param service the service
+ * @return true when the service is still in use by the bundle
+ */
+ boolean ungetService(OSGiBundleState bundleState, OSGiServiceState service)
+ {
+ return bundleState.removeServiceInUse(service);
+ }
+
+ /**
+ * Get the executor.
+ *
+ * @return the executor.
+ */
+ Executor getExecutor()
+ {
+ return executor;
+ }
+
+ /**
+ * Start the framework
+ */
+ void startFramework()
+ {
+ OSGiBundleState systemBundle = getSystemBundle();
+ systemBundle.changeState(Bundle.STARTING);
+ // todo start the osgi framework, already installed bundles and start level, etc. (fire frameworkEvent.ERROR for errors)
+ systemBundle.changeState(Bundle.ACTIVE);
+ systemBundle.fireFrameworkEvent(FrameworkEvent.STARTED, null);
+ }
+
+ /**
+ * Stop the framework
+ */
+ void stopFramework()
+ {
+ OSGiBundleState systemBundle = getSystemBundle();
+ if (systemBundle.getState() != Bundle.ACTIVE)
+ return;
+
+ systemBundle.changeState(Bundle.STOPPING);
+ for (OSGiBundleState bundle : getBundles())
+ {
+ if (bundle != systemBundle)
+ {
+ try
+ {
+ // todo don't change the persistent state
+ bundle.stop();
+ }
+ catch (Throwable t)
+ {
+ fireWarning(bundle, "stopping bundle", t);
+ }
+ }
+ }
+ systemBundle.changeState(Bundle.RESOLVED);
+ }
+
+ /**
+ * Stop the framework
+ *
+ * @param systemBundle the system bundle
+ */
+ void restartFramework()
+ {
+ OSGiBundleState systemBundle = getSystemBundle();
+ if (systemBundle.getState() != Bundle.ACTIVE)
+ return;
+
+ for (OSGiBundleState bundle : getBundles())
+ {
+ if (bundle != systemBundle && bundle.getState() == Bundle.ACTIVE)
+ {
+ try
+ {
+ // todo don't change the persistent state
+ bundle.stop();
+ }
+ catch (Throwable t)
+ {
+ fireWarning(bundle, "stopping bundle", t);
+ }
+ try
+ {
+ bundle.start();
+ }
+ catch (Throwable t)
+ {
+ fireError(bundle, "starting bundle", t);
+ }
+ }
+ }
+ }
+
+ /**
+ * Fire a framework error
+ *
+ * @param t the throwable
+ */
+ void fireError(OSGiBundleState bundleState, String context, Throwable t)
+ {
+ OSGiSystemBundle systemBundle = getSystemBundle();
+ if (t instanceof BundleException)
+ systemBundle.fireFrameworkEvent(FrameworkEvent.ERROR, t);
+ else if (bundleState != null)
+ systemBundle.fireFrameworkEvent(FrameworkEvent.ERROR, new BundleException("Error " + context + " bundle: " + bundleState.getCanonicalName(), t));
+ else
+ systemBundle.fireFrameworkEvent(FrameworkEvent.ERROR, new BundleException("Error " + context, t));
+ }
+
+ /**
+ * Fire a framework error
+ *
+ * @param t the throwable
+ */
+ void fireWarning(OSGiBundleState bundleState, String context, Throwable t)
+ {
+ OSGiSystemBundle systemBundle = getSystemBundle();
+ if (t instanceof BundleException)
+ systemBundle.fireFrameworkEvent(FrameworkEvent.WARNING, t);
+ else if (bundleState != null)
+ systemBundle.fireFrameworkEvent(FrameworkEvent.WARNING, new BundleException("Error " + context + " bundle: " + bundleState.getCanonicalName(), t));
+ else
+ systemBundle.fireFrameworkEvent(FrameworkEvent.WARNING, new BundleException("Error " + context, t));
+ }
+
+ /**
+ * ServiceComparator, reverses the order of compareTo
+ */
+ static class ServiceComparator implements Comparator<OSGiServiceState>
+ {
+ public static ServiceComparator INSTANCE = new ServiceComparator();
+
+ public int compare(OSGiServiceState o1, OSGiServiceState o2)
+ {
+ return -o1.compareTo(o2);
+ }
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleState.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleState.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleState.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,1279 @@
+/*
+* 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.plugins.facade.bundle;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.security.AccessControlContext;
+import java.security.AccessController;
+import java.security.Permission;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.jboss.beans.info.spi.BeanInfo;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.deployers.plugins.deployers.DeploymentControllerContext;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.logging.Logger;
+import org.jboss.osgi.plugins.filter.NoFilter;
+import org.jboss.osgi.spi.metadata.OSGiMetaData;
+import org.jboss.util.collection.ConcurrentSet;
+import org.jboss.virtual.VirtualFile;
+import org.osgi.framework.AdminPermission;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.BundleListener;
+import org.osgi.framework.Filter;
+import org.osgi.framework.FrameworkEvent;
+import org.osgi.framework.FrameworkListener;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.framework.SynchronousBundleListener;
+
+/**
+ * BundleState.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class OSGiBundleState implements Bundle, BundleContext
+{
+ /** The log */
+ private static final Logger log = Logger.getLogger(OSGiBundleState.class);
+
+ /** Used to generate a unique id */
+ private static final AtomicLong bundleIDGenerator = new AtomicLong();
+
+ /** The bundle id */
+ private long bundleId;
+
+ /** The last modified time stamp */
+ private long lastModified = System.currentTimeMillis();
+
+ /** The bundle manager */
+ private OSGiBundleManager bundleManager;
+
+ /** The osgi metadata */
+ private OSGiMetaData osgiMetaData;
+
+ /** The deployment unit */
+ private DeploymentUnit unit;
+
+ /** The bundle context */
+ private BundleContext bundleContext;
+
+ /** The bundle */
+ private Bundle bundle;
+
+ /** The bundle state */
+ private AtomicInteger state = new AtomicInteger(Bundle.UNINSTALLED);
+
+ /** The registered services in use */
+ private Set<OSGiServiceState> registeredServices = new ConcurrentSet<OSGiServiceState>();
+
+ /** The services in use */
+ private Map<OSGiServiceState, Integer> servicesInUse = new ConcurrentHashMap<OSGiServiceState, Integer>();
+
+ /** The bundle listeners */
+ private List<BundleListener> bundleListeners = new CopyOnWriteArrayList<BundleListener>();
+
+ /** The framework listeners */
+ private List<FrameworkListener> frameworkListeners = new CopyOnWriteArrayList<FrameworkListener>();
+
+ /** The service listeners */
+ private Map<ServiceListener, ServiceListenerRegistration> serviceListeners = new ConcurrentHashMap<ServiceListener, ServiceListenerRegistration>();
+
+ /**
+ * Create a new BundleState.
+ *
+ * @param osgiMetaData the osgi metadata
+ * @param unit the deployment unit
+ * @throws IllegalArgumentException for a null parameter
+ */
+ public OSGiBundleState(OSGiMetaData osgiMetaData, DeploymentUnit unit)
+ {
+ if (osgiMetaData == null)
+ throw new IllegalArgumentException("Null osgi metadata");
+ if (unit == null)
+ throw new IllegalArgumentException("Null deployment unit");
+ this.osgiMetaData = osgiMetaData;
+ this.unit = unit;
+ this.bundleId = bundleIDGenerator.incrementAndGet();
+ unit.getMutableMetaData().addMetaData(unit, DeploymentUnit.class);
+ changeState(Bundle.INSTALLED);
+ }
+
+ /**
+ * Create a new BundleState for the system bundle.
+ *
+ * @param osgiMetaData the osgi metadata
+ * @throws IllegalArgumentException for a null parameter
+ */
+ OSGiBundleState(OSGiMetaData osgiMetaData)
+ {
+ if (osgiMetaData == null)
+ throw new IllegalArgumentException("Null osgi metadata");
+ this.osgiMetaData = osgiMetaData;
+ this.bundleId = 0;
+ changeState(Bundle.INSTALLED);
+ }
+
+ /**
+ * Get the bundleManager.
+ *
+ * @return the bundleManager.
+ */
+ public OSGiBundleManager getBundleManager()
+ {
+ return bundleManager;
+ }
+
+ public long getBundleId()
+ {
+ return bundleId;
+ }
+
+ public String getSymbolicName()
+ {
+ return osgiMetaData.getBundleSymbolicName();
+ }
+
+ public int getState()
+ {
+ return state.get();
+ }
+
+ public synchronized BundleContext getBundleContext()
+ {
+ checkAdminPermission(AdminPermission.CONTEXT);
+ return bundleContext;
+ }
+
+ public synchronized BundleContext createBundleContext()
+ {
+ if (bundleContext == null)
+ bundleContext = new OSGiBundleContextWrapper(this);
+ return bundleContext;
+ }
+
+ public synchronized Bundle getBundle()
+ {
+ checkValidBundleContext();
+ return getBundleInternal();
+ }
+
+ public synchronized Bundle getBundleInternal()
+ {
+ if (bundle == null)
+ bundle = new OSGiBundleWrapper(this);
+ return bundle;
+ }
+
+ public Bundle getBundle(long id)
+ {
+ checkValidBundleContext();
+ OSGiBundleManager bundleManager = getBundleManager();
+ if (bundleManager == null)
+ return null;
+
+ OSGiBundleState bundleState = bundleManager.getBundle(id);
+ if (bundleState == null)
+ return null;
+ return bundleState.getBundleInternal();
+ }
+
+ public Bundle[] getBundles()
+ {
+ checkValidBundleContext();
+ OSGiBundleManager bundleManager = getBundleManager();
+ if (bundleManager == null)
+ return null;
+
+ Collection<OSGiBundleState> bundleStates = bundleManager.getBundles();
+ if (bundleStates.isEmpty())
+ return new Bundle[0];
+
+ List<Bundle> bundles = new ArrayList<Bundle>(bundleStates.size());
+ for (OSGiBundleState bundleState : bundleStates)
+ bundles.add(bundleState.getBundleInternal());
+ return bundles.toArray(new Bundle[bundles.size()]);
+ }
+
+ public long getLastModified()
+ {
+ return lastModified;
+ }
+
+ public void modified()
+ {
+ lastModified = System.currentTimeMillis();
+ }
+
+ public String getLocation()
+ {
+ checkAdminPermission(AdminPermission.METADATA);
+
+ URL url = getOSGiMetaData().getBundleUpdateLocation();
+ if (url != null)
+ return url.toString();
+
+ DeploymentUnit unit = getDeploymentUnit();
+ if (unit instanceof VFSDeploymentUnit)
+ {
+ VFSDeploymentUnit vfsDeploymentUnit = (VFSDeploymentUnit) unit;
+ VirtualFile root = vfsDeploymentUnit.getRoot();
+ return root.getName();
+ }
+
+ return null;
+ }
+
+ /**
+ * Get the osgiMetaData.
+ *
+ * @return the osgiMetaData.
+ */
+ public OSGiMetaData getOSGiMetaData()
+ {
+ return osgiMetaData;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Dictionary getHeaders()
+ {
+ return getHeaders(null);
+ }
+
+ @SuppressWarnings("unchecked")
+ public Dictionary getHeaders(String locale)
+ {
+ checkAdminPermission(AdminPermission.METADATA);
+ return getOSGiMetaData().getHeaders(locale);
+ }
+
+ public String getProperty(String key)
+ {
+ checkValidBundleContext();
+ return OSGiBundleManager.getProperty(key);
+ }
+
+ public File getDataFile(String filename)
+ {
+ checkValidBundleContext();
+ // todo getDataFile
+ return null;
+ }
+
+ public URL getEntry(String path)
+ {
+ checkInstalled();
+ if (noAdminPermission(AdminPermission.RESOURCE))
+ return null;
+
+ DeploymentUnit unit = getDeploymentUnit();
+ if (unit instanceof VFSDeploymentUnit)
+ {
+ VFSDeploymentUnit vfsDeploymentUnit = (VFSDeploymentUnit) unit;
+
+ if (path.startsWith("/"))
+ path = path.substring(1);
+ return vfsDeploymentUnit.getResourceLoader().getResource(path);
+ }
+ return null;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Enumeration getEntryPaths(String path)
+ {
+ checkInstalled();
+ if (noAdminPermission(AdminPermission.RESOURCE))
+ return null;
+
+ DeploymentUnit unit = getDeploymentUnit();
+ if (unit instanceof VFSDeploymentUnit)
+ {
+ VFSDeploymentUnit vfsDeploymentUnit = (VFSDeploymentUnit) unit;
+ VirtualFile root = vfsDeploymentUnit.getRoot();
+ if (path.startsWith("/"))
+ path = path.substring(1);
+ try
+ {
+ VirtualFile child = root.getChild(path);
+ if (child != null)
+ return new VFSEntryPathsEnumeration(root, child);
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException("Error determining entry paths for " + root + " path=" + path);
+ }
+
+ }
+ return null;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Enumeration findEntries(String path, String filePattern, boolean recurse)
+ {
+ if (path == null)
+ throw new IllegalArgumentException("Null path");
+
+ checkInstalled();
+ if (noAdminPermission(AdminPermission.RESOURCE))
+ return null;
+
+ // todo fragments
+ resolve(false);
+
+ if (filePattern == null)
+ filePattern = "*";
+
+ DeploymentUnit unit = getDeploymentUnit();
+ if (unit instanceof VFSDeploymentUnit)
+ {
+ VFSDeploymentUnit vfsDeploymentUnit = (VFSDeploymentUnit) unit;
+ VirtualFile root = vfsDeploymentUnit.getRoot();
+ if (path.startsWith("/"))
+ path = path.substring(1);
+ try
+ {
+ VirtualFile child = root.getChild(path);
+ if (child != null)
+ return new VFSFindEntriesEnumeration(root, child, filePattern, recurse);
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException("Error finding entries for " + root + " path=" + path + " pattern=" + filePattern + " recurse=" + recurse);
+ }
+
+ }
+ return null;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Class loadClass(String name) throws ClassNotFoundException
+ {
+ checkInstalled();
+ checkAdminPermission(AdminPermission.CLASS);
+ // todo bundle fragment
+
+ try
+ {
+ resolve(true);
+ }
+ catch (Exception e)
+ {
+ throw new ClassNotFoundException("Cannot load class: " + name, e);
+ }
+
+ return getDeploymentUnit().getClassLoader().loadClass(name);
+ }
+
+ public URL getResource(String name)
+ {
+ checkInstalled();
+ if (noAdminPermission(AdminPermission.RESOURCE))
+ return null;
+ // todo bundle fragment
+ // return null;
+ if (resolve(false) == false)
+ return getDeploymentUnit().getResourceLoader().getResource(name);
+ return getDeploymentUnit().getClassLoader().getResource(name);
+ }
+
+ @SuppressWarnings("unchecked")
+ public Enumeration getResources(String name) throws IOException
+ {
+ checkInstalled();
+ if (noAdminPermission(AdminPermission.RESOURCE))
+ return null;
+ // todo bundle fragment
+ // return null;
+ if (resolve(false) == false)
+ return getDeploymentUnit().getResourceLoader().getResources(name);
+ return getDeploymentUnit().getClassLoader().getResources(name);
+ }
+
+ public boolean hasPermission(Object permission)
+ {
+ if (permission == null || permission instanceof Permission == false)
+ return false;
+
+ SecurityManager sm = System.getSecurityManager();
+ if (sm == null)
+ return true;
+
+ // todo hasPermission
+ return true;
+ }
+
+ public Filter createFilter(String filter) throws InvalidSyntaxException
+ {
+ checkValidBundleContext();
+ return FrameworkUtil.createFilter(filter);
+ }
+
+ public void addServiceListener(ServiceListener listener)
+ {
+ addServiceListenerInternal(listener, null);
+ }
+
+ public void addServiceListener(ServiceListener listener, String filter) throws InvalidSyntaxException
+ {
+ Filter theFilter = null;
+ if (filter != null)
+ theFilter = createFilter(filter);
+ addServiceListenerInternal(listener, theFilter);
+ }
+
+ public void addServiceListenerInternal(ServiceListener listener, Filter filter)
+ {
+ if (listener == null)
+ throw new IllegalArgumentException("Null listener");
+ if (filter == null)
+ filter = NoFilter.INSTANCE;
+ checkValidBundleContext();
+
+ serviceListeners.put(listener, new ServiceListenerRegistration(filter));
+ }
+
+ public void removeServiceListener(ServiceListener listener)
+ {
+ if (listener == null)
+ throw new IllegalArgumentException("Null listener");
+
+ checkValidBundleContext();
+
+ serviceListeners.remove(listener);
+ }
+
+ /**
+ * Add a registered service
+ *
+ * @param serviceState the service
+ */
+ void addRegisteredService(OSGiServiceState serviceState)
+ {
+ registeredServices.add(serviceState);
+ }
+
+ /**
+ * Remove a registered service
+ *
+ * @param serviceState the service
+ */
+ void removeRegisteredService(OSGiServiceState serviceState)
+ {
+ registeredServices.remove(serviceState);
+ }
+
+ public ServiceReference[] getRegisteredServices()
+ {
+ checkInstalled();
+
+ if (registeredServices.isEmpty())
+ return null;
+
+ Set<ServiceReference> result = new HashSet<ServiceReference>(registeredServices.size());
+ for (OSGiServiceState service : registeredServices)
+ {
+ if (service.hasPermission())
+ result.add(service.getReferenceInternal());
+ }
+ if (result.isEmpty())
+ return null;
+ return result.toArray(new ServiceReference[result.size()]);
+ }
+
+ /**
+ * Increment the use count of a service for this bundle
+ *
+ * @param serviceState the service
+ */
+ void addServiceInUse(OSGiServiceState serviceState)
+ {
+ synchronized (servicesInUse)
+ {
+ Integer count = servicesInUse.get(serviceState);
+ if (count == null)
+ servicesInUse.put(serviceState, 1);
+ else
+ servicesInUse.put(serviceState, ++count);
+ }
+ serviceState.addUsingBundle(this);
+ }
+
+ /**
+ * Decrement the use count of a service for this bundle
+ *
+ * @param serviceState the service
+ * @return true when the service is still in use by the bundle
+ */
+ boolean removeServiceInUse(OSGiServiceState serviceState)
+ {
+ synchronized (servicesInUse)
+ {
+ Integer count = servicesInUse.get(serviceState);
+ if (count == null)
+ {
+ return false;
+ }
+ else if (count == 1)
+ {
+ servicesInUse.remove(serviceState);
+ serviceState.removeUsingBundle(this);
+ return false;
+ }
+ else
+ {
+ servicesInUse.put(serviceState, --count);
+ }
+ }
+ return true;
+ }
+
+ public ServiceReference[] getServicesInUse()
+ {
+ checkInstalled();
+
+ synchronized (servicesInUse)
+ {
+ Collection<OSGiServiceState> inUse = servicesInUse.keySet();
+ if (inUse.isEmpty())
+ return null;
+
+ Set<ServiceReference> result = new HashSet<ServiceReference>(inUse.size());
+ for (OSGiServiceState service : inUse)
+ {
+ if (service.hasPermission())
+ result.add(service.getReferenceInternal());
+ }
+ if (result.isEmpty())
+ return null;
+ return result.toArray(new ServiceReference[result.size()]);
+ }
+ }
+
+ public ServiceReference[] getAllServiceReferences(String clazz, String filter) throws InvalidSyntaxException
+ {
+ checkValidBundleContext();
+ return getBundleManager().getServiceReferences(this, clazz, filter, false);
+ }
+
+ public Object getService(ServiceReference reference)
+ {
+ checkValidBundleContext();
+
+ if (reference == null)
+ throw new IllegalArgumentException("Null reference");
+
+ return getBundleManager().getService(this, reference);
+ }
+
+ public ServiceReference getServiceReference(String clazz)
+ {
+ checkValidBundleContext();
+ if (clazz == null)
+ throw new IllegalArgumentException("Null clazz");
+ return getBundleManager().getServiceReference(this, clazz);
+ }
+
+ public ServiceReference[] getServiceReferences(String clazz, String filter) throws InvalidSyntaxException
+ {
+ checkValidBundleContext();
+ return getBundleManager().getServiceReferences(this, clazz, filter, true);
+ }
+
+ @SuppressWarnings("unchecked")
+ public ServiceRegistration registerService(String clazz, Object service, Dictionary properties)
+ {
+ if (clazz == null)
+ throw new IllegalArgumentException("Null class");
+ return registerService(new String[] { clazz }, service, properties);
+ }
+
+ @SuppressWarnings("unchecked")
+ public ServiceRegistration registerService(String[] clazzes, Object service, Dictionary properties)
+ {
+ checkValidBundleContext();
+
+ OSGiServiceState serviceState = getBundleManager().registerService(this, clazzes, service, properties);
+ return serviceState.getRegistration();
+ }
+
+ /**
+ * Unregister a service
+ *
+ * @param serviceState the service state
+ */
+ void unregisterService(OSGiServiceState serviceState)
+ {
+ getBundleManager().unregisterService(serviceState);
+ }
+
+ public boolean ungetService(ServiceReference reference)
+ {
+ checkValidBundleContext();
+
+ return getBundleManager().ungetService(this, reference);
+ }
+
+ boolean ungetService(OSGiServiceState state)
+ {
+ return getBundleManager().ungetService(this, state);
+ }
+
+ public void addBundleListener(BundleListener listener)
+ {
+ if (listener == null)
+ throw new IllegalArgumentException("Null listener");
+
+ checkValidBundleContext();
+
+ if (listener instanceof SynchronousBundleListener)
+ checkAdminPermission(AdminPermission.LISTENER);
+
+ if (bundleListeners.contains(listener))
+ return;
+
+ bundleListeners.add(listener);
+ }
+
+ public void removeBundleListener(BundleListener listener)
+ {
+ if (listener == null)
+ throw new IllegalArgumentException("Null listener");
+
+ checkValidBundleContext();
+
+ if (listener instanceof SynchronousBundleListener)
+ checkAdminPermission(AdminPermission.LISTENER);
+
+ bundleListeners.remove(listener);
+ }
+
+ /**
+ * Try to resolve the bundle
+ *
+ * @param errorOnFail whether to throw an error when not installed
+ * @return true when resolved
+ */
+ boolean resolve(boolean errorOnFail)
+ {
+ if (getState() != INSTALLED)
+ return true;
+
+ return getBundleManager().resolve(this, errorOnFail);
+ }
+
+ public void start() throws BundleException
+ {
+ start(0);
+ }
+
+ // todo options
+ public void start(int options) throws BundleException
+ {
+ checkInstalled();
+ checkAdminPermission(AdminPermission.EXECUTE);
+
+ if (getState() == ACTIVE)
+ return;
+
+ getBundleManager().start(this);
+ }
+
+ /**
+ * Start internal
+ *
+ * todo Start Level Service & START_TRANSIENT?
+ * todo START_ACTIVATION_POLICY
+ * todo LAZY_ACTIVATION
+ * todo locks
+ * todo options
+ * @throws Throwable for any error
+ */
+ public void startInternal() throws Throwable
+ {
+ changeState(STARTING);
+ bundleContext = createBundleContext();
+ try
+ {
+ OSGiMetaData metaData = getOSGiMetaData();
+ if (metaData != null)
+ {
+ // Do we have a bundle activator
+ String bundleActivatorClassName = metaData.getBundleActivator();
+ if (bundleActivatorClassName != null)
+ {
+ ClassLoader classLoader = unit.getClassLoader();
+
+ DeploymentControllerContext deploymentControllerContext = getDeploymentUnit().getAttachment(ControllerContext.class.getName(), DeploymentControllerContext.class);
+ if (deploymentControllerContext == null)
+ throw new BundleException("No deployment controller context: " + getCanonicalName());
+
+ KernelController controller = (KernelController) deploymentControllerContext.getController();
+ BeanInfo beanInfo = controller.getKernel().getConfig().getBeanInfo(bundleActivatorClassName, classLoader);
+ Object result = beanInfo.newInstance();
+ if (result instanceof BundleActivator == false)
+ throw new BundleException(bundleActivatorClassName + " is not an implementation of " + BundleActivator.class.getName());
+ BundleActivator bundleActivator = (BundleActivator) result;
+ unit.addAttachment(BundleActivator.class, bundleActivator);
+
+ bundleActivator.start(bundleContext);
+ }
+ }
+
+ if (getState() != STARTING)
+ throw new BundleException("Bundle has been uninstalled: " + bundle);
+
+ changeState(ACTIVE);
+ }
+ catch (Throwable t)
+ {
+ changeState(STOPPING);
+ // TODO stop the bundle
+ this.bundleContext = null;
+ changeState(RESOLVED);
+ throw t;
+ }
+ }
+
+ public void stop() throws BundleException
+ {
+ stop(0);
+ }
+
+ // todo options
+ public void stop(int options) throws BundleException
+ {
+ checkInstalled();
+ checkAdminPermission(AdminPermission.EXECUTE);
+
+ if (getState() != ACTIVE)
+ return;
+
+ getBundleManager().stop(this);
+ }
+
+ /**
+ * Stop Internal
+ *
+ * todo Start Level Service & STOP_TRANSIENT?
+ * todo locks
+ * todo options
+ * @throws Throwable for any error
+ */
+ public void stopInternal() throws Throwable
+ {
+ changeState(STOPPING);
+
+ Throwable rethrow = null;
+ try
+ {
+ BundleActivator bundleActivator = unit.getAttachment(BundleActivator.class);
+ BundleContext bundleContext = this.bundleContext;
+ if (bundleActivator != null && bundleContext != null)
+ {
+ try
+ {
+ bundleActivator.stop(bundleContext);
+ }
+ catch (Throwable t)
+ {
+ rethrow = t;
+ }
+ }
+
+ for (OSGiServiceState service : registeredServices)
+ {
+ try
+ {
+ service.unregister();
+ }
+ catch (Throwable t)
+ {
+ log.debug("Error unregistering service: " + service, t);
+ }
+ }
+
+ for (Map.Entry<OSGiServiceState, Integer> inUse : servicesInUse.entrySet())
+ {
+ OSGiServiceState service = inUse.getKey();
+ Integer count = inUse.getValue();
+ for (int i = 0; i < count; ++i)
+ {
+ try
+ {
+ getBundleManager().ungetService(this, service);
+ }
+ catch (Throwable t)
+ {
+ log.debug("Error ungetting service: " + service, t);
+ }
+ }
+ }
+
+ if (getState() != STOPPING)
+ throw new BundleException("Bundle has been uninstalled: " + getCanonicalName());
+ }
+ finally
+ {
+ if (getState() == STOPPING)
+ changeState(RESOLVED);
+ bundleContext = null;
+ unit.removeAttachment(BundleActivator.class);
+ }
+
+ if (rethrow != null)
+ throw rethrow;
+ }
+
+ public void update() throws BundleException
+ {
+ checkAdminPermission(AdminPermission.LIFECYCLE); // todo extension bundles
+ // todo update
+ throw new UnsupportedOperationException("update");
+ }
+
+ public void update(InputStream in) throws BundleException
+ {
+ checkAdminPermission(AdminPermission.LIFECYCLE); // todo extension bundles
+ // todo update
+ throw new UnsupportedOperationException("update");
+ }
+
+ public void uninstall() throws BundleException
+ {
+ checkAdminPermission(AdminPermission.LIFECYCLE); // todo extension bundles
+
+ OSGiBundleManager bundleManager = getBundleManager();
+ if (bundleManager == null)
+ return;
+
+ bundleManager.uninstall(this);
+ }
+
+ void uninstallInternal()
+ {
+ changeState(Bundle.UNINSTALLED);
+
+ frameworkListeners.clear();
+ bundleListeners.clear();
+ serviceListeners.clear();
+ }
+
+ public void addFrameworkListener(FrameworkListener listener)
+ {
+ if (listener == null)
+ throw new IllegalArgumentException("Null listener");
+
+ checkValidBundleContext();
+
+ if (frameworkListeners.contains(listener))
+ return;
+
+ frameworkListeners.add(listener);
+ }
+
+ public void removeFrameworkListener(FrameworkListener listener)
+ {
+ if (listener == null)
+ throw new IllegalArgumentException("Null listener");
+
+ checkValidBundleContext();
+
+ frameworkListeners.remove(listener);
+ }
+
+ public Bundle installBundle(String location, InputStream input) throws BundleException
+ {
+ checkValidBundleContext();
+ checkAdminPermission(AdminPermission.LIFECYCLE); // todo extension bundles
+ // todo installBundle
+ throw new UnsupportedOperationException("installBundle");
+ }
+
+ public Bundle installBundle(String location) throws BundleException
+ {
+ checkValidBundleContext();
+ checkAdminPermission(AdminPermission.LIFECYCLE); // todo extension bundles
+
+ OSGiBundleManager bundleManager = getBundleManager();
+ if (bundleManager == null)
+ throw new IllegalStateException("Bundle " + getCanonicalName() + " is not valid");
+
+ try
+ {
+ URL url = new URL(location);
+ OSGiBundleState bundleState = bundleManager.install(url);
+ return bundleState.getBundleInternal();
+ }
+ catch (MalformedURLException e)
+ {
+ throw new BundleException("Unable to handle location=" + location, e);
+ }
+ }
+
+ @Override
+ public String toString()
+ {
+ return "Bundle{" + getCanonicalName() + "}";
+ }
+
+ /**
+ * Get the canonical name of the bundle
+ *
+ * @return the canonical name
+ */
+ String getCanonicalName()
+ {
+ return getSymbolicName() + ":" + osgiMetaData.getBundleVersion();
+ }
+
+ /**
+ * Set the bundle manager
+ *
+ * @param bundleManager the bundle manager or null to uninstall the bundle
+ */
+ void setBundleManager(OSGiBundleManager bundleManager)
+ {
+ if (bundleManager != null && this.bundleManager != null)
+ throw new IllegalStateException("Bundle " + this + " is already installed");
+ this.bundleManager = bundleManager;
+ if (bundleManager == null)
+ changeState(Bundle.UNINSTALLED);
+ }
+
+ /**
+ * Get the unit.
+ *
+ * @return the unit.
+ */
+ DeploymentUnit getDeploymentUnit()
+ {
+ return unit;
+ }
+
+ /**
+ * Get the source of a class for ServiceReference.isAssignable()
+ *
+ * @param className the class name
+ * @return the source or null if no source
+ */
+ Object getSource(String className)
+ {
+ // todo some more efficient way than using the class?
+ try
+ {
+ return loadClass(className);
+ }
+ catch (ClassNotFoundException e)
+ {
+ return null;
+ }
+ }
+
+ /**
+ * Change the state of the bundle
+ *
+ * @param state the new state
+ */
+ public void changeState(int state)
+ {
+ int previous = getState();
+ int type = 0;
+ switch (state)
+ {
+ case Bundle.STARTING : type = BundleEvent.STARTING; break;
+ case Bundle.ACTIVE : type = BundleEvent.STARTED; break;
+ case Bundle.STOPPING : type = BundleEvent.STOPPING; break;
+ case Bundle.UNINSTALLED : type = BundleEvent.UNINSTALLED; break;
+ case Bundle.INSTALLED :
+ {
+ if (previous == Bundle.RESOLVED)
+ type = BundleEvent.UNRESOLVED;
+ else
+ type = BundleEvent.INSTALLED;
+ break;
+ }
+ case Bundle.RESOLVED :
+ {
+ if (previous == Bundle.STOPPING)
+ type = BundleEvent.STOPPED;
+ else
+ type = BundleEvent.RESOLVED;
+ break;
+ }
+ default :
+ throw new IllegalArgumentException("Unknown bundle state: " + state);
+ }
+ this.state.set(state);
+ log.debug(this + " change state=" + toHumanReadableStateString(state));
+ BundleEvent event = new BundleEvent(type, getBundleInternal());
+ fireBundleEvent(event);
+ }
+
+ /**
+ * Fire a bundle event
+ *
+ * @param event the event
+ */
+ void fireBundleEvent(BundleEvent event)
+ {
+ // Nobody is interested
+ if (bundleListeners.isEmpty())
+ return;
+
+ // Are we active?
+ if (getBundleManager().isActive() == false)
+ return;
+
+ // Synchronous listeners first
+ for (BundleListener listener : bundleListeners)
+ {
+ try
+ {
+ if (listener instanceof SynchronousBundleListener)
+ listener.bundleChanged(event);
+ }
+ catch (Throwable t)
+ {
+ log.warn("Error while firing bundle event: " + event.getType() + " for bundle " + getCanonicalName(), t);
+ }
+ }
+ // Normal listeners after, if required
+ int type = event.getType();
+ if (type != BundleEvent.STARTING && type != BundleEvent.STOPPING && type != BundleEvent.LAZY_ACTIVATION)
+ {
+ for (BundleListener listener : bundleListeners)
+ {
+ try
+ {
+ if (listener instanceof SynchronousBundleListener == false)
+ listener.bundleChanged(event);
+ }
+ catch (Throwable t)
+ {
+ log.warn("Error while firing bundle event: " + event.getType() + " for bundle " + this, t);
+ }
+ }
+ }
+ }
+
+ /**
+ * Fire a framework event
+ *
+ * @param type the type of event
+ * @param throwable any throwable
+ */
+ void fireFrameworkEvent(int type, Throwable throwable)
+ {
+ // Nobody is interested
+ if (frameworkListeners.isEmpty())
+ return;
+
+ // Are we active?
+ if (getBundleManager().isActive() == false)
+ return;
+
+ // Call the listeners
+ FrameworkEvent event = new FrameworkEvent(type, getBundleInternal(), throwable);
+ for (FrameworkListener listener : frameworkListeners)
+ {
+ try
+ {
+ listener.frameworkEvent(event);
+ }
+ catch (Throwable t)
+ {
+ log.warn("Error while firing framework event: " + event.getType() + " for bundle " + getCanonicalName(), t);
+ }
+ }
+ }
+
+ /**
+ * Fire a service event
+ *
+ * @param type the type
+ * @param service the service
+ */
+ void fireServiceEvent(int type, OSGiServiceState service)
+ {
+ if (service == null)
+ throw new IllegalArgumentException("No serviceReference");
+
+ // Nobody is interested
+ if (serviceListeners.isEmpty())
+ return;
+
+ // Are we active?
+ if (getBundleManager().isActive() == false)
+ return;
+
+ ServiceEvent event = new ServiceEvent(type, service.getReferenceInternal());
+
+ // Call the listeners
+ for (Map.Entry<ServiceListener, ServiceListenerRegistration> entry : serviceListeners.entrySet())
+ {
+ ServiceListener listener = entry.getKey();
+ ServiceListenerRegistration registration = entry.getValue();
+ try
+ {
+ if (registration.filter.match(service))
+ {
+ AccessControlContext accessControlContext = registration.accessControlContext;
+ if (accessControlContext == null || service.hasPermission(accessControlContext))
+ listener.serviceChanged(event);
+ }
+ }
+ catch (Throwable t)
+ {
+ log.warn("Error while firing service event: " + type + " for service " + service, t);
+ }
+ }
+ }
+
+ /**
+ * Check the bundle is installed
+ *
+ * @throws IllegalStateException when the bundle is not installed
+ */
+ private void checkInstalled()
+ {
+ if ((getState() & Bundle.UNINSTALLED) != 0)
+ throw new IllegalStateException("Bundle " + getCanonicalName() + " is not installed");
+ }
+
+ /**
+ * Check a bundle context is still valid
+ *
+ * @return the bundle context
+ * @throws IllegalArgumentException when the context is no longer valid
+ */
+ private synchronized BundleContext checkValidBundleContext()
+ {
+ BundleContext result = this.bundleContext;
+ if (result == null)
+ throw new IllegalStateException("Bundle context is no longer valid");
+ return result;
+ }
+
+ /**
+ * Check the admin permission
+ *
+ * @param what what permission to check
+ * @throws SecurityException when the caller does not have the AdminPermission
+ * and a security manager is installed
+ */
+ private void checkAdminPermission(String what)
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null)
+ sm.checkPermission(new AdminPermission(this, what));
+ }
+
+ /**
+ * Checks if we have the admin permission
+ *
+ * @param what the permission to check
+ * @return true if the caller doesn't have the permission
+ */
+ private boolean noAdminPermission(String what)
+ {
+ try
+ {
+ checkAdminPermission(what);
+ return false;
+ }
+ catch (SecurityException e)
+ {
+ return true;
+ }
+ }
+
+ /**
+ * Get a human readable version of the state
+ *
+ * @param state the state
+ * @return the human readable form
+ */
+ private static String toHumanReadableStateString(int state)
+ {
+ switch (state)
+ {
+ case Bundle.INSTALLED : return "INSTALLED";
+ case Bundle.RESOLVED : return "RESOLVED";
+ case Bundle.STARTING : return "STARTING";
+ case Bundle.ACTIVE : return "ACTIVE";
+ case Bundle.STOPPING : return "STOPPING";
+ case Bundle.UNINSTALLED : return "UNINSTALLED";
+ }
+ return "???" + state;
+ }
+
+ /**
+ * ServiceListenerRegistration.
+ */
+ private static class ServiceListenerRegistration
+ {
+ // Any filter
+ Filter filter;
+
+ // Any access control context
+ AccessControlContext accessControlContext;
+
+ /**
+ * Create a new ServiceListenerRegistration.
+ *
+ * @param filter the filter
+ */
+ public ServiceListenerRegistration(Filter filter)
+ {
+ this.filter = filter;
+
+ if (System.getSecurityManager() != null)
+ accessControlContext = AccessController.getContext();
+ }
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleWrapper.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleWrapper.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleWrapper.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,200 @@
+/*
+* 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.plugins.facade.bundle;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Dictionary;
+import java.util.Enumeration;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * OSGiBundleWrapper.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class OSGiBundleWrapper implements Bundle
+{
+ /** The bundle state */
+ private OSGiBundleState bundleState;
+
+ /**
+ * Create a new OSGiBundleImpl.
+ *
+ * @param bundleState the bundle state
+ * @throws IllegalArgumentException for a null parameter
+ */
+ public OSGiBundleWrapper(OSGiBundleState bundleState)
+ {
+ if (bundleState == null)
+ throw new IllegalArgumentException("Null bundle state");
+ this.bundleState = bundleState;
+ }
+
+ /**
+ * Get the bundle state
+ *
+ * @return the bundle state
+ */
+ OSGiBundleState getBundleState()
+ {
+ return bundleState;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Enumeration findEntries(String path, String filePattern, boolean recurse)
+ {
+ return bundleState.findEntries(path, filePattern, recurse);
+ }
+
+ public BundleContext getBundleContext()
+ {
+ return bundleState.getBundleContext();
+ }
+
+ public long getBundleId()
+ {
+ return bundleState.getBundleId();
+ }
+
+ public URL getEntry(String path)
+ {
+ return bundleState.getEntry(path);
+ }
+
+ @SuppressWarnings("unchecked")
+ public Enumeration getEntryPaths(String path)
+ {
+ return bundleState.getEntryPaths(path);
+ }
+
+ @SuppressWarnings("unchecked")
+ public Dictionary getHeaders()
+ {
+ return bundleState.getHeaders();
+ }
+
+ @SuppressWarnings("unchecked")
+ public Dictionary getHeaders(String locale)
+ {
+ return bundleState.getHeaders(locale);
+ }
+
+ public long getLastModified()
+ {
+ return bundleState.getLastModified();
+ }
+
+ public String getLocation()
+ {
+ return bundleState.getLocation();
+ }
+
+ public ServiceReference[] getRegisteredServices()
+ {
+ return bundleState.getRegisteredServices();
+ }
+
+ public URL getResource(String name)
+ {
+ return bundleState.getResource(name);
+ }
+
+ @SuppressWarnings("unchecked")
+ public Enumeration getResources(String name) throws IOException
+ {
+ return bundleState.getResources(name);
+ }
+
+ public ServiceReference[] getServicesInUse()
+ {
+ return bundleState.getServicesInUse();
+ }
+
+ public int getState()
+ {
+ return bundleState.getState();
+ }
+
+ public String getSymbolicName()
+ {
+ return bundleState.getSymbolicName();
+ }
+
+ public boolean hasPermission(Object permission)
+ {
+ return bundleState.hasPermission(permission);
+ }
+
+ @SuppressWarnings("unchecked")
+ public Class loadClass(String name) throws ClassNotFoundException
+ {
+ return bundleState.loadClass(name);
+ }
+
+ public void start() throws BundleException
+ {
+ bundleState.start();
+ }
+
+ public void start(int options) throws BundleException
+ {
+ bundleState.start(options);
+ }
+
+ public void stop() throws BundleException
+ {
+ bundleState.stop();
+ }
+
+ public void stop(int options) throws BundleException
+ {
+ bundleState.stop(options);
+ }
+
+ @Override
+ public String toString()
+ {
+ return bundleState.toString();
+ }
+
+ public void uninstall() throws BundleException
+ {
+ bundleState.uninstall();
+ }
+
+ public void update() throws BundleException
+ {
+ bundleState.update();
+ }
+
+ public void update(InputStream in) throws BundleException
+ {
+ bundleState.update(in);
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiServiceReferenceWrapper.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiServiceReferenceWrapper.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiServiceReferenceWrapper.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,108 @@
+/*
+* 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.plugins.facade.bundle;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * OSGiServiceReferenceWrapper.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class OSGiServiceReferenceWrapper implements ServiceReference
+{
+ /** The service state */
+ private OSGiServiceState serviceState;
+
+ /**
+ * Create a new OSGiServiceReferenceWrapper.
+ *
+ * @param serviceState the service state
+ * @throws IllegalArgumentException for a null parameter
+ */
+ public OSGiServiceReferenceWrapper(OSGiServiceState serviceState)
+ {
+ if (serviceState == null)
+ throw new IllegalArgumentException("Null service state");
+ this.serviceState = serviceState;
+ }
+
+ public Bundle getBundle()
+ {
+ return serviceState.getBundle();
+ }
+
+ public Object getProperty(String key)
+ {
+ return serviceState.getProperty(key);
+ }
+
+ public String[] getPropertyKeys()
+ {
+ return serviceState.getPropertyKeys();
+ }
+
+ public Bundle[] getUsingBundles()
+ {
+ return serviceState.getUsingBundles();
+ }
+
+ public boolean isAssignableTo(Bundle bundle, String className)
+ {
+ return serviceState.isAssignableTo(bundle, className);
+ }
+
+ public int compareTo(Object reference)
+ {
+ return serviceState.compareTo(reference);
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ return serviceState.equals(obj);
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return serviceState.hashCode();
+ }
+
+ @Override
+ public String toString()
+ {
+ return serviceState.toString();
+ }
+
+ /**
+ * Get the serviceState.
+ *
+ * @return the serviceState.
+ */
+ OSGiServiceState getServiceState()
+ {
+ return serviceState;
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiServiceRegistrationWrapper.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiServiceRegistrationWrapper.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiServiceRegistrationWrapper.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,74 @@
+/*
+* 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.plugins.facade.bundle;
+
+import java.util.Dictionary;
+
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * OSGiServiceRegistrationWrapper.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class OSGiServiceRegistrationWrapper implements ServiceRegistration
+{
+ /** The service state */
+ private OSGiServiceState serviceState;
+
+ /**
+ * Create a new OSGiServiceRegistrationWrapper.
+ *
+ * @param serviceState the service state
+ * @throws IllegalArgumentException for a null parameter
+ */
+ public OSGiServiceRegistrationWrapper(OSGiServiceState serviceState)
+ {
+ if (serviceState == null)
+ throw new IllegalArgumentException("Null service state");
+ this.serviceState = serviceState;
+ }
+
+ public ServiceReference getReference()
+ {
+ return serviceState.getReference();
+ }
+
+ @SuppressWarnings("unchecked")
+ public void setProperties(Dictionary properties)
+ {
+ serviceState.setProperties(properties);
+ }
+
+ public void unregister()
+ {
+ serviceState.unregister();
+ }
+
+ @Override
+ public String toString()
+ {
+ return serviceState.toString();
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiServiceState.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiServiceState.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiServiceState.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,673 @@
+/*
+* 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.plugins.facade.bundle;
+
+import java.security.AccessControlContext;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.jboss.logging.Logger;
+import org.jboss.osgi.plugins.util.CaseInsensitiveDictionary;
+import org.jboss.util.collection.ConcurrentSet;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
+import org.osgi.framework.FrameworkEvent;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceFactory;
+import org.osgi.framework.ServicePermission;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * OSGiServiceState.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class OSGiServiceState implements ServiceReference, ServiceRegistration
+{
+ /** The log */
+ private static final Logger log = Logger.getLogger(OSGiServiceState.class);
+
+ /** Used to generate a unique id */
+ private static final AtomicLong serviceIDGenerator = new AtomicLong();
+
+ /** The bundle state */
+ private OSGiBundleState bundleState;
+
+ /** The service reference */
+ private OSGiServiceReferenceWrapper serviceReference;
+
+ /** The service registration */
+ private OSGiServiceRegistrationWrapper serviceRegistration;
+
+ /** The service id */
+ private long serviceId = serviceIDGenerator.incrementAndGet();
+
+ /** The service interfaces */
+ private String[] clazzes;
+
+ /** The service */
+ private Object service;
+
+ /** The service factory */
+ private ServiceFactory serviceFactory;
+
+ /** The properties */
+ private CaseInsensitiveDictionary properties;
+
+ /** The using bundles */
+ private Set<OSGiBundleState> usingBundles = new ConcurrentSet<OSGiBundleState>();
+
+ /**
+ * Create a new OSGiServiceState.
+ *
+ * @param bundleState the bundle state
+ * @param clazzes the interfaces
+ * @param service the services
+ * @param properties the properties
+ * @throws IllegalArgumentException for a null parameter
+ */
+ @SuppressWarnings("unchecked")
+ public OSGiServiceState(OSGiBundleState bundleState, String[] clazzes, Object service, Dictionary properties)
+ {
+ if (bundleState == null)
+ throw new IllegalArgumentException("Null bundle state");
+ if (clazzes == null || clazzes.length == 0)
+ throw new IllegalArgumentException("Null or empty clazzes");
+ for (String clazz : clazzes)
+ {
+ if (clazz == null)
+ throw new IllegalArgumentException("Null class in: " + clazzes);
+ }
+ if (service == null)
+ throw new IllegalArgumentException("Null service");
+ this.bundleState = bundleState;
+ this.clazzes = clazzes;
+ if (service == null)
+ {
+ throw new IllegalArgumentException("Null service");
+ }
+ if (service instanceof ServiceFactory)
+ {
+ this.serviceFactory = (ServiceFactory) service;
+ }
+ else
+ {
+ this.service = service;
+ checkObjClass(service);
+ }
+ if (properties != null)
+ this.properties = new CaseInsensitiveDictionary(properties);
+ serviceRegistration = new OSGiServiceRegistrationWrapper(this);
+ }
+
+ /**
+ * Get the serviceId.
+ *
+ * @return the serviceId.
+ */
+ public long getServiceId()
+ {
+ return serviceId;
+ }
+
+ /**
+ * Get the service ranking.
+ *
+ * @return the service rankin.
+ */
+ public int getServiceRanking()
+ {
+ Object ranking = getProperty(Constants.SERVICE_RANKING);
+ if (ranking != null && ranking instanceof Integer)
+ return ((Integer) ranking).intValue();
+ return 0;
+ }
+
+ /**
+ * Get the classes.
+ *
+ * @return the classes.
+ */
+ public String[] getClasses()
+ {
+ return clazzes;
+ }
+
+ /**
+ * Get the service.
+ *
+ * @return the service.
+ */
+ public Object getService()
+ {
+ // todo fix race condition with unregistration
+ if (isUnregistered())
+ return null;
+ checkPermission("get", false);
+
+ if (service != null)
+ return service;
+
+ if (serviceFactory != null)
+ {
+ try
+ {
+ service = checkObjClass(serviceFactory.getService(getBundle(), getRegistration()));
+ }
+ catch (Throwable t)
+ {
+ log.error("Error from getService for " + this, t);
+ getBundleState().fireFrameworkEvent(FrameworkEvent.ERROR, new BundleException("Error using service factory:" + serviceFactory, t));
+ return null;
+ }
+ }
+ return service;
+ }
+
+ /**
+ * Get the service registration
+ *
+ * @return the service registration
+ */
+ public ServiceRegistration getRegistration()
+ {
+ return serviceRegistration;
+ }
+
+ public ServiceReference getReference()
+ {
+ checkUnregistered();
+ return getReferenceInternal();
+ }
+
+ public ServiceReference getReferenceInternal()
+ {
+ if (serviceReference == null)
+ serviceReference = new OSGiServiceReferenceWrapper(this);
+ return serviceReference;
+ }
+
+ public Bundle getBundle()
+ {
+ if (isUnregistered())
+ return null;
+ return bundleState.getBundleInternal();
+ }
+
+ /**
+ * Get the bundleState.
+ *
+ * @return the bundleState.
+ */
+ public OSGiBundleState getBundleState()
+ {
+ return bundleState;
+ }
+
+ public Object getProperty(String key)
+ {
+ if (key == null)
+ return null;
+ if (Constants.SERVICE_ID.equalsIgnoreCase(key))
+ return getServiceId();
+ if (Constants.OBJECTCLASS.equalsIgnoreCase(key))
+ return getClasses();
+ if (properties == null)
+ return null;
+ return properties.get(key);
+ }
+
+ public String[] getPropertyKeys()
+ {
+ ArrayList<String> result = new ArrayList<String>();
+ if (properties != null)
+ {
+ Enumeration<String> keys = properties.keys();
+ while (keys.hasMoreElements())
+ result.add(keys.nextElement());
+ }
+ result.add(Constants.SERVICE_ID);
+ result.add(Constants.OBJECTCLASS);
+ return result.toArray(new String[result.size()]);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void setProperties(Dictionary properties)
+ {
+ checkUnregistered();
+
+ if (properties == null)
+ this.properties = null;
+ else
+ this.properties = new CaseInsensitiveDictionary(properties);
+ bundleState.fireServiceEvent(ServiceEvent.MODIFIED, this);
+ }
+
+ /**
+ * Mark a bundle as using this service
+ *
+ * @param bundleState the bundle
+ */
+ void addUsingBundle(OSGiBundleState bundleState)
+ {
+ usingBundles.add(bundleState);
+ }
+
+ /**
+ * Unmark a bundle as using this service
+ *
+ * @param bundleState the bundle
+ */
+ void removeUsingBundle(OSGiBundleState bundleState)
+ {
+ usingBundles.remove(bundleState);
+ }
+
+ public Bundle[] getUsingBundles()
+ {
+ if (usingBundles.isEmpty())
+ return null;
+
+ Set<Bundle> result = new HashSet<Bundle>();
+ for (OSGiBundleState bundleState : usingBundles)
+ result.add(bundleState.getBundleInternal());
+ return result.toArray(new Bundle[result.size()]);
+ }
+
+ public boolean isAssignableTo(Bundle bundle, String className)
+ {
+ if (bundle == null)
+ throw new IllegalArgumentException("Null bundle");
+ if (className == null)
+ throw new IllegalArgumentException("Null class name");
+ if (bundle instanceof OSGiBundleWrapper == false)
+ throw new IllegalArgumentException("Unknown bundle: " + bundle);
+
+ OSGiBundleWrapper wrapper = (OSGiBundleWrapper) bundle;
+ OSGiBundleState other = wrapper.getBundleState();
+ return isAssignableTo(other, className);
+ }
+
+ /**
+ * Check the isAssignableTo
+ *
+ * @param other the bundle state
+ * @param className the class name
+ * @return true when assignable
+ */
+ boolean isAssignableTo(OSGiBundleState other, String className)
+ {
+ if (className == null)
+ throw new IllegalArgumentException("Null class name");
+
+ if (other == bundleState)
+ return true;
+
+ if (isUnregistered())
+ return false;
+
+ Object otherSource = other.getSource(className);
+ if (otherSource == null)
+ return false;
+ Object source = bundleState.getSource(className);
+ return otherSource.equals(source);
+ }
+
+ /**
+ * Check the isAssignable
+ *
+ * @param other the bundle state
+ * @return true when assignable
+ */
+ boolean isAssignable(OSGiBundleState other)
+ {
+ if (other == bundleState)
+ return true;
+
+ if (isUnregistered())
+ return false;
+
+ for (String clazz : getClasses())
+ {
+ if (isAssignableTo(other, clazz) == false)
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Match the class
+ *
+ * @param className the class name
+ * @return true when the class name matches
+ */
+ boolean matchClass(OSGiBundleState other, String className)
+ {
+ if (clazzes == null || clazzes.length == 0)
+ return false;
+
+ for (String clazz : clazzes)
+ {
+ if (className.equals(clazz))
+ return true;
+ }
+ return false;
+ }
+
+ public void unregister()
+ {
+ checkUnregistered();
+
+ try
+ {
+ getBundleState().unregisterService(this);
+ }
+ finally
+ {
+ synchronized (this)
+ {
+ serviceRegistration = null;
+ }
+ }
+ }
+
+ public int compareTo(Object reference)
+ {
+ if (reference == null)
+ throw new IllegalArgumentException("Null reference");
+
+ OSGiServiceState other;
+ if (reference instanceof OSGiServiceState)
+ other = (OSGiServiceState) reference;
+ else if (reference instanceof OSGiServiceReferenceWrapper)
+ other = ((OSGiServiceReferenceWrapper) reference).getServiceState();
+ else
+ throw new IllegalArgumentException(reference + " is not a service reference");
+
+ long thisServiceId = this.getServiceId();
+ long otherServiceId = other.getServiceId();
+ if (thisServiceId == otherServiceId)
+ return 0;
+
+ int thisRanking = this.getServiceRanking();
+ int otherRanking = other.getServiceRanking();
+ int ranking = thisRanking - otherRanking;
+ if (ranking != 0)
+ return ranking;
+
+ if (thisServiceId > otherServiceId)
+ return -1;
+ else
+ return +1;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj == null)
+ return false;
+
+ OSGiServiceState other = null;
+ if (obj instanceof OSGiServiceState)
+ other = (OSGiServiceState) obj;
+ else if (obj instanceof OSGiServiceReferenceWrapper)
+ other = ((OSGiServiceReferenceWrapper) obj).getServiceState();
+ else
+ return false;
+ return this == other;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return toString().hashCode();
+ }
+
+ @Override
+ public String toString()
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.append("Service{");
+ builder.append("id=").append(getServiceId());
+ builder.append(" bundle=").append(getBundleState().getCanonicalName());
+ builder.append(" classes=").append(Arrays.asList(getClasses()));
+ builder.append("}");
+ return builder.toString();
+ }
+
+ public String toLongString()
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.append("Service{");
+ builder.append("id=").append(getServiceId());
+ builder.append(" bundle=").append(getBundleState().getCanonicalName());
+ builder.append(" classes=").append(Arrays.asList(getClasses()));
+ if (service != null)
+ builder.append(" service=").append(service);
+ if (serviceFactory != null)
+ builder.append(" factory=").append(serviceFactory);
+ if (properties != null)
+ builder.append(" properties=").append(properties);
+ if (usingBundles.isEmpty() == false)
+ builder.append(" using=").append(usingBundles);
+ builder.append("}");
+ return builder.toString();
+ }
+
+ /**
+ * Register the service
+ */
+ void internalRegister()
+ {
+ checkPermission("register", true);
+ getBundleState().addRegisteredService(this);
+ }
+
+ /**
+ * Unregister the service
+ */
+ void internalUnregister()
+ {
+ if (usingBundles.isEmpty() == false)
+ {
+ for (OSGiBundleState using : usingBundles)
+ using.ungetService(this);
+ }
+
+ getBundleState().removeRegisteredService(this);
+
+ if (serviceFactory != null && service != null)
+ {
+ try
+ {
+ serviceFactory.ungetService(getBundle(), getRegistration(), service);
+ }
+ catch (Throwable t)
+ {
+ log.warn("Error from ungetService for " + this, t);
+ getBundleState().fireFrameworkEvent(FrameworkEvent.WARNING, new BundleException("Error using service factory:" + serviceFactory, t));
+ }
+ finally
+ {
+ service = null;
+ }
+ }
+ }
+
+ /**
+ * Check an object matches the specified classes
+ *
+ * @param object the object
+ * @return the object if all is ok
+ */
+ private Object checkObjClass(Object object)
+ {
+ if (object == null)
+ throw new IllegalArgumentException("Null object");
+ for (String className : getClasses())
+ {
+ try
+ {
+ Class<?> clazz = getBundleState().loadClass(className);
+ // todo show classloader information all interfaces for debugging purposes
+ if (clazz.isInstance(object) == false)
+ throw new IllegalArgumentException(object + " of type " + object.getClass().getName() + " does not implement " + className);
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new IllegalArgumentException("Cannot load class: " + className, e);
+ }
+ }
+ return object;
+ }
+
+ /**
+ * Check whether the caller has permission
+ *
+ * @param action the action to check
+ * @param all whether all permissions are required
+ */
+ void checkPermission(String action, boolean all)
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm == null)
+ return;
+
+ String[] clazzes = getClasses();
+ SecurityException se = null;
+ for (String clazz : clazzes)
+ {
+ try
+ {
+ ServicePermission permission = new ServicePermission(clazz, action);
+ sm.checkPermission(permission);
+ if (all == false)
+ return;
+ }
+ catch (SecurityException e)
+ {
+ if (all)
+ throw e;
+ se = e;
+ }
+ }
+ if (se != null)
+ throw se;
+ }
+
+ /**
+ * Check whether the caller has permission
+ *
+ * @param action the action to check
+ * @param all whether all permissions are required
+ */
+ void checkPermission(AccessControlContext accessControlContext, String action, boolean all)
+ {
+ if (System.getSecurityManager() == null)
+ return;
+
+ String[] clazzes = getClasses();
+ SecurityException se = null;
+ for (String clazz : clazzes)
+ {
+ try
+ {
+ ServicePermission permission = new ServicePermission(clazz, action);
+ accessControlContext.checkPermission(permission);
+ if (all == false)
+ return;
+ }
+ catch (SecurityException e)
+ {
+ if (all)
+ throw e;
+ se = e;
+ }
+ }
+ if (se != null)
+ throw se;
+ }
+
+ /**
+ * Check whether the caller has permission to this object
+ *
+ * @return true when the caller has permission
+ */
+ boolean hasPermission()
+ {
+ try
+ {
+ checkPermission("get", false);
+ return true;
+ }
+ catch (SecurityException ignored)
+ {
+ }
+ return false;
+ }
+
+ /**
+ * Check whether the caller has permission to this object
+ *
+ * @param accessControlContext
+ * @return true when the caller has permission
+ */
+ boolean hasPermission(AccessControlContext accessControlContext)
+ {
+ try
+ {
+ checkPermission(accessControlContext, "get", false);
+ return true;
+ }
+ catch (SecurityException ignored)
+ {
+ }
+ return false;
+ }
+
+ /**
+ * Check if the service is unregistered
+ *
+ * @throws IllegalStateException if unregistered
+ */
+ private void checkUnregistered()
+ {
+ if (isUnregistered())
+ throw new IllegalStateException("Service is unregistered: " + this);
+ }
+
+ /**
+ * @return true when the service is unregistered
+ */
+ synchronized boolean isUnregistered()
+ {
+ return serviceRegistration == null;
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiSystemBundle.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiSystemBundle.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiSystemBundle.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,91 @@
+/*
+* 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.plugins.facade.bundle;
+
+import java.io.InputStream;
+
+import org.jboss.osgi.spi.metadata.OSGiMetaData;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
+
+/**
+ * OSGiSystemBundle.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+class OSGiSystemBundle extends OSGiBundleState
+{
+ /**
+ * Create a new OSGiSystemBundle.
+ *
+ * @param osgiMetaData the metadata for the system bundle
+ */
+ public OSGiSystemBundle(OSGiMetaData osgiMetaData)
+ {
+ super(osgiMetaData);
+ }
+
+ @Override
+ public String getLocation()
+ {
+ return Constants.SYSTEM_BUNDLE_LOCATION;
+ }
+
+ @Override
+ public void stop(int options) throws BundleException
+ {
+ final OSGiBundleManager bundleManager = getBundleManager();
+ getBundleManager().getExecutor().execute(new Runnable()
+ {
+ public void run()
+ {
+ bundleManager.stopFramework();
+ }
+ });
+ }
+
+ @Override
+ public void update() throws BundleException
+ {
+ final OSGiBundleManager bundleManager = getBundleManager();
+ getBundleManager().getExecutor().execute(new Runnable()
+ {
+ public void run()
+ {
+ bundleManager.restartFramework();
+ }
+ });
+ }
+
+ @Override
+ public void update(InputStream in) throws BundleException
+ {
+ throw new BundleException("The system bundle cannot be updated from a stream");
+ }
+
+ @Override
+ public void uninstall() throws BundleException
+ {
+ throw new BundleException("The system bundle cannot be uninstalled");
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/bundle/VFSEntryPathsEnumeration.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/bundle/VFSEntryPathsEnumeration.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/bundle/VFSEntryPathsEnumeration.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,101 @@
+/*
+* 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.plugins.facade.bundle;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
+
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * VFSEntryPathsEnumeration.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+class VFSEntryPathsEnumeration implements Enumeration<String>
+{
+ /** The paths */
+ private Iterator<String> paths;
+
+ /**
+ * Fix the path
+ *
+ * @param file the file to fix
+ * @param rootPath the root path
+ * @return the fixxed path
+ */
+ private String fixPath(VirtualFile file, String rootPath)
+ {
+ try
+ {
+ String result = file.getPathName();
+ int length = rootPath.length();
+ if (length != 0)
+ result = result.substring(length);
+ if (file.isLeaf() == false && result.endsWith("/") == false)
+ result += "/";
+ return result;
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException("Error fixing path for " + file, e);
+ }
+ }
+
+ /**
+ * Create a new VFSEntryPathsEnumeration.
+ *
+ * @param root the root file
+ * @param file the file to enumerate
+ * @throws IOException for any error
+ */
+ public VFSEntryPathsEnumeration(VirtualFile root, VirtualFile file) throws IOException
+ {
+ if (root == null)
+ throw new IllegalArgumentException("Null root");
+ if (file == null)
+ throw new IllegalArgumentException("Null file");
+
+ String rootPath = root.getPathName();
+ ArrayList<String> paths = new ArrayList<String>();
+ paths.add(fixPath(file, rootPath));
+
+ List<VirtualFile> children = file.getChildrenRecursively();
+ for (VirtualFile child : children)
+ paths.add(fixPath(child, rootPath));
+ this.paths = paths.iterator();
+ }
+
+ public boolean hasMoreElements()
+ {
+ return paths.hasNext();
+ }
+
+ public String nextElement()
+ {
+ return paths.next();
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/bundle/VFSFindEntriesEnumeration.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/bundle/VFSFindEntriesEnumeration.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/facade/bundle/VFSFindEntriesEnumeration.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,134 @@
+/*
+* 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.plugins.facade.bundle;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VirtualFileVisitor;
+import org.jboss.virtual.VisitorAttributes;
+import org.jboss.virtual.plugins.vfs.helpers.MatchAllVirtualFileFilter;
+
+/**
+ * VFSFindEntriesEnumeration.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+class VFSFindEntriesEnumeration implements Enumeration<URL>
+{
+ /** The paths */
+ private Iterator<URL> paths;
+
+ /**
+ * Convert file pattern (RFC 1960-based Filter) into a RegEx pattern
+ *
+ * @param filePattern the file pattern
+ * @return Regular expressions pattern
+ */
+ private static Pattern convertToPattern(String filePattern)
+ {
+ filePattern = filePattern.replace("*", ".*");
+ return Pattern.compile("^" + filePattern + "$");
+ }
+
+ /**
+ * Create a new VFSFindEntriesEnumeration.
+ *
+ * @param root the root file
+ * @param file the file to enumerate
+ * @param filePattern the file pattern
+ * @param recurse whether to recurse
+ * @throws IOException for any error
+ */
+ public VFSFindEntriesEnumeration(VirtualFile root, VirtualFile file, String filePattern, boolean recurse) throws IOException
+ {
+ if (root == null)
+ throw new IllegalArgumentException("Null root");
+ if (file == null)
+ throw new IllegalArgumentException("Null file");
+
+ String rootPath = root.getPathName();
+ VisitorAttributes attributes = new VisitorAttributes();
+ attributes.setIncludeRoot(false);
+ attributes.setLeavesOnly(true);
+ if (recurse)
+ attributes.setRecurseFilter(MatchAllVirtualFileFilter.INSTANCE);
+ VisitorImpl visitor = new VisitorImpl(rootPath, filePattern, attributes);
+ file.visit(visitor);
+ this.paths = visitor.paths.iterator();
+ }
+
+ public boolean hasMoreElements()
+ {
+ return paths.hasNext();
+ }
+
+ public URL nextElement()
+ {
+ return paths.next();
+ }
+
+ static class VisitorImpl implements VirtualFileVisitor
+ {
+ ArrayList<URL> paths = new ArrayList<URL>();
+
+ Pattern filter;
+ String rootPath;
+ VisitorAttributes attributes;
+
+ VisitorImpl(String rootPath, String filter, VisitorAttributes attributes)
+ {
+ this.rootPath = rootPath;
+ this.filter = convertToPattern(filter);
+ this.attributes = attributes;
+ }
+
+ public VisitorAttributes getAttributes()
+ {
+ return attributes;
+ }
+
+ public void visit(VirtualFile virtualFile)
+ {
+ // See if the filter matches
+ Matcher matcher = filter.matcher(virtualFile.getName());
+ if (matcher.find() == false)
+ return;
+
+ try
+ {
+ paths.add(virtualFile.toURL());
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Error visiting " + virtualFile, e);
+ }
+ }
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/FilterImpl.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/FilterImpl.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/FilterImpl.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,108 @@
+/*
+* 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.plugins.filter;
+
+import java.util.Dictionary;
+
+import org.jboss.osgi.plugins.filter.model.Operation;
+import org.jboss.osgi.plugins.filter.parser.FilterParser;
+import org.jboss.osgi.plugins.filter.property.PropertySource;
+import org.osgi.framework.Filter;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * FilterImpl.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class FilterImpl implements Filter
+{
+ /** The operation */
+ private Operation operation;
+
+ /** The cached string */
+ private String cachedString;
+
+ /**
+ * Create a new FilterImpl.
+ *
+ * @param filter the filter
+ * @throws InvalidSyntaxException if the filter syntax is invalid
+ */
+ public FilterImpl(String filter) throws InvalidSyntaxException
+ {
+ if (filter == null)
+ throw new InvalidSyntaxException("Null filter", "?");
+
+ FilterParser parser = new FilterParser();
+ this.operation = parser.parse(filter);
+ }
+
+ @SuppressWarnings("unchecked")
+ public boolean match(Dictionary dictionary)
+ {
+ return operation.match(PropertySource.fromDictionary(dictionary, false));
+ }
+
+ public boolean match(ServiceReference reference)
+ {
+ return operation.match(PropertySource.fromServiceReference(reference));
+ }
+
+ @SuppressWarnings("unchecked")
+ public boolean matchCase(Dictionary dictionary)
+ {
+ return operation.match(PropertySource.fromDictionary(dictionary, true));
+ }
+
+ @Override
+ public String toString()
+ {
+ if (cachedString == null)
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.append('(');
+ operation.toString(builder);
+ builder.append(')');
+ cachedString = builder.toString();
+ }
+ return cachedString;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return toString().hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj == this)
+ return true;
+ if (obj == null || obj instanceof Filter == false)
+ return false;
+ return toString().equals(obj.toString());
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/NoFilter.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/NoFilter.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/NoFilter.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,63 @@
+/*
+* 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.plugins.filter;
+
+import java.util.Dictionary;
+
+import org.osgi.framework.Filter;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * Dummy filter implementation
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class NoFilter implements Filter
+{
+ /** Singleton instance */
+ public static final Filter INSTANCE = new NoFilter();
+
+ /**
+ * Singleton
+ */
+ private NoFilter()
+ {
+ }
+
+ @SuppressWarnings("unchecked")
+ public boolean match(Dictionary dictionary)
+ {
+ return true;
+ }
+
+ public boolean match(ServiceReference reference)
+ {
+ return true;
+ }
+
+ @SuppressWarnings("unchecked")
+ public boolean matchCase(Dictionary dictionary)
+ {
+ return true;
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/model/AndOperation.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/model/AndOperation.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/model/AndOperation.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,73 @@
+/*
+* 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.plugins.filter.model;
+
+import java.util.List;
+
+import org.jboss.osgi.plugins.filter.property.PropertySource;
+
+/**
+ * AndOperation.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class AndOperation extends Operation
+{
+ /** The operations */
+ private List<Operation> operations;
+
+ /**
+ * Create a new AndOperation.
+ *
+ * @param operations the operations
+ */
+ public AndOperation(List<Operation> operations)
+ {
+ if (operations == null)
+ throw new IllegalArgumentException("Null opertations");
+ this.operations = operations;
+ }
+
+ @Override
+ public boolean doMatch(PropertySource source)
+ {
+ for (Operation operation : operations)
+ {
+ if (operation.match(source) == false)
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public void toString(StringBuilder builder)
+ {
+ builder.append('&');
+ for (Operation operation : operations)
+ {
+ builder.append('(');
+ operation.toString(builder);
+ builder.append(')');
+ }
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/model/ApproximateOperation.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/model/ApproximateOperation.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/model/ApproximateOperation.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,74 @@
+/*
+* 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.plugins.filter.model;
+
+/**
+ * ApproximateOperation.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class ApproximateOperation extends CompareOperation
+{
+ /**
+ * Create a new ApproximateOperation.
+ *
+ * @param left the attribute
+ * @param right the value
+ */
+ public ApproximateOperation(String left, String right)
+ {
+ super(left, right);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ protected boolean compare(Comparable lhs, Object rhs)
+ {
+ return isApproximate(lhs, rhs);
+ }
+
+ @Override
+ protected boolean equals(Object lhs, Object rhs)
+ {
+ return isApproximate(lhs, rhs);
+ }
+
+ /**
+ * Test whether two values are approximately equal
+ *
+ * @param lhs the left hand side
+ * @param rhs the right hand side
+ * @return true when approximate
+ */
+ protected boolean isApproximate(Object lhs, Object rhs)
+ {
+ // TODO approximate
+ return lhs.equals(rhs);
+ }
+
+ @Override
+ public void appendOperation(StringBuilder builder)
+ {
+ builder.append("~=");
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/model/CompareOperation.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/model/CompareOperation.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/model/CompareOperation.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,192 @@
+/*
+* 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.
+*/
+
+// This class is based on some original classes from
+// Apache Felix which is licensed as below
+
+/*
+ * 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.jboss.osgi.plugins.filter.model;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.util.Iterator;
+
+import org.jboss.osgi.plugins.filter.property.PropertySource;
+
+/**
+ * CompareOperation.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class CompareOperation extends Operation
+{
+ /** The left attribute */
+ private String left;
+
+ /** The right value */
+ private String right;
+
+ /**
+ * Create a new CompareOperation.
+ *
+ * @param left the attribute
+ * @param right the value
+ */
+ public CompareOperation(String left, String right)
+ {
+ if (left == null)
+ throw new IllegalArgumentException("Null left");
+ if (right == null)
+ throw new IllegalArgumentException("Null right");
+ this.left = left;
+ this.right = right;
+ }
+
+ @Override
+ public boolean doMatch(PropertySource source)
+ {
+ Object value = source.getProperty(left);
+ if (value == null)
+ return false;
+ return compare(value, right);
+ }
+
+ /**
+ * Compare two values
+ *
+ * @param lhs the left hand side
+ * @param rhs the right hand side
+ * @return true when they compare according to the operation
+ */
+ @SuppressWarnings("unchecked")
+ protected boolean compare(Object lhs, String rhs)
+ {
+ if (lhs.getClass().isArray())
+ {
+ // TODO primitive arrays
+
+ Object[] array = (Object[]) lhs;
+ for (int i = 0; i < array.length; ++i)
+ {
+ if (compare(array[i], rhs))
+ return true;
+ }
+ return false;
+ }
+ else if (lhs instanceof Iterable)
+ {
+ Iterable<?> iterable = Iterable.class.cast(lhs);
+ Iterator<?> iterator = iterable.iterator();
+ while (iterator.hasNext())
+ {
+ if (compare(iterator.next(), rhs))
+ return true;
+ }
+ return false;
+ }
+
+ Object rhsValue = null;
+ Class<?> lhsClass = lhs.getClass();
+ try
+ {
+ // Convert to the correct type
+ if (lhsClass == String.class)
+ rhsValue = rhs;
+ else if (lhsClass == Character.class)
+ rhsValue = new Character(rhs.charAt(0)); // REVIEW Ignore remaining characters?
+ else
+ {
+ // TODO use jboss-reflect
+ try
+ {
+ Method method = lhsClass.getMethod("valueOf", new Class[] { String.class });
+ rhsValue = method.invoke(null, rhs);
+ }
+ catch (Exception e)
+ {
+ Constructor<?> constructor = lhsClass.getConstructor(new Class[] { String.class });
+ rhsValue = constructor.newInstance(rhs);
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Unable to create a comparable using new " + lhsClass.getName() + "(java.lang.String)", e);
+ }
+
+ if (Comparable.class.isAssignableFrom(lhs.getClass()) == false)
+ return equals(lhs, rhsValue);
+
+ Comparable<?> lhsComparable = Comparable.class.cast(lhs);
+ return compare(lhsComparable, rhsValue);
+ }
+
+ /**
+ * Compare using equals
+ *
+ * @param lhs the attribute value
+ * @param rhs the string value converted to the attribute's type
+ * @return true when equal
+ */
+ protected boolean equals(Object lhs, Object rhs)
+ {
+ throw new IllegalArgumentException("Cannot do '" + toString() + " since " + lhs.getClass().getName() + " is not comparable");
+ }
+
+ /**
+ * Compare using comparator
+ *
+ * @param lhs the attribute value
+ * @param rhs the string value converted to the attribute's type
+ * @return true when equal
+ */
+ @SuppressWarnings("unchecked")
+ protected abstract boolean compare(Comparable lhs, Object rhs);
+
+ @Override
+ public void toString(StringBuilder builder)
+ {
+ builder.append(left);
+ appendOperation(builder);
+ builder.append(right);
+ }
+
+ public abstract void appendOperation(StringBuilder builder);
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/model/EqualsOperation.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/model/EqualsOperation.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/model/EqualsOperation.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,61 @@
+/*
+* 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.plugins.filter.model;
+
+/**
+ * EqualsOperation.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class EqualsOperation extends CompareOperation
+{
+ /**
+ * Create a new EqualsOperation.
+ *
+ * @param left the attribute
+ * @param right the value
+ */
+ public EqualsOperation(String left, String right)
+ {
+ super(left, right);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ protected boolean compare(Comparable lhs, Object rhs)
+ {
+ return lhs.compareTo(rhs) == 0;
+ }
+
+ @Override
+ protected boolean equals(Object lhs, Object rhs)
+ {
+ return lhs.equals(rhs);
+ }
+
+ @Override
+ public void appendOperation(StringBuilder builder)
+ {
+ builder.append('=');
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/model/GreaterThanOperation.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/model/GreaterThanOperation.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/model/GreaterThanOperation.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,55 @@
+/*
+* 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.plugins.filter.model;
+
+/**
+ * GreaterThanOperation.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class GreaterThanOperation extends CompareOperation
+{
+ /**
+ * Create a new GreaterThanOperation.
+ *
+ * @param left the attribute
+ * @param right the value
+ */
+ public GreaterThanOperation(String left, String right)
+ {
+ super(left, right);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ protected boolean compare(Comparable lhs, Object rhs)
+ {
+ return lhs.compareTo(rhs) >= 0;
+ }
+
+ @Override
+ public void appendOperation(StringBuilder builder)
+ {
+ builder.append(">=");
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/model/LessThanOperation.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/model/LessThanOperation.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/model/LessThanOperation.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,55 @@
+/*
+* 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.plugins.filter.model;
+
+/**
+ * LessThanOperation.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class LessThanOperation extends CompareOperation
+{
+ /**
+ * Create a new GreaterThanOperation.
+ *
+ * @param left the attribute
+ * @param right the value
+ */
+ public LessThanOperation(String left, String right)
+ {
+ super(left, right);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ protected boolean compare(Comparable lhs, Object rhs)
+ {
+ return lhs.compareTo(rhs) <= 0;
+ }
+
+ @Override
+ public void appendOperation(StringBuilder builder)
+ {
+ builder.append("<=");
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/model/NotOperation.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/model/NotOperation.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/model/NotOperation.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,62 @@
+/*
+* 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.plugins.filter.model;
+
+import org.jboss.osgi.plugins.filter.property.PropertySource;
+
+/**
+ * NotOperation.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class NotOperation extends Operation
+{
+ /** The other operation */
+ private Operation other;
+
+ /**
+ * Create a new NotOperation.
+ *
+ * @param other the operation to negate
+ */
+ public NotOperation(Operation other)
+ {
+ if (other == null)
+ throw new IllegalArgumentException("Null other");
+ this.other = other;
+ }
+
+ @Override
+ public boolean doMatch(PropertySource source)
+ {
+ return other.match(source) == false;
+ }
+
+ @Override
+ public void toString(StringBuilder builder)
+ {
+ builder.append("!(");
+ other.toString(builder);
+ builder.append(')');
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/model/Operation.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/model/Operation.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/model/Operation.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,79 @@
+/*
+* 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.plugins.filter.model;
+
+import org.jboss.logging.Logger;
+import org.jboss.osgi.plugins.filter.property.PropertySource;
+
+/**
+ * Operation.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class Operation
+{
+ /** The log */
+ private static final Logger log = Logger.getLogger(Operation.class);
+
+ /**
+ * Match a filter against the property source
+ *
+ * @param source the property source
+ * @return true for a match
+ */
+ public final boolean match(PropertySource source)
+ {
+ try
+ {
+ return doMatch(source);
+ }
+ catch (Exception e)
+ {
+ log.trace("Error during match for " + this, e);
+ return false;
+ }
+ }
+
+ /**
+ * Match a filter against the property source
+ *
+ * @param source the property source
+ * @return true for a match
+ */
+ public abstract boolean doMatch(PropertySource source);
+
+ /**
+ * Describe the operation
+ *
+ * @param builder the builder to use
+ */
+ public abstract void toString(StringBuilder builder);
+
+ @Override
+ public String toString()
+ {
+ StringBuilder builder = new StringBuilder();
+ toString(builder);
+ return builder.toString();
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/model/OrOperation.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/model/OrOperation.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/model/OrOperation.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,73 @@
+/*
+* 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.plugins.filter.model;
+
+import java.util.List;
+
+import org.jboss.osgi.plugins.filter.property.PropertySource;
+
+/**
+ * OrOperation.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class OrOperation extends Operation
+{
+ /** The operations */
+ private List<Operation> operations;
+
+ /**
+ * Create a new OrOperation.
+ *
+ * @param operations the operations
+ */
+ public OrOperation(List<Operation> operations)
+ {
+ if (operations == null)
+ throw new IllegalArgumentException("Null opertations");
+ this.operations = operations;
+ }
+
+ @Override
+ public boolean doMatch(PropertySource source)
+ {
+ for (Operation operation : operations)
+ {
+ if (operation.match(source))
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public void toString(StringBuilder builder)
+ {
+ builder.append('|');
+ for (Operation operation : operations)
+ {
+ builder.append('(');
+ operation.toString(builder);
+ builder.append(')');
+ }
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/model/PresentOperation.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/model/PresentOperation.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/model/PresentOperation.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,61 @@
+/*
+* 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.plugins.filter.model;
+
+import org.jboss.osgi.plugins.filter.property.PropertySource;
+
+/**
+ * PresentOperation.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class PresentOperation extends Operation
+{
+ /** The attribute */
+ private String attribute;
+
+ /**
+ * Create a new PresentOperation.
+ *
+ * @param attribute the attribute
+ */
+ public PresentOperation(String attribute)
+ {
+ if (attribute == null)
+ throw new IllegalArgumentException("Null attribute");
+ this.attribute = attribute;
+ }
+
+ @Override
+ public boolean doMatch(PropertySource source)
+ {
+ Object value = source.getProperty(attribute);
+ return value != null;
+ }
+
+ @Override
+ public void toString(StringBuilder builder)
+ {
+ builder.append(attribute).append("=*");
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/model/SubStringOperation.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/model/SubStringOperation.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/model/SubStringOperation.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,153 @@
+/*
+* 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.
+*/
+
+// This class is based on some original classes from
+// Apache Felix which is licensed as below
+
+/*
+ * 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.jboss.osgi.plugins.filter.model;
+
+import java.util.List;
+
+import org.jboss.osgi.plugins.filter.property.PropertySource;
+
+/**
+ * SubStringOperation.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class SubStringOperation extends Operation
+{
+ /** The attribute */
+ private String attribute;
+
+ /** The prieces */
+ private List<String> pieces;
+
+ /**
+ * Create a new SubStringOperation.
+ *
+ * @param attribute the attribute
+ * @param pieces the pieces
+ */
+ public SubStringOperation(String attribute, List<String> pieces)
+ {
+ if (attribute == null)
+ throw new IllegalArgumentException("Null attribute");
+ if (pieces == null)
+ throw new IllegalStateException("Null pieces");
+ this.attribute = attribute;
+ this.pieces = pieces;
+ }
+
+ @Override
+ public boolean doMatch(PropertySource source)
+ {
+ Object value = source.getProperty(attribute);
+ if (value == null)
+ return false;
+ if (value instanceof String)
+ return compare((String) value);
+ else if (value instanceof String[])
+ {
+ String[] values = (String[]) value;
+ for (String val : values)
+ {
+ if (compare(val))
+ return true;
+ }
+ return false;
+ }
+ throw new RuntimeException("Attribute " + value + " is not a String or String[] type=" + value.getClass().getName());
+ }
+
+ /**
+ * Compare the string to the pieces
+ *
+ * @param value the string
+ * @return true when it matchs
+ */
+ protected boolean compare(String value)
+ {
+ // Current index in value
+ int index = 0;
+
+ // Go through each piece
+ int noPieces = pieces.size();
+ for (int i = 0; i < noPieces; ++i)
+ {
+ String piece = pieces.get(i);
+
+ // Last piece
+ if (i == noPieces-1)
+ return piece.length() <= value.length() - index && value.endsWith(piece);
+ // First piece
+ if (i == 0)
+ {
+ if (value.startsWith(piece) == false)
+ return false;
+ }
+ // Middle pieces
+ else
+ {
+ index = value.indexOf(piece, index);
+ if (index == -1)
+ return false;
+ }
+ index += piece.length();
+ }
+ return false;
+ }
+
+ @Override
+ public void toString(StringBuilder builder)
+ {
+ builder.append(attribute).append('=');
+ boolean first = true;
+ for (String piece : pieces)
+ {
+ if (first)
+ first = false;
+ else
+ builder.append('*');
+ builder.append(piece);
+ }
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/parser/FilterParser.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/parser/FilterParser.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/parser/FilterParser.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,454 @@
+/*
+* 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.
+*/
+
+// This class is based on some original classes from
+// Apache Felix which is licensed as below
+
+/*
+ * 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.jboss.osgi.plugins.filter.parser;
+
+import java.io.CharArrayReader;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.osgi.plugins.filter.model.AndOperation;
+import org.jboss.osgi.plugins.filter.model.ApproximateOperation;
+import org.jboss.osgi.plugins.filter.model.EqualsOperation;
+import org.jboss.osgi.plugins.filter.model.GreaterThanOperation;
+import org.jboss.osgi.plugins.filter.model.LessThanOperation;
+import org.jboss.osgi.plugins.filter.model.NotOperation;
+import org.jboss.osgi.plugins.filter.model.Operation;
+import org.jboss.osgi.plugins.filter.model.OrOperation;
+import org.jboss.osgi.plugins.filter.model.PresentOperation;
+import org.jboss.osgi.plugins.filter.model.SubStringOperation;
+import org.osgi.framework.InvalidSyntaxException;
+
+/**
+ * FilterParser.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class FilterParser
+{
+ /** EOF */
+ private static final int EOF = -1;
+
+ /** Left parenthesis */
+ private static final int LEFT_PAREN = '(';
+
+ /** Right parenthesis */
+ private static final int RIGHT_PAREN = ')';
+
+ /** Asterisk */
+ private static final int ASTERISK = '*';
+
+ /** Leading Attribute Characters */
+ private static final String LEADING_ATTRIBUTE = ".abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_";
+
+ /** Internal Attribute Characters */
+ private static final String INTERNAL_ATTRIBUTE = ".abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_ ";
+
+ /** Simple operation */
+ private static final int SIMPLE = 0;
+
+ /** Present operation */
+ private static final int PRESENT = 1;
+
+ /** Substring operation */
+ private static final int SUBSTRING = 2;
+
+ /** Next character not reader */
+ private static final int NO_NEXT_CHAR = 0;
+
+ /** The current character */
+ private int nextChar = NO_NEXT_CHAR;
+
+ /** The current position in the stream */
+ private int position = 0;
+
+ /** The filter */
+ private String filter;
+
+ /** The reader */
+ private Reader reader;
+
+ /**
+ * Parse a filter from a string
+ *
+ * @param filter the filter string
+ * @return the operation
+ * @throws InvalidSyntaxException for any error parsing the filter
+ */
+ public Operation parse(String filter) throws InvalidSyntaxException
+ {
+ if (filter == null)
+ throw new InvalidSyntaxException("Null filter", "?");
+
+ this.filter = filter;
+ reader = new CharArrayReader(filter.toCharArray());
+
+ try
+ {
+ Operation result = matchFilter();
+ if (peekEOF() != EOF)
+ throw raiseSyntaxError("Expected EOF but was '" + peekChar() + "'");
+ return result;
+ }
+ catch (InvalidSyntaxException e)
+ {
+ throw e;
+ }
+ catch (Throwable t)
+ {
+ throw raiseSyntaxError("Error parsing filter", t);
+ }
+ }
+
+ // filter = '(' filter-comp ')'
+ private Operation matchFilter() throws Exception
+ {
+ if (peekNWS() != LEFT_PAREN)
+ throw raiseSyntaxError("Expected ( but was '" + peekChar() + "'");
+ eat();
+
+ Operation result = matchFilterComp();
+
+ if (peekNWS() != RIGHT_PAREN)
+ throw raiseSyntaxError("Expected ) but was '" + peekChar() + "'");
+ eat();
+
+ return result;
+ }
+
+ // filter-comp = and | or | not | operation
+ // and = '&' filter-list
+ // or = '|' filter-list
+ // not = '!' filter
+ private Operation matchFilterComp() throws Exception
+ {
+ int c = peekNWS();
+ switch (c)
+ {
+ case '&':
+ case '|':
+ {
+ char op = nextChar();
+ List<Operation> operations = matchFilterList();
+ if (operations.isEmpty())
+ throw raiseSyntaxError("Expected filters after " + op + "'");
+ if (c == '&')
+ return new AndOperation(operations);
+ else
+ return new OrOperation(operations);
+ }
+ case '!':
+ {
+ eat();
+ Operation other = matchFilter();
+ return new NotOperation(other);
+ }
+ default:
+ {
+ return matchOperation();
+ }
+ }
+ }
+
+ // filter-list = filter | filter filter-list
+ private List<Operation> matchFilterList() throws Exception
+ {
+ List<Operation> operations = new ArrayList<Operation>();
+
+ int c = peekNWS();
+ while (c == LEFT_PAREN)
+ {
+ operations.add(matchFilter());
+ c = peekNWS();
+ }
+ return operations;
+ }
+
+ // operation = simple | present | substring
+ private Operation matchOperation() throws Exception
+ {
+ String attribute = matchAttribute();
+
+ int op = peekNWS();
+ char opChar = peekChar();
+ switch (op)
+ {
+ case '=':
+ {
+ eat();
+ break;
+ }
+ case '~':
+ case '<':
+ case '>':
+ {
+ eat();
+ char next = peekChar();
+ if (next != '=')
+ throw raiseSyntaxError("Expected = but was '" + next + "'");
+ eat();
+ break;
+ }
+ default:
+ {
+ throw raiseSyntaxError("Expected an operation i,e. =|<=|>=|<= but was '" + opChar + "'");
+ }
+ }
+
+ ArrayList<String> pieces = new ArrayList<String>();
+ int kind = substring(pieces);
+ if (op != '=' && kind != SIMPLE)
+ throw raiseSyntaxError("Operation " + op + "= is only allowed in simple cases");
+
+ switch (kind)
+ {
+ case SIMPLE:
+ {
+ switch (op)
+ {
+ case '=':
+ return new EqualsOperation(attribute, pieces.get(0));
+ case '<':
+ return new LessThanOperation(attribute, pieces.get(0));
+ case '>':
+ return new GreaterThanOperation(attribute, pieces.get(0));
+ case '~':
+ return new ApproximateOperation(attribute, pieces.get(0));
+ }
+ throw new IllegalStateException("Unknown operation: " + opChar);
+ }
+ case PRESENT:
+ {
+ return new PresentOperation(attribute);
+ }
+ case SUBSTRING:
+ {
+ return new SubStringOperation(attribute, pieces);
+ }
+ default:
+ {
+ throw new IllegalStateException("Unknown kind=" + kind);
+ }
+ }
+ }
+
+ private String matchAttribute() throws Exception
+ {
+ int c = peekNWS();
+ if (LEADING_ATTRIBUTE.indexOf(c) == -1)
+ throw raiseSyntaxError(peekChar() + " is not allowed to start an attribute name");
+
+ StringBuilder builder = new StringBuilder();
+ do
+ {
+ builder.append(nextChar());
+ }
+ while (INTERNAL_ATTRIBUTE.indexOf(peek()) >= 0);
+
+ // Trim trailing blanks
+ int i = builder.length()-1;
+ while (i > 0 && builder.charAt(i) == ' ')
+ i--;
+ builder.setLength(i+1);
+ return builder.toString();
+ }
+
+ // substring = attr '=' initial any final
+ // initial = () | value
+ // any = '*' star-value
+ // star-value = () | value '*' star-value
+ // final = () | value
+ int substring(ArrayList<String> pieces) throws Exception
+ {
+ StringBuilder builder = new StringBuilder();
+ boolean wasStar = false; // last piece was a star
+ boolean leftStar = false; // initial piece is a star
+ boolean rightStar = false; // final piece is a star
+
+ int c = NO_NEXT_CHAR;
+ while (c != RIGHT_PAREN)
+ {
+ c = peek();
+ switch (c)
+ {
+ case EOF:
+ {
+ throw raiseSyntaxError("Unexpected EOF");
+ }
+ case RIGHT_PAREN:
+ {
+ if (wasStar)
+ rightStar = true;
+ else
+ pieces.add(builder.toString());
+ break;
+ }
+ case '\\':
+ {
+ wasStar = false;
+ eat();
+ char nextChar = safeNextChar();
+ builder.append(nextChar);
+ break;
+ }
+ case ASTERISK:
+ {
+ if (wasStar)
+ throw raiseSyntaxError("Unexpected **");
+ eat();
+ if (builder.length() > 0)
+ pieces.add(builder.toString());
+ builder.setLength(0);
+ // Leading star
+ if (pieces.isEmpty())
+ leftStar = true;
+ wasStar = true;
+ break;
+ }
+ default:
+ {
+ wasStar = false;
+ builder.append(safeNextChar());
+ }
+ }
+ }
+
+ if (pieces.isEmpty())
+ return PRESENT; // Check leftStar???
+
+ if (leftStar || rightStar || pieces.size() > 1)
+ {
+ if (rightStar)
+ pieces.add("");
+ if (leftStar)
+ pieces.add(0, "");
+ return SUBSTRING;
+ }
+
+ return SIMPLE;
+ }
+
+ private InvalidSyntaxException raiseSyntaxError(String message) throws InvalidSyntaxException
+ {
+ throw new InvalidSyntaxException(message + " at position " + position + " filter='" + filter + "'", filter);
+ }
+
+ private InvalidSyntaxException raiseSyntaxError(String message, Throwable t) throws InvalidSyntaxException
+ {
+ throw new InvalidSyntaxException(message + " at position " + position + " filter='" + filter + "' (" + t.getClass().getName() + ": " + t.getMessage() + ")", filter, t);
+ }
+
+ private int read() throws Exception
+ {
+ ++position;
+ return reader.read();
+ }
+
+ private void eat() throws Exception
+ {
+ next();
+ }
+
+ private char nextChar() throws Exception
+ {
+ return (char) next();
+ }
+
+ private char safeNextChar() throws Exception
+ {
+ char result = nextChar();
+ if (result == EOF)
+ throw raiseSyntaxError("Unexpected EOF");
+ return result;
+ }
+
+ private int next() throws Exception
+ {
+ // We haven't read it yet
+ if (nextChar == NO_NEXT_CHAR)
+ return read();
+
+ // We already peeked it
+ int result = nextChar;
+ nextChar = NO_NEXT_CHAR;
+ return result;
+ }
+
+ private char peekChar() throws Exception
+ {
+ return (char) peek();
+ }
+
+ private int peek() throws Exception
+ {
+ // Haven't already peeked it
+ if (nextChar == NO_NEXT_CHAR)
+ nextChar = read();
+
+ // Return the peeked value
+ return nextChar;
+ }
+
+ private void skipWS() throws Exception
+ {
+ while (Character.isWhitespace(peekChar()))
+ next();
+ }
+
+ private int peekNWS() throws Exception
+ {
+ skipWS();
+ int result = peek();
+ if (result == EOF)
+ raiseSyntaxError("Unexpected EOF");
+ return result;
+ }
+
+ private int peekEOF() throws Exception
+ {
+ skipWS();
+ return peek();
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/property/DictionaryToPropertySource.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/property/DictionaryToPropertySource.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/property/DictionaryToPropertySource.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,56 @@
+/*
+* 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.plugins.filter.property;
+
+import java.util.Dictionary;
+
+
+/**
+ * DictionaryToPropertySource.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+class DictionaryToPropertySource extends PropertySource
+{
+ /** The dictionary */
+ @SuppressWarnings("unchecked")
+ private Dictionary dictionary;
+
+ /**
+ * Create a new DictionaryToPropertySource.
+ *
+ * @param dictionary the dictionary
+ */
+ @SuppressWarnings("unchecked")
+ public DictionaryToPropertySource(Dictionary dictionary)
+ {
+ if (dictionary == null)
+ throw new IllegalArgumentException("Null dictionary");
+ this.dictionary = dictionary;
+ }
+
+ public Object getProperty(String key)
+ {
+ return dictionary.get(key);
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/property/PropertySource.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/property/PropertySource.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/property/PropertySource.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,69 @@
+/*
+* 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.plugins.filter.property;
+
+import java.util.Dictionary;
+
+import org.jboss.osgi.plugins.util.CaseInsensitiveDictionary;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * PropertySource.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class PropertySource
+{
+ /**
+ * Create a property source for a dictionary
+ *
+ * @param dictionary the dictionary
+ * @param caseSensitive whether the match should be case sensitive
+ * @return the property source
+ */
+ @SuppressWarnings("unchecked")
+ public static PropertySource fromDictionary(Dictionary dictionary, boolean caseSensitive)
+ {
+ if (caseSensitive == false)
+ dictionary = new CaseInsensitiveDictionary(dictionary);
+ return new DictionaryToPropertySource(dictionary);
+ }
+ /**
+ * Create a property source for a service reference
+ *
+ * @param reference the service reference
+ * @return the property source
+ */
+ public static PropertySource fromServiceReference(ServiceReference reference)
+ {
+ return new ServiceReferenceToPropertySource(reference);
+ }
+
+ /**
+ * Get a property
+ *
+ * @param key the key
+ * @return the property or null if not found
+ */
+ public abstract Object getProperty(String key);
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/property/ServiceReferenceToPropertySource.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/property/ServiceReferenceToPropertySource.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/filter/property/ServiceReferenceToPropertySource.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,53 @@
+/*
+* 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.plugins.filter.property;
+
+import org.osgi.framework.ServiceReference;
+
+/**
+ * ServiceReferenceToPropertySource.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+class ServiceReferenceToPropertySource extends PropertySource
+{
+ /** The service reference */
+ private ServiceReference serviceReference;
+
+ /**
+ * Create a new ServiceReferenceToPropertySource.
+ *
+ * @param serviceReference the service reference
+ */
+ public ServiceReferenceToPropertySource(ServiceReference serviceReference)
+ {
+ if (serviceReference == null)
+ throw new IllegalArgumentException("Null serviceReference");
+ this.serviceReference = serviceReference;
+ }
+
+ public Object getProperty(String key)
+ {
+ return serviceReference.getProperty(key);
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/framework/AdminPermission.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/framework/AdminPermission.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/framework/AdminPermission.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,54 @@
+/*
+* 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.plugins.framework;
+
+import java.security.BasicPermission;
+
+import org.osgi.framework.Bundle;
+
+/**
+ * AdminPermission.
+ *
+ * todo this properly
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class AdminPermission extends BasicPermission
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 8276694645277531048L;
+
+ /** The bundle */
+ //private Bundle bundle;
+
+ /**
+ * Create a new AdminPermission.
+ *
+ * @param bundle the bundle
+ * @param actions the actions
+ */
+ public AdminPermission(Bundle bundle, String actions)
+ {
+ super(bundle.toString(), actions);
+ //this.bundle = bundle;
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/framework/FrameworkUtil.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/framework/FrameworkUtil.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/framework/FrameworkUtil.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,40 @@
+/*
+* 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.plugins.framework;
+
+import org.jboss.osgi.plugins.filter.FilterImpl;
+import org.osgi.framework.Filter;
+import org.osgi.framework.InvalidSyntaxException;
+
+/**
+ * FrameworkUtil.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class FrameworkUtil
+{
+ public static Filter createFilter(String filter) throws InvalidSyntaxException
+ {
+ return new FilterImpl(filter);
+ }
+}
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/metadata/AbstractOSGiMetaData.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/metadata/AbstractOSGiMetaData.java 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/metadata/AbstractOSGiMetaData.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -21,20 +21,51 @@
*/
package org.jboss.osgi.plugins.metadata;
+import static org.jboss.osgi.plugins.metadata.ValueCreatorUtil.ACTIVATION_POLICY_VC;
+import static org.jboss.osgi.plugins.metadata.ValueCreatorUtil.INTEGER_VC;
+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_CATEGORY;
+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_LOCALIZATION_DEFAULT_BASENAME;
+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.net.URL;
import java.util.Arrays;
+import java.util.Dictionary;
import java.util.HashMap;
+import java.util.Hashtable;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.jar.Manifest;
+import java.util.jar.Attributes.Name;
import org.jboss.deployers.vfs.spi.deployer.helpers.AbstractManifestMetaData;
-import static org.jboss.osgi.plugins.metadata.ValueCreatorUtil.*;
+import org.jboss.osgi.spi.metadata.ActivationPolicyMetaData;
import org.jboss.osgi.spi.metadata.OSGiMetaData;
import org.jboss.osgi.spi.metadata.PackageAttribute;
import org.jboss.osgi.spi.metadata.ParameterizedAttribute;
-import org.jboss.osgi.spi.metadata.ActivationPolicyMetaData;
-import static org.osgi.framework.Constants.*;
import org.osgi.framework.Version;
/**
@@ -57,6 +88,17 @@
super(manifest);
}
+ @SuppressWarnings("unchecked")
+ public Dictionary<String, String> getHeaders(String locale)
+ {
+ // TODO localisation
+ Map<Name, String> attributes = (Map) getManifest().getMainAttributes();
+ Hashtable<String, String> result = new Hashtable<String, String>();
+ for (Entry<Name, String> entry : attributes.entrySet())
+ result.put(entry.getKey().toString(), entry.getValue());
+ return result;
+ }
+
public String getHeader(String key)
{
return get(key, STRING_VC);
@@ -152,7 +194,6 @@
return get(REQUIRE_BUNDLE, QNAME_ATTRIB_LIST_VC);
}
- @SuppressWarnings("unchecked")
protected <T> T get(String key, ValueCreator<T> creator)
{
return get(key, creator, null);
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/metadata/AbstractReferenceMetaData.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/metadata/AbstractReferenceMetaData.java 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/metadata/AbstractReferenceMetaData.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -56,13 +56,13 @@
public Object getValue(BundleContext bundleContext) throws Throwable
{
- // todo - add dynamic behaviour
+ // tdo - add dynamic behaviour
return GeneratedAOPProxyFactory.createProxy(null, null);
}
public void visit(ServiceMetaDataVisitor visitor)
{
- // todo - add dependency
+ // tdo - add dependency
super.visit(visitor);
}
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/metadata/AbstractServiceMetaData.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/metadata/AbstractServiceMetaData.java 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/metadata/AbstractServiceMetaData.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -49,11 +49,10 @@
private List<AttributeMetaData> attributes = Collections.emptyList();
/** The dependencies */
- // todo
public void visit(ServiceMetaDataVisitor visitor)
{
- // todo - add children, depend on ref bean from MC
+ // tdo - add children, depend on ref bean from MC
super.visit(visitor);
}
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/metadata/AbstractVersionRange.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/metadata/AbstractVersionRange.java 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/metadata/AbstractVersionRange.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -21,13 +21,12 @@
*/
package org.jboss.osgi.plugins.metadata;
-import java.io.ObjectStreamException;
import java.io.Serializable;
import java.util.StringTokenizer;
+import org.jboss.classloading.spi.version.VersionComparator;
+import org.jboss.classloading.spi.version.VersionComparatorRegistry;
import org.jboss.osgi.spi.metadata.VersionRange;
-import org.jboss.util.JBossObject;
-import org.jboss.util.JBossStringBuilder;
import org.osgi.framework.Version;
/**
@@ -38,36 +37,46 @@
* floor ::= version
* ceiling ::= version
*
+ * todo do we really need this extra class or just use our version range?
* @author Scott.Stark at jboss.org
* @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ * @author adrian at jboss.org
*/
-public class AbstractVersionRange extends JBossObject implements VersionRange, Serializable
+public class AbstractVersionRange extends org.jboss.classloading.spi.version.VersionRange implements VersionRange, Serializable
{
- private static final long serialVersionUID = 1l;
+ /** The serialVersionUID */
+ private static final long serialVersionUID = -178825219621278882L;
+ static
+ {
+ VersionComparatorRegistry registry = VersionComparatorRegistry.getInstance();
+ registry.registerVersionComparator(Version.class, Version.class, new OSGiVersionToOSGiVersionComparator());
+ registry.registerVersionComparator(Version.class, org.jboss.classloading.spi.version.Version.class, new OSGiVersionToVersionComparator());
+ registry.registerVersionComparator(Version.class, String.class, new OSGiVersionToStringComparator());
+ }
+
/**
- * The lower bound of the range
+ * Get the version range from a string
+ *
+ * @param rangeSpec the range spec
+ * @return the version range
*/
- private transient Version floor;
+ public static VersionRange valueOf(String rangeSpec)
+ {
+ return parseRangeSpec(rangeSpec);
+ }
+
/**
- * The upper bound of the range
+ * Parse a range spec
+ *
+ * @param rangeSpec
+ * @return the version range
*/
- private transient Version ceiling;
- /**
- * is the floor version a >(true) or >= constraint(false)
- */
- private transient boolean floorIsGreaterThan;
- /**
- * is the ceiling version a <(true) or <= constraint(false)
- */
- private transient boolean ceilingIsLessThan;
- /**
- * create object from this after serialization
- */
- private String rangeSpec;
-
public static VersionRange parseRangeSpec(String rangeSpec)
{
+ if (rangeSpec == null)
+ throw new IllegalArgumentException("Null rangeSpec");
+
Version floor = null;
Version ceiling = null;
StringTokenizer st = new StringTokenizer(rangeSpec, ",[]()", true);
@@ -108,87 +117,96 @@
ceilingIsLessThan = false;
}
- return new AbstractVersionRange(rangeSpec, floor, ceiling, floorIsGreaterThan, ceilingIsLessThan);
+ return new AbstractVersionRange(floor, ceiling, floorIsGreaterThan, ceilingIsLessThan);
}
- public AbstractVersionRange(String rangeSpec, Version floor, Version ceiling, boolean floorIsLessThan, boolean ceilingIsLessThan)
+ /**
+ * Create a new AbstractVersionRange.
+ *
+ * @param floor the floor
+ * @param ceiling the ceiling
+ * @param floorIsLessThan whether the floor is <
+ * @param ceilingIsLessThan whether the ceiling is <
+ */
+ public AbstractVersionRange(Version floor, Version ceiling, boolean floorIsLessThan, boolean ceilingIsLessThan)
{
- this.rangeSpec = rangeSpec;
- this.floor = floor;
- this.ceiling = ceiling;
- this.floorIsGreaterThan = floorIsLessThan;
- this.ceilingIsLessThan = ceilingIsLessThan;
+ super(floor == null ? Version.emptyVersion : floor, floorIsLessThan == false, ceiling, ceilingIsLessThan == false);
}
+ /**
+ * Get the floor
+ *
+ * @return the floor
+ */
public Version getFloor()
{
- return floor;
+ return (Version) getLow();
}
+ /**
+ * Get the ceiling
+ *
+ * @return the ceiling
+ */
public Version getCeiling()
{
- return ceiling;
+ return (Version) getHigh();
}
+ /**
+ * Test whether the version is in range
+ *
+ * @return true when the version is in range
+ */
public boolean isInRange(Version v)
{
- // Test a null floor version which implies 0.0.0 <= v <= inf
- boolean isInRange = floor == null;
- if (isInRange == false)
- {
- // Test the floor version
- int floorCompare = v.compareTo(floor);
- if ((floorIsGreaterThan && floorCompare > 0) || (floorIsGreaterThan == false && floorCompare >= 0))
- {
- isInRange = ceiling == null;
- if (isInRange == false)
- {
- // Test the ceiling version
- int ceilingCompare = v.compareTo(ceiling);
- if ((ceilingIsLessThan && ceilingCompare < 0) || (ceilingIsLessThan == false && ceilingCompare <= 0))
- {
- isInRange = true;
- }
- }
- }
- }
- return isInRange;
+ return super.isInRange(v);
}
- protected int getHashCode()
+ /**
+ * OSGiVersionToOSGiVersionComparator.
+ */
+ private static class OSGiVersionToOSGiVersionComparator implements VersionComparator<Version, Version>
{
- return rangeSpec.hashCode();
+ public int compare(Version t, Version u)
+ {
+ return t.compareTo(u);
+ }
}
- public boolean equals(Object obj)
+ /**
+ * OSGiVersionToVersionComparator.
+ */
+ private static class OSGiVersionToVersionComparator implements VersionComparator<Version, org.jboss.classloading.spi.version.Version>
{
- return (obj instanceof AbstractVersionRange && rangeSpec.equals(((AbstractVersionRange)obj).rangeSpec));
- }
+ public int compare(Version t, org.jboss.classloading.spi.version.Version u)
+ {
+ int result = t.getMajor() - u.getMajor();
+ if (result != 0)
+ return result;
- protected void toString(JBossStringBuilder tmp)
- {
- if (floor == null)
- tmp.append("0.0.0");
- else
- tmp.append(floor.toString());
- tmp.append(" <");
- if (floorIsGreaterThan == false)
- tmp.append('=');
- tmp.append(" v ");
- // Ceiling
- tmp.append('<');
- if (ceilingIsLessThan == false)
- tmp.append('=');
- tmp.append(' ');
- if (ceiling == null)
- tmp.append("inf");
- else
- tmp.append(ceiling.toString());
+ result = t.getMinor() - u.getMinor();
+ if (result != 0)
+ return result;
+
+ result = t.getMicro() - u.getMicro();
+ if (result != 0)
+ return result;
+
+ String q1 = t.getQualifier();
+ String q2 = u.getQualifier();
+ return q1.compareTo(q2);
+ }
}
- protected Object readResolve() throws ObjectStreamException
+ /**
+ * VersionToStringComparator.
+ */
+ private static class OSGiVersionToStringComparator implements VersionComparator<Version, String>
{
- return parseRangeSpec(rangeSpec);
+ public int compare(Version t, String u)
+ {
+ return t.compareTo(Version.parseVersion(u));
+ }
}
-
}
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/metadata/OSGiParameters.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/metadata/OSGiParameters.java 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/metadata/OSGiParameters.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -80,7 +80,6 @@
return get(RESOLUTION_DIRECTIVE, ValueCreatorUtil.STRING_VC, RESOLUTION_MANDATORY);
}
- @SuppressWarnings("unchecked")
protected <T> T get(String key, ValueCreator<T> creator)
{
return get(key, creator, null);
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/util/CaseInsensitiveDictionary.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/util/CaseInsensitiveDictionary.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/plugins/util/CaseInsensitiveDictionary.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,139 @@
+/*
+* 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.plugins.util;
+
+import java.util.Collections;
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Set;
+
+import org.jboss.util.collection.Iterators;
+
+/**
+ * CaseInsensitiveDictionary.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class CaseInsensitiveDictionary extends Dictionary<String, Object>
+{
+ /** The delegate dictionary */
+ private Dictionary<String, Object> delegate;
+
+ /** The original keys */
+ private Set<String> originalKeys;
+
+ /**
+ * Create a new CaseInsensitiveDictionary.
+ *
+ * @param delegate the delegate
+ */
+ public CaseInsensitiveDictionary(Dictionary<String, Object> 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();
+ while (e.hasMoreElements())
+ {
+ 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")
+ 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;
+
+ if (size() != other.size())
+ return false;
+ if (isEmpty())
+ return true;
+
+ for (String key : originalKeys)
+ {
+ if (get(key).equals(other.get(key)))
+ return false;
+ }
+ return true;
+ }
+
+ public Object get(Object key)
+ {
+ if (key instanceof String)
+ key = ((String) key).toLowerCase();
+ return delegate.get(key);
+ }
+
+ public int hashCode()
+ {
+ return delegate.hashCode();
+ }
+
+ public boolean isEmpty()
+ {
+ return delegate.isEmpty();
+ }
+
+ @SuppressWarnings("unchecked")
+ public Enumeration<String> keys()
+ {
+ return Iterators.toEnumeration(originalKeys.iterator());
+ }
+
+ public Object put(String key, Object value)
+ {
+ throw new UnsupportedOperationException("immutable");
+ }
+
+ public Object remove(Object key)
+ {
+ throw new UnsupportedOperationException("immutable");
+ }
+
+ public int size()
+ {
+ return delegate.size();
+ }
+
+ public String toString()
+ {
+ return delegate.toString();
+ }
+}
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/spi/metadata/OSGiMetaData.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/spi/metadata/OSGiMetaData.java 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/main/java/org/jboss/osgi/spi/metadata/OSGiMetaData.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -22,6 +22,7 @@
package org.jboss.osgi.spi.metadata;
import java.net.URL;
+import java.util.Dictionary;
import java.util.List;
import org.jboss.deployers.vfs.spi.deployer.ManifestMetaData;
@@ -35,6 +36,14 @@
public interface OSGiMetaData extends ManifestMetaData
{
/**
+ * Get the headers
+ *
+ * @param locale the locale to use
+ * @return the headers
+ */
+ Dictionary<String, String> getHeaders(String locale);
+
+ /**
* Extension point to read custom manifest headers.
*
* @param key the header key
Deleted: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/OSGiAllTestSuite.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/OSGiAllTestSuite.java 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/OSGiAllTestSuite.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -1,49 +0,0 @@
-/*
-* 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.test;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import junit.textui.TestRunner;
-import org.jboss.test.bundle.BundleTestSuite;
-
-/**
- * OSGi All Test Suite
- *
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
- */
-public class OSGiAllTestSuite extends TestSuite
-{
- public static void main(String[] args)
- {
- TestRunner.run(suite());
- }
-
- public static Test suite()
- {
- TestSuite suite = new TestSuite("OSGi All Tests");
-
- suite.addTest(BundleTestSuite.suite());
-
- return suite;
- }
-}
Deleted: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/OSGiTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/OSGiTestCase.java 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/OSGiTestCase.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -1,167 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, 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.test;
-
-import java.net.URL;
-
-import org.jboss.deployers.client.spi.DeployerClient;
-import org.jboss.deployers.spi.DeploymentException;
-import org.jboss.deployers.spi.deployer.DeploymentStage;
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.deployers.structure.spi.main.MainDeployerStructure;
-import org.jboss.deployers.vfs.spi.client.VFSDeployment;
-import org.jboss.deployers.vfs.spi.client.VFSDeploymentFactory;
-import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
-import org.jboss.test.kernel.junit.MicrocontainerTest;
-import org.jboss.virtual.VFS;
-import org.jboss.virtual.VirtualFile;
-
-/**
- * OSGiTestCase - Parent Test Case for OSGi tests.
- *
- * @author <a href="baileyje at gmail.com">John Bailey</a>
- * @version $Revision$
- */
-public abstract class OSGiTestCase extends MicrocontainerTest
-{
-
- /**
- * Create a new OSGiTestCase.
- *
- * @param name the test name
- */
- public OSGiTestCase(String name)
- {
- super(name);
- }
-
- /**
- * Get the AbstractTestDelegate
- *
- * @param clazz the test class
- * @return The AbstractTestDelegate
- * @throws Exception for any error
- */
- public static AbstractTestDelegate getDelegate(Class<?> clazz) throws Exception
- {
- return new OSGiTestDelegate(clazz);
- }
-
- /**
- * Get OSGiTestDelegate
- */
- protected OSGiTestDelegate getDelegate()
- {
- return (OSGiTestDelegate) super.getDelegate();
- }
-
- /**
- * Get DeployerClient from Delegate
- *
- * @return The DeployerClient
- */
- protected DeployerClient getDeployerClient()
- {
- return getDelegate().getMainDeployer();
- }
-
- /**
- * Assert the given DeploymentUnit is in the specified DeployemntStage
- *
- * @param unit A DeploymentUnit
- * @param stage A DeploymentStage
- * @throws DeploymentException If the DeployerClient is unable to determine the current stage
- */
- protected void assertStage(DeploymentUnit unit, DeploymentStage stage) throws DeploymentException
- {
- assertEquals(stage, getDeployerClient().getDeploymentStage(unit.getName()));
- }
-
- /**
- * Create a VFSDeployment
- *
- * @param root the root location of the deployment
- * @param child the child to deploy
- * @return VFSDeployment
- * @throws Exception for any error
- */
- protected VFSDeployment createVFSDeployment(String root, String child) throws Exception
- {
- URL resourceRoot = getClass().getResource(root);
- if (resourceRoot == null)
- fail("Resource not found: " + root);
- VirtualFile deployment = VFS.getVirtualFile(resourceRoot, child);
- if (deployment == null)
- fail("Child not found " + child + " from " + resourceRoot);
- return createVFSDeployment(deployment);
- }
-
- /**
- * Create a VFSDeployment
- *
- * @param root the VirtualFile to deploy
- * @return VFSDeployment
- * @throws Exception for any error
- */
- protected VFSDeployment createVFSDeployment(VirtualFile root) throws Exception
- {
- VFSDeploymentFactory factory = VFSDeploymentFactory.getInstance();
- return factory.createVFSDeployment(root);
- }
-
- /**
- * Create a VFSDeployment and add the Deployment to the DeployerClient, and return the DeploymentUnit
- *
- * @param root the location of the VirtualFile to deploy
- * @param child the child to deploy
- * @return VFSDeploymentUnit for the deployment
- * @throws Exception for any error
- */
- protected VFSDeploymentUnit addDeployment(String root, String child) throws Exception
- {
- VFSDeployment deployment = createVFSDeployment(root, child);
- getDeployerClient().addDeployment(deployment);
- getDeployerClient().process();
- return (VFSDeploymentUnit) getMainDeployerStructure().getDeploymentUnit(deployment.getName(), true);
- }
-
- /**
- * Remove a deployment
- *
- * @param unit the deployment unit
- * @throws Exception for any error
- */
- protected void removeDeployment(DeploymentUnit unit) throws Exception
- {
- getDeployerClient().undeploy(unit.getName());
- }
-
- /**
- * Get MainDeployerStructure from Delegate
- *
- * @return MainDeployerStructure
- */
- protected MainDeployerStructure getMainDeployerStructure()
- {
- return getDelegate().getMainDeployer();
- }
-}
Deleted: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/OSGiTestDelegate.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/OSGiTestDelegate.java 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/OSGiTestDelegate.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -1,87 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, 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.test;
-
-import java.net.URL;
-
-import org.jboss.classloading.spi.metadata.ClassLoadingMetaData10;
-import org.jboss.classloading.spi.vfs.metadata.VFSClassLoaderFactory10;
-import org.jboss.dependency.spi.ControllerState;
-import org.jboss.deployers.plugins.main.MainDeployerImpl;
-import org.jboss.test.kernel.junit.MicrocontainerTestDelegate;
-import org.jboss.xb.binding.sunday.unmarshalling.DefaultSchemaResolver;
-import org.jboss.xb.binding.sunday.unmarshalling.SingletonSchemaResolverFactory;
-
-/**
- * A OSGiTestDelegate
- *
- * @author <a href="baileyje at gmail.com">John Bailey</a>
- * @version $Revision$
- */
-public class OSGiTestDelegate extends MicrocontainerTestDelegate
-{
- private MainDeployerImpl mainDeployer;
-
- static
- {
- DefaultSchemaResolver resolver = (DefaultSchemaResolver) SingletonSchemaResolverFactory.getInstance().getSchemaBindingResolver();
- resolver.addClassBinding("urn:jboss:classloader:1.0", VFSClassLoaderFactory10.class);
- resolver.addClassBinding("urn:jboss:classloading:1.0", ClassLoadingMetaData10.class);
- }
-
- /**
- * Create a new OSGiTestDelegate.
- *
- * @param clazz
- * @throws Exception
- */
- public OSGiTestDelegate(Class<?> clazz) throws Exception
- {
- super(clazz);
- }
-
- /**
- * Deploys the bootstrap.xml bean descriptor to setup OSGi deployers
- */
- protected void deploy() throws Exception
- {
- String common = "/bootstrap/bootstrap.xml";
- URL url = getClass().getResource(common);
- if (url == null)
- throw new IllegalStateException(common + " not found");
- deploy(url);
-
- super.deploy();
- }
-
- /**
- * Get the MainDeployer bean from the MC
- *
- * @return MainDeployerImpl
- */
- protected MainDeployerImpl getMainDeployer()
- {
- if (mainDeployer == null)
- mainDeployer = getBean("MainDeployer", ControllerState.INSTALLED, MainDeployerImpl.class);
- return mainDeployer;
- }
-}
Deleted: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/bundle/BundleTestSuite.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/bundle/BundleTestSuite.java 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/bundle/BundleTestSuite.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -1,54 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, 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.test.bundle;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import junit.textui.TestRunner;
-import org.jboss.test.bundle.facade.FacadeTestSuite;
-import org.jboss.test.bundle.helper.BundleHelperTestSuite;
-import org.jboss.test.bundle.metadata.MetaDataTestSuite;
-
-/**
- * Bundle Test Suite.
- *
- * @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 BundleTestSuite extends TestSuite
-{
- public static void main(String[] args)
- {
- TestRunner.run(suite());
- }
-
- public static Test suite()
- {
- TestSuite suite = new TestSuite("Bundle Tests");
-
- suite.addTest(FacadeTestSuite.suite());
- suite.addTest(MetaDataTestSuite.suite());
- suite.addTest(BundleHelperTestSuite.suite());
-
- return suite;
- }
-}
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/bundle/metadata/HeaderValuesTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/bundle/metadata/HeaderValuesTestCase.java 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/bundle/metadata/HeaderValuesTestCase.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -245,7 +245,7 @@
public void testIllegalManifest() throws Exception
{
getManifest(createName("Illegal"));
- // todo
+ // TDO
}
}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/OSGiClassLoaderSystem.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/OSGiClassLoaderSystem.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/OSGiClassLoaderSystem.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,60 @@
+/*
+* 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.test.osgi;
+
+import org.jboss.classloader.plugins.filter.PatternClassFilter;
+import org.jboss.classloader.plugins.jdk.AbstractJDKChecker;
+import org.jboss.classloader.spi.ClassLoaderDomain;
+import org.jboss.classloader.spi.ClassLoaderSystem;
+import org.jboss.classloader.spi.ParentPolicy;
+import org.jboss.classloader.spi.filter.ClassFilter;
+import org.jboss.classloader.spi.filter.RecursivePackageClassFilter;
+import org.jboss.osgi.plugins.facade.bundle.OSGiBundleState;
+
+/**
+ * OSGiClassLoaderSystem.<p>
+ *
+ * TODO Figure out how to make this more easily configurable
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class OSGiClassLoaderSystem extends ClassLoaderSystem
+{
+ /**
+ * Create a new OSGiClassLoaderSystem.
+ */
+ public OSGiClassLoaderSystem()
+ {
+ ClassLoaderDomain domain = getDefaultDomain();
+ PatternClassFilter filter = RecursivePackageClassFilter.createRecursivePackageClassFilterFromString("org.osgi");
+ filter.setIncludeJava(true);
+ domain.setParentPolicy(new ParentPolicy(filter, ClassFilter.NOTHING));
+ AbstractJDKChecker.getExcluded().add(OSGiBundleState.class);
+ }
+
+ @Override
+ protected ClassLoaderDomain createDomain(String name)
+ {
+ return new ClassLoaderDomain(name);
+ }
+}
\ No newline at end of file
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/OSGiTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/OSGiTestCase.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/OSGiTestCase.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,512 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, 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.test.osgi;
+
+import java.net.URL;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.jboss.classloader.plugins.ClassLoaderUtils;
+import org.jboss.deployers.client.spi.DeployerClient;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.structure.spi.main.MainDeployerStructure;
+import org.jboss.osgi.plugins.facade.bundle.OSGiBundleManager;
+import org.jboss.test.AbstractTestDelegate;
+import org.jboss.test.kernel.junit.MicrocontainerTest;
+import org.jboss.virtual.AssembledDirectory;
+import org.jboss.virtual.VirtualFile;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
+import org.osgi.framework.FrameworkEvent;
+import org.osgi.framework.FrameworkListener;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.SynchronousBundleListener;
+
+/**
+ * OSGiTestCase - Parent Test Case for OSGi tests.
+ *
+ * @author <a href="baileyje at gmail.com">John Bailey</a>
+ * @version $Revision: 87848 $
+ */
+public abstract class OSGiTestCase extends MicrocontainerTest implements FrameworkListener, SynchronousBundleListener, ServiceListener
+{
+ private List<FrameworkEvent> frameworkEvents = new CopyOnWriteArrayList<FrameworkEvent>();
+ private List<BundleEvent> bundleEvents = new CopyOnWriteArrayList<BundleEvent>();
+ private List<ServiceEvent> serviceEvents = new CopyOnWriteArrayList<ServiceEvent>();
+
+ /**
+ * Create a new OSGiTestCase.
+ *
+ * @param name the test name
+ */
+ public OSGiTestCase(String name)
+ {
+ super(name);
+ }
+
+ /**
+ * Get the AbstractTestDelegate
+ *
+ * @param clazz the test class
+ * @return The AbstractTestDelegate
+ * @throws Exception for any error
+ */
+ public static AbstractTestDelegate getDelegate(Class<?> clazz) throws Exception
+ {
+ OSGiTestDelegate delegate = new OSGiTestDelegate(clazz);
+ //delegate.enableSecurity = true;
+ return delegate;
+ }
+
+ /**
+ * Get OSGiTestDelegate
+ */
+ protected OSGiTestDelegate getDelegate()
+ {
+ return (OSGiTestDelegate) super.getDelegate();
+ }
+
+ /**
+ * Get DeployerClient from Delegate
+ *
+ * @return The DeployerClient
+ */
+ protected DeployerClient getDeployerClient()
+ {
+ return getDelegate().getMainDeployer();
+ }
+
+ /**
+ * Get BundleManager from Delegate
+ *
+ * @return The BundleManager
+ */
+ protected OSGiBundleManager getBundleManager()
+ {
+ return getDelegate().getBundleManager();
+ }
+
+ /**
+ * Get the system bundle
+ *
+ * @return the system bundle
+ */
+ protected Bundle getSystemBundle()
+ {
+ return getBundleManager().getBundle(0).getBundleInternal();
+ }
+
+ /**
+ * Add the base bundles
+ *
+ * @param expected the collection to add to
+ */
+ protected void addBaseBundles(Collection<Bundle> expected)
+ {
+ expected.add(getSystemBundle());
+ }
+
+ /**
+ * Create a bundle
+ *
+ * @param root the location of the location to deploy
+ * @param child the child to deploy
+ * @return Bundle for the deployment
+ * @throws Exception for any error
+ */
+ protected Bundle addBundle(String root, String child) throws Exception
+ {
+ return getDelegate().addBundle(root, child);
+ }
+
+ /**
+ * Create a bundle
+ *
+ * @param file the virtual file
+ * @return Bundle for the deployment
+ * @throws Exception for any error
+ */
+ protected Bundle addBundle(VirtualFile file) throws Exception
+ {
+ return getDelegate().addBundle(file);
+ }
+
+ /**
+ * Remove a bundle
+ *
+ * @param bundle the bundle to remove
+ * @throws Exception for any error
+ */
+ protected void uninstall(Bundle bundle) throws Exception
+ {
+ getDelegate().uninstall(bundle);
+ }
+
+ protected DeploymentUnit getDeploymentUnit(Bundle bundle)
+ {
+ return getDelegate().getDeploymentUnit(bundle);
+ }
+
+ /**
+ * Get MainDeployerStructure from Delegate
+ *
+ * @return MainDeployerStructure
+ */
+ protected MainDeployerStructure getMainDeployerStructure()
+ {
+ return getDelegate().getMainDeployer();
+ }
+
+ protected Bundle assembleBundle(String name, String resources, Class<?>... packages) throws Exception
+ {
+ return getDelegate().assembleBundle(name, new String[] { resources }, packages);
+ }
+
+ protected Bundle assembleBundle(String name, String[] resourcePaths, Class<?>... packages) throws Exception
+ {
+ return getDelegate().assembleBundle(name, resourcePaths, packages);
+ }
+
+ protected AssembledDirectory createAssembledDirectory(String name) throws Exception
+ {
+ return getDelegate().createAssembledDirectory(name, "");
+ }
+
+ protected AssembledDirectory createAssembledDirectory(String name, String rootName) throws Exception
+ {
+ return getDelegate().createAssembledDirectory(name, rootName);
+ }
+
+ protected void addPackage(AssembledDirectory dir, Class<?> reference) throws Exception
+ {
+ getDelegate().addPackage(dir, reference);
+ }
+
+ protected void addPath(final AssembledDirectory dir, String path, String name) throws Exception
+ {
+ getDelegate().addPath(dir, path, name);
+ }
+
+ protected void assertClassEquality(Class<?> expected, Class<?> actual)
+ {
+ assertTrue("Should be the same " + ClassLoaderUtils.classToString(expected) +" and " + ClassLoaderUtils.classToString(actual), expected == actual);
+ }
+
+ protected void assertNoClassEquality(Class<?> expected, Class<?> actual)
+ {
+ assertTrue("Should NOT be the same " + ClassLoaderUtils.classToString(expected) +" and " + ClassLoaderUtils.classToString(actual), expected != actual);
+ }
+
+ protected void assertClassLoader(Class<?> clazz, Bundle expected)
+ {
+ if (expected == null)
+ return;
+ ClassLoader cl = clazz.getClassLoader();
+ ClassLoader bundleClassLoader = getBundleClassLoader(expected);
+ boolean result = bundleClassLoader.equals(cl);
+ assertTrue(ClassLoaderUtils.classToString(clazz) + " should have expected classloader=" + expected, result);
+ }
+
+ protected ClassLoader getBundleClassLoader(Bundle expected)
+ {
+ return getDeploymentUnit(expected).getClassLoader();
+ }
+
+ protected Class<?> assertLoadClass(Bundle start, Class<?> reference) throws Exception
+ {
+ return assertLoadClass(start, reference, start);
+ }
+
+ protected Class<?> assertLoadClass(Bundle start, Class<?> reference, Bundle expected) throws Exception
+ {
+ return assertLoadClass(start, reference, expected, false);
+ }
+
+ protected Class<?> assertLoadClass(Bundle start, Class<?> reference, Bundle expected, boolean isReference) throws Exception
+ {
+ Class<?> result = assertLoadClass(reference.getName(), start, expected);
+ if (isReference)
+ assertClassEquality(reference, result);
+ else
+ assertNoClassEquality(reference, result);
+ return result;
+ }
+
+ protected Class<?> assertLoadClass(String name, Bundle start, Bundle expected)
+ {
+ Class<?> result = null;
+ try
+ {
+ result = start.loadClass(name);
+ getLog().debug("Got class: " + ClassLoaderUtils.classToString(result) + " for " + name + " from " + start);
+ }
+ catch (ClassNotFoundException e)
+ {
+ failure("Did not expect CNFE for " + name + " from " + start, e);
+ }
+ assertClassLoader(result, expected);
+ return result;
+ }
+
+ protected void assertLoadClassFail(Bundle start, Class<?> reference)
+ {
+ assertLoadClassFail(start, reference.getName());
+ }
+
+ protected void assertLoadClassFail(Bundle start, String name)
+ {
+ try
+ {
+ start.loadClass(name);
+ fail("Should not be here!");
+ }
+ catch (Exception expected)
+ {
+ checkThrowable(ClassNotFoundException.class, expected);
+ }
+ }
+
+ protected URL getBundleResource(Bundle bundle, String path)
+ {
+ return getDelegate().getBundleResource(bundle, path);
+ }
+
+ protected Enumeration<URL> getBundleResources(Bundle bundle, String path) throws Exception
+ {
+ return getDelegate().getBundleResources(bundle, path);
+ }
+
+ protected void assertNoAllReferences(BundleContext bundleContext, String clazz) throws Exception
+ {
+ assertNoAllReferences(bundleContext, clazz, null);
+ }
+
+ protected void assertNoAllReferences(BundleContext bundleContext, String clazz, String filter) throws Exception
+ {
+ ServiceReference[] actual = bundleContext.getAllServiceReferences(clazz, filter);
+ if (actual != null)
+ getLog().debug(bundleContext + " got " + Arrays.asList(actual) + " for clazz=" + clazz + " filter=" + filter);
+ else
+ getLog().debug(bundleContext + " got nothing for clazz=" + clazz + " filter=" + filter);
+ assertNull("Expected no references for clazz=" + clazz + " filter=" + filter, actual);
+ }
+
+ protected void assertAllReferences(BundleContext bundleContext, String clazz, ServiceReference... expected) throws Exception
+ {
+ assertAllReferences(bundleContext, clazz, null, expected);
+ }
+
+ protected void assertAllReferences(BundleContext bundleContext, String clazz, String filter, ServiceReference... expected) throws Exception
+ {
+ ServiceReference[] actual = bundleContext.getAllServiceReferences(clazz, filter);
+ if (actual != null)
+ getLog().debug(bundleContext + " got " + Arrays.asList(actual) + " for clazz=" + clazz + " filter=" + filter);
+ else
+ getLog().debug(bundleContext + " got nothing for clazz=" + clazz + " filter=" + filter);
+ assertEquals(bundleContext + " with clazz=" + clazz + " filter=" + filter, expected, actual);
+ }
+
+ protected void assertNoReferences(BundleContext bundleContext, String clazz) throws Exception
+ {
+ assertNoReferences(bundleContext, clazz, null);
+ }
+
+ protected void assertNoReferences(BundleContext bundleContext, String clazz, String filter) throws Exception
+ {
+ ServiceReference[] actual = bundleContext.getServiceReferences(clazz, filter);
+ if (actual != null)
+ getLog().debug(bundleContext + " got " + Arrays.asList(actual) + " for clazz=" + clazz + " filter=" + filter);
+ else
+ getLog().debug(bundleContext + " got nothing for clazz=" + clazz + " filter=" + filter);
+ assertNull("Expected no references for clazz=" + clazz + " filter=" + filter, actual);
+ }
+
+ protected void assertReferences(BundleContext bundleContext, String clazz, ServiceReference... expected) throws Exception
+ {
+ assertReferences(bundleContext, clazz, null, expected);
+ }
+
+ protected void assertReferences(BundleContext bundleContext, String clazz, String filter, ServiceReference... expected) throws Exception
+ {
+ ServiceReference[] actual = bundleContext.getServiceReferences(clazz, filter);
+ if (actual != null)
+ getLog().debug(bundleContext + " got " + Arrays.asList(actual) + " for clazz=" + clazz + " filter=" + filter);
+ else
+ getLog().debug(bundleContext + " got nothing for clazz=" + clazz + " filter=" + filter);
+ assertEquals(bundleContext + " with clazz=" + clazz + " filter=" + filter, expected, actual);
+ }
+
+ protected void assertNoGetReference(BundleContext bundleContext, String clazz) throws Exception
+ {
+ ServiceReference actual = bundleContext.getServiceReference(clazz);
+ if (actual != null)
+ getLog().debug(bundleContext + " got " + actual + " for clazz=" + clazz);
+ else
+ getLog().debug(bundleContext + " got nothing for clazz=" + clazz);
+ assertNull("Expected no references for clazz=" + clazz, actual);
+ }
+
+ protected void assertGetReference(BundleContext bundleContext, String clazz, ServiceReference expected) throws Exception
+ {
+ ServiceReference actual = bundleContext.getServiceReference(clazz);
+ if (actual != null)
+ getLog().debug(bundleContext + " got " + Arrays.asList(actual) + " for clazz=" + clazz);
+ else
+ getLog().debug(bundleContext + " got nothing for clazz=" + clazz);
+ assertEquals(bundleContext + " with clazz=" + clazz, expected, actual);
+ }
+
+ protected void assertUsingBundles(ServiceReference reference, Bundle... bundles)
+ {
+ Set<Bundle> expected = new HashSet<Bundle>();
+ for (Bundle bundle : bundles)
+ expected.add(bundle);
+
+ Set<Bundle> actual = new HashSet<Bundle>();
+ Bundle[] users = reference.getUsingBundles();
+ if (users != null)
+ for (Bundle bundle : users)
+ actual.add(bundle);
+
+ getLog().debug(reference + " users=" + actual);
+
+ assertEquals(expected, actual);
+ }
+
+ protected void assertObjectClass(String expected, ServiceReference reference)
+ {
+ assertObjectClass(new String[] { expected }, reference);
+ }
+
+ protected void assertObjectClass(String[] expected, ServiceReference reference)
+ {
+ Object actual = reference.getProperty(Constants.OBJECTCLASS);
+ if (actual == null)
+ fail("no object class???");
+ if (actual instanceof String[] == false)
+ fail(actual + " is not a string array??? " + actual.getClass().getName());
+ assertEquals(expected, (String[]) actual);
+ }
+
+ public void frameworkEvent(FrameworkEvent event)
+ {
+ getLog().debug("FrameworkEvent type=" + event.getType() + " for " + event);
+ frameworkEvents.add(event);
+ }
+
+ protected void assertNoFrameworkEvent() throws Exception
+ {
+ getLog().debug("frameworkEvents=" + frameworkEvents);
+ assertEquals(0, frameworkEvents.size());
+ }
+
+ protected void assertFrameworkEvent(int type) throws Exception
+ {
+ assertFrameworkEvent(type, getSystemBundle(), null);
+ }
+
+ protected void assertFrameworkEvent(int type, Class<? extends Throwable> expectedThrowable) throws Exception
+ {
+ assertFrameworkEvent(type, getSystemBundle(), expectedThrowable);
+ }
+
+ protected void assertFrameworkEvent(int type, Bundle bundle, Class<? extends Throwable> expectedThrowable) throws Exception
+ {
+ getLog().debug("frameworkEvents=" + frameworkEvents);
+ int size = frameworkEvents.size();
+ assertTrue("" + size, size > 0);
+ FrameworkEvent event = frameworkEvents.remove(0);
+ assertEquals(type, event.getType());
+ Throwable t = event.getThrowable();
+ if (expectedThrowable == null)
+ {
+ if (t != null)
+ {
+ getLog().error("Unexpected error in Framework event: ", t);
+ fail("Unexpected throwable: " + t);
+ }
+ }
+ else
+ {
+ checkThrowable(BundleException.class, t);
+ checkDeepThrowable(expectedThrowable, t);
+ }
+ assertEquals(bundle, event.getSource());
+ assertEquals(bundle, event.getBundle());
+ }
+
+ public void bundleChanged(BundleEvent event)
+ {
+ getLog().debug("BundleChanged type=" + event.getType() + " for " + event);
+ bundleEvents.add(event);
+ }
+
+ protected void assertNoBundleEvent() throws Exception
+ {
+ getLog().debug("bundleEvents=" + bundleEvents);
+ assertEquals(0, bundleEvents.size());
+ }
+
+ protected void assertBundleEvent(int type, Bundle bundle) throws Exception
+ {
+ getLog().debug("bundleEvents=" + bundleEvents);
+ int size = bundleEvents.size();
+ assertTrue("" + size, size > 0);
+ BundleEvent event = bundleEvents.remove(0);
+ assertEquals(type, event.getType());
+ assertEquals(bundle, event.getSource());
+ assertEquals(bundle, event.getBundle());
+ }
+
+ public void serviceChanged(ServiceEvent event)
+ {
+ getLog().debug("ServiceChanged type=" + event.getType() + " for " + event);
+ serviceEvents.add(event);
+ }
+
+ protected void assertNoServiceEvent() throws Exception
+ {
+ getLog().debug("serviceEvents=" + serviceEvents);
+ assertEquals(0, serviceEvents.size());
+ }
+
+ protected void assertServiceEvent(int type, ServiceReference reference) throws Exception
+ {
+ getLog().debug("serviceEvents=" + serviceEvents);
+ int size = serviceEvents.size();
+ assertTrue("" + size, size > 0);
+ ServiceEvent event = serviceEvents.remove(0);
+ assertEquals(type, event.getType());
+ assertEquals(reference, event.getSource());
+ assertEquals(reference, event.getServiceReference());
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/OSGiTestDelegate.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/OSGiTestDelegate.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/OSGiTestDelegate.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,268 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, 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.test.osgi;
+
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.util.Collection;
+import java.util.Enumeration;
+
+import junit.framework.AssertionFailedError;
+
+import org.jboss.classloader.plugins.ClassLoaderUtils;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.deployers.plugins.main.MainDeployerImpl;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.osgi.plugins.facade.bundle.OSGiBundleManager;
+import org.jboss.osgi.plugins.facade.bundle.OSGiBundleState;
+import org.jboss.test.kernel.junit.MicrocontainerTestDelegate;
+import org.jboss.virtual.AssembledDirectory;
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.plugins.context.jar.JarUtils;
+import org.jboss.virtual.plugins.vfs.helpers.SuffixesExcludeFilter;
+import org.osgi.framework.Bundle;
+
+/**
+ * A OSGiTestDelegate
+ *
+ * @author <a href="baileyje at gmail.com">John Bailey</a>
+ * @version $Revision: 87848 $
+ */
+public class OSGiTestDelegate extends MicrocontainerTestDelegate
+{
+ private MainDeployerImpl mainDeployer;
+ private OSGiBundleManager bundleManager;
+
+ static
+ {
+ // FIXME the vfs is not initialising itself properly
+ VFS.init();
+ try
+ {
+ VFS.getRoot(new URL("file:/"));
+ }
+ catch (Exception ignored) {}
+ }
+
+ /**
+ * Create a new OSGiTestDelegate.
+ *
+ * @param clazz
+ * @throws Exception
+ */
+ public OSGiTestDelegate(Class<?> clazz) throws Exception
+ {
+ super(clazz);
+ }
+
+ /**
+ * Deploys the bootstrap.xml bean descriptor to setup OSGi deployers
+ */
+ protected void deploy() throws Exception
+ {
+ String common = "/bootstrap/bootstrap.xml";
+ URL url = getClass().getResource(common);
+ if (url == null)
+ throw new IllegalStateException(common + " not found");
+ deploy(url);
+ try
+ {
+ super.deploy();
+ deployBundles();
+ }
+ catch (Throwable t)
+ {
+ undeploy();
+ if (t instanceof Exception)
+ throw (Exception) t;
+ if (t instanceof Error)
+ throw (Error) t;
+ throw new RuntimeException("Error during deploy", t);
+ }
+ }
+
+ protected void undeploy()
+ {
+ undeployBundles();
+ super.undeploy();
+ }
+
+ protected void deployBundles() throws Exception
+ {
+ try
+ {
+ Method method = clazz.getMethod("deployBundles", new Class[] { OSGiTestDelegate.class });
+ log.debug("Deploying Bundles...");
+ method.invoke(null, this);
+ }
+ catch (NoSuchMethodException e)
+ {
+ log.debug("No deployBundles() in " + clazz.getName());
+ }
+ }
+
+ protected void undeployBundles()
+ {
+ OSGiBundleManager bundleManager = getBundleManager();
+ Collection<OSGiBundleState> bundles = bundleManager.getBundles();
+ for (OSGiBundleState bundleState : bundles)
+ {
+ try
+ {
+ if (bundleState.getBundleId() != 0)
+ bundleManager.uninstall(bundleState);
+ }
+ catch (Throwable t)
+ {
+ getLog().warn("Error undeploying bundle: " + bundleState, t);
+ }
+ }
+ }
+
+ /**
+ * Get the MainDeployer bean from the MC
+ *
+ * @return MainDeployerImpl
+ */
+ protected MainDeployerImpl getMainDeployer()
+ {
+ if (mainDeployer == null)
+ mainDeployer = getBean("MainDeployer", ControllerState.INSTALLED, MainDeployerImpl.class);
+ return mainDeployer;
+ }
+
+ /**
+ * Get the BundleManager bean from the MC
+ *
+ * @return the BundleManager
+ */
+ protected OSGiBundleManager getBundleManager()
+ {
+ if (bundleManager == null)
+ bundleManager = getBean("OSGiBundleManager", ControllerState.INSTALLED, OSGiBundleManager.class);
+ return bundleManager;
+ }
+
+ /**
+ * Create a bundle
+ *
+ * @param root the location of the location to deploy
+ * @param child the child to deploy
+ * @return Bundle for the deployment
+ * @throws Exception for any error
+ */
+ public Bundle addBundle(String root, String child) throws Exception
+ {
+ URL resourceRoot = getClass().getResource(root);
+ if (resourceRoot == null)
+ throw new AssertionFailedError("Resource not found: " + root);
+ URL childResource = new URL(resourceRoot, child);
+ OSGiBundleState bundleState = getBundleManager().install(childResource);
+ return bundleState.getBundleInternal();
+ }
+
+ /**
+ * Create a bundle
+ *
+ * @param file the virtual file
+ * @return Bundle for the deployment
+ * @throws Exception for any error
+ */
+ public Bundle addBundle(VirtualFile file) throws Exception
+ {
+ OSGiBundleState bundleState = getBundleManager().install(file);
+ return bundleState.getBundleInternal();
+ }
+
+ /**
+ * Remove a bundle
+ *
+ * @param bundle the bundle to remove
+ * @throws Exception for any error
+ */
+ public void uninstall(Bundle bundle) throws Exception
+ {
+ getBundleManager().uninstall(bundle);
+ }
+
+ protected DeploymentUnit getDeploymentUnit(Bundle bundle)
+ {
+ DeploymentUnit deploymentUnit = getBundleManager().getDeployment(bundle.getBundleId());
+ if (deploymentUnit == null)
+ throw new AssertionFailedError("Bundle not installed: " + bundle);
+ return deploymentUnit;
+ }
+
+ public Bundle assembleBundle(String name, String resources, Class<?>... packages) throws Exception
+ {
+ return assembleBundle(name, new String[] { resources }, packages);
+ }
+
+ public Bundle assembleBundle(String name, String[] resourcePaths, Class<?>... packages) throws Exception
+ {
+ AssembledDirectory assembledDirectory = createAssembledDirectory(name, "");
+ for (String path : resourcePaths)
+ addPath(assembledDirectory, path, "");
+ for (Class<?> reference : packages)
+ addPackage(assembledDirectory, reference);
+ return addBundle(assembledDirectory);
+ }
+
+ public AssembledDirectory createAssembledDirectory(String name) throws Exception
+ {
+ return createAssembledDirectory(name, "");
+ }
+
+ public AssembledDirectory createAssembledDirectory(String name, String rootName) throws Exception
+ {
+ return AssembledDirectory.createAssembledDirectory(name, rootName);
+ }
+
+ public void addPackage(AssembledDirectory dir, Class<?> reference) throws Exception
+ {
+ String packagePath = ClassLoaderUtils.packageNameToPath(reference.getName());
+ dir.addResources(reference, new String[] { packagePath + "/*.class" } , new String[0]);
+ }
+
+ public void addPath(final AssembledDirectory dir, String path, String name) throws Exception
+ {
+ URL url = getClass().getResource(path);
+ if (url == null)
+ throw new AssertionFailedError(path + " not found");
+
+ VirtualFile file = VFS.getVirtualFile(url, name);
+ // TODO - remove this filter after new VFS relase
+ SuffixesExcludeFilter noJars = new SuffixesExcludeFilter(JarUtils.getSuffixes());
+ dir.addPath(file, noJars);
+ }
+
+ protected URL getBundleResource(Bundle bundle, String path)
+ {
+ return getDeploymentUnit(bundle).getResourceLoader().getResource(path);
+ }
+
+ protected Enumeration<URL> getBundleResources(Bundle bundle, String path) throws Exception
+ {
+ return getDeploymentUnit(bundle).getResourceLoader().getResources(path);
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/OSGiTestSuite.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/OSGiTestSuite.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/OSGiTestSuite.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,59 @@
+/*
+* 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.test.osgi;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+import org.jboss.test.bundle.metadata.MetaDataTestSuite;
+import org.jboss.test.osgi.bundle.BundleTestSuite;
+import org.jboss.test.osgi.filter.FilterTestSuite;
+import org.jboss.test.osgi.service.ServiceTestSuite;
+import org.jboss.test.osgi.smoke.SmokeTestSuite;
+
+/**
+ * OSGiTestSuite.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class OSGiTestSuite extends TestSuite
+{
+ public static void main(String[] args)
+ {
+ TestRunner.run(suite());
+ }
+
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite("OSGi Tests");
+
+ suite.addTest(MetaDataTestSuite.suite());
+ suite.addTest(SmokeTestSuite.suite());
+ suite.addTest(FilterTestSuite.suite());
+ suite.addTest(BundleTestSuite.suite());
+ suite.addTest(ServiceTestSuite.suite());
+
+ return suite;
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/bundle/BundleTestSuite.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/bundle/BundleTestSuite.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/bundle/BundleTestSuite.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,57 @@
+/*
+* 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.test.osgi.bundle;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+import org.jboss.test.osgi.bundle.test.BundleContextUnitTestCase;
+import org.jboss.test.osgi.bundle.test.BundleEntriesUnitTestCase;
+import org.jboss.test.osgi.bundle.test.BundleUnitTestCase;
+import org.jboss.test.osgi.bundle.test.SystemBundleUnitTestCase;
+
+/**
+ * BundleTestSuite.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class BundleTestSuite extends TestSuite
+{
+ public static void main(String[] args)
+ {
+ TestRunner.run(suite());
+ }
+
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite("Bundle Tests");
+
+ suite.addTest(BundleUnitTestCase.suite());
+ suite.addTest(BundleEntriesUnitTestCase.suite());
+ suite.addTest(BundleContextUnitTestCase.suite());
+ suite.addTest(SystemBundleUnitTestCase.suite());
+
+ return suite;
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/bundle/test/BundleContextUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/bundle/test/BundleContextUnitTestCase.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/bundle/test/BundleContextUnitTestCase.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,505 @@
+/*
+* 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.test.osgi.bundle.test;
+
+import java.util.Arrays;
+import java.util.Dictionary;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Locale;
+import java.util.Set;
+
+import junit.framework.Test;
+
+import org.jboss.test.osgi.OSGiTestCase;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * BundleContextUnitTestCase.
+ *
+ * TODO test security
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class BundleContextUnitTestCase extends OSGiTestCase
+{
+ public BundleContextUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(BundleContextUnitTestCase.class);
+ }
+
+ public void testGetBundle() throws Exception
+ {
+ Bundle bundle1 = addBundle("/bundles/simple/", "simple-bundle1");
+ BundleContext context1 = null;
+ try
+ {
+ bundle1.start();
+ context1 = bundle1.getBundleContext();
+ assertEquals(bundle1, context1.getBundle());
+ assertEquals(bundle1, context1.getBundle(bundle1.getBundleId()));
+
+ Bundle[] bundles = context1.getBundles();
+ Set<Bundle> actual = new HashSet<Bundle>(Arrays.asList(bundles));
+ Set<Bundle> expected = new HashSet<Bundle>(Arrays.asList(bundle1));
+ addBaseBundles(expected);
+ assertEquals(expected, actual);
+
+ Bundle bundle2 = addBundle("/bundles/simple/", "simple-bundle2");
+ BundleContext context2 = null;
+ try
+ {
+ bundle2.start();
+ context2 = bundle2.getBundleContext();
+ assertEquals(bundle2, context2.getBundle());
+
+ bundles = context1.getBundles();
+ actual = new HashSet<Bundle>(Arrays.asList(bundles));
+ expected = new HashSet<Bundle>(Arrays.asList(bundle1, bundle2));
+ addBaseBundles(expected);
+ assertEquals(expected, actual);
+
+ assertEquals(bundle1, context2.getBundle(bundle1.getBundleId()));
+ assertEquals(bundle2, context1.getBundle(bundle2.getBundleId()));
+ }
+ finally
+ {
+ uninstall(bundle2);
+ }
+
+ assertEquals(bundle1, context1.getBundle(bundle1.getBundleId()));
+ assertNull(context1.getBundle(bundle2.getBundleId()));
+
+ bundles = context1.getBundles();
+ actual = new HashSet<Bundle>(Arrays.asList(bundles));
+ expected = new HashSet<Bundle>(Arrays.asList(bundle1));
+ addBaseBundles(expected);
+ assertEquals(expected, actual);
+
+ try
+ {
+ context2.getBundle();
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+
+ try
+ {
+ context2.getBundle(bundle1.getBundleId());
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+
+ try
+ {
+ context2.getBundles();
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ }
+ finally
+ {
+ uninstall(bundle1);
+ }
+
+ try
+ {
+ context1.getBundle();
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+
+ try
+ {
+ context1.getBundle(bundle1.getBundleId());
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+
+ try
+ {
+ context1.getBundles();
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ }
+
+ public void testProperties() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+ assertEquals("r4v41", bundleContext.getProperty(Constants.FRAMEWORK_VERSION)); // TODO externalise
+ assertEquals("jboss.org", bundleContext.getProperty(Constants.FRAMEWORK_VENDOR)); // TODO externalise
+ assertEquals(Locale.getDefault().getISO3Language(), bundleContext.getProperty(Constants.FRAMEWORK_LANGUAGE));
+ assertSystemProperty(bundleContext, "os.name", Constants.FRAMEWORK_OS_NAME);
+ assertSystemProperty(bundleContext, "os.version", Constants.FRAMEWORK_OS_VERSION);
+ assertSystemProperty(bundleContext, "os.arch", Constants.FRAMEWORK_PROCESSOR);
+
+ assertNull(bundleContext.getProperty(getClass().getName()));
+ System.setProperty(getClass().getName(), "test");
+ assertEquals("test", bundleContext.getProperty(getClass().getName()));
+
+ bundle.stop();
+ try
+ {
+ bundleContext.getProperty(getClass().getName());
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testInstallBundle() throws Exception
+ {
+ // TODO testInstallBundle
+ }
+
+ public void testServiceListener() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ try
+ {
+ bundleContext.addServiceListener(null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+
+ try
+ {
+ bundleContext.addServiceListener(null, "(a=b)");
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+
+ try
+ {
+ bundleContext.removeServiceListener(null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+
+ bundleContext.addServiceListener(this);
+ bundleContext = assertServiceLifecycle(bundle, bundleContext, true);
+ bundleContext.removeServiceListener(this);
+
+ bundleContext.addServiceListener(this);
+ bundleContext.removeServiceListener(this);
+ bundleContext = assertServiceLifecycle(bundle, bundleContext, false);
+
+ bundleContext.addServiceListener(this);
+ bundleContext.addServiceListener(this);
+ bundleContext = assertServiceLifecycle(bundle, bundleContext, true);
+ bundleContext.removeServiceListener(this);
+
+ bundleContext.addServiceListener(this, null);
+ bundleContext = assertServiceLifecycle(bundle, bundleContext, true);
+ bundleContext.removeServiceListener(this);
+
+ bundleContext.addServiceListener(this, null);
+ bundleContext.removeServiceListener(this);
+ bundleContext = assertServiceLifecycle(bundle, bundleContext, false);
+
+ bundleContext.addServiceListener(this, null);
+ bundleContext.addServiceListener(this, null);
+ bundleContext = assertServiceLifecycle(bundle, bundleContext, true);
+ bundleContext.removeServiceListener(this);
+
+ Dictionary<String, Object> properties = new Hashtable<String, Object>();
+ properties.put("a", "b");
+
+ bundleContext.addServiceListener(this, ("(a=b)"));
+ bundleContext = assertServiceLifecycle(bundle, bundleContext, properties, true);
+ bundleContext.removeServiceListener(this);
+
+ bundleContext.addServiceListener(this, ("(c=d)"));
+ bundleContext = assertServiceLifecycle(bundle, bundleContext, properties, false);
+ bundleContext.removeServiceListener(this);
+
+ bundleContext.addServiceListener(this, "(a=b)");
+ bundleContext.removeServiceListener(this);
+ bundleContext = assertServiceLifecycle(bundle, bundleContext, properties, false);
+
+ bundleContext.addServiceListener(this, "(c=d)");
+ bundleContext.addServiceListener(this, "(a=b)");
+ assertServiceLifecycle(bundle, bundleContext, properties, true);
+ bundleContext.removeServiceListener(this);
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ protected BundleContext assertServiceLifecycle(Bundle bundle, BundleContext bundleContext, boolean events) throws Exception
+ {
+ return assertServiceLifecycle(bundle, bundleContext, null, events);
+ }
+
+ protected BundleContext assertServiceLifecycle(Bundle bundle, BundleContext bundleContext, Dictionary<String, Object> properties, boolean events) throws Exception
+ {
+ assertNoServiceEvent();
+
+ ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, properties);
+ ServiceReference reference = registration.getReference();
+ if (events)
+ assertServiceEvent(ServiceEvent.REGISTERED, reference);
+ else
+ assertNoServiceEvent();
+
+ registration.setProperties(properties);
+ if (events)
+ assertServiceEvent(ServiceEvent.MODIFIED, reference);
+ else
+ assertNoServiceEvent();
+
+ registration.unregister();
+ if (events)
+ assertServiceEvent(ServiceEvent.UNREGISTERING, reference);
+ else
+ assertNoServiceEvent();
+
+ registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, properties);
+ reference = registration.getReference();
+ if (events)
+ assertServiceEvent(ServiceEvent.REGISTERED, reference);
+ else
+ assertNoServiceEvent();
+
+ bundle.stop();
+ if (events)
+ assertServiceEvent(ServiceEvent.UNREGISTERING, reference);
+ else
+ assertNoServiceEvent();
+
+ try
+ {
+ bundleContext.addServiceListener(this);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+
+ bundle.start();
+ bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+ return bundleContext;
+ }
+
+ public void testBundleListener() throws Exception
+ {
+ // todo how to test INSTALLED/RESOLVED?
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ try
+ {
+ bundleContext.addBundleListener(null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+
+ try
+ {
+ bundleContext.removeBundleListener(null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+
+ bundleContext.addBundleListener(this);
+ bundleContext = assertBundleLifecycle(bundle, bundleContext, true);
+ bundleContext.removeBundleListener(this);
+
+ bundleContext.addBundleListener(this);
+ bundleContext.removeBundleListener(this);
+ bundleContext = assertBundleLifecycle(bundle, bundleContext, false);
+
+ bundleContext.addBundleListener(this);
+ bundleContext.addBundleListener(this);
+ bundleContext = assertBundleLifecycle(bundle, bundleContext, true);
+ bundleContext.removeBundleListener(this);
+
+ bundleContext.addBundleListener(this);
+
+ // todo test asynch BundleListener
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ assertBundleEvent(BundleEvent.STOPPING, bundle);
+ assertBundleEvent(BundleEvent.STOPPED, bundle);
+ // todo assertBundleEvent(BundleEvent.UNRESOLVED, bundle);
+ assertBundleEvent(BundleEvent.UNINSTALLED, bundle);
+ }
+
+ protected BundleContext assertBundleLifecycle(Bundle bundle, BundleContext bundleContext, boolean events) throws Exception
+ {
+ assertNoBundleEvent();
+
+ bundle.stop();
+ if (events)
+ {
+ assertBundleEvent(BundleEvent.STOPPING, bundle);
+ assertBundleEvent(BundleEvent.STOPPED, bundle);
+ }
+ else
+ assertNoBundleEvent();
+
+ bundle.start();
+ if (events)
+ {
+ assertBundleEvent(BundleEvent.STARTING, bundle);
+ assertBundleEvent(BundleEvent.STARTED, bundle);
+ }
+ else
+ assertNoBundleEvent();
+
+ return bundleContext;
+ }
+
+ public void testFrameworkListener() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ try
+ {
+ bundleContext.addFrameworkListener(null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+
+ try
+ {
+ bundleContext.removeFrameworkListener(null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+
+ // todo test events
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testGetDataFile() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+ assertNull(bundleContext.getDataFile("blah"));
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ protected void assertSystemProperty(BundleContext bundleContext, String property, String osgiProperty)
+ {
+ String expected = System.getProperty(property);
+ assertNotNull(expected);
+ assertEquals(expected, bundleContext.getProperty(osgiProperty));
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/bundle/test/BundleEntriesUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/bundle/test/BundleEntriesUnitTestCase.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/bundle/test/BundleEntriesUnitTestCase.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,469 @@
+/*
+* 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.test.osgi.bundle.test;
+
+import java.net.URL;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Set;
+
+import junit.framework.Test;
+
+import org.jboss.test.osgi.OSGiTestCase;
+import org.osgi.framework.Bundle;
+
+/**
+ * BundleEntriesUnitTestCase.
+ *
+ * TODO test security
+ * TODO test fragments
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class BundleEntriesUnitTestCase extends OSGiTestCase
+{
+ public BundleEntriesUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(BundleEntriesUnitTestCase.class);
+ }
+
+ public void testEntriesNotInstalled() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/entries/", "entries-simple");
+ uninstall(bundle);
+ try
+ {
+ bundle.getEntry("root.xml");
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ try
+ {
+ bundle.findEntries("", "root.xml", false);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ }
+
+ public void testFindEntriesNoPath() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/entries/", "entries-simple");
+ try
+ {
+ bundle.findEntries(null, "root.xml", false);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testEntries() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/entries/", "entries-simple");
+ try
+ {
+ assertEntry(bundle, "");
+ assertNoEntries(bundle, "", "", false);
+ assertNoEntries(bundle, "", "", true);
+ assertEntryPaths("", bundle,
+ "/",
+ "root.xml",
+ "root-no-suffix",
+ "entry1.xml",
+ "META-INF/",
+ "META-INF/MANIFEST.MF",
+ "org/",
+ "org/jboss/",
+ "org/jboss/test/",
+ "org/jboss/test/osgi/",
+ "org/jboss/test/osgi/bundle/",
+ "org/jboss/test/osgi/bundle/entries/",
+ "org/jboss/test/osgi/bundle/entries/notxml.suffix",
+ "org/jboss/test/osgi/bundle/entries/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/entry2.xml",
+ "org/jboss/test/osgi/bundle/entries/sub/",
+ "org/jboss/test/osgi/bundle/entries/sub/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/sub/entry2.xml"
+ );
+
+ assertNoEntry(bundle, "DoesNotExist");
+ assertNoEntries(bundle, "", "DoesNotExist", false);
+ assertNoEntries(bundle, "", "DoesNotExist", true);
+ assertNoEntryPaths(bundle, "DoesNotExist");
+
+ assertEntry(bundle, "root-no-suffix");
+ assertEntries(bundle, "", "root-no-suffix", false, "root-no-suffix");
+ assertEntries(bundle, "", "root-no-suffix", true, "root-no-suffix");
+ assertEntryPaths(bundle, "root-no-suffix");
+
+ assertEntry(bundle, "root.xml");
+ assertEntries(bundle, "", "root.xml", false, "root.xml");
+ assertEntries(bundle, "", "root.xml", true, "root.xml");
+ assertEntryPaths(bundle, "root.xml");
+
+ assertEntry(bundle, "entry1.xml");
+ assertEntries(bundle, "", "entry1.xml", false, "entry1.xml");
+ assertEntries(bundle, "", "entry1.xml", true,
+ "entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/sub/entry1.xml"
+ );
+ assertEntryPaths(bundle, "entry1.xml");
+
+ assertEntry(bundle, "META-INF");
+ assertNoEntries(bundle, "", "META-INF", false);
+ assertNoEntries(bundle, "", "META-INF", true);
+ assertEntryPaths("META-INF", bundle,
+ "META-INF/",
+ "META-INF/MANIFEST.MF"
+ );
+
+ assertNoEntry(bundle, "META-INF/DoesNotExist");
+ assertNoEntries(bundle, "META-INF", "DoesNotExist", false);
+ assertNoEntries(bundle, "META-INF", "DoesNotExist", true);
+ assertNoEntryPaths(bundle, "META-INF/DoesNotExist");
+
+ assertEntry(bundle, "META-INF/MANIFEST.MF");
+ assertEntries(bundle, "META-INF", "MANIFEST.MF", false, "META-INF/MANIFEST.MF");
+ assertEntries(bundle, "META-INF", "MANIFEST.MF", true, "META-INF/MANIFEST.MF");
+ assertEntryPaths(bundle, "META-INF/MANIFEST.MF");
+
+ assertEntry(bundle, "org");
+ assertNoEntries(bundle, "", "org", false);
+ assertNoEntries(bundle, "", "org", true);
+ assertEntryPaths("org", bundle,
+ "org/",
+ "org/jboss/",
+ "org/jboss/test/",
+ "org/jboss/test/osgi/",
+ "org/jboss/test/osgi/bundle/",
+ "org/jboss/test/osgi/bundle/entries/",
+ "org/jboss/test/osgi/bundle/entries/notxml.suffix",
+ "org/jboss/test/osgi/bundle/entries/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/entry2.xml",
+ "org/jboss/test/osgi/bundle/entries/sub/",
+ "org/jboss/test/osgi/bundle/entries/sub/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/sub/entry2.xml"
+ );
+
+ assertNoEntry(bundle, "org/DoesNotExist");
+ assertNoEntries(bundle, "org", "DoesNotExist", false);
+ assertNoEntries(bundle, "org", "DoesNotExist", true);
+ assertNoEntryPaths(bundle, "org/DoesNotExist");
+
+ assertEntry(bundle, "org/jboss/test/osgi/bundle/entries");
+ assertEntries(bundle, "", "org/jboss/test/osgi/bundle/entries", false);
+ assertEntries(bundle, "", "org/jboss/test/osgi/bundle/entries", true);
+ assertEntryPaths("org/jboss/test/osgi/bundle/entries", bundle,
+ "org/jboss/test/osgi/bundle/entries/",
+ "org/jboss/test/osgi/bundle/entries/notxml.suffix",
+ "org/jboss/test/osgi/bundle/entries/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/entry2.xml",
+ "org/jboss/test/osgi/bundle/entries/sub/",
+ "org/jboss/test/osgi/bundle/entries/sub/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/sub/entry2.xml"
+ );
+
+ assertNoEntry(bundle, "org/jboss/test/osgi/bundle/DoesNotExist");
+ assertNoEntries(bundle, "org/jboss/test/osgi/bundle", "DoesNotExist", false);
+ assertNoEntries(bundle, "org/jboss/test/osgi/bundle", "DoesNotExist", true);
+ assertNoEntryPaths(bundle, "org/jboss/test/osgi/bundle/DoesNotExist");
+
+ assertEntry(bundle, "org/jboss/test/osgi/bundle/entries/notxml.suffix");
+ assertEntries(bundle, "org/jboss/test/osgi/bundle/entries", "notxml.suffix", false,
+ "org/jboss/test/osgi/bundle/entries/notxml.suffix");
+ assertEntries(bundle, "org/jboss/test/osgi/bundle/entries", "notxml.suffix", true,
+ "org/jboss/test/osgi/bundle/entries/notxml.suffix"
+ );
+ assertEntryPaths(bundle, "org/jboss/test/osgi/bundle/entries/notxml.suffix");
+
+ assertEntry(bundle, "org/jboss/test/osgi/bundle/entries/entry1.xml");
+ assertEntries(bundle, "org/jboss/test/osgi/bundle/entries", "entry1.xml", false,
+ "org/jboss/test/osgi/bundle/entries/entry1.xml");
+ assertEntries(bundle, "org/jboss/test/osgi/bundle/entries", "entry1.xml", true,
+ "org/jboss/test/osgi/bundle/entries/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/sub/entry1.xml"
+ );
+ assertEntryPaths(bundle, "org/jboss/test/osgi/bundle/entries/entry1.xml");
+
+ assertEntry(bundle, "org/jboss/test/osgi/bundle/entries/entry2.xml");
+ assertEntries(bundle, "org/jboss/test/osgi/bundle/entries", "entry2.xml", false,
+ "org/jboss/test/osgi/bundle/entries/entry2.xml");
+ assertEntries(bundle, "org/jboss/test/osgi/bundle/entries", "entry2.xml", true,
+ "org/jboss/test/osgi/bundle/entries/entry2.xml",
+ "org/jboss/test/osgi/bundle/entries/sub/entry2.xml"
+ );
+ assertEntryPaths(bundle, "org/jboss/test/osgi/bundle/entries/entry2.xml");
+
+ assertEntry(bundle, "org/jboss/test/osgi/bundle/entries/sub");
+ assertEntries(bundle, "", "org/jboss/test/osgi/bundle/entries/sub", false);
+ assertEntries(bundle, "", "org/jboss/test/osgi/bundle/entries/sub", true);
+ assertEntryPaths("org/jboss/test/osgi/bundle/entries/sub", bundle,
+ "org/jboss/test/osgi/bundle/entries/sub/",
+ "org/jboss/test/osgi/bundle/entries/sub/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/sub/entry2.xml"
+ );
+
+ assertNoEntry(bundle, "org/jboss/test/osgi/bundle/DoesNotExist/sub");
+ assertNoEntries(bundle, "org/jboss/test/osgi/bundle/sub", "DoesNotExist", false);
+ assertNoEntries(bundle, "org/jboss/test/osgi/bundle/sub", "DoesNotExist", true);
+ assertNoEntryPaths(bundle, "org/jboss/test/osgi/bundle/DoesNotExist/sub");
+
+ assertEntry(bundle, "org/jboss/test/osgi/bundle/entries/sub/entry1.xml");
+ assertEntries(bundle, "org/jboss/test/osgi/bundle/entries/sub", "entry1.xml", false,
+ "org/jboss/test/osgi/bundle/entries/sub/entry1.xml");
+ assertEntries(bundle, "org/jboss/test/osgi/bundle/entries/sub", "entry1.xml", true,
+ "org/jboss/test/osgi/bundle/entries/sub/entry1.xml");
+ assertEntryPaths(bundle, "org/jboss/test/osgi/bundle/entries/sub/entry1.xml");
+
+ assertEntry(bundle, "org/jboss/test/osgi/bundle/entries/sub/entry2.xml");
+ assertEntries(bundle, "org/jboss/test/osgi/bundle/entries/sub", "entry2.xml", false,
+ "org/jboss/test/osgi/bundle/entries/sub/entry2.xml");
+ assertEntries(bundle, "org/jboss/test/osgi/bundle/entries/sub", "entry2.xml", true,
+ "org/jboss/test/osgi/bundle/entries/sub/entry2.xml");
+ assertEntryPaths(bundle, "org/jboss/test/osgi/bundle/entries/sub/entry2.xml");
+
+ assertEntries(bundle, "", "*", false,
+ "root.xml",
+ "root-no-suffix",
+ "entry1.xml"
+ );
+ assertEntries(bundle, "", "*", true,
+ "root.xml",
+ "root-no-suffix",
+ "entry1.xml",
+ "META-INF/MANIFEST.MF",
+ "org/jboss/test/osgi/bundle/entries/notxml.suffix",
+ "org/jboss/test/osgi/bundle/entries/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/sub/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/entry2.xml",
+ "org/jboss/test/osgi/bundle/entries/sub/entry2.xml"
+ );
+
+ assertEntries(bundle, "", null, false,
+ "root.xml",
+ "root-no-suffix",
+ "entry1.xml"
+ );
+ assertEntries(bundle, "", null, true,
+ "root.xml",
+ "root-no-suffix",
+ "entry1.xml",
+ "META-INF/MANIFEST.MF",
+ "org/jboss/test/osgi/bundle/entries/notxml.suffix",
+ "org/jboss/test/osgi/bundle/entries/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/sub/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/entry2.xml",
+ "org/jboss/test/osgi/bundle/entries/sub/entry2.xml"
+ );
+
+ assertEntries(bundle, "", "root*", false,
+ "root-no-suffix",
+ "root.xml"
+ );
+ assertEntries(bundle, "", "root*", true,
+ "root-no-suffix",
+ "root.xml"
+ );
+
+ assertEntries(bundle, "", "entry*", false,
+ "entry1.xml"
+ );
+ assertEntries(bundle, "", "entry*", true,
+ "entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/sub/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/entry2.xml",
+ "org/jboss/test/osgi/bundle/entries/sub/entry2.xml"
+ );
+
+ assertEntries(bundle, "org/jboss/test/osgi/bundle/entries", "entry*", false,
+ "org/jboss/test/osgi/bundle/entries/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/entry2.xml"
+ );
+ assertEntries(bundle, "org/jboss/test/osgi/bundle/entries", "entry*", true,
+ "org/jboss/test/osgi/bundle/entries/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/sub/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/entry2.xml",
+ "org/jboss/test/osgi/bundle/entries/sub/entry2.xml"
+ );
+
+ assertEntries(bundle, "", "*.xml", false,
+ "root.xml",
+ "entry1.xml"
+ );
+ assertEntries(bundle, "", "*.xml", true,
+ "root.xml",
+ "entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/sub/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/entry2.xml",
+ "org/jboss/test/osgi/bundle/entries/sub/entry2.xml"
+ );
+
+ assertEntries(bundle, "", "*xml*", false,
+ "root.xml",
+ "entry1.xml"
+ );
+ assertEntries(bundle, "", "*xml*", true,
+ "root.xml",
+ "entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/notxml.suffix",
+ "org/jboss/test/osgi/bundle/entries/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/sub/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/entry2.xml",
+ "org/jboss/test/osgi/bundle/entries/sub/entry2.xml"
+ );
+
+ assertEntries(bundle, "org/jboss/test/osgi/bundle/entries", "*xml*", false,
+ "org/jboss/test/osgi/bundle/entries/notxml.suffix",
+ "org/jboss/test/osgi/bundle/entries/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/entry2.xml"
+ );
+ assertEntries(bundle, "org/jboss/test/osgi/bundle/entries", "*xml*", true,
+ "org/jboss/test/osgi/bundle/entries/notxml.suffix",
+ "org/jboss/test/osgi/bundle/entries/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/sub/entry1.xml",
+ "org/jboss/test/osgi/bundle/entries/entry2.xml",
+ "org/jboss/test/osgi/bundle/entries/sub/entry2.xml"
+ );
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ protected void assertEntry(Bundle bundle, String path) throws Exception
+ {
+ URL expected = getBundleResource(bundle, path);
+ if (expected == null)
+ fail("Expected resource not found: " + path);
+
+ assertEntry(bundle, path, expected);
+ assertEntry(bundle, "/" + path, expected);
+ }
+
+ protected void assertEntry(Bundle bundle, String path, URL expected) throws Exception
+ {
+ URL actual = bundle.getEntry(path);
+ assertEquals(expected, actual);
+ }
+
+ protected void assertNoEntry(Bundle bundle, String path) throws Exception
+ {
+ URL actual = bundle.getEntry(path);
+ assertNull("Did not expect entry: " + actual + " for path: " + path, actual);
+ }
+
+ protected void assertEntries(Bundle bundle, String path, String filePattern, boolean recurse, String... entries) throws Exception
+ {
+ Set<URL> expected = new HashSet<URL>();
+ for (String entry : entries)
+ {
+ Enumeration<URL> urls = getBundleResources(bundle, entry);
+ if (urls == null || urls.hasMoreElements() == false)
+ fail("Expected resource not found: " + entry);
+ while (urls.hasMoreElements())
+ expected.add(urls.nextElement());
+ }
+
+ assertEntries(bundle, path, filePattern, recurse, expected);
+ assertEntries(bundle, "/" + path, filePattern, recurse, expected);
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void assertEntries(Bundle bundle, String path, String filePattern, boolean recurse, Set<URL> expected) throws Exception
+ {
+ Set<URL> actual = new HashSet<URL>();
+ Enumeration<URL> enumeration = bundle.findEntries(path, filePattern, recurse);
+ while (enumeration != null && enumeration.hasMoreElements())
+ actual.add(enumeration.nextElement());
+
+ assertEquals(expected, actual);
+ }
+
+ protected void assertNoEntries(Bundle bundle, String path, String filePattern, boolean recurse) throws Exception
+ {
+ assertEntries(bundle, path, filePattern, recurse);
+ }
+
+ protected void assertEntryPaths(Bundle bundle, String path) throws Exception
+ {
+ Set<String> expected = Collections.singleton(path);
+
+ assertEntryPaths(bundle, path, expected);
+ assertEntryPaths(bundle, "/" + path, expected);
+ }
+
+ protected void assertEntryPaths(String path, Bundle bundle, String... entries) throws Exception
+ {
+ Set<String> expected = new HashSet<String>();
+ expected.addAll(Arrays.asList(entries));
+
+ assertEntryPaths(bundle, path, expected);
+ assertEntryPaths(bundle, "/" + path, expected);
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void assertEntryPaths(Bundle bundle, String path, Set<String> expected) throws Exception
+ {
+ Set<String> actual = new HashSet<String>();
+ Enumeration<String> enumeration = bundle.getEntryPaths(path);
+ while (enumeration != null && enumeration.hasMoreElements())
+ actual.add(enumeration.nextElement());
+
+ assertEquals(expected, actual);
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void assertNoEntryPaths(Bundle bundle, String path) throws Exception
+ {
+ Enumeration<String> enumeration = bundle.getEntryPaths(path);
+ if (enumeration != null)
+ {
+ Set<String> actual = new HashSet<String>();
+ while (enumeration.hasMoreElements())
+ actual.add(enumeration.nextElement());
+ fail("For path " + path + " did not expect entry paths: " + actual);
+ }
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/bundle/test/BundleUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/bundle/test/BundleUnitTestCase.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/bundle/test/BundleUnitTestCase.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,214 @@
+/*
+* 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.test.osgi.bundle.test;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.jar.Attributes;
+
+import junit.framework.Test;
+
+import org.jboss.test.osgi.OSGiTestCase;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+
+/**
+ * BundleUnitTestCase.
+ *
+ * TODO test security
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class BundleUnitTestCase extends OSGiTestCase
+{
+ public BundleUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(BundleUnitTestCase.class);
+ }
+
+ public void testBundleId() throws Exception
+ {
+ long id1 = -1;
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ id1 = bundle.getBundleId();
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ assertEquals(id1, bundle.getBundleId());
+
+ long id2 = -1;
+ bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ id2 = bundle.getBundleId();
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ assertEquals(id2, bundle.getBundleId());
+ assertTrue("Ids should be different" + id1 + "," + id2, id1 != id2);
+ }
+
+ public void testSymbolicName() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ assertEquals("org.jboss.test.osgi.simple1", bundle.getSymbolicName());
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ assertEquals("org.jboss.test.osgi.simple1", bundle.getSymbolicName());
+ }
+
+ public void testState() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ assertEquals(Bundle.INSTALLED, bundle.getState());
+
+ bundle.getResource("META-INF/MANIFEST"); // Resolves the bundle
+ // todo assertEquals(Bundle.RESOLVED, bundle.getState());
+
+ bundle.start();
+ assertEquals(Bundle.ACTIVE, bundle.getState());
+
+ bundle.stop();
+ assertEquals(Bundle.RESOLVED, bundle.getState());
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ assertEquals(Bundle.UNINSTALLED, bundle.getState());
+ }
+
+ public void testGetBundleContext() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNull(bundleContext);
+
+ bundle.start();
+ bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ bundle.stop();
+ bundleContext = bundle.getBundleContext();
+ assertNull(bundleContext);
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testLastModified() throws Exception
+ {
+ // TODO testLastModified
+ }
+
+ public void testStartStop() throws Exception
+ {
+ // TODO testStartStop
+ }
+
+ public void testUpdate() throws Exception
+ {
+ // TODO testUpdate
+ }
+
+ public void testUninstall() throws Exception
+ {
+ // TODO testUninstall
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testGetHeaders() throws Exception
+ {
+ // TODO case insensistive
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ Dictionary expected = new Hashtable();
+ expected.put(Constants.BUNDLE_NAME, "Simple1");
+ expected.put(Constants.BUNDLE_SYMBOLICNAME, "org.jboss.test.osgi.simple1");
+ expected.put(Attributes.Name.MANIFEST_VERSION.toString(), "1.0");
+ expected.put(Attributes.Name.IMPLEMENTATION_TITLE.toString(), "JBoss OSGi tests");
+ expected.put(Attributes.Name.IMPLEMENTATION_VENDOR.toString(), "jboss.org");
+ expected.put(Attributes.Name.IMPLEMENTATION_VERSION.toString(), "test");
+
+ Dictionary dictionary = bundle.getHeaders();
+ assertEquals(expected, dictionary);
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testLocation() throws Exception
+ {
+ // TODO testGetLocation
+ }
+
+ public void testGetRegisteredServices() throws Exception
+ {
+ // TODO testGetRegisteredServices
+ }
+
+ public void testServicesInUse() throws Exception
+ {
+ // TODO testServicesInUse
+ }
+
+ public void testHasPermission() throws Exception
+ {
+ // TODO testHasPermission
+ }
+
+ public void testGetResources() throws Exception
+ {
+ // TODO testGetResource(s)
+ }
+
+ public void testLoadClass() throws Exception
+ {
+ // TODO testLoadClass
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/bundle/test/SystemBundleUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/bundle/test/SystemBundleUnitTestCase.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/bundle/test/SystemBundleUnitTestCase.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,124 @@
+/*
+* 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.test.osgi.bundle.test;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import junit.framework.Test;
+
+import org.jboss.test.osgi.OSGiTestCase;
+import org.jboss.test.osgi.OSGiTestDelegate;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
+
+/**
+ * SystemBundleUnitTestCase.
+ *
+ * TODO test security
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class SystemBundleUnitTestCase extends OSGiTestCase
+{
+ /** The system bundle */
+ private static Bundle systemBundle = null;
+
+ public SystemBundleUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(SystemBundleUnitTestCase.class);
+ }
+
+ public static void deployBundles(OSGiTestDelegate delegate) throws Exception
+ {
+ Bundle bundle = delegate.addBundle("/bundles/simple/", "simple-bundle1");
+ bundle.start();
+ BundleContext context = bundle.getBundleContext();
+ assertNotNull(context);
+ systemBundle = context.getBundle(0);
+ assertNotNull(systemBundle);
+ }
+
+ public void testBundleId() throws Exception
+ {
+ assertEquals(0, systemBundle.getBundleId());
+ }
+
+ public void testSymbolicName() throws Exception
+ {
+ assertEquals(Constants.SYSTEM_BUNDLE_SYMBOLICNAME, systemBundle.getSymbolicName());
+ }
+
+ public void testState() throws Exception
+ {
+ assertEquals(Bundle.ACTIVE, systemBundle.getState());
+ }
+
+ public void testStartStop() throws Exception
+ {
+ // TODO testStartStop
+ }
+
+ public void testUpdate() throws Exception
+ {
+ // TODO testUpdate
+ }
+
+ public void testUninstall() throws Exception
+ {
+ try
+ {
+ systemBundle.uninstall();
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(BundleException.class, t);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testGetHeaders() throws Exception
+ {
+ Dictionary expected = new Hashtable();
+ expected.put(Constants.BUNDLE_NAME, Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
+ expected.put(Constants.BUNDLE_SYMBOLICNAME, Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
+ // todo expected.put(Attributes.Name.IMPLEMENTATION_TITLE.toString(), "JBoss OSGi");
+ // todo expected.put(Attributes.Name.IMPLEMENTATION_VENDOR.toString(), "jboss.org");
+ // todo expected.put(Attributes.Name.IMPLEMENTATION_VERSION.toString(), "r4v41");
+
+ Dictionary dictionary = systemBundle.getHeaders();
+ assertEquals(expected, dictionary);
+ }
+
+ public void testLocation() throws Exception
+ {
+ assertEquals(Constants.SYSTEM_BUNDLE_LOCATION, systemBundle.getLocation());
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/filter/FilterTestSuite.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/filter/FilterTestSuite.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/filter/FilterTestSuite.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,53 @@
+/*
+* 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.test.osgi.filter;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+import org.jboss.test.osgi.filter.test.BundleContextFilterUnitTestCase;
+import org.jboss.test.osgi.filter.test.FrameworkUtilFilterUnitTestCase;
+
+/**
+ * BundleTestSuite.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class FilterTestSuite extends TestSuite
+{
+ public static void main(String[] args)
+ {
+ TestRunner.run(suite());
+ }
+
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite("Filter Tests");
+
+ suite.addTest(FrameworkUtilFilterUnitTestCase.suite());
+ suite.addTest(BundleContextFilterUnitTestCase.suite());
+
+ return suite;
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/filter/test/AbstractFilterTest.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/filter/test/AbstractFilterTest.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/filter/test/AbstractFilterTest.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,447 @@
+/*
+* 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.test.osgi.filter.test;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.jboss.test.osgi.OSGiTestCase;
+import org.osgi.framework.Filter;
+import org.osgi.framework.InvalidSyntaxException;
+
+/**
+ * AbstractFilterTest.
+ *
+ * TODO test type conversions
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class AbstractFilterTest extends OSGiTestCase
+{
+ public AbstractFilterTest(String name)
+ {
+ super(name);
+ }
+
+ protected abstract Filter createFilter(String filter) throws Exception;
+
+ public void testBasic() throws Exception
+ {
+ // Null filter
+ assertInvalid(null);
+ // Empty
+ assertInvalid("");
+ // No left parenthesis
+ assertInvalid("a=b)");
+ // No right parenthesis
+ assertInvalid("(a=b");
+ // No filter
+ assertInvalid("()");
+ // Missing EOF
+ assertInvalid("(a=b)A");
+
+ // Simple filter
+ assertValid("(a=b)");
+ // Simple Whitespace tests
+ assertValid(" (a=b)");
+ assertValid("(a=b) ");
+ }
+
+ public void testEquals() throws Exception
+ {
+ PropertyBuilder properties = PropertyBuilder.build()
+ .put("a", "b")
+ .put("c", " d")
+ .put("e", "f ")
+ .put("star", "*")
+ .put("slash", "\\")
+ .put("rightparen", ")");
+
+ assertInvalid("(=)");
+ assertInvalid("(=");
+ assertInvalid("(=b)");
+ assertInvalid("(!=b)");
+ assertInvalid("(&=b)");
+ assertInvalid("(|=b)");
+ assertInvalid("(<=b)");
+ assertInvalid("(>=b)");
+ assertInvalid("(~=b)");
+ assertInvalid("(*=b)");
+ assertInvalid("(a=\\)");
+
+ assertMatch("(a=b)", properties);
+ assertMatch("( a=b)", properties);
+ assertMatch("(a =b)", properties);
+ assertMatch("(c= d)", properties);
+ assertMatch("(e=f )", properties);
+ assertNoMatch("(a=)", properties);
+ assertNoMatch("(a=c)", properties);
+ assertNoMatch("(x=c)", properties);
+
+ assertMatch("(star=\\*)", properties);
+ assertNoMatch("(a=\\*)", properties);
+ assertMatch("(slash=\\\\)", properties);
+ assertNoMatch("(a=\\\\)", properties);
+ assertMatch("(rightparen=\\))", properties);
+ assertNoMatch("(a=\\))", properties);
+ }
+
+ public void testLess() throws Exception
+ {
+ PropertyBuilder properties = PropertyBuilder.build()
+ .put("a", 1)
+ .put("string", "2");
+
+ assertInvalid("(<)");
+ assertInvalid("(< =)");
+ assertInvalid("(<=)");
+ assertInvalid("(<=");
+ assertInvalid("(<=b)");
+
+ assertMatch("(a<=2)", properties);
+ assertMatch("( a<=2)", properties);
+ assertMatch("(a <=2)", properties);
+ assertNoMatch("(a<= 2)", properties);
+ assertNoMatch("(a<=2 )", properties);
+ assertNoMatch("(a<=0)", properties);
+ assertNoMatch("( a<=0)", properties);
+ assertNoMatch("(a <=0)", properties);
+ assertNoMatch("(a<= 0)", properties);
+ assertNoMatch("(a<=0 )", properties);
+ assertNoMatch("(a<=)", properties);
+ assertNoMatch("(a<= )", properties);
+
+ assertMatch("(string<=3)", properties);
+ assertMatch("(string<=3 )", properties);
+ assertNoMatch("(string<=1)", properties);
+ assertNoMatch("(string<= 3)", properties);
+ }
+
+ public void testGreater() throws Exception
+ {
+ PropertyBuilder properties = PropertyBuilder.build()
+ .put("a", 1)
+ .put("string", "2");
+
+ assertInvalid("(>)");
+ assertInvalid("(> =)");
+ assertInvalid("(>=)");
+ assertInvalid("(>=");
+ assertInvalid("(>=b)");
+
+ assertMatch("(a>=0)", properties);
+ assertMatch("( a>=0)", properties);
+ assertMatch("(a >=0)", properties);
+ assertNoMatch("(a>= 0)", properties);
+ assertNoMatch("(a>=0 )", properties);
+ assertNoMatch("(a>=2)", properties);
+ assertNoMatch("( a>=2)", properties);
+ assertNoMatch("(a >=2)", properties);
+ assertNoMatch("(a>= 2)", properties);
+ assertNoMatch("(a>=2 )", properties);
+ assertNoMatch("(a>=)", properties);
+ assertNoMatch("(a>= )", properties);
+
+ assertMatch("(string>=1)", properties);
+ assertMatch("(string>=1 )", properties);
+ assertNoMatch("(string>=3)", properties);
+ assertMatch("(string>= 1)", properties);
+ }
+
+ public void testApprox() throws Exception
+ {
+ assertInvalid("(~)");
+ assertInvalid("(~ =)");
+ assertInvalid("(~=)");
+ assertInvalid("(~=");
+ assertInvalid("(~=b)");
+
+ // TODO testApprox
+ }
+
+ public void testPresent() throws Exception
+ {
+ PropertyBuilder properties = PropertyBuilder.build()
+ .put("a", "b");
+
+ assertInvalid("(=*)");
+ assertInvalid("(= *)");
+
+ assertMatch("(a=*)", properties);
+ assertMatch("( a=*)", properties);
+ assertMatch("(a =*)", properties);
+ assertNoMatch("(x=*)", properties);
+ assertNoMatch("( x=*)", properties);
+ assertNoMatch("(x =*)", properties);
+ }
+
+ public void testSubstring() throws Exception
+ {
+ PropertyBuilder properties = PropertyBuilder.build()
+ .put("a", "abcdef")
+ .put("astar", "a*")
+ .put("aslash", "a\\")
+ .put("arightparen", "a)");
+
+ assertInvalid("(=**)");
+ assertInvalid("(=a**b)");
+
+ assertMatch("(a=*bcdef)", properties);
+ assertMatch("( a=*bcdef)", properties);
+ assertMatch("(a =*bcdef)", properties);
+ assertMatch("(a=abcde*)", properties);
+ assertMatch("(a=ab*def)", properties);
+ assertMatch("(a=a*def)", properties);
+ assertMatch("(a=a*ef)", properties);
+ assertMatch("(a=a*f)", properties);
+ assertMatch("(a=a*)", properties);
+ assertMatch("(a=*f)", properties);
+ assertMatch("(a=*bcde*)", properties);
+ assertMatch("(a=*b*de*)", properties);
+ assertNoMatch("(x=*bcdef)", properties);
+ assertNoMatch("( x=*bcdef)", properties);
+ assertNoMatch("(x =*bcdef)", properties);
+ assertNoMatch("(a = *bcdef)", properties);
+ assertNoMatch("(a =*bcdef )", properties);
+ assertNoMatch("(a=x*)", properties);
+ assertNoMatch("(a=*x)", properties);
+ assertNoMatch("(a=xbcde*)", properties);
+ assertNoMatch("(a=*bcdex)", properties);
+ assertNoMatch("(a=*bcxe*)", properties);
+ assertNoMatch("(a=*b*xe*)", properties);
+ assertMatch("(a=ab*d*ef)", properties);
+ assertNoMatch("(a=ab*d*def)", properties);
+
+ assertMatch("(astar=*\\*)", properties);
+ assertMatch("(aslash=*\\\\)", properties);
+ assertMatch("(arightparen=*\\))", properties);
+ }
+
+ public void testNot() throws Exception
+ {
+ PropertyBuilder properties = PropertyBuilder.build()
+ .put("a", "b")
+ .put("c", " d")
+ .put("e", "f ");
+
+ assertInvalid("(!)");
+ assertInvalid("(!())");
+
+ assertMatch("(!(a=c))", properties);
+ assertMatch("(! (a=c))", properties);
+ assertMatch("(!(a=c) )", properties);
+ assertMatch("(!( a=c))", properties);
+ assertMatch("(!(a =c))", properties);
+ assertMatch("(!(a= c))", properties);
+ assertMatch("(!(a=c ))", properties);
+ assertNoMatch("(!(a=b))", properties);
+ assertNoMatch("(! (a=b))", properties);
+ assertNoMatch("(!( a=b))", properties);
+ assertNoMatch("(!(a =b))", properties);
+ assertNoMatch("(!(c= d))", properties);
+ assertNoMatch("(!(e=f ))", properties);
+ assertNoMatch("(!(a=b) )", properties);
+ assertMatch("(!(x=))", properties);
+ assertMatch("(!(x=c))", properties);
+ }
+
+ public void testAnd() throws Exception
+ {
+ PropertyBuilder properties = PropertyBuilder.build()
+ .put("a", "b")
+ .put("c", "d")
+ .put("e", "f");
+
+ assertInvalid("(&)");
+ assertInvalid("(&())");
+ assertInvalid("(&()(a=b))");
+ assertInvalid("(&(a=b)())");
+
+ assertMatch("(&(a=b)(c=d)(e=f))", properties);
+ assertMatch("(& (a=b)(c=d)(e=f))", properties);
+ assertMatch("(&(a=b) (c=d)(e=f))", properties);
+ assertMatch("(&(a=b)(c=d) (e=f))", properties);
+ assertMatch("(&(a=b)(c=d)(e=f) )", properties);
+ assertNoMatch("(&(a=x)(c=d)(e=f))", properties);
+ assertNoMatch("(& (a=x)(c=d)(e=f))", properties);
+ assertNoMatch("(&(a=x) (c=d)(e=f))", properties);
+ assertNoMatch("(&(a=x)(c=d) (e=f))", properties);
+ assertNoMatch("(&(a=x)(c=d)(e=f) )", properties);
+ assertNoMatch("(&(a=b)(c=x)(e=f))", properties);
+ assertNoMatch("(&(a=b)(c=d)(e=x))", properties);
+ assertNoMatch("(&(a=b)(c=d)(e=f)(x=a))", properties);
+ }
+
+ public void testOr() throws Exception
+ {
+ PropertyBuilder properties = PropertyBuilder.build()
+ .put("a", "b")
+ .put("c", "d")
+ .put("e", "f");
+
+ assertInvalid("(|)");
+ assertInvalid("(|())");
+ assertInvalid("(|()(a=b))");
+ assertInvalid("(|(a=b)())");
+
+ assertMatch("(|(a=b)(c=d)(e=f))", properties);
+ assertMatch("(| (a=b)(c=d)(e=f))", properties);
+ assertMatch("(|(a=b) (c=d)(e=f))", properties);
+ assertMatch("(|(a=b)(c=d) (e=f))", properties);
+ assertMatch("(|(a=b)(c=d)(e=f) )", properties);
+ assertMatch("(|(a=x)(c=d)(e=f))", properties);
+ assertMatch("(|(a=b)(c=x)(e=f))", properties);
+ assertMatch("(|(a=b)(c=d)(e=x))", properties);
+ assertMatch("(|(a=b)(c=d)(e=f)(x=a))", properties);
+ assertMatch("(|(x=a)(a=b)(c=d)(e=f))", properties);
+ assertNoMatch("(|(a=x)(c=x)(e=x))", properties);
+ assertNoMatch("(| (a=x)(c=x)(e=x))", properties);
+ assertNoMatch("(|(a=x) (c=x)(e=x))", properties);
+ assertNoMatch("(|(a=x)(c=x) (e=x))", properties);
+ assertNoMatch("(|(a=x)(c=x)(e=x) )", properties);
+ assertNoMatch("(|(a=x)(c=x)(e=x)(x=a))", properties);
+ }
+
+ public void testCaseSensitive() throws Exception
+ {
+ PropertyBuilder properties = PropertyBuilder.build()
+ .put("a", "b")
+ .put("C", "d")
+ .put("MiXeD", "Case");
+
+ assertNoMatchCaseSensitive("(A=b)", properties);
+ assertMatchNotCaseSensitive("(A=b)", properties);
+ assertMatchCaseSensitive("(a=b)", properties);
+ assertMatchNotCaseSensitive("(a=b)", properties);
+ assertNoMatchCaseSensitive("(c=d)", properties);
+ assertMatchNotCaseSensitive("(c=d)", properties);
+ assertMatchCaseSensitive("(C=d)", properties);
+ assertMatchNotCaseSensitive("(C=d)", properties);
+ assertNoMatchCaseSensitive("(mixed=Case)", properties);
+ assertMatchNotCaseSensitive("(mixed=Case)", properties);
+ assertNoMatchCaseSensitive("(MIXED=Case)", properties);
+ assertMatchNotCaseSensitive("(MIXED=Case)", properties);
+ assertMatchCaseSensitive("(MiXeD=Case)", properties);
+ assertMatchNotCaseSensitive("(MiXeD=Case)", properties);
+ }
+
+ protected void assertValid(String filter) throws Exception
+ {
+ createFilter(filter);
+ }
+
+ protected void assertInvalid(String filter) throws Exception
+ {
+ try
+ {
+ createFilter(filter);
+ fail("Should not be here! filter=" + filter);
+ }
+ catch (Exception e)
+ {
+ checkThrowable(InvalidSyntaxException.class, e);
+ }
+ }
+
+ protected void assertMatch(String filter, PropertyBuilder properties) throws Exception
+ {
+ assertFilter(filter, properties, true);
+ }
+
+ protected void assertNoMatch(String filter, PropertyBuilder properties) throws Exception
+ {
+ assertFilter(filter, properties, false);
+ }
+
+ protected void assertFilter(String filter, PropertyBuilder properties, boolean expected) throws Exception
+ {
+ Filter f = createFilter(filter);
+ assertFilter(f, properties, expected, false);
+ assertFilter(f, properties, expected, true);
+ }
+
+ protected void assertFilter(Filter filter, PropertyBuilder properties, boolean expected, boolean caseSensitive) throws Exception
+ {
+ Dictionary<String, Object> dictionary = properties.getDictionary();
+ boolean result;
+ String description = "";
+ if (caseSensitive)
+ {
+ result = filter.matchCase(dictionary);
+ description = "(case sensitive)";
+ }
+ else
+ result = filter.match(dictionary);
+
+ getLog().debug(filter + " with " + dictionary + " result=" + result + " " + description);
+ if (expected)
+ assertTrue("Expected " + filter + " to match " + description + " with properties " + dictionary, result);
+ else
+ assertFalse("Expected " + filter + " to NOT match " + description + " with properties " + dictionary, result);
+ }
+
+ protected void assertMatchCaseSensitive(String filter, PropertyBuilder properties) throws Exception
+ {
+ assertFilterCaseSensitive(filter, properties, true);
+ }
+
+ protected void assertNoMatchCaseSensitive(String filter, PropertyBuilder properties) throws Exception
+ {
+ assertFilterCaseSensitive(filter, properties, false);
+ }
+
+ protected void assertMatchNotCaseSensitive(String filter, PropertyBuilder properties) throws Exception
+ {
+ assertFilter(createFilter(filter), properties, true, false);
+ }
+
+ protected void assertNoMatchNotCaseSensitive(String filter, PropertyBuilder properties) throws Exception
+ {
+ assertFilter(createFilter(filter), properties, false, false);
+ }
+
+ protected void assertFilterCaseSensitive(String filter, PropertyBuilder properties, boolean expected) throws Exception
+ {
+ // Only the direct FilterImpl can do this
+ }
+
+ public static class PropertyBuilder
+ {
+ private Dictionary<String, Object> dictionary = new Hashtable<String, Object>();
+
+ public static PropertyBuilder build()
+ {
+ return new PropertyBuilder();
+ }
+
+ public Dictionary<String, Object> getDictionary()
+ {
+ return dictionary;
+ }
+
+ public PropertyBuilder put(String key, Object value)
+ {
+ dictionary.put(key, value);
+ return this;
+ }
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/filter/test/BundleContextFilterUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/filter/test/BundleContextFilterUnitTestCase.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/filter/test/BundleContextFilterUnitTestCase.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,103 @@
+/*
+* 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.test.osgi.filter.test;
+
+import java.util.Dictionary;
+
+import junit.framework.Test;
+
+import org.jboss.test.osgi.OSGiTestDelegate;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Filter;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * BundleContextFilterUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class BundleContextFilterUnitTestCase extends AbstractFilterTest
+{
+ static BundleContext bundleContext;
+
+ public BundleContextFilterUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(BundleContextFilterUnitTestCase.class);
+ }
+
+ public static void deployBundles(OSGiTestDelegate delegate) throws Exception
+ {
+ Bundle bundle = delegate.addBundle("/bundles/simple/", "simple-bundle1");
+ bundle.start();
+ bundleContext = bundle.getBundleContext();
+ }
+
+ protected void assertFilter(String filter, PropertyBuilder properties, boolean expected) throws Exception
+ {
+ super.assertFilter(filter, properties, expected);
+
+ Dictionary<String, Object> dictionary = properties.getDictionary();
+ ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, dictionary);
+ try
+ {
+ ServiceReference reference = registration.getReference();
+ boolean result = createFilter(filter).match(reference);
+ getLog().debug(filter + " with service reference " + dictionary + " result=" + result);
+ if (expected)
+ assertTrue("Expected " + filter + " to match with service reference properties " + dictionary, result);
+ else
+ assertFalse("Expected " + filter + " to NOT match with service reference properties " + dictionary, result);
+
+ if (expected)
+ {
+ assertAllReferences(bundleContext, null, filter, reference);
+ assertReferences(bundleContext, null, filter, reference);
+ }
+ else
+ {
+ assertNoAllReferences(bundleContext, null, filter);
+ }
+ }
+ finally
+ {
+ registration.unregister();
+ }
+ }
+
+ protected void assertFilterCaseSensitive(String filter, PropertyBuilder properties, boolean expected) throws Exception
+ {
+ assertFilter(createFilter(filter), properties, expected, true);
+ }
+
+ protected Filter createFilter(String filter) throws Exception
+ {
+ return bundleContext.createFilter(filter);
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/filter/test/FrameworkUtilFilterUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/filter/test/FrameworkUtilFilterUnitTestCase.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/filter/test/FrameworkUtilFilterUnitTestCase.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,56 @@
+/*
+* 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.test.osgi.filter.test;
+
+import junit.framework.Test;
+
+import org.osgi.framework.Filter;
+import org.osgi.framework.FrameworkUtil;
+
+/**
+ * FrameworkUtilFilterUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class FrameworkUtilFilterUnitTestCase extends AbstractFilterTest
+{
+ public FrameworkUtilFilterUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(FrameworkUtilFilterUnitTestCase.class);
+ }
+
+ protected void assertFilterCaseSensitive(String filter, PropertyBuilder properties, boolean expected) throws Exception
+ {
+ assertFilter(createFilter(filter), properties, expected, true);
+ }
+
+ protected Filter createFilter(String filter) throws Exception
+ {
+ return FrameworkUtil.createFilter(filter);
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/service/ServiceTestSuite.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/service/ServiceTestSuite.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/service/ServiceTestSuite.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,59 @@
+/*
+* 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.test.osgi.service;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+import org.jboss.test.osgi.service.test.GetServiceReferencesUnitTestCase;
+import org.jboss.test.osgi.service.test.GetUnGetServiceUnitTestCase;
+import org.jboss.test.osgi.service.test.RegisterServiceUnitTestCase;
+import org.jboss.test.osgi.service.test.ServiceReferenceUnitTestCase;
+import org.jboss.test.osgi.service.test.ServiceRegistrationUnitTestCase;
+
+/**
+ * ServiceTestSuite.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class ServiceTestSuite extends TestSuite
+{
+ public static void main(String[] args)
+ {
+ TestRunner.run(suite());
+ }
+
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite("Service Tests");
+
+ suite.addTest(RegisterServiceUnitTestCase.suite());
+ suite.addTest(ServiceRegistrationUnitTestCase.suite());
+ suite.addTest(ServiceReferenceUnitTestCase.suite());
+ suite.addTest(GetServiceReferencesUnitTestCase.suite());
+ suite.addTest(GetUnGetServiceUnitTestCase.suite());
+
+ return suite;
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/service/support/BrokenServiceFactory.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/service/support/BrokenServiceFactory.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/service/support/BrokenServiceFactory.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,58 @@
+/*
+* 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.test.osgi.service.support;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceFactory;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * BrokenServiceFactory.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class BrokenServiceFactory implements ServiceFactory
+{
+ Object service;
+ boolean inGet;
+
+ public BrokenServiceFactory(Object service, boolean inGet)
+ {
+ this.service = service;
+ this.inGet = inGet;
+ }
+
+ public Object getService(Bundle bundle, ServiceRegistration registration)
+ {
+ if (inGet)
+ throw new RuntimeException("told to throw error");
+ return service;
+ }
+
+ public void ungetService(Bundle bundle, ServiceRegistration registration, Object service)
+ {
+ if (inGet == false)
+ throw new RuntimeException("told to throw error");
+ }
+
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/service/support/SimpleServiceFactory.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/service/support/SimpleServiceFactory.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/service/support/SimpleServiceFactory.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,59 @@
+/*
+* 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.test.osgi.service.support;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceFactory;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * SimpleServiceFactory.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class SimpleServiceFactory implements ServiceFactory
+{
+ public Object service;
+
+ public Bundle ungetBundle;
+ public ServiceRegistration ungetRegisation;
+ public Object ungetService;
+
+ public SimpleServiceFactory(Object service)
+ {
+ this.service = service;
+ }
+
+ public Object getService(Bundle bundle, ServiceRegistration registration)
+ {
+ return service;
+ }
+
+ public void ungetService(Bundle bundle, ServiceRegistration registration, Object service)
+ {
+ ungetBundle = bundle;
+ ungetRegisation = registration;
+ ungetService = service;
+ }
+
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/service/support/a/A.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/service/support/a/A.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/service/support/a/A.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,32 @@
+/*
+* 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.test.osgi.service.support.a;
+
+/**
+ * A.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class A
+{
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/service/support/b/B.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/service/support/b/B.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/service/support/b/B.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,32 @@
+/*
+* 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.test.osgi.service.support.b;
+
+/**
+ * B.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class B
+{
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/service/test/GetServiceReferencesUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/service/test/GetServiceReferencesUnitTestCase.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/service/test/GetServiceReferencesUnitTestCase.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,630 @@
+/*
+* 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.test.osgi.service.test;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import junit.framework.Test;
+
+import org.jboss.test.osgi.OSGiTestCase;
+import org.jboss.test.osgi.service.support.a.A;
+import org.jboss.test.osgi.service.support.b.B;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * GetServiceReferencesUnitTestCase.
+ *
+ * todo test service permissions
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class GetServiceReferencesUnitTestCase extends OSGiTestCase
+{
+ public GetServiceReferencesUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(GetServiceReferencesUnitTestCase.class);
+ }
+
+ public void testGetServiceReferences() throws Exception
+ {
+ Bundle bundle1 = assembleBundle("simple1", "/bundles/simple/simple-bundle1", A.class);
+ try
+ {
+ bundle1.start();
+ BundleContext bundleContext1 = bundle1.getBundleContext();
+ assertNotNull(bundleContext1);
+
+ assertNoGetReference(bundleContext1, A.class.getName());
+ assertNoReferences(bundleContext1, A.class.getName());
+ assertNoAllReferences(bundleContext1, A.class.getName());
+ assertNoGetReference(bundleContext1, B.class.getName());
+ assertNoReferences(bundleContext1, B.class.getName());
+ assertNoAllReferences(bundleContext1, B.class.getName());
+ assertNoReferences(bundleContext1, null);
+ assertNoAllReferences(bundleContext1, null);
+
+ Class<?> clazz = bundle1.loadClass(A.class.getName());
+ Object service1 = clazz.newInstance();
+ ServiceRegistration registration1 = bundleContext1.registerService(A.class.getName(), service1, null);
+ assertNotNull(registration1);
+ ServiceReference reference1 = registration1.getReference();
+ assertNotNull(reference1);
+
+ assertGetReference(bundleContext1, A.class.getName(), reference1);
+ assertReferences(bundleContext1, A.class.getName(), reference1);
+ assertAllReferences(bundleContext1, A.class.getName(), reference1);
+ assertNoGetReference(bundleContext1, B.class.getName());
+ assertNoReferences(bundleContext1, B.class.getName());
+ assertNoAllReferences(bundleContext1, B.class.getName());
+ assertReferences(bundleContext1, null, reference1);
+ assertAllReferences(bundleContext1, null, reference1);
+
+ registration1.unregister();
+
+ assertNoGetReference(bundleContext1, A.class.getName());
+ assertNoReferences(bundleContext1, A.class.getName());
+ assertNoAllReferences(bundleContext1, A.class.getName());
+ assertNoGetReference(bundleContext1, B.class.getName());
+ assertNoReferences(bundleContext1, B.class.getName());
+ assertNoAllReferences(bundleContext1, B.class.getName());
+ assertNoReferences(bundleContext1, null);
+ assertNoAllReferences(bundleContext1, null);
+
+ try
+ {
+ bundleContext1.getServiceReference(null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+
+ try
+ {
+ bundleContext1.getServiceReferences(null, "invalid");
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(InvalidSyntaxException.class, t);
+ }
+
+ try
+ {
+ bundleContext1.getAllServiceReferences(null, "invalid");
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(InvalidSyntaxException.class, t);
+ }
+
+ bundle1.stop();
+
+ try
+ {
+ bundleContext1.getServiceReference(A.class.getName());
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+
+ try
+ {
+ bundleContext1.getServiceReferences(null, null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+
+ try
+ {
+ bundleContext1.getAllServiceReferences(null, null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ }
+ finally
+ {
+ uninstall(bundle1);
+ }
+ }
+
+ public void testGetServiceReferencesNoClassNotAssignable() throws Exception
+ {
+ assertGetServiceReferencesNotAssignable(null);
+ }
+
+ public void testGetServiceReferencesNotAssignable() throws Exception
+ {
+ assertGetServiceReferencesNotAssignable(A.class.getName());
+ }
+
+ public void assertGetServiceReferencesNotAssignable(String className) throws Exception
+ {
+ Bundle bundle1 = assembleBundle("simple1", "/bundles/simple/simple-bundle1", A.class);
+ try
+ {
+ bundle1.start();
+ BundleContext bundleContext1 = bundle1.getBundleContext();
+ assertNotNull(bundleContext1);
+
+ if (className != null)
+ assertNoGetReference(bundleContext1, className);
+ assertNoReferences(bundleContext1, className);
+ assertNoAllReferences(bundleContext1, className);
+
+ Class<?> clazz = bundle1.loadClass(A.class.getName());
+ Object service1 = clazz.newInstance();
+ ServiceRegistration registration1 = bundleContext1.registerService(A.class.getName(), service1, null);
+ assertNotNull(registration1);
+ ServiceReference reference1 = registration1.getReference();
+ assertNotNull(reference1);
+
+ Bundle bundle2 = assembleBundle("simple2", "/bundles/simple/simple-bundle2", A.class);
+ try
+ {
+ bundle2.start();
+ BundleContext bundleContext2 = bundle2.getBundleContext();
+ assertNotNull(bundleContext2);
+
+ if (className != null)
+ assertNoGetReference(bundleContext2, className);
+ assertNoReferences(bundleContext2, className);
+ assertAllReferences(bundleContext2, className, reference1);
+
+ clazz = bundle2.loadClass(A.class.getName());
+ Object service2 = clazz.newInstance();
+ ServiceRegistration registration2 = bundleContext2.registerService(A.class.getName(), service2, null);
+ assertNotNull(registration2);
+ ServiceReference reference2 = registration2.getReference();
+ assertNotNull(reference2);
+
+ if (className != null)
+ assertGetReference(bundleContext1, className, reference1);
+ assertReferences(bundleContext1, className, reference1);
+ assertAllReferences(bundleContext1, className, reference1, reference2);
+
+ if (className != null)
+ assertGetReference(bundleContext2, className, reference2);
+ assertReferences(bundleContext2, className, reference2);
+ assertAllReferences(bundleContext2, className, reference1, reference2);
+
+ registration1.unregister();
+
+ if (className != null)
+ assertNoGetReference(bundleContext1, className);
+ assertNoReferences(bundleContext1, className);
+ assertAllReferences(bundleContext1, className, reference2);
+
+ if (className != null)
+ assertGetReference(bundleContext2, className, reference2);
+ assertReferences(bundleContext2, className, reference2);
+ assertAllReferences(bundleContext2, className, reference2);
+
+ registration1 = bundleContext1.registerService(A.class.getName(), service1, null);
+ assertNotNull(registration1);
+ reference1 = registration1.getReference();
+ assertNotNull(reference1);
+
+ if (className != null)
+ assertGetReference(bundleContext1, className, reference1);
+ assertReferences(bundleContext1, className, reference1);
+ assertAllReferences(bundleContext1, className, reference2, reference1);
+
+ if (className != null)
+ assertGetReference(bundleContext2, className, reference2);
+ assertReferences(bundleContext2, className, reference2);
+ assertAllReferences(bundleContext2, className, reference2, reference1);
+
+ registration2.unregister();
+
+ if (className != null)
+ assertGetReference(bundleContext1, className, reference1);
+ assertReferences(bundleContext1, className, reference1);
+ assertAllReferences(bundleContext1, className, reference1);
+
+ if (className != null)
+ assertNoGetReference(bundleContext2, className);
+ assertNoReferences(bundleContext2, className);
+ assertAllReferences(bundleContext2, className, reference1);
+
+ registration1.unregister();
+
+ if (className != null)
+ assertNoGetReference(bundleContext1, className);
+ assertNoReferences(bundleContext1, className);
+ assertNoAllReferences(bundleContext1, className);
+
+ if (className != null)
+ assertNoGetReference(bundleContext2, className);
+ assertNoReferences(bundleContext2, className);
+ assertNoAllReferences(bundleContext2, className);
+ }
+ finally
+ {
+ uninstall(bundle2);
+ }
+ }
+ finally
+ {
+ uninstall(bundle1);
+ }
+ }
+
+ public void testGetServiceReferencesNoClassAssignable() throws Exception
+ {
+ assertGetServiceReferencesAssignable(null);
+ }
+
+ public void testGetServiceReferencesClassAssignable() throws Exception
+ {
+ assertGetServiceReferencesAssignable(A.class.getName());
+ }
+
+ public void assertGetServiceReferencesAssignable(String className) throws Exception
+ {
+ Bundle bundle1 = assembleBundle("service2", "/bundles/service/service-bundle2", A.class);
+ try
+ {
+ bundle1.start();
+ BundleContext bundleContext1 = bundle1.getBundleContext();
+ assertNotNull(bundleContext1);
+
+ if (className != null)
+ assertNoGetReference(bundleContext1, className);
+ assertNoReferences(bundleContext1, className);
+ assertNoAllReferences(bundleContext1, className);
+
+ Class<?> clazz = bundle1.loadClass(A.class.getName());
+ Object service1 = clazz.newInstance();
+ ServiceRegistration registration1 = bundleContext1.registerService(A.class.getName(), service1, null);
+ assertNotNull(registration1);
+ ServiceReference reference1 = registration1.getReference();
+ assertNotNull(reference1);
+
+ Bundle bundle2 = assembleBundle("service1", "/bundles/service/service-bundle1");
+ try
+ {
+ bundle2.start();
+ BundleContext bundleContext2 = bundle2.getBundleContext();
+ assertNotNull(bundleContext2);
+
+ if (className != null)
+ assertGetReference(bundleContext2, className, reference1);
+ assertReferences(bundleContext2, className, reference1);
+ assertAllReferences(bundleContext2, className, reference1);
+
+ clazz = bundle2.loadClass(A.class.getName());
+ Object service2 = clazz.newInstance();
+ ServiceRegistration registration2 = bundleContext2.registerService(A.class.getName(), service2, null);
+ assertNotNull(registration2);
+ ServiceReference reference2 = registration2.getReference();
+ assertNotNull(reference2);
+
+ if (className != null)
+ assertGetReference(bundleContext1, className, reference1);
+ assertReferences(bundleContext1, className, reference1, reference2);
+ assertAllReferences(bundleContext1, className, reference1, reference2);
+
+ if (className != null)
+ assertGetReference(bundleContext2, className, reference1);
+ assertReferences(bundleContext2, className, reference1, reference2);
+ assertAllReferences(bundleContext2, className, reference1, reference2);
+
+ registration1.unregister();
+
+ if (className != null)
+ assertGetReference(bundleContext1, className, reference2);
+ assertReferences(bundleContext1, className, reference2);
+ assertAllReferences(bundleContext1, className, reference2);
+
+ if (className != null)
+ assertGetReference(bundleContext2, className, reference2);
+ assertReferences(bundleContext2, className, reference2);
+ assertAllReferences(bundleContext2, className, reference2);
+
+ registration1 = bundleContext1.registerService(A.class.getName(), service1, null);
+ assertNotNull(registration1);
+ reference1 = registration1.getReference();
+ assertNotNull(reference1);
+
+ if (className != null)
+ assertGetReference(bundleContext1, className, reference2);
+ assertReferences(bundleContext1, className, reference2, reference1);
+ assertAllReferences(bundleContext1, className, reference2, reference1);
+
+ if (className != null)
+ assertGetReference(bundleContext2, className, reference2);
+ assertReferences(bundleContext2, className, reference2, reference1);
+ assertAllReferences(bundleContext2, className, reference2, reference1);
+
+ registration2.unregister();
+
+ if (className != null)
+ assertGetReference(bundleContext1, className, reference1);
+ assertReferences(bundleContext1, className, reference1);
+ assertAllReferences(bundleContext1, className, reference1);
+
+ if (className != null)
+ assertGetReference(bundleContext2, className, reference1);
+ assertReferences(bundleContext2, className, reference1);
+ assertAllReferences(bundleContext2, className, reference1);
+
+ registration1.unregister();
+
+ if (className != null)
+ assertNoGetReference(bundleContext1, className);
+ assertNoReferences(bundleContext1, className);
+ assertNoAllReferences(bundleContext1, className);
+
+ if (className != null)
+ assertNoGetReference(bundleContext2, className);
+ assertNoReferences(bundleContext2, className);
+ assertNoAllReferences(bundleContext2, className);
+ }
+ finally
+ {
+ uninstall(bundle2);
+ }
+ }
+ finally
+ {
+ uninstall(bundle1);
+ }
+ }
+
+ public void testGetServiceReferencesRankings() throws Exception
+ {
+ String className = A.class.getName();
+
+ Bundle bundle1 = assembleBundle("service2", "/bundles/service/service-bundle2", A.class);
+ try
+ {
+ bundle1.start();
+ BundleContext bundleContext1 = bundle1.getBundleContext();
+ assertNotNull(bundleContext1);
+
+ assertNoGetReference(bundleContext1, className);
+ assertNoReferences(bundleContext1, className);
+ assertNoAllReferences(bundleContext1, className);
+
+ Dictionary<String, Object> properties1 = new Hashtable<String, Object>();
+ properties1.put(Constants.SERVICE_RANKING, 1);
+ Class<?> clazz = bundle1.loadClass(className);
+ Object service1 = clazz.newInstance();
+ ServiceRegistration registration1 = bundleContext1.registerService(className, service1, properties1);
+ assertNotNull(registration1);
+ ServiceReference reference1 = registration1.getReference();
+ assertNotNull(reference1);
+
+ Bundle bundle2 = assembleBundle("service1", "/bundles/service/service-bundle1");
+ try
+ {
+ bundle2.start();
+ BundleContext bundleContext2 = bundle2.getBundleContext();
+ assertNotNull(bundleContext2);
+
+ assertGetReference(bundleContext2, className, reference1);
+ assertReferences(bundleContext2, className, reference1);
+ assertAllReferences(bundleContext2, className, reference1);
+
+ Dictionary<String, Object> properties2 = new Hashtable<String, Object>();
+ properties2.put(Constants.SERVICE_RANKING, 2);
+ clazz = bundle2.loadClass(className);
+ Object service2 = clazz.newInstance();
+ ServiceRegistration registration2 = bundleContext2.registerService(className, service2, properties2);
+ assertNotNull(registration2);
+ ServiceReference reference2 = registration2.getReference();
+ assertNotNull(reference2);
+
+ assertGetReference(bundleContext1, className, reference2);
+ assertReferences(bundleContext1, className, reference2, reference1);
+ assertAllReferences(bundleContext1, className, reference2, reference1);
+
+ assertGetReference(bundleContext2, className, reference2);
+ assertReferences(bundleContext2, className, reference2, reference1);
+ assertAllReferences(bundleContext2, className, reference2, reference1);
+
+ registration1.unregister();
+
+ assertGetReference(bundleContext1, className, reference2);
+ assertReferences(bundleContext1, className, reference2);
+ assertAllReferences(bundleContext1, className, reference2);
+
+ assertGetReference(bundleContext2, className, reference2);
+ assertReferences(bundleContext2, className, reference2);
+ assertAllReferences(bundleContext2, className, reference2);
+
+ registration1 = bundleContext1.registerService(className, service1, properties1);
+ assertNotNull(registration1);
+ reference1 = registration1.getReference();
+ assertNotNull(reference1);
+
+ assertGetReference(bundleContext1, className, reference2);
+ assertReferences(bundleContext1, className, reference2, reference1);
+ assertAllReferences(bundleContext1, className, reference2, reference1);
+
+ assertGetReference(bundleContext2, className, reference2);
+ assertReferences(bundleContext2, className, reference2, reference1);
+ assertAllReferences(bundleContext2, className, reference2, reference1);
+
+ registration2.unregister();
+
+ assertGetReference(bundleContext1, className, reference1);
+ assertReferences(bundleContext1, className, reference1);
+ assertAllReferences(bundleContext1, className, reference1);
+
+ assertGetReference(bundleContext2, className, reference1);
+ assertReferences(bundleContext2, className, reference1);
+ assertAllReferences(bundleContext2, className, reference1);
+
+ registration1.unregister();
+
+ assertNoGetReference(bundleContext1, className);
+ assertNoReferences(bundleContext1, className);
+ assertNoAllReferences(bundleContext1, className);
+
+ if (className != null)
+ assertNoGetReference(bundleContext2, className);
+ assertNoReferences(bundleContext2, className);
+ assertNoAllReferences(bundleContext2, className);
+ }
+ finally
+ {
+ uninstall(bundle2);
+ }
+ }
+ finally
+ {
+ uninstall(bundle1);
+ }
+ }
+
+ public void testGetServiceReferencesFilterted() throws Exception
+ {
+ String className = A.class.getName();
+ String wrongClassName = B.class.getName();
+
+ Bundle bundle1 = assembleBundle("simple1", "/bundles/simple/simple-bundle1", A.class);
+ try
+ {
+ bundle1.start();
+ BundleContext bundleContext1 = bundle1.getBundleContext();
+ assertNotNull(bundleContext1);
+
+ assertNoGetReference(bundleContext1, A.class.getName());
+ assertNoReferences(bundleContext1, null, "(a=b)");
+ assertNoAllReferences(bundleContext1, null, "(a=b)");
+ assertNoReferences(bundleContext1, className, "(a=b)");
+ assertNoAllReferences(bundleContext1, className, "(a=b)");
+ assertNoReferences(bundleContext1, wrongClassName, "(a=b)");
+ assertNoAllReferences(bundleContext1, wrongClassName, "(a=b)");
+ assertNoReferences(bundleContext1, null, "(c=d)");
+ assertNoAllReferences(bundleContext1, null, "(c=d)");
+ assertNoReferences(bundleContext1, className, "(c=d)");
+ assertNoAllReferences(bundleContext1, className, "(c=d)");
+ assertNoReferences(bundleContext1, wrongClassName, "(c=d)");
+ assertNoAllReferences(bundleContext1, wrongClassName, "(c=d)");
+ assertNoReferences(bundleContext1, null, "(c=x)");
+ assertNoAllReferences(bundleContext1, null, "(c=x)");
+ assertNoReferences(bundleContext1, className, "(c=x)");
+ assertNoAllReferences(bundleContext1, className, "(c=x)");
+ assertNoReferences(bundleContext1, wrongClassName, "(c=x)");
+ assertNoAllReferences(bundleContext1, wrongClassName, "(c=x)");
+ assertNoReferences(bundleContext1, null, "(x=d)");
+ assertNoAllReferences(bundleContext1, null, "(x=d)");
+ assertNoReferences(bundleContext1, className, "(x=d)");
+ assertNoAllReferences(bundleContext1, className, "(x=d)");
+ assertNoReferences(bundleContext1, wrongClassName, "(x=d)");
+ assertNoAllReferences(bundleContext1, wrongClassName, "(x=d)");
+
+ Dictionary<String, Object> properties = new Hashtable<String, Object>();
+ properties.put("a", "b");
+ properties.put("c", "d");
+
+ Class<?> clazz = bundle1.loadClass(A.class.getName());
+ Object service1 = clazz.newInstance();
+ ServiceRegistration registration1 = bundleContext1.registerService(A.class.getName(), service1, properties);
+ assertNotNull(registration1);
+ ServiceReference reference1 = registration1.getReference();
+ assertNotNull(reference1);
+
+ assertGetReference(bundleContext1, A.class.getName(), reference1);
+ assertReferences(bundleContext1, null, "(a=b)", reference1);
+ assertAllReferences(bundleContext1, null, "(a=b)", reference1);
+ assertReferences(bundleContext1, className, "(a=b)", reference1);
+ assertAllReferences(bundleContext1, className, "(a=b)", reference1);
+ assertNoReferences(bundleContext1, wrongClassName, "(a=b)");
+ assertNoAllReferences(bundleContext1, wrongClassName, "(a=b)");
+ assertReferences(bundleContext1, null, "(c=d)", reference1);
+ assertAllReferences(bundleContext1, null, "(c=d)", reference1);
+ assertReferences(bundleContext1, className, "(c=d)", reference1);
+ assertAllReferences(bundleContext1, className, "(c=d)", reference1);
+ assertNoReferences(bundleContext1, wrongClassName, "(c=d)");
+ assertNoAllReferences(bundleContext1, wrongClassName, "(c=d)");
+ assertNoReferences(bundleContext1, null, "(c=x)");
+ assertNoAllReferences(bundleContext1, null, "(c=x)");
+ assertNoReferences(bundleContext1, className, "(c=x)");
+ assertNoAllReferences(bundleContext1, className, "(c=x)");
+ assertNoReferences(bundleContext1, wrongClassName, "(c=x)");
+ assertNoAllReferences(bundleContext1, wrongClassName, "(c=x)");
+ assertNoReferences(bundleContext1, null, "(x=d)");
+ assertNoAllReferences(bundleContext1, null, "(x=d)");
+ assertNoReferences(bundleContext1, className, "(x=d)");
+ assertNoAllReferences(bundleContext1, className, "(x=d)");
+ assertNoReferences(bundleContext1, wrongClassName, "(x=d)");
+ assertNoAllReferences(bundleContext1, wrongClassName, "(x=d)");
+
+ registration1.unregister();
+
+ assertNoGetReference(bundleContext1, A.class.getName());
+ assertNoReferences(bundleContext1, null, "(a=b)");
+ assertNoAllReferences(bundleContext1, null, "(a=b)");
+ assertNoReferences(bundleContext1, className, "(a=b)");
+ assertNoAllReferences(bundleContext1, className, "(a=b)");
+ assertNoReferences(bundleContext1, wrongClassName, "(a=b)");
+ assertNoAllReferences(bundleContext1, wrongClassName, "(a=b)");
+ assertNoReferences(bundleContext1, null, "(c=d)");
+ assertNoAllReferences(bundleContext1, null, "(c=d)");
+ assertNoReferences(bundleContext1, className, "(c=d)");
+ assertNoAllReferences(bundleContext1, className, "(c=d)");
+ assertNoReferences(bundleContext1, wrongClassName, "(c=d)");
+ assertNoAllReferences(bundleContext1, wrongClassName, "(c=d)");
+ assertNoReferences(bundleContext1, null, "(c=x)");
+ assertNoAllReferences(bundleContext1, null, "(c=x)");
+ assertNoReferences(bundleContext1, className, "(c=x)");
+ assertNoAllReferences(bundleContext1, className, "(c=x)");
+ assertNoReferences(bundleContext1, wrongClassName, "(c=x)");
+ assertNoAllReferences(bundleContext1, wrongClassName, "(c=x)");
+ assertNoReferences(bundleContext1, null, "(x=d)");
+ assertNoAllReferences(bundleContext1, null, "(x=d)");
+ assertNoReferences(bundleContext1, className, "(x=d)");
+ assertNoAllReferences(bundleContext1, className, "(x=d)");
+ assertNoReferences(bundleContext1, wrongClassName, "(x=d)");
+ assertNoAllReferences(bundleContext1, wrongClassName, "(x=d)");
+ }
+ finally
+ {
+ uninstall(bundle1);
+ }
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/service/test/GetUnGetServiceUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/service/test/GetUnGetServiceUnitTestCase.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/service/test/GetUnGetServiceUnitTestCase.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,302 @@
+/*
+* 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.test.osgi.service.test;
+
+import junit.framework.Test;
+
+import org.jboss.test.osgi.OSGiTestCase;
+import org.jboss.test.osgi.service.support.BrokenServiceFactory;
+import org.jboss.test.osgi.service.support.SimpleServiceFactory;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkEvent;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * GetUnGetServiceUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class GetUnGetServiceUnitTestCase extends OSGiTestCase
+{
+ static String OBJCLASS = BundleContext.class.getName();
+
+ public GetUnGetServiceUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(GetUnGetServiceUnitTestCase.class);
+ }
+
+ public void testGetUnServiceErrors() throws Exception
+ {
+ String OBJCLASS = BundleContext.class.getName();
+
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ bundleContext.registerService(OBJCLASS, bundleContext, null);
+
+ try
+ {
+ bundleContext.getService(null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+
+ try
+ {
+ bundleContext.ungetService(null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testGetService() throws Exception
+ {
+ String OBJCLASS = BundleContext.class.getName();
+
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ ServiceRegistration registration = bundleContext.registerService(OBJCLASS, bundleContext, null);
+ ServiceReference reference = registration.getReference();
+
+ Object actual = bundleContext.getService(reference);
+ assertEquals(bundleContext, actual);
+
+ registration.unregister();
+ actual = bundleContext.getService(reference);
+ assertNull("" + actual, actual);
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testGetServiceAfterStop() throws Exception
+ {
+ String OBJCLASS = BundleContext.class.getName();
+
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ ServiceRegistration registration = bundleContext.registerService(OBJCLASS, bundleContext, null);
+ ServiceReference reference = registration.getReference();
+
+ Object actual = bundleContext.getService(reference);
+ assertEquals(bundleContext, actual);
+
+ bundle.stop();
+ try
+ {
+ bundleContext.getService(reference);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testGetServiceFactory() throws Exception
+ {
+ String OBJCLASS = BundleContext.class.getName();
+
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ ServiceRegistration registration = bundleContext.registerService(OBJCLASS, new SimpleServiceFactory(bundleContext), null);
+ ServiceReference reference = registration.getReference();
+
+ Object actual = bundleContext.getService(reference);
+ assertEquals(bundleContext, actual);
+
+ actual = bundleContext.getService(reference);
+ assertEquals(bundleContext, actual);
+
+ registration.unregister();
+ actual = bundleContext.getService(reference);
+ assertNull("" + actual, actual);
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testGetServiceFactoryAfterStop() throws Exception
+ {
+ String OBJCLASS = BundleContext.class.getName();
+
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ ServiceRegistration registration = bundleContext.registerService(OBJCLASS, new SimpleServiceFactory(bundleContext), null);
+ ServiceReference reference = registration.getReference();
+
+ Object actual = bundleContext.getService(reference);
+ assertEquals(bundleContext, actual);
+
+ bundle.stop();
+ try
+ {
+ bundleContext.getService(reference);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testGetWrongInterfacesForServiceFactory() throws Exception
+ {
+ String[] OBJCLASSES = {String.class.getName(), BundleContext.class.getName()};
+
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ bundleContext.addFrameworkListener(this);
+
+ ServiceRegistration registration = bundleContext.registerService(String.class.getName(), new SimpleServiceFactory(bundleContext), null);
+ ServiceReference reference = registration.getReference();
+ Object actual = bundleContext.getService(reference);
+ assertNull("" + actual, actual);
+
+ assertFrameworkEvent(FrameworkEvent.ERROR, bundle, IllegalArgumentException.class);
+
+ registration = bundleContext.registerService(OBJCLASSES, new SimpleServiceFactory(bundleContext), null);
+ reference = registration.getReference();
+ actual = bundleContext.getService(reference);
+ assertNull("" + actual, actual);
+
+ assertFrameworkEvent(FrameworkEvent.ERROR, bundle, IllegalArgumentException.class);
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testErrorInGetService() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ bundleContext.addFrameworkListener(this);
+
+ ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), new BrokenServiceFactory(bundleContext, true), null);
+ ServiceReference reference = registration.getReference();
+ Object actual = bundleContext.getService(reference);
+ assertNull("" + actual, actual);
+
+ assertFrameworkEvent(FrameworkEvent.ERROR, bundle, RuntimeException.class);
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testErrorInUnGetService() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ bundleContext.addFrameworkListener(this);
+
+ ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), new BrokenServiceFactory(bundleContext, false), null);
+ ServiceReference reference = registration.getReference();
+ Object actual = bundleContext.getService(reference);
+ assertEquals(bundleContext, actual);
+ assertNoFrameworkEvent();
+
+ registration.unregister();
+
+ assertFrameworkEvent(FrameworkEvent.WARNING, bundle, RuntimeException.class);
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/service/test/RegisterServiceUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/service/test/RegisterServiceUnitTestCase.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/service/test/RegisterServiceUnitTestCase.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,273 @@
+/*
+* 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.test.osgi.service.test;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import junit.framework.Test;
+
+import org.jboss.test.osgi.OSGiTestCase;
+import org.jboss.test.osgi.service.support.SimpleServiceFactory;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * RegisterServiceUnitTestCase.
+ *
+ * todo test secutiry
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class RegisterServiceUnitTestCase extends OSGiTestCase
+{
+ static String OBJCLASS = BundleContext.class.getName();
+ static String[] OBJCLASSES = new String[] { OBJCLASS };
+
+ public RegisterServiceUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(RegisterServiceUnitTestCase.class);
+ }
+
+ public void testRegisterServiceErrors() throws Exception
+ {
+ String OBJCLASS = BundleContext.class.getName();
+ String[] OBJCLASSES = new String[] { OBJCLASS };
+
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ try
+ {
+ bundleContext.registerService((String) null, new Object(), null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+
+ try
+ {
+ bundleContext.registerService((String[]) null, new Object(), null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+
+ try
+ {
+ bundleContext.registerService(new String[0], new Object(), null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+
+ try
+ {
+ bundleContext.registerService(OBJCLASS, null, null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+
+ try
+ {
+ bundleContext.registerService(OBJCLASSES, null, null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+
+ try
+ {
+ bundleContext.registerService(OBJCLASS, new Object(), null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+
+ try
+ {
+ bundleContext.registerService(OBJCLASSES, new Object(), null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+
+ Dictionary<String, Object> properties = new Hashtable<String, Object>();
+ properties.put("case", "a");
+ properties.put("CASE", "a");
+ try
+ {
+ bundleContext.registerService(OBJCLASS, bundleContext, properties);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+
+ try
+ {
+ bundleContext.registerService(OBJCLASSES, bundleContext, properties);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+
+ bundle.stop();
+
+ try
+ {
+ bundleContext.registerService(OBJCLASS, bundleContext, null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+
+ try
+ {
+ bundleContext.registerService(OBJCLASSES, bundleContext, null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testRegisterServiceOBJCLASS() throws Exception
+ {
+ Dictionary<String, Object> properties = new Hashtable<String, Object>();
+ properties.put(Constants.OBJECTCLASS, new String[] { "rubbish" });
+
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ ServiceRegistration registration = bundleContext.registerService(OBJCLASS, bundleContext, null);
+ ServiceReference reference = registration.getReference();
+ assertObjectClass(OBJCLASS, reference);
+ registration.setProperties(properties);
+ assertObjectClass(OBJCLASS, reference);
+ registration.unregister();
+
+ registration = bundleContext.registerService(OBJCLASSES, bundleContext, null);
+ reference = registration.getReference();
+ assertObjectClass(OBJCLASSES, reference);
+ registration.setProperties(properties);
+ assertObjectClass(OBJCLASSES, reference);
+ registration.unregister();
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testRegisterService() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ ServiceRegistration registration = bundleContext.registerService(OBJCLASS, bundleContext, null);
+ ServiceReference reference = registration.getReference();
+ Object actual = bundleContext.getService(reference);
+ assertEquals(bundleContext, actual);
+
+ registration = bundleContext.registerService(OBJCLASSES, bundleContext, null);
+ reference = registration.getReference();
+ actual = bundleContext.getService(reference);
+ assertEquals(bundleContext, actual);
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testRegisterServiceFactory() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ ServiceRegistration registration = bundleContext.registerService(OBJCLASS, new SimpleServiceFactory(bundleContext), null);
+ ServiceReference reference = registration.getReference();
+ Object actual = bundleContext.getService(reference);
+ assertEquals(bundleContext, actual);
+
+ registration = bundleContext.registerService(OBJCLASSES, new SimpleServiceFactory(bundleContext), null);
+ reference = registration.getReference();
+ actual = bundleContext.getService(reference);
+ assertEquals(bundleContext, actual);
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/service/test/ServiceReferenceUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/service/test/ServiceReferenceUnitTestCase.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/service/test/ServiceReferenceUnitTestCase.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,604 @@
+/*
+* 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.test.osgi.service.test;
+
+import java.util.Dictionary;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.TreeSet;
+
+import junit.framework.Test;
+
+import org.jboss.test.osgi.OSGiTestCase;
+import org.jboss.test.osgi.service.support.a.A;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * ServiceReferenceUnitTestCase.
+ *
+ * todo more isAssignableTests
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class ServiceReferenceUnitTestCase extends OSGiTestCase
+{
+ public ServiceReferenceUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(ServiceReferenceUnitTestCase.class);
+ }
+
+ public void testGetProperty() throws Exception
+ {
+ ServiceReference reference = null;
+ String[] clazzes = new String[] { BundleContext.class.getName() };
+ Object serviceID = null;
+
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ Dictionary<String, Object> properties = new Hashtable<String, Object>();
+ properties.put("testA", "a");
+ properties.put("testB", "b");
+ properties.put("MiXeD", "Case");
+ ServiceRegistration registration = bundleContext.registerService(clazzes, bundleContext, properties);
+ assertNotNull(registration);
+
+ reference = registration.getReference();
+ assertNotNull(reference);
+
+ serviceID = reference.getProperty(Constants.SERVICE_ID);
+ assertNotNull(serviceID);
+ assertEquals(serviceID, reference.getProperty(Constants.SERVICE_ID.toLowerCase()));
+ assertEquals(serviceID, reference.getProperty(Constants.SERVICE_ID.toUpperCase()));
+ assertEquals(clazzes, (String[]) reference.getProperty(Constants.OBJECTCLASS));
+ assertEquals(clazzes, (String[]) reference.getProperty(Constants.OBJECTCLASS.toLowerCase()));
+ assertEquals(clazzes, (String[]) reference.getProperty(Constants.OBJECTCLASS.toUpperCase()));
+ assertEquals("a", reference.getProperty("testA"));
+ assertEquals("b", reference.getProperty("testB"));
+ assertEquals("Case", reference.getProperty("MiXeD"));
+ assertEquals("Case", reference.getProperty("mixed"));
+ assertEquals("Case", reference.getProperty("MIXED"));
+ assertNull(reference.getProperty(null));
+ assertNull(reference.getProperty("doesNotExist"));
+
+ properties.put("testA", "notA");
+ assertEquals("a", reference.getProperty("testA"));
+ properties.put(Constants.SERVICE_ID, "rubbish");
+ assertEquals(serviceID, reference.getProperty(Constants.SERVICE_ID));
+ properties.put(Constants.OBJECTCLASS, "rubbish");
+ assertEquals(clazzes, reference.getProperty(Constants.OBJECTCLASS));
+
+ registration.setProperties(properties);
+ assertEquals(serviceID, reference.getProperty(Constants.SERVICE_ID));
+ assertEquals(clazzes, reference.getProperty(Constants.OBJECTCLASS));
+ assertEquals("notA", reference.getProperty("testA"));
+ assertEquals("b", reference.getProperty("testB"));
+ assertEquals("Case", reference.getProperty("MiXeD"));
+ assertEquals("Case", reference.getProperty("mixed"));
+ assertEquals("Case", reference.getProperty("MIXED"));
+
+ registration.setProperties(null);
+ assertEquals(serviceID, reference.getProperty(Constants.SERVICE_ID));
+ assertEquals(clazzes, reference.getProperty(Constants.OBJECTCLASS));
+ assertNull(reference.getProperty("testA"));
+ assertNull(reference.getProperty("testB"));
+ assertNull(reference.getProperty("MiXeD"));
+ assertNull(reference.getProperty("mixed"));
+ assertNull(reference.getProperty("MIXED"));
+ assertNull(reference.getProperty(null));
+
+ registration.setProperties(properties);
+ assertEquals(serviceID, reference.getProperty(Constants.SERVICE_ID));
+ assertEquals(clazzes, reference.getProperty(Constants.OBJECTCLASS));
+ assertEquals("notA", reference.getProperty("testA"));
+ assertEquals("b", reference.getProperty("testB"));
+ assertEquals("Case", reference.getProperty("MiXeD"));
+ assertEquals("Case", reference.getProperty("mixed"));
+ assertEquals("Case", reference.getProperty("MIXED"));
+ assertNull(reference.getProperty(null));
+
+ registration.unregister();
+ assertEquals(serviceID, reference.getProperty(Constants.SERVICE_ID));
+ assertEquals(clazzes, reference.getProperty(Constants.OBJECTCLASS));
+ assertEquals("notA", reference.getProperty("testA"));
+ assertEquals("b", reference.getProperty("testB"));
+ assertEquals("Case", reference.getProperty("MiXeD"));
+ assertEquals("Case", reference.getProperty("mixed"));
+ assertEquals("Case", reference.getProperty("MIXED"));
+ assertNull(reference.getProperty(null));
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+
+ assertEquals(serviceID, reference.getProperty(Constants.SERVICE_ID));
+ assertEquals(clazzes, reference.getProperty(Constants.OBJECTCLASS));
+ assertEquals("notA", reference.getProperty("testA"));
+ assertEquals("b", reference.getProperty("testB"));
+ assertEquals("Case", reference.getProperty("MiXeD"));
+ assertEquals("Case", reference.getProperty("mixed"));
+ assertEquals("Case", reference.getProperty("MIXED"));
+ assertNull(reference.getProperty(null));
+ }
+
+ public void testGetPropertyKeys() throws Exception
+ {
+ ServiceReference reference = null;
+
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ Dictionary<String, Object> properties = new Hashtable<String, Object>();
+ properties.put("testA", "a");
+ properties.put("testB", "b");
+ properties.put("MiXeD", "Case");
+ ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, properties);
+ assertNotNull(registration);
+
+ reference = registration.getReference();
+ assertNotNull(reference);
+
+ assertPropertyKeys(reference, "testA", "testB", "MiXeD");
+
+ properties.put("testC", "c");
+ assertPropertyKeys(reference, "testA", "testB", "MiXeD");
+
+ registration.setProperties(properties);
+ assertPropertyKeys(reference, "testA", "testB", "testC", "MiXeD");
+
+ registration.setProperties(null);
+ assertPropertyKeys(reference);
+
+ registration.setProperties(properties);
+ assertPropertyKeys(reference, "testA", "testB", "testC", "MiXeD");
+
+ registration.unregister();
+ assertPropertyKeys(reference, "testA", "testB", "testC", "MiXeD");
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ assertPropertyKeys(reference, "testA", "testB", "testC", "MiXeD");
+ }
+
+ protected void assertPropertyKeys(ServiceReference reference, String... expectedKeys)
+ {
+ Set<String> expected = new HashSet<String>();
+ expected.add(Constants.SERVICE_ID);
+ expected.add(Constants.OBJECTCLASS);
+ for (String key : expectedKeys)
+ expected.add(key);
+
+ Set<String> actual = new HashSet<String>();
+ for (String key : reference.getPropertyKeys())
+ actual.add(key);
+
+ assertEquals(expected, actual);
+ }
+
+ public void testGetBundle() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, null);
+ assertNotNull(registration);
+
+ ServiceReference reference = registration.getReference();
+ assertNotNull(reference);
+
+ Bundle other = reference.getBundle();
+ assertEquals(bundle, other);
+
+ registration.unregister();
+
+ other = reference.getBundle();
+ assertNull("" + other, other);
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testGetBundleAfterStop() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, null);
+ assertNotNull(registration);
+
+ ServiceReference reference = registration.getReference();
+ assertNotNull(reference);
+
+ Bundle other = reference.getBundle();
+ assertEquals(bundle, other);
+
+ bundle.stop();
+
+ other = reference.getBundle();
+ assertNull("" + other, other);
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testUsingBundles() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, null);
+ assertNotNull(registration);
+
+ ServiceReference reference = registration.getReference();
+ assertNotNull(reference);
+
+ assertUsingBundles(reference);
+
+ Bundle bundle2 = addBundle("/bundles/simple/", "simple-bundle2");
+ try
+ {
+ bundle2.start();
+ BundleContext bundleContext2 = bundle2.getBundleContext();
+ assertNotNull(bundleContext2);
+
+ bundleContext2.getService(reference);
+ assertUsingBundles(reference, bundle2);
+
+ bundleContext2.ungetService(reference);
+ assertUsingBundles(reference);
+
+ bundleContext2.getService(reference);
+ bundleContext2.getService(reference);
+ assertUsingBundles(reference, bundle2);
+ bundleContext2.ungetService(reference);
+ assertUsingBundles(reference, bundle2);
+ bundleContext2.ungetService(reference);
+ assertUsingBundles(reference);
+
+ bundleContext.getService(reference);
+ bundleContext2.getService(reference);
+ assertUsingBundles(reference, bundle, bundle2);
+
+ registration.unregister();
+ assertUsingBundles(reference);
+ }
+ finally
+ {
+ uninstall(bundle2);
+ }
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testUsingBundlesAfterStop() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, null);
+ assertNotNull(registration);
+
+ ServiceReference reference = registration.getReference();
+ assertNotNull(reference);
+
+ assertUsingBundles(reference);
+
+ Bundle bundle2 = addBundle("/bundles/simple/", "simple-bundle2");
+ try
+ {
+ bundle2.start();
+ BundleContext bundleContext2 = bundle2.getBundleContext();
+ assertNotNull(bundleContext2);
+
+ bundleContext.getService(reference);
+ bundleContext2.getService(reference);
+ assertUsingBundles(reference, bundle, bundle2);
+
+ bundle.stop();
+ assertUsingBundles(reference);
+ }
+ finally
+ {
+ uninstall(bundle2);
+ }
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testIsAssignableToErrors() throws Exception
+ {
+ Bundle bundle = assembleBundle("simple1", "/bundles/simple/simple-bundle1", A.class);
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, null);
+ assertNotNull(registration);
+
+ ServiceReference reference = registration.getReference();
+ assertNotNull(reference);
+
+ try
+ {
+ reference.isAssignableTo(null, A.class.getName());
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+
+ try
+ {
+ reference.isAssignableTo(bundle, null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testNotAssignableTo() throws Exception
+ {
+ Bundle bundle = assembleBundle("simple1", "/bundles/simple/simple-bundle1", A.class);
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, null);
+ assertNotNull(registration);
+
+ ServiceReference reference = registration.getReference();
+ assertNotNull(reference);
+
+ Bundle bundle2 = assembleBundle("simple2", "/bundles/simple/simple-bundle2", A.class);
+ try
+ {
+ assertFalse(reference.isAssignableTo(bundle2, A.class.getName()));
+ assertTrue(reference.isAssignableTo(bundle2, String.class.getName()));
+
+ registration.unregister();
+ assertFalse(reference.isAssignableTo(bundle2, A.class.getName()));
+ assertFalse(reference.isAssignableTo(bundle2, String.class.getName())); // review ???
+ }
+ finally
+ {
+ uninstall(bundle2);
+ }
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testIsAssignableTo() throws Exception
+ {
+ Bundle bundle = assembleBundle("service2", "/bundles/service/service-bundle2", A.class);
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ Bundle bundle2 = assembleBundle("service1", "/bundles/service/service-bundle1");
+ try
+ {
+
+ ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, null);
+ assertNotNull(registration);
+
+ ServiceReference reference = registration.getReference();
+ assertNotNull(reference);
+
+ assertTrue(reference.isAssignableTo(bundle, A.class.getName()));
+ assertTrue(reference.isAssignableTo(bundle, String.class.getName()));
+ assertTrue(reference.isAssignableTo(bundle2, A.class.getName()));
+ assertTrue(reference.isAssignableTo(bundle2, String.class.getName()));
+
+ registration.unregister();
+ assertTrue(reference.isAssignableTo(bundle, A.class.getName()));
+ assertTrue(reference.isAssignableTo(bundle, String.class.getName()));
+ assertFalse(reference.isAssignableTo(bundle2, A.class.getName()));
+ assertFalse(reference.isAssignableTo(bundle2, String.class.getName())); // review ???
+ }
+ finally
+ {
+ uninstall(bundle2);
+ }
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testCompareTo() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ ServiceRegistration registration1 = bundleContext.registerService(BundleContext.class.getName(), bundleContext, null);
+ assertNotNull(registration1);
+
+ ServiceReference reference1 = registration1.getReference();
+ assertNotNull(reference1);
+
+ ServiceRegistration registration2 = bundleContext.registerService(BundleContext.class.getName(), bundleContext, null);
+ assertNotNull(registration2);
+
+ ServiceReference reference2 = registration2.getReference();
+ assertNotNull(reference2);
+
+ Dictionary<String, Object> properties = new Hashtable<String, Object>();
+ properties.put(Constants.SERVICE_RANKING, 10);
+ ServiceRegistration registration3 = bundleContext.registerService(BundleContext.class.getName(), bundleContext, properties);
+ assertNotNull(registration3);
+
+ ServiceReference reference3 = registration3.getReference();
+ assertNotNull(reference3);
+
+ properties = new Hashtable<String, Object>();
+ properties.put(Constants.SERVICE_RANKING, -10);
+ ServiceRegistration registration4 = bundleContext.registerService(BundleContext.class.getName(), bundleContext, properties);
+ assertNotNull(registration4);
+
+ ServiceReference reference4 = registration4.getReference();
+ assertNotNull(reference4);
+
+ assertGreaterRanking(reference1, reference2);
+ assertGreaterRanking(reference3, reference1);
+ assertGreaterRanking(reference3, reference2);
+ assertGreaterRanking(reference1, reference4);
+ assertGreaterRanking(reference2, reference4);
+ assertGreaterRanking(reference3, reference4);
+
+ try
+ {
+ reference1.compareTo(null);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+
+ try
+ {
+ reference1.compareTo(new Object());
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+
+ properties = new Hashtable<String, Object>();
+ properties.put(Constants.SERVICE_RANKING, "NotANumber");
+ ServiceRegistration registration5 = bundleContext.registerService(BundleContext.class.getName(), bundleContext, properties);
+ assertNotNull(registration5);
+
+ ServiceReference reference5 = registration5.getReference();
+ assertNotNull(reference5);
+
+ assertGreaterRanking(reference1, reference5); // review ???
+
+ Set<ServiceReference> ordering = new TreeSet<ServiceReference>();
+ ordering.add(reference1);
+ ordering.add(reference2);
+ ordering.add(reference3);
+ ordering.add(reference4);
+ ordering.add(reference5);
+ Iterator<ServiceReference> iterator = ordering.iterator();
+ assertEquals(reference4, iterator.next());
+ assertEquals(reference5, iterator.next());
+ assertEquals(reference2, iterator.next());
+ assertEquals(reference1, iterator.next());
+ assertEquals(reference3, iterator.next());
+
+ ordering = new TreeSet<ServiceReference>();
+ ordering.add(reference5);
+ ordering.add(reference4);
+ ordering.add(reference3);
+ ordering.add(reference2);
+ ordering.add(reference1);
+ iterator = ordering.iterator();
+ assertEquals(reference4, iterator.next());
+ assertEquals(reference5, iterator.next());
+ assertEquals(reference2, iterator.next());
+ assertEquals(reference1, iterator.next());
+ assertEquals(reference3, iterator.next());
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ protected void assertGreaterRanking(ServiceReference reference1, ServiceReference reference2) throws Exception
+ {
+ assertTrue(reference1 + " > " + reference2, reference1.compareTo(reference2) > 0);
+ assertTrue(reference2 + " < " + reference1, reference2.compareTo(reference1) < 0);
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/service/test/ServiceRegistrationUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/service/test/ServiceRegistrationUnitTestCase.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/service/test/ServiceRegistrationUnitTestCase.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,354 @@
+/*
+* 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.test.osgi.service.test;
+
+import java.util.Hashtable;
+
+import junit.framework.Test;
+
+import org.jboss.test.osgi.OSGiTestCase;
+import org.jboss.test.osgi.service.support.SimpleServiceFactory;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * ServiceRegistrationUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class ServiceRegistrationUnitTestCase extends OSGiTestCase
+{
+ public ServiceRegistrationUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(ServiceRegistrationUnitTestCase.class);
+ }
+
+ public void testGetReference() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, null);
+ assertNotNull(registration);
+
+ ServiceReference reference = registration.getReference();
+ assertNotNull(reference);
+
+ ServiceReference reference2 = bundleContext.getServiceReference(BundleContext.class.getName());
+ assertEquals(reference, reference2);
+
+ Object object = bundleContext.getService(reference);
+ assertEquals(bundleContext, object);
+
+ reference2 = registration.getReference();
+ assertEquals(reference, reference2);
+
+ registration.unregister();
+ try
+ {
+ registration.getReference();
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+
+ ServiceRegistration registration2 = bundleContext.registerService(BundleContext.class.getName(), bundleContext, null);
+ assertNotNull(registration);
+ assertNotSame(registration, registration2);
+
+ reference2 = registration2.getReference();
+ assertNotNull(reference2);
+ assertNotSame(reference, reference2);
+
+ bundle.stop();
+ try
+ {
+ registration2.getReference();
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testSetProperties() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ String propertyA = "org.jboss.osgi.test.PropertyA";
+ String propertyALower = "org.jboss.osgi.test.propertya";
+
+ Hashtable<String, Object> properties = new Hashtable<String, Object>();
+ properties.put(propertyA, "testA");
+ ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, properties);
+ assertNotNull(registration);
+ ServiceReference reference = registration.getReference();
+ assertNotNull(reference);
+ assertEquals("testA", reference.getProperty(propertyA));
+ assertEquals("testA", reference.getProperty(propertyALower));
+
+ Object serviceID = reference.getProperty(Constants.SERVICE_ID);
+ Object objectClass = reference.getProperty(Constants.OBJECTCLASS);
+
+ assertAllReferences(bundleContext, null, "(" + propertyA + "=testA)", reference);
+ assertAllReferences(bundleContext, null, "(" + propertyALower + "=testA)", reference);
+ assertAllReferences(bundleContext, null, "(" + Constants.SERVICE_ID + "=" + serviceID + ")", reference);
+
+ bundleContext.addServiceListener(this);
+
+ properties = new Hashtable<String, Object>();
+ properties.put(propertyA, "testAChanged");
+ registration.setProperties(properties);
+ assertServiceEvent(ServiceEvent.MODIFIED, reference);
+ assertEquals("testAChanged", reference.getProperty(propertyA));
+ assertNoAllReferences(bundleContext, null, "(" + propertyA + "=testA)");
+ assertNoAllReferences(bundleContext, null, "(" + propertyALower + "=testA)");
+ assertAllReferences(bundleContext, null, "(" + propertyA + "=testAChanged)", reference);
+ assertAllReferences(bundleContext, null, "(" + propertyALower + "=testAChanged)", reference);
+
+ registration.setProperties(null);
+ assertServiceEvent(ServiceEvent.MODIFIED, reference);
+ assertNull(reference.getProperty(propertyA));
+ assertNoAllReferences(bundleContext, null, "(" + propertyA + "=testA)");
+ assertNoAllReferences(bundleContext, null, "(" + propertyALower + "=testA)");
+ assertNoAllReferences(bundleContext, null, "(" + propertyA + "=testAChanged)");
+ assertNoAllReferences(bundleContext, null, "(" + propertyALower + "=testAChanged)");
+
+ properties = new Hashtable<String, Object>();
+ properties.put(propertyA, "testA2");
+ properties.put(Constants.SERVICE_ID, "rubbish1");
+ properties.put(Constants.OBJECTCLASS, "rubbish2");
+ registration.setProperties(properties);
+ assertServiceEvent(ServiceEvent.MODIFIED, reference);
+ assertEquals("testA2", reference.getProperty(propertyA));
+ assertEquals("testA2", reference.getProperty(propertyALower));
+ assertEquals(serviceID, reference.getProperty(Constants.SERVICE_ID));
+ assertEquals(serviceID, reference.getProperty(Constants.SERVICE_ID.toLowerCase()));
+ assertEquals(objectClass, reference.getProperty(Constants.OBJECTCLASS));
+ assertEquals(objectClass, reference.getProperty(Constants.OBJECTCLASS.toLowerCase()));
+
+ assertNoAllReferences(bundleContext, null, "(" + Constants.SERVICE_ID + "=rubbish1)");
+ assertAllReferences(bundleContext, null, "(" + Constants.SERVICE_ID + "=" + serviceID + ")", reference);
+
+ properties = new Hashtable<String, Object>();
+ properties.put("a", "1");
+ properties.put("A", "2");
+ try
+ {
+ registration.setProperties(properties);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+ assertNoServiceEvent();
+
+ registration.unregister();
+ assertServiceEvent(ServiceEvent.UNREGISTERING, reference);
+
+ try
+ {
+ registration.setProperties(new Hashtable<String, Object>());
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ assertNoServiceEvent();
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testSetPropertiesAfterStop() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, null);
+ assertNotNull(registration);
+
+ bundle.stop();
+
+ try
+ {
+ registration.setProperties(new Hashtable<String, Object>());
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ assertNoServiceEvent();
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testUnregister() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ SimpleServiceFactory factory = new SimpleServiceFactory(bundleContext);
+ ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), factory, null);
+ assertNotNull(registration);
+
+ ServiceReference reference = registration.getReference();
+ assertNotNull(reference);
+
+ ServiceReference reference2 = bundleContext.getServiceReference(BundleContext.class.getName());
+ assertEquals(reference, reference2);
+
+ ServiceReference[] inUse = bundle.getServicesInUse();
+ assertNull(inUse);
+
+ bundleContext.getService(reference);
+ inUse = bundle.getServicesInUse();
+ assertEquals(new ServiceReference[] { reference }, inUse);
+
+ Bundle bundle2 = addBundle("/bundles/simple/", "simple-bundle2");
+ try
+ {
+ bundle2.start();
+ BundleContext bundleContext2 = bundle2.getBundleContext();
+ assertNotNull(bundleContext2);
+ bundleContext2.getService(reference);
+ inUse = bundle2.getServicesInUse();
+ assertEquals(new ServiceReference[] { reference }, inUse);
+
+ assertNull(factory.ungetBundle);
+ assertNull(factory.ungetRegisation);
+ assertNull(factory.ungetService);
+
+ bundleContext.addServiceListener(this);
+ registration.unregister();
+
+ reference2 = bundleContext.getServiceReference(BundleContext.class.getName());
+ assertNull("" + reference2, reference2);
+
+ Object actual = bundleContext.getService(reference);
+ assertNull("" + actual, actual);
+
+ assertServiceEvent(ServiceEvent.UNREGISTERING, reference);
+
+ inUse = bundle.getServicesInUse();
+ assertNull(inUse);
+ inUse = bundle2.getServicesInUse();
+ assertNull(inUse);
+
+ assertEquals(bundle, factory.ungetBundle);
+ assertEquals(registration, factory.ungetRegisation);
+ assertEquals(bundleContext, factory.ungetService);
+ }
+ finally
+ {
+ uninstall(bundle2);
+ }
+
+ try
+ {
+ registration.unregister();
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testUnregisterAfterStop() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, null);
+ assertNotNull(registration);
+
+ bundle.stop();
+
+ try
+ {
+ registration.unregister();
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/smoke/SmokeTestSuite.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/smoke/SmokeTestSuite.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/smoke/SmokeTestSuite.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,51 @@
+/*
+* 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.test.osgi.smoke;
+
+import org.jboss.test.osgi.smoke.test.OSGiSmokeTestCase;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+/**
+ * SmokeTestSuite.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class SmokeTestSuite extends TestSuite
+{
+ public static void main(String[] args)
+ {
+ TestRunner.run(suite());
+ }
+
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite("Smoke Tests");
+
+ suite.addTest(OSGiSmokeTestCase.suite());
+
+ return suite;
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/smoke/support/a/A.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/smoke/support/a/A.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/smoke/support/a/A.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,32 @@
+/*
+* 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.test.osgi.smoke.support.a;
+
+/**
+ * A.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class A
+{
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/smoke/support/a/b/B.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/smoke/support/a/b/B.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/smoke/support/a/b/B.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,33 @@
+/*
+* 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.test.osgi.smoke.support.a.b;
+
+/**
+ * B.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class B
+{
+
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/smoke/support/c/C.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/smoke/support/c/C.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/smoke/support/c/C.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,33 @@
+/*
+* 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.test.osgi.smoke.support.c;
+
+/**
+ * C.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class C
+{
+
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/smoke/test/OSGiSmokeTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/smoke/test/OSGiSmokeTestCase.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/java/org/jboss/test/osgi/smoke/test/OSGiSmokeTestCase.java 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,117 @@
+/*
+* 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.test.osgi.smoke.test;
+
+import java.io.InputStream;
+import java.net.URL;
+
+import junit.framework.Test;
+
+import org.jboss.test.osgi.OSGiTestCase;
+import org.jboss.test.osgi.smoke.support.a.A;
+import org.jboss.test.osgi.smoke.support.a.b.B;
+import org.jboss.test.osgi.smoke.support.c.C;
+import org.osgi.framework.Bundle;
+
+/**
+ * OSGiSmokeTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class OSGiSmokeTestCase extends OSGiTestCase
+{
+ public OSGiSmokeTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(OSGiSmokeTestCase.class);
+ }
+
+ public void testNoManifest() throws Exception
+ {
+ testBundle("smoke-no-manifest", Bundle.ACTIVE);
+ }
+
+ public void testNonOSGiManifest() throws Exception
+ {
+ testBundle("smoke-non-osgi-manifest", Bundle.ACTIVE);
+ }
+
+ public void testOSGiManifest() throws Exception
+ {
+ testBundle("smoke-osgi-manifest", Bundle.INSTALLED);
+ }
+
+ public void testAssembled() throws Exception
+ {
+ Bundle bundle = assembleBundle("smoke-assembled", "/bundles/smoke/smoke-assembled", A.class);
+ try
+ {
+ testBundle(bundle, "smoke-assembled", Bundle.INSTALLED);
+ bundle.start();
+ assertLoadClass(bundle, A.class);
+ assertLoadClassFail(bundle, B.class);
+ assertLoadClassFail(bundle, C.class);
+ }
+ finally
+ {
+ bundle.uninstall();
+ }
+ }
+
+ protected void testBundle(String name, int expectedState) throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/smoke/", name);
+ try
+ {
+ testBundle(bundle, name, expectedState);
+ }
+ finally
+ {
+ bundle.uninstall();
+ }
+ }
+
+ protected void testBundle(Bundle bundle, String name, int expectedState) throws Exception
+ {
+ assertEquals(expectedState, bundle.getState());
+ checkId(bundle, name);
+ bundle.start();
+ bundle.stop();
+ }
+
+ protected void checkId(Bundle bundle, String name) throws Exception
+ {
+ URL url = bundle.getEntry("id");
+ if (url == null)
+ fail("id entry not found for " + bundle);
+ InputStream is = url.openStream();
+ byte[] bytes = new byte[100];
+ is.read(bytes);
+ String value = new String(bytes);
+ assertTrue("Expected=" + name + " was " + value, value.startsWith(name));
+ }
+}
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bootstrap/bootstrap.xml
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bootstrap/bootstrap.xml 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bootstrap/bootstrap.xml 2009-08-17 13:47:07 UTC (rev 92424)
@@ -4,12 +4,8 @@
<bean name="MainDeployer" class="org.jboss.deployers.plugins.main.MainDeployerImpl">
<property name="structuralDeployers"><inject bean="StructuralDeployers"/></property>
<property name="deployers"><inject bean="Deployers"/></property>
- <property name="mgtDeploymentCreator"><inject bean="ManagedDeploymentCreator"/></property>
</bean>
- <!-- The ManagedDeploymentCreator implementation -->
- <bean name="ManagedDeploymentCreator" class="org.jboss.deployers.plugins.managed.DefaultManagedDeploymentCreator" />
-
<!-- The holder for deployers that determine structure -->
<bean name="StructuralDeployers" class="org.jboss.deployers.vfs.plugins.structure.VFSStructuralDeployersImpl">
<property name="structureBuilder">
@@ -92,15 +88,18 @@
</bean>
<!-- OSGI Deployment -->
- <bean name="BundleActivatorDeployer" class="org.jboss.osgi.plugins.deployers.BundleActivatorDeployer">
- <constructor><parameter class="org.jboss.kernel.spi.dependency.KernelController"><inject bean="jboss.kernel:service=KernelController"/></parameter></constructor>
+ <bean name="OSGiBundleManager" class="org.jboss.osgi.plugins.facade.bundle.OSGiBundleManager">
+ <constructor><parameter><inject bean="MainDeployer"/></parameter></constructor>
</bean>
- <bean name="OSGIMetaDataDeployer" class="org.jboss.osgi.plugins.deployers.OSGiMetaDataDeployer"/>
-
- <!-- VFS ClassLoader -->
- <bean name="ClassLoaderSystem" class="org.jboss.classloader.spi.ClassLoaderSystem">
- <constructor factoryClass="org.jboss.classloader.spi.ClassLoaderSystem" factoryMethod="getInstance"/>
+ <bean name="OSGiManifestParsingDeployer" class="org.jboss.osgi.plugins.deployers.bundle.OSGiManifestParsingDeployer"/>
+ <bean name="OSGiBundleStateDeployer" class="org.jboss.osgi.plugins.deployers.bundle.OSGiBundleStateDeployer">
+ <constructor><parameter><inject bean="OSGiBundleManager"/></parameter></constructor>
</bean>
+ <bean name="OSGiBundleClassLoadingDeployer" class="org.jboss.osgi.plugins.deployers.bundle.OSGiBundleClassLoadingDeployer"/>
+ <bean name="OSGiBundleActivatorDeployer" class="org.jboss.osgi.plugins.deployers.bundle.OSGiBundleActivatorDeployer"/>
+
+ <!-- ClassLoading -->
+ <bean name="ClassLoaderSystem" class="org.jboss.test.osgi.OSGiClassLoaderSystem"/>
<bean name="ClassLoading" class="org.jboss.classloading.spi.dependency.ClassLoading">
<incallback method="addModule" state="Configured"/>
<uncallback method="removeModule" state="Configured"/>
@@ -110,7 +109,6 @@
<parameter>org.jboss.classloading.spi.metadata.ClassLoadingMetaData</parameter>
</constructor>
<property name="name">jboss-classloading.xml</property>
- <property name="buildManagedObject">true</property>
</bean>
<bean name="ClassLoadingDefaultDeployer" class="org.jboss.deployers.plugins.classloading.ClassLoadingDefaultDeployer">
<property name="defaultMetaData">
@@ -125,4 +123,5 @@
<property name="classLoading"><inject bean="ClassLoading"/></property>
<property name="system"><inject bean="ClassLoaderSystem"/></property>
</bean>
+
</deployment>
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/entries/entries-simple/META-INF/MANIFEST.MF
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/entries/entries-simple/META-INF/MANIFEST.MF (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/entries/entries-simple/META-INF/MANIFEST.MF 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,6 @@
+Manifest-Version: 1.0
+Implementation-Title: JBoss OSGi tests
+Implementation-Version: test
+Implementation-Vendor: jboss.org
+Bundle-Name: EntriesSimple
+Bundle-SymbolicName: org.jboss.test.osgi.entries.simple
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/entries/entries-simple/entry1.xml
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/entries/entries-simple/entry1.xml (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/entries/entries-simple/entry1.xml 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1 @@
+entry1.xml
\ No newline at end of file
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/entries/entries-simple/org/jboss/test/osgi/bundle/entries/entry1.xml
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/entries/entries-simple/org/jboss/test/osgi/bundle/entries/entry1.xml (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/entries/entries-simple/org/jboss/test/osgi/bundle/entries/entry1.xml 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1 @@
+org.jboss.test.osgi.bundle.entries.entry1.xml
\ No newline at end of file
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/entries/entries-simple/org/jboss/test/osgi/bundle/entries/entry2.xml
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/entries/entries-simple/org/jboss/test/osgi/bundle/entries/entry2.xml (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/entries/entries-simple/org/jboss/test/osgi/bundle/entries/entry2.xml 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1 @@
+org.jboss.test.osgi.bundle.entries.entry2.xml
\ No newline at end of file
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/entries/entries-simple/org/jboss/test/osgi/bundle/entries/notxml.suffix
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/entries/entries-simple/org/jboss/test/osgi/bundle/entries/notxml.suffix (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/entries/entries-simple/org/jboss/test/osgi/bundle/entries/notxml.suffix 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1 @@
+notxml.suffix
\ No newline at end of file
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/entries/entries-simple/org/jboss/test/osgi/bundle/entries/sub/entry1.xml
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/entries/entries-simple/org/jboss/test/osgi/bundle/entries/sub/entry1.xml (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/entries/entries-simple/org/jboss/test/osgi/bundle/entries/sub/entry1.xml 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1 @@
+org.jboss.test.osgi.bundle.entries.entry1.xml
\ No newline at end of file
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/entries/entries-simple/org/jboss/test/osgi/bundle/entries/sub/entry2.xml
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/entries/entries-simple/org/jboss/test/osgi/bundle/entries/sub/entry2.xml (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/entries/entries-simple/org/jboss/test/osgi/bundle/entries/sub/entry2.xml 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1 @@
+org.jboss.test.osgi.bundle.entries.entry2.xml
\ No newline at end of file
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/entries/entries-simple/root-no-suffix
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/entries/entries-simple/root-no-suffix (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/entries/entries-simple/root-no-suffix 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1 @@
+root-no-suffix
\ No newline at end of file
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/entries/entries-simple/root.xml
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/entries/entries-simple/root.xml (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/entries/entries-simple/root.xml 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1 @@
+root.xml
\ No newline at end of file
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/service/service-bundle1/META-INF/MANIFEST.MF
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/service/service-bundle1/META-INF/MANIFEST.MF (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/service/service-bundle1/META-INF/MANIFEST.MF 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,7 @@
+Manifest-Version: 1.0
+Implementation-Title: JBoss OSGi tests
+Implementation-Version: test
+Implementation-Vendor: jboss.org
+Bundle-Name: Service1
+Bundle-SymbolicName: org.jboss.test.osgi.service1
+Import-Package: org.jboss.test.osgi.service.support.a
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/service/service-bundle2/META-INF/MANIFEST.MF
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/service/service-bundle2/META-INF/MANIFEST.MF (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/service/service-bundle2/META-INF/MANIFEST.MF 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,7 @@
+Manifest-Version: 1.0
+Implementation-Title: JBoss OSGi tests
+Implementation-Version: test
+Implementation-Vendor: jboss.org
+Bundle-Name: Service2
+Bundle-SymbolicName: org.jboss.test.osgi.service2
+Export-Package: org.jboss.test.osgi.service.support.a
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/simple/simple-bundle1/META-INF/MANIFEST.MF
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/simple/simple-bundle1/META-INF/MANIFEST.MF (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/simple/simple-bundle1/META-INF/MANIFEST.MF 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,6 @@
+Manifest-Version: 1.0
+Implementation-Title: JBoss OSGi tests
+Implementation-Version: test
+Implementation-Vendor: jboss.org
+Bundle-Name: Simple1
+Bundle-SymbolicName: org.jboss.test.osgi.simple1
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/simple/simple-bundle2/META-INF/MANIFEST.MF
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/simple/simple-bundle2/META-INF/MANIFEST.MF (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/simple/simple-bundle2/META-INF/MANIFEST.MF 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,6 @@
+Manifest-Version: 1.0
+Implementation-Title: JBoss OSGi tests
+Implementation-Version: test
+Implementation-Vendor: jboss.org
+Bundle-Name: Simple2
+Bundle-SymbolicName: org.jboss.test.osgi.simple2
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/smoke/smoke-assembled/META-INF/MANIFEST.MF
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/smoke/smoke-assembled/META-INF/MANIFEST.MF (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/smoke/smoke-assembled/META-INF/MANIFEST.MF 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,6 @@
+Manifest-Version: 1.0
+Implementation-Title: JBoss OSGi tests
+Implementation-Version: test
+Implementation-Vendor: jboss.org
+Bundle-Name: SmokeAssmbled
+Bundle-SymbolicName: org.jboss.test.osgi.smoke.assembled
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/smoke/smoke-assembled/id
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/smoke/smoke-assembled/id (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/smoke/smoke-assembled/id 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1 @@
+smoke-assembled
\ No newline at end of file
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/smoke/smoke-no-manifest/id
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/smoke/smoke-no-manifest/id (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/smoke/smoke-no-manifest/id 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1 @@
+smoke-no-manifest
\ No newline at end of file
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/smoke/smoke-non-osgi-manifest/META-INF/MANIFEST.MF
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/smoke/smoke-non-osgi-manifest/META-INF/MANIFEST.MF (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/smoke/smoke-non-osgi-manifest/META-INF/MANIFEST.MF 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,4 @@
+Manifest-Version: 1.0
+Implementation-Title: JBoss OSGi tests
+Implementation-Version: test
+Implementation-Vendor: jboss.org
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/smoke/smoke-non-osgi-manifest/id
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/smoke/smoke-non-osgi-manifest/id (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/smoke/smoke-non-osgi-manifest/id 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1 @@
+smoke-non-osgi-manifest
\ No newline at end of file
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/smoke/smoke-osgi-manifest/META-INF/MANIFEST.MF
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/smoke/smoke-osgi-manifest/META-INF/MANIFEST.MF (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/smoke/smoke-osgi-manifest/META-INF/MANIFEST.MF 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1,6 @@
+Manifest-Version: 1.0
+Implementation-Title: JBoss OSGi tests
+Implementation-Version: test
+Implementation-Vendor: jboss.org
+Bundle-Name: Smoke
+Bundle-SymbolicName: org.jboss.test.osgi.smoke
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/smoke/smoke-osgi-manifest/id
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/smoke/smoke-osgi-manifest/id (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/bundles/smoke/smoke-osgi-manifest/id 2009-08-17 13:47:07 UTC (rev 92424)
@@ -0,0 +1 @@
+smoke-osgi-manifest
\ No newline at end of file
Deleted: projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/log4j.xml
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/log4j.xml 2009-08-17 13:40:37 UTC (rev 92423)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/osgi-int/src/test/resources/log4j.xml 2009-08-17 13:47:07 UTC (rev 92424)
@@ -1,75 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
-
-<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
-
- <!-- ================================= -->
- <!-- Preserve messages in a local file -->
- <!-- ================================= -->
-
- <appender name="FILE" class="org.apache.log4j.FileAppender">
- <param name="File" value="${log4j.output.dir}/test.log"/>
- <param name="Append" value="false"/>
- <layout class="org.apache.log4j.PatternLayout">
- <!-- The default pattern: Date Priority [Category] Message\n -->
- <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
- </layout>
- </appender>
-
- <!-- ============================== -->
- <!-- Append messages to the console -->
- <!-- ============================== -->
-
- <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
- <param name="Target" value="System.out" />
- <param name="Threshold" value="INFO" />
- <layout class="org.apache.log4j.PatternLayout">
- <param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{1}] %m%n" />
- </layout>
- </appender>
-
- <!-- ================ -->
- <!-- Limit categories -->
- <!-- ================ -->
-
- <category name="org.hibernate">
- <priority value="INFO" />
- </category>
-
- <!-- hide optimistic locking failures
- <category name="org.hibernate.event.def.AbstractFlushingEventListener">
- <priority value="FATAL" />
- </category>
- -->
-
- <!-- hide proxy narrowing warns -->
- <category name="org.hibernate.engine.StatefulPersistenceContext.ProxyWarnLog">
- <priority value="ERROR" />
- </category>
-
- <!-- show SQL DML statements as they are executed -->
- <category name="org.hibernate.SQL">
- <priority value="DEBUG" />
- </category>
-
- <!-- show JDBC parameters
- <category name="org.hibernate.type">
- <priority value="TRACE" />
- </category>
- -->
-
- <!-- hide httpclient wire dumps -->
- <category name="httpclient.wire.header">
- <priority value="INFO" />
- </category>
-
- <!-- ======================= -->
- <!-- Setup the Root category -->
- <!-- ======================= -->
-
- <root>
- <!--appender-ref ref="CONSOLE"/-->
- <appender-ref ref="FILE"/>
- </root>
-
-</log4j:configuration>
More information about the jboss-cvs-commits
mailing list