2 * Copyright (C) 2007-2012 Mathieu Baudier
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
.BasicNameVersion
;
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
.process
.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 BasicNameVersion
implements Module
{
33 private static final long serialVersionUID
= 35073826504550477L;
35 private ResourceDistribution distribution
;
37 private Long internalBundleId
;
40 private String description
;
46 public OsgiBundle(String name
, String version
) {
50 public OsgiBundle(NameVersion nameVersion
) {
54 public OsgiBundle(Bundle bundle
) {
55 super(bundle
.getSymbolicName(), getVersionSafe(bundle
));
56 internalBundleId
= bundle
.getBundleId();
60 * Initialize from a {@link RealizedFlow}.
62 * @deprecated introduce an unnecessary dependency. TODO: create a separate
65 public OsgiBundle(RealizedFlow realizedFlow
) {
66 super(realizedFlow
.getModuleName(), realizedFlow
.getModuleVersion());
69 /** Utility to avoid NPE. */
70 private static String
getVersionSafe(Bundle bundle
) {
71 Object versionObj
= bundle
.getHeaders().get(Constants
.BUNDLE_VERSION
);
72 if (versionObj
!= null)
73 return versionObj
.toString();
78 /** Unique deployed system id. TODO: use internal bundle id when available? */
79 public String
getDeployedSystemId() {
80 return getName() + ":" + getVersion();
84 * OSGi bundle are self-contained and do not require additional deployment
89 public DeploymentData
getDeploymentData() {
93 /** The related distribution. */
94 public Distribution
getDistribution() {
99 * The related distribution, a jar file with OSGi metadata referenced by a
102 public ResourceDistribution
getResourceDistribution() {
106 /** TODO: reference the {@link OsgiRuntime} as target data? */
107 public TargetData
getTargetData() {
108 throw new UnsupportedOperationException();
111 public void setResourceDistribution(ResourceDistribution distribution
) {
112 this.distribution
= distribution
;
116 * Bundle ID used by the OSGi runtime. To be used for optimization when
117 * looking in the bundle context. Can therefore be null.
119 public Long
getInternalBundleId() {
120 return internalBundleId
;
123 /** Only package access for the time being. e.g. from {@link BundlesManager} */
124 void setInternalBundleId(Long internalBundleId
) {
125 this.internalBundleId
= internalBundleId
;
128 /** Value of the <code>Bundle-Name</code> directive. */
129 public String
getTitle() {
133 public void setTitle(String label
) {
137 /** Value of the <code>Bundle-Description</code> directive. */
138 public String
getDescription() {
142 public void setDescription(String description
) {
143 this.description
= description
;
146 public ModuleDescriptor
getModuleDescriptor() {
147 ModuleDescriptor moduleDescriptor
= new ModuleDescriptor();
148 moduleDescriptor
.setName(getName());
149 moduleDescriptor
.setVersion(getVersion());
150 moduleDescriptor
.setDescription(description
);
151 moduleDescriptor
.setTitle(title
);
152 return moduleDescriptor
;