2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
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.
17 package org
.argeo
.slc
.osgi
;
19 import org
.argeo
.slc
.BasicNameVersion
;
20 import org
.argeo
.slc
.NameVersion
;
21 import org
.argeo
.slc
.build
.Distribution
;
22 import org
.argeo
.slc
.core
.build
.ResourceDistribution
;
23 import org
.argeo
.slc
.deploy
.DeploymentData
;
24 import org
.argeo
.slc
.deploy
.Module
;
25 import org
.argeo
.slc
.deploy
.ModuleDescriptor
;
26 import org
.argeo
.slc
.deploy
.TargetData
;
27 import org
.argeo
.slc
.process
.RealizedFlow
;
28 import org
.osgi
.framework
.Bundle
;
29 import org
.osgi
.framework
.Constants
;
30 import org
.springframework
.core
.io
.Resource
;
32 /** A deployed OSGi bundle. */
33 public class OsgiBundle
extends BasicNameVersion
implements Module
{
34 private static final long serialVersionUID
= 35073826504550477L;
36 private ResourceDistribution distribution
;
38 private Long internalBundleId
;
41 private String description
;
47 public OsgiBundle(String name
, String version
) {
51 public OsgiBundle(NameVersion nameVersion
) {
55 public OsgiBundle(Bundle bundle
) {
56 super(bundle
.getSymbolicName(), getVersionSafe(bundle
));
57 internalBundleId
= bundle
.getBundleId();
61 * Initialize from a {@link RealizedFlow}.
63 * @deprecated introduce an unnecessary dependency. TODO: create a separate
66 public OsgiBundle(RealizedFlow realizedFlow
) {
67 super(realizedFlow
.getModuleName(), realizedFlow
.getModuleVersion());
70 /** Utility to avoid NPE. */
71 private static String
getVersionSafe(Bundle bundle
) {
72 Object versionObj
= bundle
.getHeaders().get(Constants
.BUNDLE_VERSION
);
73 if (versionObj
!= null)
74 return versionObj
.toString();
79 /** Unique deployed system id. TODO: use internal bundle id when available? */
80 public String
getDeployedSystemId() {
81 return getName() + ":" + getVersion();
85 * OSGi bundle are self-contained and do not require additional deployment
90 public DeploymentData
getDeploymentData() {
94 /** The related distribution. */
95 public Distribution
getDistribution() {
100 * The related distribution, a jar file with OSGi metadata referenced by a
103 public ResourceDistribution
getResourceDistribution() {
107 /** TODO: reference the {@link OsgiRuntime} as target data? */
108 public TargetData
getTargetData() {
109 throw new UnsupportedOperationException();
112 public void setResourceDistribution(ResourceDistribution distribution
) {
113 this.distribution
= distribution
;
117 * Bundle ID used by the OSGi runtime. To be used for optimization when
118 * looking in the bundle context. Can therefore be null.
120 public Long
getInternalBundleId() {
121 return internalBundleId
;
124 /** Only package access for the time being. e.g. from {@link BundlesManager} */
125 void setInternalBundleId(Long internalBundleId
) {
126 this.internalBundleId
= internalBundleId
;
129 /** Value of the <code>Bundle-Name</code> directive. */
130 public String
getTitle() {
134 public void setTitle(String label
) {
138 /** Value of the <code>Bundle-Description</code> directive. */
139 public String
getDescription() {
143 public void setDescription(String description
) {
144 this.description
= description
;
147 public ModuleDescriptor
getModuleDescriptor() {
148 ModuleDescriptor moduleDescriptor
= new ModuleDescriptor();
149 moduleDescriptor
.setName(getName());
150 moduleDescriptor
.setVersion(getVersion());
151 moduleDescriptor
.setDescription(description
);
152 moduleDescriptor
.setTitle(title
);
153 return moduleDescriptor
;