/** * Loads a class file by {@code java.lang.invoke.MethodHandles.Lookup}. * It is obtained by using {@code neighbor}. * * @param neighbor a class belonging to the same package that the loaded * class belogns to. * @param bcode the bytecode. * @since 3.24 */ public static Class<?> toClass(Class<?> neighbor, byte[] bcode) throws CannotCompileException { try { DefineClassHelper.class.getModule().addReads(neighbor.getModule()); Lookup lookup = MethodHandles.lookup(); Lookup prvlookup = MethodHandles.privateLookupIn(neighbor, lookup); return prvlookup.defineClass(bcode); } catch (IllegalAccessException | IllegalArgumentException e) { throw new CannotCompileException(e.getMessage() + ": " + neighbor.getName() + " has no permission to define the class"); } }
/** * Loads a class file by {@code java.lang.invoke.MethodHandles.Lookup}. * It is obtained by using {@code neighbor}. * * @param neighbor a class belonging to the same package that the loaded * class belogns to. * @param bcode the bytecode. * @since 3.24 */ public static Class<?> toClass(Class<?> neighbor, byte[] bcode) throws CannotCompileException { try { DefineClassHelper.class.getModule().addReads(neighbor.getModule()); Lookup lookup = MethodHandles.lookup(); Lookup prvlookup = MethodHandles.privateLookupIn(neighbor, lookup); return prvlookup.defineClass(bcode); } catch (IllegalAccessException | IllegalArgumentException e) { throw new CannotCompileException(e.getMessage() + ": " + neighbor.getName() + " has no permission to define the class"); } }
@Override public boolean appliesTo(SSLEngine sslEngine) { Module module = sslEngine.getClass().getModule(); return module!=null && "java.base".equals(module.getName()); }
@Override public boolean appliesTo(SSLEngine sslEngine) { Module module = sslEngine.getClass().getModule(); return module!=null && "java.base".equals(module.getName()); }
@Override protected Lookup computeValue(Class<?> type) { if ( !getClass().getModule().canRead( type.getModule() ) ) { getClass().getModule().addReads( type.getModule() ); } packageOpener.openPackageIfNeeded( type.getModule(), type.getPackageName(), FieldValueReaderImpl.class.getModule() ); try { return MethodHandles.privateLookupIn( type, MethodHandles.lookup() ); } catch (IllegalAccessException e) { throw new RuntimeException( e ); } } };
private static Module getCallerModule() { return StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE) .walk(stackFrameStream -> stackFrameStream .map(StackWalker.StackFrame::getDeclaringClass) .map(Class::getModule) .filter(module -> module != ModuleContextRegistry.class.getModule()) .findFirst() .orElseThrow(() -> new UnsupportedOperationException("Can only get an application context for a Module annotated with @ModuleContext"))); }
@Nullable @Override public Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException { Module usingModule = beanClass.getModule(); for (Field field : beanClass.getDeclaredFields()) { if (field.isAnnotationPresent(ModuleServiceReference.class)) { Class<?> injectionType = field.getType(); if(injectionType.isAssignableFrom(List.class)) { registerServiceListFactoryBean(usingModule, field); } else { registerServiceFactoryBean(usingModule, field); } } } return null; }
private void buildRef(MetadataItem.Reference reference, StringBuilder builder) { builder.append(reference.serviceClass().getModule().getName()); builder.append(COLON); builder.append(reference.serviceClass().getName()); builder.append(SEMI_COLON); builder.append(reference.setterMethodName()); builder.append(SEMI_COLON); builder.append(reference.isList()); builder.append(SEMI_COLON); builder.append(reference.isOptional()); }
public static Module getModule(Class cls) { if (JAVA_NINE) { return new Module9(cls.getModule()); } return new ModuleDummy(); }
public StaticContentBuilderImpl( @Message InjectionPoint injectionPoint, Provider<HttpContext> httpContextProv, ResourceKit resourceKit) { this.httpContextProv = httpContextProv; this.resourceKit = resourceKit; if (injectionPoint != null) { String moduleName = injectionPoint.getTargetClass().getModule().getName(); if (moduleName!=null) { String contentRootPkg = moduleName.replace('.', '/') + "/" + DEFAULT_RESOURCES_DIR; this.resourcesRoot = contentRootPkg; } else { throw new RuntimeException("Unnamed module for injection point: "+injectionPoint); } } log.debug("Initial content root: " + resourcesRoot); }
/** * Creates a module info. * * @param hook the module hook */ public ModuleInfo(ModuleHook hook) { this.hook = hook; this.urlPath = hook.getClass().getProtectionDomain().getCodeSource().getLocation().getPath(); this.module = hook.getClass().getModule(); if (module == null || !module.isNamed()) { throw new TentackleRuntimeException(hook.getClass() + " does not belong to a named module"); } requiredModuleNames = new HashSet<>(); for (ModuleDescriptor.Requires req : module.getDescriptor().requires()) { requiredModuleNames.add(req.name()); } }
throws IOException, SuselMetadataNullException { var module = serviceProvider.getModule(); var metadata = perModuleMetadataCache.get(module); var properties = new Properties(); try (InputStream inStream = serviceProvider.getModule().getResourceAsStream(SUSEL_METADATA_RESOURCE_PATH)) { properties.load(inStream); } catch (NullPointerException ex) {
/** * Loads a class file by {@code java.lang.invoke.MethodHandles.Lookup}. * It is obtained by using {@code neighbor}. * * @param neighbor a class belonging to the same package that the loaded * class belogns to. * @param bcode the bytecode. * @since 3.24 */ public static Class<?> toClass(Class<?> neighbor, byte[] bcode) throws CannotCompileException { try { DefineClassHelper.class.getModule().addReads(neighbor.getModule()); Lookup lookup = MethodHandles.lookup(); Lookup prvlookup = MethodHandles.privateLookupIn(neighbor, lookup); return prvlookup.defineClass(bcode); } catch (IllegalAccessException | IllegalArgumentException e) { throw new CannotCompileException(e.getMessage() + ": " + neighbor.getName() + " has no permission to define the class"); } }
throws IOException, SuselMetadataNullException { var module = serviceProvider.getModule(); var metadata = perModuleMetadataCache.get(module); var properties = new Properties(); try (InputStream inStream = serviceProvider.getModule().getResourceAsStream(SUSEL_METADATA_RESOURCE_PATH)) { properties.load(inStream); } catch (NullPointerException ex) {
protected ServiceLocator(Class<?> caller, Class<S> service, ClassLoader classLoader, Predicate<Class<? extends S>> classFilter) { if (caller == null) { throw new ServiceConfigurationError("Caller class is null"); } this.caller = caller; if (service == null) { throw new ServiceConfigurationError("Service class is null"); } this.service = service; Module callerModule = caller.getModule(); if (!callerModule.canUse(service)) { throw new ServiceConfigurationError("Module '" + callerModule + "' does not declare 'uses' for class " + service.getName()); } if (classLoader != null) { this.classLoader = classLoader; } else { this.classLoader = ClassLoader.getSystemClassLoader(); } this.classFilter = classFilter; this.acc = (System.getSecurityManager() != null) ? AccessController.getContext() : null; }
public static <SERVICETYPE> SERVICETYPE retrieveInstanceFromContext(Class<SERVICETYPE> serviceClass) { LOGGER.log(INFO, "Providing instance of " + serviceClass.getSimpleName() + " from module " + serviceClass.getModule().getName()); GenericApplicationContext context = get(); if (!context.isActive()) { LOGGER.log(INFO, "Lazy starting ApplicationContext for module " + serviceClass.getModule().getName()); context.refresh(); } return context.getBean(serviceClass); }
extraReads.add(AccessEnabler.class.getModule());
extraReads.add(AccessEnabler.class.getModule());