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