From 1f6776f237cb98c1222ee9dd2f75220de0d02c34 Mon Sep 17 00:00:00 2001 From: ulrich Date: Sun, 01 Dec 2024 17:07:47 +0000 Subject: [PATCH] wireActors zugunsten von Scanner aufgeloest --- src/de/uhilger/neon/Factory.java | 46 +++++++--------------------------------------- 1 files changed, 7 insertions(+), 39 deletions(-) diff --git a/src/de/uhilger/neon/Factory.java b/src/de/uhilger/neon/Factory.java index 48ceb6d..ddbb717 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,9 +187,7 @@ ctxAttrs.putAll(cd.attributes); if (h instanceof Handler) { for (String packageName : packageNames) { - wireActors(c, - packageName, Actor.class, (Handler) h, - cd.attributes.get("contextName")); + scn.process(this, packageName, (Handler) h, cd.attributes.get("contextName")); ctx.getAttributes().put("serverDataProviderList", sdp); } } @@ -262,36 +260,6 @@ | InvocationTargetException ex) { // Klasse nicht gefunden. Muss das geloggt oder sonstwie behandel werden? return null; - } - } - - @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); - } - } - } else { - js.processZipContent(packageName, this, h, contextName); } } @@ -427,7 +395,7 @@ } } - /* -------------- JarScannerListener Implementierung --------------- */ + /* -------------- ScannerListener Implementierung --------------- */ @Override public void annotationFound(Class foundClass, Handler h, String contextName) { wire(h, foundClass, contextName); -- Gitblit v1.9.3