public String getClassName() { return classId.getName(); }
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()); }
@SuppressWarnings("unchecked") private static Class<Object> resolveFromClassPath(BundleInstantiationSpecification spec) { try { return (Class<Object>) Class.forName(spec.classId.getName()); } catch (ClassNotFoundException e) { throw new IllegalArgumentException("Could not create a component with id '" + spec.classId.getName() + "'. Tried to load class directly, since no bundle was found for spec: " + spec.bundle + ". If a bundle with the same name is installed, there is a either a version mismatch" + " or the installed bundle's version contains a qualifier string."); } }
public ComponentSpecification nestInNamespace(ComponentId namespace) { ComponentId newNameSpace = (getNamespace() == null) ? namespace : getNamespace().nestInNamespace(namespace); return new ComponentSpecification(getName(), getVersionSpecification(), newNameSpace); }
private static Set<String> names(Set<ComponentSpecification> components) { Set<String> names = new LinkedHashSet<>(); for (ComponentSpecification component : components) { names.add(component.getName()); } return names; }
/** Converts the specification to an id */ public ComponentId toId() { Version version = (getVersionSpecification() == VersionSpecification.emptyVersionSpecification) ? Version.emptyVersion : getVersionSpecification().lowestMatchingVersion(); return new ComponentId(getName(), version, getNamespace()); }
static Map<String, ComponentSpecification> componentsByName(Set<ComponentSpecification> componentSpecifications) { Map<String, ComponentSpecification> componentsByName = new LinkedHashMap<>(); for (ComponentSpecification component : componentSpecifications) componentsByName.put(component.getName(), component); return componentsByName; }
public static BundleClasspathMapping matchingBundleClassPathMapping(ComponentSpecification bundleSpec, Collection<BundleClasspathMapping> providedBundlesClassPathMappings) { for (BundleClasspathMapping mapping : providedBundlesClassPathMappings) { if (mapping.bundleSymbolicName.equals(bundleSpec.getName())) { return mapping; } } throw new RuntimeException("No such bundle: " + bundleSpec); }
private static Set<ComponentSpecification> filterByName(Set<ComponentSpecification> components, Set<String> names) { Set<ComponentSpecification> result = new LinkedHashSet<>(); for (ComponentSpecification component : components) { if (!names.contains(component.getName())) result.add(component); } return result; }
@SuppressWarnings("unchecked") private static Class<Object> resolveFromBundle(BundleInstantiationSpecification spec, Bundle bundle) { try { ensureBundleActive(bundle); return (Class<Object>) bundle.loadClass(spec.classId.getName()); } catch (ClassNotFoundException e) { throw new IllegalArgumentException("Could not load class '" + spec.classId.getName() + "' from bundle " + bundle, e); } }
default Class<?> resolveClass(BundleInstantiationSpecification spec) { System.out.println("resolving class " + spec.classId); try { return Class.forName(spec.classId.getName()); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } }
/** * Get the name of the format desired for result rendering. */ @NonNull public String getFormat() { return format.getName(); }
private static void mergeInto(Map<String, ComponentSpecification> resultingComponents, Set<ComponentSpecification> components) { for (ComponentSpecification component : components) { String name = component.getName(); if (resultingComponents.containsKey(name)) { resultingComponents.put(name, component.intersect(resultingComponents.get(name))); } else { resultingComponents.put(name, component); } } }
public static boolean isBuiltinGetOnly(Handler<?> handler) { return UNPROTECTED_HANDLERS.contains(handler.getClassId().getName()); }
private void readComponentReference(Element componentElement, ComponentType componentType, ComponentSpecification componentSpecification, Map<String, ComponentType> outerComponentTypeByComponentName) { String componentName = componentSpecification.getName(); ensureTypesMatch(componentType, outerComponentTypeByComponentName.get(componentName), componentName); ensureNotDefinition(componentName, componentElement); outerComponentReferences.add(componentSpecification); }
private static BundleClasspathMapping bundleClassPathMapping(ComponentSpecification bundleSpec, ClassLoader classLoader) { ProjectBundleClassPaths projectBundleClassPaths = loadProjectBundleClassPaths(classLoader); if (projectBundleClassPaths.mainBundle.bundleSymbolicName.equals(bundleSpec.getName())) { return projectBundleClassPaths.mainBundle; } else { log.log(Level.WARNING, "Dependencies of the bundle " + bundleSpec + " will not be scanned. Please file a feature request if you need this"); return matchingBundleClassPathMapping(bundleSpec, projectBundleClassPaths.providedDependencies); } }
/** Returns a copy of this spec with namespace set to null **/ public ComponentSpecification withoutNamespace() { return new ComponentSpecification(getName(), getVersionSpecification(), null); }
private boolean hasOnlyName(ComponentSpecification sourceSpec) { return new ComponentSpecification(sourceSpec.getName()).equals(sourceSpec); }
private void readComponent(DeployState deployState, AbstractConfigProducer ancestor, Element componentElement, ComponentType<T> componentType, Map<String, ComponentType> outerComponentTypeByComponentName) { ComponentSpecification componentSpecification = XmlHelper.getIdRef(componentElement); if (outerComponentTypeByComponentName.containsKey(componentSpecification.getName())) { readComponentReference(componentElement, componentType, componentSpecification, outerComponentTypeByComponentName); } else { readComponentDefinition(deployState, ancestor, componentElement, componentType); } }
/** * 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()); }