private void export(ClassData def) throws InvalidPluginException { Class<?> clazz; try { clazz = Class.forName(def.className, false, classLoader); } catch (ClassNotFoundException err) { throw new InvalidPluginException( String.format("Cannot load %s with @Export(\"%s\")", def.className, def.exportedAsName), err); } Export export = clazz.getAnnotation(Export.class); if (export == null) { PluginLoader.log.warn( String.format( "In plugin %s asm incorrectly parsed %s with @Export(\"%s\")", pluginName, clazz.getName(), def.exportedAsName)); return; } if (is("org.apache.sshd.server.Command", clazz)) { if (sshGen != null) { sshGen.export(export, clazz); } } else if (is("javax.servlet.http.HttpServlet", clazz)) { if (httpGen != null) { httpGen.export(export, clazz); listen(clazz, clazz); } } else { int cnt = sysListen.size(); listen(clazz, clazz); if (cnt == sysListen.size()) { // If no bindings were recorded, the extension isn't recognized. throw new InvalidPluginException( String.format( "Class %s with @Export(\"%s\") not supported", clazz.getName(), export.value())); } } }
AutoRegisterModules discover() throws InvalidPluginException { sysSingletons = Sets.newHashSet(); sysListen = LinkedListMultimap.create(); if (sshGen != null) { sshGen.setPluginName(pluginName); } if (httpGen != null) { httpGen.setPluginName(pluginName); } scan(); if (!sysSingletons.isEmpty() || !sysListen.isEmpty()) { sysModule = makeSystemModule(); } if (sshGen != null) { sshModule = sshGen.create(); } if (httpGen != null) { httpModule = httpGen.create(); } return this; }
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(); } }