@Override public void start() { // add application caches module Optional<String> applicationPackage = Optional.fromNullable(settings.getApplicationPackage()); String fullClassName = ClassUtil.buildClassName(applicationPackage, CACHES_CLASS); if (ClassUtil.doesClassExist(fullClassName)) { Class<?> moduleClass = ClassUtil.getClass(fullClassName); if (CachesModule.class.isAssignableFrom(moduleClass)) { CachesModule cachesModule = (CachesModule) ClassUtil.newInstance(moduleClass); if (cachesModule != null) { log.info("Setting up JCache caches in '{}'", cachesModule.getClass().getName()); cachesModule.setup(settings, cachingProvider.getCacheManager()); } } } }
public static <T extends Annotation> T getAnnotation(Class<?> objectClass, Class<T> annotationClass) { if (objectClass == null || Object.class == objectClass) { return null; } T annotation = objectClass.getAnnotation(annotationClass); if (annotation != null) { return annotation; } return getAnnotation(objectClass.getSuperclass(), annotationClass); }
private static InputStream loadFromClassPath(String path) throws IOException { log.debug("Opening resource from classpath '{}'", path); return ClassUtil.getResource(path).openStream(); }
public static boolean doesClassExist(Optional<String> packageName, String className) { String fullClassName = buildClassName(packageName, className); return doesClassExist(fullClassName); }
public static <T> Class<T> getClass(Optional<String> packageName, String className) { String fullClassName = buildClassName(packageName, className); return getClass(fullClassName); }
private Class<? extends Fathom> getFathomClass(Optional<String> applicationPackage) { String fathomClassName = ClassUtil.buildClassName(applicationPackage, FATHOM_CLASS); final Class<? extends Fathom> fathomClass; if (ClassUtil.doesClassExist(fathomClassName)) { final Class<?> specifiedClass = ClassUtil.getClass(fathomClassName); if (Fathom.class.isAssignableFrom(specifiedClass)) { fathomClass = (Class<? extends Fathom>) specifiedClass; } else { throw new FathomException("Your Fathom class '{}' does not implement '{}'!", fathomClassName, Fathom.class.getName()); } } else { // use the default Fathom implementation fathomClass = Ftm.class; } return fathomClass; }
Preconditions.checkNotNull(realmType, "Realm 'type' is null!"); if (ClassUtil.doesClassExist(realmType)) { Class<? extends Realm> realmClass = ClassUtil.getClass(realmType); if (RequireUtil.allowClass(settings, realmClass)) { try {
protected void validateResponseHeaders(Return aReturn, Context context) { for (Class<? extends ReturnHeader> returnHeader : aReturn.headers()) { ReturnHeader header = ClassUtil.newInstance(returnHeader); String name = header.getHeaderName(); String defaultValue = header.getDefaultValue(); // FIXME need to expose getHeader in Pippo Response String value = null; //context.getHeader(name); if (value == null) { if (Strings.isNullOrEmpty(defaultValue)) { log.warn("No value specified for the declared response header '{}'", name); } else { context.setHeader(name, defaultValue); log.debug("No value specified for the declared response header '{}', defaulting to '{}'", name, defaultValue); } } } }
public static String loadStringResource(String resource) { try { URL url; if (resource.startsWith("classpath:")) { url = getResource(resource.substring("classpath:".length())); } else if (resource.startsWith("url:")) { url = new URL(resource.substring("url:".length())); } else if (resource.startsWith("file:")) { url = new URL(resource.substring("file:".length())); } else { url = new URL(resource); } return loadStringResource(url); } catch (IOException e) { throw new FathomException(e, "Failed to read String resource from '{}'", resource); } }
final String packagePath = packageName.replace('.', '/'); final String packagePrefix = packageName + '.'; List<URL> packageUrls = getResources(packagePath); for (URL packageUrl : packageUrls) { if (packageUrl.getProtocol().equals("jar")) { String className = entry.getName().replace(".class", "").replace('/', '.'); if (className.startsWith(packagePrefix)) { Class<?> aClass = getClass(className); classes.add(aClass); String className = line.replace(".class", "").replace('/', '.'); try { Class<?> aClass = getClass(packagePrefix + className); return aClass; } catch (Exception e) {
private KeycloakConfig parseKeycloakConfig(String configFile) { String content = ClassUtil.loadStringResource(configFile); if (content == null) { log.warn("Failed to find Keycloak config '{}'", configFile); } else { try { return JsonSerialization.readValue(content, KeycloakConfig.class); } catch (IOException e) { throw new FathomException("Failed to deserialize {}", configFile, e); } } return new KeycloakConfig(); }
for (Field field : ClassUtil.getAllFields(modelClass)) { } else if (Collection.class.isAssignableFrom(fieldType)) { Class<?> componentClass = ClassUtil.getGenericType(field); Property componentProperty = getSwaggerProperty(swagger, componentClass); ArrayProperty arrayProperty = new ArrayProperty();
public static List<Class<? extends RouteHandler<Context>>> collectRouteInterceptors(Method method) { List<Class<? extends RouteHandler<Context>>> classList = ClassUtil.collectNestedAnnotation(method, RouteInterceptor.class).stream() .map(RouteInterceptor::value) .collect(Collectors.toList()); return classList; }
public static List<Field> getAllFields(Class clazz) { List<Field> allFields = new ArrayList<>(); allFields.addAll(Arrays.asList(clazz.getDeclaredFields())); Class superClass = clazz.getSuperclass(); if (superClass != null && !superClass.equals(Object.class)) { allFields.addAll(getAllFields(superClass)); } return allFields; }
private void initializeRouter(Optional<String> applicationPackage) { String routesClassName = ClassUtil.buildClassName(applicationPackage, ROUTES_CLASS); if (ClassUtil.doesClassExist(routesClassName)) { Class<?> routesClass = ClassUtil.getClass(routesClassName); if (RoutesModule.class.isAssignableFrom(routesClass)) { RoutesModule routes = (RoutesModule) injector.getInstance(routesClass); routes.init(); } else { throw new FathomException("Your Routes class '{}' does not subclass '{}'!", routesClassName, RoutesModule.class.getName()); } } else { log.debug("Did not find '{}' in your application!", routesClassName); } }
Preconditions.checkNotNull(realmType, "Realm 'type' is null!"); if (ClassUtil.doesClassExist(realmType)) { Class<? extends Realm> realmClass = ClassUtil.getClass(realmType); if (RequireUtil.allowClass(settings, realmClass)) { try {
protected void validateResponseHeaders(Return aReturn, Context context) { for (Class<? extends ReturnHeader> returnHeader : aReturn.headers()) { ReturnHeader header = ClassUtil.newInstance(returnHeader); String name = header.getHeaderName(); String defaultValue = header.getDefaultValue(); // FIXME need to expose getHeader in Pippo Response String value = null; //context.getHeader(name); if (value == null) { if (Strings.isNullOrEmpty(defaultValue)) { log.warn("No value specified for the declared response header '{}'", name); } else { context.setHeader(name, defaultValue); log.debug("No value specified for the declared response header '{}', defaulting to '{}'", name, defaultValue); } } } }
protected String getNotes(Method method) { if (method.isAnnotationPresent(ApiNotes.class)) { ApiNotes apiNotes = method.getAnnotation(ApiNotes.class); String resource = "classpath:swagger/" + method.getDeclaringClass().getName().replace('.', '/') + "/" + method.getName() + ".md"; if (!Strings.isNullOrEmpty(apiNotes.value())) { resource = apiNotes.value(); } if (resource.startsWith("classpath:")) { String content = ClassUtil.loadStringResource(resource); if (Strings.isNullOrEmpty(content)) { log.error("'{}' specifies @{} but '{}' was not found!", Util.toString(method), ApiNotes.class.getSimpleName(), resource); } return content; } else { String notes = translate(apiNotes.key(), apiNotes.value()); return notes; } } return null; }
for (Field field : ClassUtil.getAllFields(modelClass)) { } else if (Collection.class.isAssignableFrom(fieldType)) { Class<?> componentClass = ClassUtil.getGenericType(field); Property componentProperty = getSwaggerProperty(swagger, componentClass); ArrayProperty arrayProperty = new ArrayProperty();
public static List<Class<? extends RouteHandler<Context>>> collectRouteInterceptors(Method method) { List<Class<? extends RouteHandler<Context>>> classList = ClassUtil.collectNestedAnnotation(method, RouteInterceptor.class).stream() .map(RouteInterceptor::value) .collect(Collectors.toList()); return classList; }