001: /**********************************************************************
002: Copyright (c) 2006 Erik Bengtson and others. All rights reserved.
003: Licensed under the Apache License, Version 2.0 (the "License");
004: you may not use this file except in compliance with the License.
005: You may obtain a copy of the License at
006:
007: http://www.apache.org/licenses/LICENSE-2.0
008:
009: Unless required by applicable law or agreed to in writing, software
010: distributed under the License is distributed on an "AS IS" BASIS,
011: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: See the License for the specific language governing permissions and
013: limitations under the License.
014:
015:
016: Contributors:
017: ...
018: **********************************************************************/package org.jpox.plugin;
019:
020: import java.net.URL;
021: import java.util.HashMap;
022: import java.util.List;
023: import java.util.Map;
024:
025: /**
026: * A Plug-in (OSGi Bundle) definition. Represents the XML declaration
027: * @version $Revision: 1.3 $
028: */
029: public class Bundle {
030: /** unique id - bundle symbolic name * */
031: final private String symbolicName;
032:
033: /** vendor name * */
034: final private String vendorName;
035:
036: /** name * */
037: final private String name;
038:
039: /** plugin version * */
040: final private String version;
041:
042: /** location of the manifest.mf file * */
043: final private URL manifestLocation;
044:
045: /** Set of BundleDescription objects representing Require-Bundle entries **/
046: private List requireBundle;
047:
048: /**
049: * Constructor
050: * @param symbolicName the unique id - bundle symbolic name
051: * @param name the name
052: * @param vendorName the vendor name
053: * @param version the version number
054: * @param manifestLocation the path to the declaration file
055: */
056: public Bundle(String symbolicName, String name, String vendorName,
057: String version, URL manifestLocation) {
058: this .symbolicName = symbolicName;
059: this .name = name;
060: this .vendorName = vendorName;
061: this .version = version;
062: this .manifestLocation = manifestLocation;
063: }
064:
065: /**
066: * Accessor for the plug-in id - bundle symbolic name
067: * @return id of the plug-in
068: */
069: public String getSymbolicName() {
070: return symbolicName;
071: }
072:
073: /**
074: * Accessor for the provider name of this plug-in
075: * @return provider name
076: */
077: public String getVendorName() {
078: return vendorName;
079: }
080:
081: /**
082: * Acessor for the version of this plug-in
083: * @return version
084: */
085: public String getVersion() {
086: return version;
087: }
088:
089: /**
090: * Acessor for the location of the manifest.mf file
091: * @return the manifest.mf location
092: */
093: public URL getManifestLocation() {
094: return manifestLocation;
095: }
096:
097: /**
098: * Acessor for the plug-in name
099: * @return plug-in name
100: */
101: public String getName() {
102: return name;
103: }
104:
105: /**
106: * Acessor for the RequireBundle.
107: * @param requireBundle A List of {@link Bundle.BundleDescription} elements
108: */
109: public void setRequireBundle(List requireBundle) {
110: this .requireBundle = requireBundle;
111: }
112:
113: /**
114: * Acessor for the RequireBundle
115: * @return A List of {@link Bundle.BundleDescription} elements
116: */
117: public List getRequireBundle() {
118: return requireBundle;
119: }
120:
121: /**
122: * Description of bundles
123: * bundle-description = symbolic-name (';' parameter )*
124: *
125: * See OSGI 3.0 $ 1.4.2
126: *
127: */
128: public static class BundleDescription {
129: private String bundleSymbolicName;
130:
131: /**
132: * List of parameters for the BundleDescription
133: */
134: private Map parameters = new HashMap();
135:
136: public String getBundleSymbolicName() {
137: return bundleSymbolicName;
138: }
139:
140: public void setBundleSymbolicName(String bundleSymbolicName) {
141: this .bundleSymbolicName = bundleSymbolicName;
142: }
143:
144: public String getParameter(String name) {
145: return (String) parameters.get(name);
146: }
147:
148: public void setParameter(String name, String value) {
149: parameters.put(name, value);
150: }
151:
152: public void setParameters(Map parameters) {
153: this .parameters.putAll(parameters);
154: }
155:
156: public String toString() {
157: return "BundleDescription [Symbolic Name] "
158: + bundleSymbolicName + " [Parameters] "
159: + parameters;
160: }
161: }
162:
163: /**
164: * Bundle Version - according to OSGi spec 3.0 §3.2.4
165: */
166: public static class BundleVersion {
167: public int major;
168: public int minor;
169: public int micro;
170: public String qualifier = "";
171:
172: public int compareTo(Object object) {
173: if (object == this ) {
174: return 0;
175: }
176: BundleVersion other = (BundleVersion) object;
177: int result = major - other.major;
178: if (result != 0) {
179: return result;
180: }
181: result = minor - other.minor;
182: if (result != 0) {
183: return result;
184: }
185: result = micro - other.micro;
186: if (result != 0) {
187: return result;
188: } else {
189: return qualifier.compareTo(other.qualifier);
190: }
191: }
192:
193: public String toString() {
194: return "" + major + "." + minor + "." + micro
195: + (qualifier.length() > 0 ? "." + qualifier : "");
196: }
197: }
198:
199: /**
200: * Bundle Range - according to OSGi spec 3.0 §3.2.5
201: */
202: public static class BundleVersionRange {
203: public BundleVersion floor;
204: public BundleVersion ceiling;
205: public boolean floor_inclusive = true;
206: public boolean ceiling_inclusive = false;
207:
208: public String toString() {
209: return "Bundle VersionRange [Floor] " + floor
210: + " inclusive:" + floor_inclusive + " [Ceiling] "
211: + ceiling + " inclusive:" + ceiling_inclusive;
212: }
213: }
214:
215: public String toString() {
216: return "Bundle [Symbolic Name]" + symbolicName + " [Version] "
217: + version;
218: }
219: }
|