Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.xbean.osgi.bundle.util;
import java.util.ArrayList;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
import org.apache.xbean.osgi.bundle.util.HeaderParser.HeaderElement;
import org.osgi.framework.Constants;
import org.osgi.framework.Version;
/**
* @version $Rev: 937957 $, $Date: 2010-04-26 10:00:08 +0200 (lun. 26 avril 2010) $
*/
public class BundleDescription {
private Map headers;
public BundleDescription(Manifest manifest) {
this.headers = manifestToMap(manifest);
}
public BundleDescription(Dictionary dictionary) {
this.headers = new DictionaryMap(dictionary);
}
public BundleDescription(Map headers) {
this.headers = headers;
}
/**
* Returns a list of packages that are listed in Import-Package header.
*/
public List getImportPackage() {
String headerValue = (String) headers.get(Constants.IMPORT_PACKAGE);
List imports = new ArrayList();
List elements = HeaderParser.parseHeader(headerValue);
for (HeaderElement element : elements) {
ImportPackage p = new ImportPackage(element.getName(), element.getAttributes(), element.getDirectives());
imports.add(p);
}
return imports;
}
/**
* Returns a list of packages that are listed in Export-Package header.
*/
public List getExportPackage() {
String headerValue = (String) headers.get(Constants.EXPORT_PACKAGE);
List exports = new ArrayList();
List elements = HeaderParser.parseHeader(headerValue);
for (HeaderElement element : elements) {
ExportPackage p = new ExportPackage(element.getName(), element.getAttributes(), element.getDirectives());
exports.add(p);
}
return exports;
}
/**
* Returns a list of packages that are listed in Import-Package header
* and are not listed in Export-Package header.
*/
public List getExternalImports() {
List imports = getImportPackage();
List exports = getExportPackage();
List realImports = new ArrayList();
for (ImportPackage p : imports) {
if (!isExported(exports, p)) {
realImports.add(p);
}
}
return realImports;
}
private static boolean isExported(List exports, ImportPackage p) {
for (ExportPackage export : exports) {
if (export.getName().equals(p.getName())) {
return true;
}
}
return false;
}
/**
* Returns a list of bundle names that are listed in Require-Bundle header.
*/
public List getRequireBundle() {
String headerValue = (String) headers.get(Constants.REQUIRE_BUNDLE);
List requireBundles = new ArrayList();
List elements = HeaderParser.parseHeader(headerValue);
for (HeaderElement element : elements) {
RequireBundle p = new RequireBundle(element.getName(), element.getAttributes(), element.getDirectives());
requireBundles.add(p);
}
return requireBundles;
}
/**
* Returns Fragment-Host header.
*/
public FragmentHost getFragmentHost() {
String headerValue = (String) headers.get(Constants.FRAGMENT_HOST);
List elements = HeaderParser.parseHeader(headerValue);
if (elements.size() == 1) {
HeaderElement element = elements.get(0);
return new FragmentHost(element.getName(), element.getAttributes(), element.getDirectives());
}
return null;
}
/**
* Returns a list of packages that are listed in DynamicImport-Package header.
*/
public List getDynamicImportPackage() {
String headerValue = (String) headers.get(Constants.DYNAMICIMPORT_PACKAGE);
return parseStandardHeader(headerValue);
}
/**
* Returns a list of paths that are listed in Bundle-ClassPath header.
*/
public List getBundleClassPath() {
String headerValue = (String) headers.get(Constants.BUNDLE_CLASSPATH);
return parseStandardHeader(headerValue);
}
public SymbolicName getSymbolicName() {
String headerValue = (String) headers.get(Constants.BUNDLE_SYMBOLICNAME);
List elements = HeaderParser.parseHeader(headerValue);
if (elements.size() == 1) {
HeaderElement element = elements.get(0);
return new SymbolicName(element.getName(), element.getAttributes(), element.getDirectives());
}
return null;
}
public Version getVersion() {
String headerValue = (String) headers.get(Constants.BUNDLE_VERSION);
return getVersionRange(headerValue).getLow();
}
public Map getHeaders() {
return headers;
}
private List parseStandardHeader(String headerValue) {
List imports = new ArrayList();
List elements = HeaderParser.parseHeader(headerValue);
for (HeaderElement element : elements) {
HeaderEntry p = new HeaderEntry(element.getName(), element.getAttributes(), element.getDirectives());
imports.add(p);
}
return imports;
}
private static Map manifestToMap(Manifest manifest) {
Attributes attributes = manifest.getMainAttributes();
Map headers = new HashMap();
for (Map.Entry