]> git.argeo.org Git - gpl/argeo-slc.git/blob - cms/org.argeo.slc.spring/src/org/argeo/slc/osgi/OsgiBundle.java
01275da276c1befaf1bc2fb63946c722206cc03d
[gpl/argeo-slc.git] / cms / org.argeo.slc.spring / src / org / argeo / slc / osgi / OsgiBundle.java
1 package org.argeo.slc.osgi;
2
3 import org.argeo.slc.DefaultNameVersion;
4 import org.argeo.slc.NameVersion;
5 import org.argeo.slc.build.Distribution;
6 import org.argeo.slc.core.build.ResourceDistribution;
7 import org.argeo.slc.deploy.DeploymentData;
8 import org.argeo.slc.deploy.Module;
9 import org.argeo.slc.deploy.ModuleDescriptor;
10 import org.argeo.slc.deploy.TargetData;
11 import org.argeo.slc.execution.RealizedFlow;
12 import org.osgi.framework.Bundle;
13 import org.osgi.framework.Constants;
14 import org.springframework.core.io.Resource;
15
16 /** A deployed OSGi bundle. */
17 public class OsgiBundle extends DefaultNameVersion implements Module {
18 private ResourceDistribution distribution;
19
20 private Long internalBundleId;
21
22 private String title;
23 private String description;
24
25 public OsgiBundle() {
26
27 }
28
29 public OsgiBundle(String name, String version) {
30 super(name, version);
31 }
32
33 public OsgiBundle(NameVersion nameVersion) {
34 super(nameVersion);
35 }
36
37 public OsgiBundle(Bundle bundle) {
38 super(bundle.getSymbolicName(), getVersionSafe(bundle));
39 internalBundleId = bundle.getBundleId();
40 }
41
42 /**
43 * Initialize from a {@link RealizedFlow}.
44 *
45 * @deprecated introduce an unnecessary dependency. TODO: create a separate
46 * helper.
47 */
48 public OsgiBundle(RealizedFlow realizedFlow) {
49 super(realizedFlow.getModuleName(), realizedFlow.getModuleVersion());
50 }
51
52 /** Utility to avoid NPE. */
53 private static String getVersionSafe(Bundle bundle) {
54 Object versionObj = bundle.getHeaders().get(Constants.BUNDLE_VERSION);
55 if (versionObj != null)
56 return versionObj.toString();
57 else
58 return null;
59 }
60
61 /** Unique deployed system id. TODO: use internal bundle id when available? */
62 public String getDeployedSystemId() {
63 return getName() + ":" + getVersion();
64 }
65
66 /**
67 * OSGi bundle are self-contained and do not require additional deployment
68 * data.
69 *
70 * @return always null
71 */
72 public DeploymentData getDeploymentData() {
73 return null;
74 }
75
76 /** The related distribution. */
77 public Distribution getDistribution() {
78 return distribution;
79 }
80
81 /**
82 * The related distribution, a jar file with OSGi metadata referenced by a
83 * {@link Resource}.
84 */
85 public ResourceDistribution getResourceDistribution() {
86 return distribution;
87 }
88
89 /** TODO: reference the {@link OsgiRuntime} as target data? */
90 public TargetData getTargetData() {
91 throw new UnsupportedOperationException();
92 }
93
94 public void setResourceDistribution(ResourceDistribution distribution) {
95 this.distribution = distribution;
96 }
97
98 /**
99 * Bundle ID used by the OSGi runtime. To be used for optimization when
100 * looking in the bundle context. Can therefore be null.
101 */
102 public Long getInternalBundleId() {
103 return internalBundleId;
104 }
105
106 /** Only package access for the time being. e.g. from {@link BundlesManager} */
107 void setInternalBundleId(Long internalBundleId) {
108 this.internalBundleId = internalBundleId;
109 }
110
111 /** Value of the <code>Bundle-Name</code> directive. */
112 public String getTitle() {
113 return title;
114 }
115
116 public void setTitle(String label) {
117 this.title = label;
118 }
119
120 /** Value of the <code>Bundle-Description</code> directive. */
121 public String getDescription() {
122 return description;
123 }
124
125 public void setDescription(String description) {
126 this.description = description;
127 }
128
129 public ModuleDescriptor getModuleDescriptor() {
130 ModuleDescriptor moduleDescriptor = new ModuleDescriptor();
131 moduleDescriptor.setName(getName());
132 moduleDescriptor.setVersion(getVersion());
133 moduleDescriptor.setDescription(description);
134 moduleDescriptor.setTitle(title);
135 return moduleDescriptor;
136 }
137 }