public Bundle getBundle() { return ctx.getBundle(); }
public Script getScript() throws IOException { if (rc != null) { URL url = rc.getBundle().getEntry(script); if (url == null) { // if not found using bundle entries try using classloader // in a test environment bundle entries may not work url = rc.getResource(script); if (url == null) { throw new IOException("Script Not found: " + script); } } return Script.newScript(url); } else { return Script.newScript(script); } }
protected URL getUrlFromPath(String path, RuntimeContext extensionContext) { if (path == null) { return null; } URL url; try { url = new URL(path); } catch (MalformedURLException e) { url = extensionContext.getLocalResource(path); if (url == null) { url = extensionContext.getResource(path); } } return url; }
protected void registerVersioningService(VersioningServiceDescriptor contrib) { String klass = contrib.className; try { VersioningService vs = (VersioningService) context.getRuntimeContext().loadClass(klass).newInstance(); versioningServices.put(contrib, vs); } catch (ReflectiveOperationException e) { throw new RuntimeException("Failed to instantiate: " + klass, e); } log.info("Registered versioning service: " + klass); recompute(); }
private static void registerTemplate(TemplateDescriptor td) { if (td.src != null && td.src.length() > 0) { URL url = td.getContext().getResource(td.src); TEMPLATES_MAP.put(td.name, url); } }
protected void computeResourceUri(ResourceDescriptor resource, ComponentInstance contributor) { String uri = resource.getURI(); if (uri == null) { // build it from local classpath // XXX: hacky wildcard support String path = resource.getPath(); if (path != null) { boolean hasWildcard = false; if (path.endsWith("*")) { hasWildcard = true; path = path.substring(0, path.length() - 1); } URL url = contributor.getContext().getLocalResource(path); if (url == null) { log.error("Cannot resolve local URL for resource '" + resource.getName() + "' with path '" + resource.getPath() + "'"); } else { String builtUri = url.toString(); if (hasWildcard) { builtUri += "*"; } resource.setURI(builtUri); } } } }
public void deploy(URL url) throws Exception { context.deploy(url); }
protected void registerOrphanVersionRemovalFilter(CoreServiceOrphanVersionRemovalFilterDescriptor contrib) { String klass = contrib.getKlass(); try { OrphanVersionRemovalFilter filter = (OrphanVersionRemovalFilter) context.getRuntimeContext().loadClass( klass).newInstance(); orphanVersionRemovalFilters.put(contrib, filter); } catch (ReflectiveOperationException e) { throw new RuntimeException("Failed to instantiate " + ORPHAN_VERSION_REMOVAL_FILTER_XP + ": " + klass, e); } }
URL url = context.getRuntimeContext().getResource(descriptor.file); try (InputStream stream = url == null ? null : url.openStream()) { if (stream == null) {
@Override public void deployContrib(String name, String contrib) throws Exception { RuntimeContext context = runtime.getContext(name); if (context == null) { context = runtime.getContext(); BundleFile file = lookupBundle(name); URL location = file.getEntry(contrib); if (location == null) { throw new AssertionError("Cannot locate " + contrib + " in " + name); } context.deploy(location); } else { context.deploy(contrib); } }
public static PackageAdmin getPackageAdmin() { BundleContext sysctx = Framework.getRuntime().getContext().getBundle().getBundleContext(); ServiceReference ref = sysctx.getServiceReference(PackageAdmin.class.getName()); return (PackageAdmin) sysctx.getService(ref); }
protected void copySchema(SchemaBindingDescriptor sd) throws IOException { if (sd.src == null || sd.src.length() == 0) { // log.error("INLINE Schemas ARE NOT YET IMPLEMENTED!"); return; } URL url = sd.context.getLocalResource(sd.src); if (url == null) { // try asking the class loader url = sd.context.getResource(sd.src); } if (url == null) { log.error("XSD Schema not found: " + sd.src); return; } try (InputStream in = url.openStream()) { sd.file = new File(schemaDir, sd.name + ".xsd"); FileUtils.copyInputStreamToFile(in, sd.file); // may overwrite } }
protected void registerVersionRemovalPolicy(CoreServicePolicyDescriptor contrib) { String klass = contrib.getKlass(); try { VersionRemovalPolicy policy = (VersionRemovalPolicy) context.getRuntimeContext().loadClass(klass).newInstance(); versionRemovalPolicies.put(contrib, policy); } catch (ReflectiveOperationException e) { throw new RuntimeException("Failed to instantiate " + VERSION_REMOVAL_POLICY_XP + ": " + klass, e); } }
protected void deployContrib(URL url) { assertEquals(runtime, Framework.getRuntime()); log.info("Deploying contribution from " + url.toString()); try { runtime.getContext().deploy(url); } catch (Exception e) { fail("Failed to deploy contrib " + url.toString()); } }
public static Bundle[] getBundles() { return Framework.getRuntime().getContext().getBundle().getBundleContext().getBundles(); }
protected URL getUrlFromPath(RouteModelResourceType res, RuntimeContext extensionContext) { String path = res.getPath(); if (path == null) { return null; } URL url; try { url = new URL(path); } catch (MalformedURLException e) { url = extensionContext.getLocalResource(path); if (url == null) { url = extensionContext.getResource(path); } if (url == null) { url = res.getClass().getResource(path); } } return url; }
Class<?> klass; try { klass = getRuntimeContext().loadClass(className); } catch (ClassNotFoundException e) { throw new RuntimeException(e);
/** * Read a component from his StreamRef and create a new component (suffixed with `-partial`, and the base component * name aliased) with only matching contributions of the extensionPoints parameter. * * @param ctx RuntimeContext in which the new component will be deployed * @param extensionPoints Set of white listed TargetExtensions * @param component Reference to the original component * @throws IOException Signals that an I/O exception has occurred. */ protected void deployPartialComponent(RuntimeContext ctx, Set<TargetExtensions> extensionPoints, StreamRef component) throws IOException { RegistrationInfo ri = ((DefaultRuntimeContext) ctx).createRegistrationInfo(component); String name = ri.getName().getName() + "-partial"; // Flatten Target Extension Points Set<String> targets = extensionPoints.stream() .map(TargetExtensions::getTargetExtensions) .flatMap(Set::stream) .collect(Collectors.toSet()); String ext = Arrays.stream(ri.getExtensions()) .filter(e -> targets.contains(TargetExtensions.newTargetExtension( e.getTargetComponent().getName(), e.getExtensionPoint()))) .map(Extension::toXML) .collect(joining()); ctx.deploy(new InlineRef(name, String.format("<component name=\"%s\">%s</component>", name, ext))); }
@Override public void activate(ComponentContext context) { super.activate(context); bundle = context.getRuntimeContext().getBundle(); }
@Override public InputSource resolveEntity(String publicId, String systemId) throws IOException { String[] parts = systemId.split("/" + SchemaManagerImpl.SCHEMAS_DIR_NAME + "/"); String importXSDSubPath = parts[1]; File xsd = new File(schemaManager.getSchemasDir(), importXSDSubPath); if (!xsd.exists()) { int idx = sd.src.lastIndexOf("/"); importXSDSubPath = sd.src.substring(0, idx + 1) + importXSDSubPath; URL url = sd.context.getLocalResource(importXSDSubPath); if (url == null) { // try asking the class loader url = sd.context.getResource(importXSDSubPath); } if (url != null) { return new InputSource(url.openStream()); } } return null; }