AutoRegisterModules( String pluginName, PluginGuiceEnvironment env, JarFile jarFile, ClassLoader classLoader) { this.pluginName = pluginName; this.env = env; this.jarFile = jarFile; this.classLoader = classLoader; this.sshGen = env.hasSshModule() ? env.newSshModuleGenerator() : null; this.httpGen = env.hasHttpModule() ? env.newHttpModuleGenerator() : null; }
private void listen(java.lang.reflect.Type type, Class<?> clazz) throws InvalidPluginException { while (type != null) { Class<?> rawType; if (type instanceof ParameterizedType) { rawType = (Class<?>) ((ParameterizedType) type).getRawType(); } else if (type instanceof Class) { rawType = (Class<?>) type; } else { return; } if (rawType.getAnnotation(ExtensionPoint.class) != null) { TypeLiteral<?> tl = TypeLiteral.get(type); if (env.hasDynamicItem(tl)) { sysSingletons.add(clazz); sysListen.put(tl, clazz); httpGen.listen(tl, clazz); sshGen.listen(tl, clazz); } else if (env.hasDynamicSet(tl)) { sysSingletons.add(clazz); sysListen.put(tl, clazz); httpGen.listen(tl, clazz); sshGen.listen(tl, clazz); } else if (env.hasDynamicMap(tl)) { if (clazz.getAnnotation(Export.class) == null) { throw new InvalidPluginException( String.format( "Class %s requires @Export(\"name\") annotation for %s", clazz.getName(), rawType.getName())); } sysSingletons.add(clazz); sysListen.put(tl, clazz); httpGen.listen(tl, clazz); sshGen.listen(tl, clazz); } else { throw new InvalidPluginException( String.format( "Cannot register %s, server does not accept %s", clazz.getName(), rawType.getName())); } return; } java.lang.reflect.Type[] interfaces = rawType.getGenericInterfaces(); if (interfaces != null) { for (java.lang.reflect.Type i : interfaces) { listen(i, clazz); } } type = rawType.getGenericSuperclass(); } }