/** Converts the specification to an id */ public ComponentId toId() { Version version = (getVersionSpecification() == VersionSpecification.emptyVersionSpecification) ? Version.emptyVersion : getVersionSpecification().lowestMatchingVersion(); return new ComponentId(getName(), version, getNamespace()); }
/** Returns a copy of this spec with namespace set to null **/ public ComponentSpecification withoutNamespace() { return new ComponentSpecification(getName(), getVersionSpecification(), null); }
/** * Returns a component. If the id does not specify an (exact) version, the newest (matching) version is returned. * For example, if version 3.1 is specified and we have 3.1.0, 3.1.1 and 3.1.3 registered, 3.1.3 is returned. * * @param id the id of the component to return. May not include a version, or include * an underspecified version, in which case the highest (matching) version which * does not contain a qualifier is returned * @return the search chain or null if no component of this name (and matching version, if specified) is registered */ public COMPONENT getComponent(ComponentSpecification id) { Map<String, Map<Version, COMPONENT>> componentVersionsByName = componentsByNameByNamespace.get(id.getNamespace()); if (componentVersionsByName == null) return null; // No matching namespace Map<Version, COMPONENT> versions = componentVersionsByName.get(id.getName()); if (versions==null) return null; // No versions of this component Version version=findBestMatch(id.getVersionSpecification(), versions.keySet()); //if (version==null) return null; // No matching version return versions.get(version); }
public ComponentSpecification intersect(ComponentSpecification other) { if (!getName().equals(other.getName())) { throw new RuntimeException("The names of the component specifications does not match(" + getName() + "!=" + other.getName() + ")."); } if (!namespaceMatch(other.getNamespace())) { throw new RuntimeException("The namespaces of the component specifications does not match(" + this + ", " + other +")"); } return new ComponentSpecification(getName(), getVersionSpecification().intersect(other.getVersionSpecification()), getNamespace()); }
/** * Checks if a componentId matches a given spec */ public boolean matches(ComponentId id) { boolean versionMatch = getVersionSpecification().matches(id.getVersion()); return getName().equals(id.getName()) && versionMatch && namespaceMatch(id.getNamespace()); }
/** * Returns the bundle of a given name having the highest matching version * * @param id the id of the component to return. May not include a version, or include * an underspecified version, in which case the highest (mathcing) version which * does not contain a qualifier is returned * @return the bundle match having the highest version, or null if there was no matches */ public Bundle getBundle(ComponentSpecification id) { Bundle highestMatch=null; for (Bundle bundle : getBundles()) { assert bundle.getSymbolicName() != null : "ensureHasBundleSymbolicName not called during installation"; if ( ! bundle.getSymbolicName().equals(id.getName())) continue; if ( ! id.getVersionSpecification().matches(versionOf(bundle))) continue; if (highestMatch==null || versionOf(highestMatch).compareTo(versionOf(bundle))<0) highestMatch=bundle; } return highestMatch; }
public ComponentSpecification nestInNamespace(ComponentId namespace) { ComponentId newNameSpace = (getNamespace() == null) ? namespace : getNamespace().nestInNamespace(namespace); return new ComponentSpecification(getName(), getVersionSpecification(), newNameSpace); }
private QueryProfile findPathParentQueryProfile(ComponentSpecification id) { // Try the name with "/" appended - should have the same semantics with path matching QueryProfile slashedProfile=getComponent(new ComponentSpecification(id.getName() + "/",id.getVersionSpecification())); if (slashedProfile!=null && slashedProfile.getType()!=null && slashedProfile.getType().getMatchAsPath()) return slashedProfile; // Extract the parent (if any) int slashIndex=id.getName().lastIndexOf("/"); if (slashIndex<1) return null; String parentName=id.getName().substring(0,slashIndex); if (parentName.equals("")) return null; ComponentSpecification parentId=new ComponentSpecification(parentName,id.getVersionSpecification()); QueryProfile pathParentProfile=getComponent(parentId); if (pathParentProfile!=null && pathParentProfile.getType()!=null && pathParentProfile.getType().getMatchAsPath()) return pathParentProfile; return findPathParentQueryProfile(parentId); }
private CompiledQueryProfile findPathParentQueryProfile(ComponentSpecification id) { // Try the name with "/" appended - should have the same semantics with path matching CompiledQueryProfile slashedProfile = getComponent(new ComponentSpecification(id.getName() + "/", id.getVersionSpecification())); if (slashedProfile != null && slashedProfile.getType() != null && slashedProfile.getType().getMatchAsPath()) return slashedProfile; // Extract the parent (if any) int slashIndex = id.getName().lastIndexOf("/"); if (slashIndex < 1) return null; String parentName = id.getName().substring(0, slashIndex); if (parentName.equals("")) return null; ComponentSpecification parentId = new ComponentSpecification(parentName,id.getVersionSpecification()); CompiledQueryProfile pathParentProfile = getComponent(parentId); if (pathParentProfile!=null && pathParentProfile.getType() != null && pathParentProfile.getType().getMatchAsPath()) return pathParentProfile; return findPathParentQueryProfile(parentId); }