From 692dc7be9791f131bfb253c13363b75bc41b8467 Mon Sep 17 00:00:00 2001 From: ulrich Date: Sun, 01 Dec 2024 16:56:40 +0000 Subject: [PATCH] JarScanner umbenannt, das Laden von Klassen ohne Jar ebenfalls auf Scanner umgestellt --- src/de/uhilger/neon/Factory.java | 45 ++++++++++++--------------------------------- 1 files changed, 12 insertions(+), 33 deletions(-) diff --git a/src/de/uhilger/neon/Factory.java b/src/de/uhilger/neon/Factory.java index 48ceb6d..7cb2a86 100644 --- a/src/de/uhilger/neon/Factory.java +++ b/src/de/uhilger/neon/Factory.java @@ -23,7 +23,6 @@ import com.sun.net.httpserver.HttpContext; import com.sun.net.httpserver.HttpHandler; import com.sun.net.httpserver.HttpServer; -import de.uhilger.neon.JarScanner.JarScannerListener; import de.uhilger.neon.entity.ContextDescriptor; import de.uhilger.neon.entity.NeonDescriptor; import de.uhilger.neon.entity.ServerDescriptor; @@ -48,6 +47,7 @@ import java.util.concurrent.Executors; import java.util.logging.Level; import java.util.logging.Logger; +import de.uhilger.neon.Scanner.ScannerListener; /** * Einen Neon-Server aus einer Beschreibungsdatei herstellen @@ -65,7 +65,7 @@ * @author Ulrich Hilger * @version 1, 6.2.2024 */ -public class Factory implements JarScannerListener { +public class Factory implements ScannerListener { public Factory() { listeners = new ArrayList<>(); @@ -138,8 +138,8 @@ if (packageNames == null) { packageNames = d.actorPackages; - } - addContexts(starter, d, server, sd.contexts, packageNames, sdp); + } + addContexts(new Scanner(starter, Actor.class), d, server, sd.contexts, packageNames, sdp); server.setExecutor(Executors.newFixedThreadPool(10)); server.start(); @@ -167,7 +167,7 @@ return auth; } - private void addContexts(Class c, NeonDescriptor d, HttpServer server, List contextList, List<String> packageNames, + private void addContexts(Scanner scn, NeonDescriptor d, HttpServer server, List contextList, List<String> packageNames, List<DataProvider> sdp) throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, IOException { @@ -187,8 +187,8 @@ ctxAttrs.putAll(cd.attributes); if (h instanceof Handler) { for (String packageName : packageNames) { - wireActors(c, - packageName, Actor.class, (Handler) h, + wireActors(scn, + packageName, (Handler) h, cd.attributes.get("contextName")); ctx.getAttributes().put("serverDataProviderList", sdp); } @@ -266,32 +266,11 @@ } @SuppressWarnings("unchecked") - private void wireActors(Class c, String packageName, Class annotation, Handler h, String contextName) { - JarScanner js = new JarScanner(c, annotation); - if (!js.isJar()) { - ClassLoader cl = c.getClassLoader(); - InputStream stream = cl - .getResourceAsStream(packageName.replaceAll("[.]", "/")); - BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); - Iterator i = reader.lines().iterator(); - while (i.hasNext()) { - String line = i.next().toString(); - if (line.endsWith(".class")) { - try { - Class actorClass = cl.loadClass(packageName + "." - + line.substring(0, line.lastIndexOf('.'))); - if (actorClass != null && actorClass.isAnnotationPresent(annotation)) { - wire(h, actorClass, contextName); - } - } catch (ClassNotFoundException ex) { - // Klasse nicht gefunden. Muss das geloggt oder sonstwie behandel werden? - } - } else { - wireActors(c, packageName + "." + line, annotation, h, contextName); - } - } + private void wireActors(Scanner scn, String packageName, /*Class annotation, */Handler h, String contextName) { + if (!scn.isJar()) { + scn.processClasses(this, packageName, h, contextName); } else { - js.processZipContent(packageName, this, h, contextName); + scn.processZipContent(packageName, this, h, contextName); } } @@ -427,7 +406,7 @@ } } - /* -------------- JarScannerListener Implementierung --------------- */ + /* -------------- ScannerListener Implementierung --------------- */ @Override public void annotationFound(Class foundClass, Handler h, String contextName) { wire(h, foundClass, contextName); -- Gitblit v1.9.3