]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/OsgiBundle.java
Reactivate launcher
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.osgi / src / main / java / org / argeo / slc / osgi / OsgiBundle.java
1 /*
2 * Copyright (C) 2007-2012 Mathieu Baudier
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16 package org.argeo.slc.osgi;
17
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.execution.RealizedFlow;
27 import org.osgi.framework.Bundle;
28 import org.osgi.framework.Constants;
29 import org.springframework.core.io.Resource;
30
31 /** A deployed OSGi bundle. */
32 public class OsgiBundle extends BasicNameVersion implements Module {
33 private static final long serialVersionUID = 35073826504550477L;
34
35 private ResourceDistribution distribution;
36
37 private Long internalBundleId;
38
39 private String title;
40 private String description;
41
42 public OsgiBundle() {
43
44 }
45
46 public OsgiBundle(String name, String version) {
47 super(name, version);
48 }
49
50 public OsgiBundle(NameVersion nameVersion) {
51 super(nameVersion);
52 }
53
54 public OsgiBundle(Bundle bundle) {
55 super(bundle.getSymbolicName(), getVersionSafe(bundle));
56 internalBundleId = bundle.getBundleId();
57 }
58
59 /**
60 * Initialize from a {@link RealizedFlow}.
61 *
62 * @deprecated introduce an unnecessary dependency. TODO: create a separate
63 * helper.
64 */
65 public OsgiBundle(RealizedFlow realizedFlow) {
66 super(realizedFlow.getModuleName(), realizedFlow.getModuleVersion());
67 }
68
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();
74 else
75 return null;
76 }
77
78 /** Unique deployed system id. TODO: use internal bundle id when available? */
79 public String getDeployedSystemId() {
80 return getName() + ":" + getVersion();
81 }
82
83 /**
84 * OSGi bundle are self-contained and do not require additional deployment
85 * data.
86 *
87 * @return always null
88 */
89 public DeploymentData getDeploymentData() {
90 return null;
91 }
92
93 /** The related distribution. */
94 public Distribution getDistribution() {
95 return distribution;
96 }
97
98 /**
99 * The related distribution, a jar file with OSGi metadata referenced by a
100 * {@link Resource}.
101 */
102 public ResourceDistribution getResourceDistribution() {
103 return distribution;
104 }
105
106 /** TODO: reference the {@link OsgiRuntime} as target data? */
107 public TargetData getTargetData() {
108 throw new UnsupportedOperationException();
109 }
110
111 public void setResourceDistribution(ResourceDistribution distribution) {
112 this.distribution = distribution;
113 }
114
115 /**
116 * Bundle ID used by the OSGi runtime. To be used for optimization when
117 * looking in the bundle context. Can therefore be null.
118 */
119 public Long getInternalBundleId() {
120 return internalBundleId;
121 }
122
123 /** Only package access for the time being. e.g. from {@link BundlesManager} */
124 void setInternalBundleId(Long internalBundleId) {
125 this.internalBundleId = internalBundleId;
126 }
127
128 /** Value of the <code>Bundle-Name</code> directive. */
129 public String getTitle() {
130 return title;
131 }
132
133 public void setTitle(String label) {
134 this.title = label;
135 }
136
137 /** Value of the <code>Bundle-Description</code> directive. */
138 public String getDescription() {
139 return description;
140 }
141
142 public void setDescription(String description) {
143 this.description = description;
144 }
145
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;
153 }
154 }