blob: c4adcc2023a7487bcb2b751e3ff62580f190847d [file] [log] [blame]
/*********************************************************************
* Copyright (c) 2007, 2012 SpringSource
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
package org.eclipse.virgo.ide.bundlerepository.domain;
import org.eclipse.virgo.ide.runtime.core.artefacts.ArtefactRepositoryManager;
/**
* Represent an import-package declaration for an OSGi bundle. Ignores matching attributes and only worries about
* version range and optionality.
*
* @author acolyer
*/
public class PackageImport {
private byte[] name; // name of the package to be imported
private boolean isOptional; // whether or not this import is optional
private VersionRange importRange; // the range of version that are
// acceptable
/** for persistence use only */
protected PackageImport() {
}
/**
* Create a new package import.
*
* @param name the name of the package to be imported
* @param isOptional true if this is an optional import
* @param range the range of versions that are acceptable
*/
public PackageImport(String name, boolean isOptional, VersionRange range) {
this.name = ArtefactRepositoryManager.convert(name);
this.isOptional = isOptional;
this.importRange = range;
}
public String getName() {
return this.name != null ? new String(this.name) : null;
}
public boolean isOptional() {
return this.isOptional;
}
public VersionRange getImportRange() {
return this.importRange;
}
/**
* Return true if this import can be satisfied by the given exported package
*
* @param pkg the candidate package for satisfying this import
*/
public boolean isSatisfiedBy(PackageExport pkg) {
return this.name.equals(pkg.getName()) && this.importRange.contains(pkg.getVersion());
}
}