]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/OsgiBundle.java
7cce2308350f9d7000d932ce120be25e0bb9d813
[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.build.BasicNameVersion;
20 import org.argeo.slc.build.Distribution;
21 import org.argeo.slc.build.NameVersion;
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.TargetData;
26 import org.argeo.slc.process.RealizedFlow;
27 import org.osgi.framework.Bundle;
28 import org.osgi.framework.Constants;
29
30 public class OsgiBundle extends BasicNameVersion implements Module {
31 private ResourceDistribution distribution;
32
33 private Long internalBundleId;
34
35 private String label;
36 private String description;
37
38 public OsgiBundle() {
39
40 }
41
42 public OsgiBundle(String name, String version) {
43 super(name, version);
44 }
45
46 public OsgiBundle(NameVersion nameVersion) {
47 super(nameVersion);
48 }
49
50 public OsgiBundle(Bundle bundle) {
51 super(bundle.getSymbolicName(), getVersionSafe(bundle));
52 internalBundleId = bundle.getBundleId();
53 }
54
55 private static String getVersionSafe(Bundle bundle) {
56 Object versionObj = bundle.getHeaders().get(Constants.BUNDLE_VERSION);
57 if (versionObj != null)
58 return versionObj.toString();
59 else
60 return null;
61 }
62
63 public OsgiBundle(RealizedFlow realizedFlow) {
64 super(realizedFlow.getModuleName(), realizedFlow.getModuleVersion());
65 }
66
67 public String getDeployedSystemId() {
68 return getName() + ":" + getVersion();
69 }
70
71 public DeploymentData getDeploymentData() {
72 throw new UnsupportedOperationException();
73 }
74
75 public Distribution getDistribution() {
76 return distribution;
77 }
78
79 public ResourceDistribution getResourceDistribution() {
80 return distribution;
81 }
82
83 public TargetData getTargetData() {
84 throw new UnsupportedOperationException();
85 }
86
87 public void setResourceDistribution(ResourceDistribution distribution) {
88 this.distribution = distribution;
89 }
90
91 /**
92 * To be used for optimization when looking in the bundle context. Can
93 * therefore be null.
94 */
95 public Long getInternalBundleId() {
96 return internalBundleId;
97 }
98
99 /** Only package access for the time being. e.g. from {@link BundlesManager} */
100 void setInternalBundleId(Long internalBundleId) {
101 this.internalBundleId = internalBundleId;
102 }
103
104 public String getLabel() {
105 return label;
106 }
107
108 public void setLabel(String label) {
109 this.label = label;
110 }
111
112 public String getDescription() {
113 return description;
114 }
115
116 public void setDescription(String description) {
117 this.description = description;
118 }
119
120 }