2 * Copyright (C) 2007-2012 Argeo GmbH
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.slc
.osgi
;
18 import org
.argeo
.slc
.DefaultNameVersion
;
19 import org
.argeo
.slc
.NameVersion
;
20 import org
.argeo
.slc
.build
.Distribution
;
21 import org
.argeo
.slc
.core
.build
.ResourceDistribution
;
22 import org
.argeo
.slc
.deploy
.DeploymentData
;
23 import org
.argeo
.slc
.deploy
.Module
;
24 import org
.argeo
.slc
.deploy
.ModuleDescriptor
;
25 import org
.argeo
.slc
.deploy
.TargetData
;
26 import org
.argeo
.slc
.execution
.RealizedFlow
;
27 import org
.osgi
.framework
.Bundle
;
28 import org
.osgi
.framework
.Constants
;
29 import org
.springframework
.core
.io
.Resource
;
31 /** A deployed OSGi bundle. */
32 public class OsgiBundle
extends DefaultNameVersion
implements Module
{
33 private ResourceDistribution distribution
;
35 private Long internalBundleId
;
38 private String description
;
44 public OsgiBundle(String name
, String version
) {
48 public OsgiBundle(NameVersion nameVersion
) {
52 public OsgiBundle(Bundle bundle
) {
53 super(bundle
.getSymbolicName(), getVersionSafe(bundle
));
54 internalBundleId
= bundle
.getBundleId();
58 * Initialize from a {@link RealizedFlow}.
60 * @deprecated introduce an unnecessary dependency. TODO: create a separate
63 public OsgiBundle(RealizedFlow realizedFlow
) {
64 super(realizedFlow
.getModuleName(), realizedFlow
.getModuleVersion());
67 /** Utility to avoid NPE. */
68 private static String
getVersionSafe(Bundle bundle
) {
69 Object versionObj
= bundle
.getHeaders().get(Constants
.BUNDLE_VERSION
);
70 if (versionObj
!= null)
71 return versionObj
.toString();
76 /** Unique deployed system id. TODO: use internal bundle id when available? */
77 public String
getDeployedSystemId() {
78 return getName() + ":" + getVersion();
82 * OSGi bundle are self-contained and do not require additional deployment
87 public DeploymentData
getDeploymentData() {
91 /** The related distribution. */
92 public Distribution
getDistribution() {
97 * The related distribution, a jar file with OSGi metadata referenced by a
100 public ResourceDistribution
getResourceDistribution() {
104 /** TODO: reference the {@link OsgiRuntime} as target data? */
105 public TargetData
getTargetData() {
106 throw new UnsupportedOperationException();
109 public void setResourceDistribution(ResourceDistribution distribution
) {
110 this.distribution
= distribution
;
114 * Bundle ID used by the OSGi runtime. To be used for optimization when
115 * looking in the bundle context. Can therefore be null.
117 public Long
getInternalBundleId() {
118 return internalBundleId
;
121 /** Only package access for the time being. e.g. from {@link BundlesManager} */
122 void setInternalBundleId(Long internalBundleId
) {
123 this.internalBundleId
= internalBundleId
;
126 /** Value of the <code>Bundle-Name</code> directive. */
127 public String
getTitle() {
131 public void setTitle(String label
) {
135 /** Value of the <code>Bundle-Description</code> directive. */
136 public String
getDescription() {
140 public void setDescription(String description
) {
141 this.description
= description
;
144 public ModuleDescriptor
getModuleDescriptor() {
145 ModuleDescriptor moduleDescriptor
= new ModuleDescriptor();
146 moduleDescriptor
.setName(getName());
147 moduleDescriptor
.setVersion(getVersion());
148 moduleDescriptor
.setDescription(description
);
149 moduleDescriptor
.setTitle(title
);
150 return moduleDescriptor
;