| | |
| | | /* |
| | | * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license |
| | | * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template |
| | | */ |
| | | neon - Embeddable HTTP Server based on jdk.httpserver |
| | | Copyright (C) 2024 Ulrich Hilger |
| | | |
| | | This program is free software: you can redistribute it and/or modify |
| | | it under the terms of the GNU Affero General Public License as |
| | | published by the Free Software Foundation, either version 3 of the |
| | | License, or (at your option) any later version. |
| | | |
| | | This program is distributed in the hope that it will be useful, |
| | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| | | GNU Affero General Public License for more details. |
| | | |
| | | You should have received a copy of the GNU Affero General Public License |
| | | along with this program. If not, see <https://www.gnu.org/licenses/>. |
| | | */ |
| | | package de.uhilger.neon; |
| | | |
| | | import java.io.File; |
| | |
| | | } |
| | | |
| | | private void processZipEntry(ClassLoader urlCL, ZipEntry zipentry, String packageName, JarScannerListener l, Handler h, String contextName) { |
| | | log(Level.FINEST, zipentry.getName()); |
| | | finest(zipentry.getName()); |
| | | String zName = zipentry.getName(); |
| | | if (zName.toLowerCase().endsWith(".class")) { |
| | | int pos = zName.indexOf(".class"); |
| | | String fullClassName = zName.substring(0, pos); |
| | | log(Level.FINEST, "full class name: " + zName); |
| | | finest("full class name: " + zName); |
| | | String fullClassNameDots = fullClassName.replace('/', '.'); |
| | | log(Level.FINEST, "full class name dots: " + fullClassNameDots); |
| | | finest("full class name dots: " + fullClassNameDots); |
| | | String pkgName = getPackageName(fullClassNameDots); |
| | | log(Level.FINEST, " -- package name: " + pkgName); |
| | | finest(" -- package name: " + pkgName); |
| | | if (null != urlCL && pkgName.toLowerCase().startsWith(packageName)) { |
| | | Class c = null; |
| | | try { |
| | | c = urlCL.loadClass(fullClassNameDots); |
| | | if (c != null) { |
| | | if (c.isAnnotationPresent(Actor.class)) { |
| | | log(Level.FINER, " ---- ACTOR ---- " + fullClassNameDots); |
| | | finest(" ---- ACTOR ---- " + fullClassNameDots); |
| | | l.actorFound(c, h, contextName); |
| | | } else { |
| | | log(Level.FINER, "kein Actor " + fullClassNameDots); |
| | | finest("kein Actor " + fullClassNameDots); |
| | | } |
| | | } else { |
| | | log(Level.FINER, "class NOT loaded: " + zName); |
| | | finest("class NOT loaded: " + zName); |
| | | } |
| | | } catch (ClassNotFoundException ex) { |
| | | log(Level.FINER, " +++++ Class not found: " + ex.getMessage()); |
| | | finest(" +++++ Class not found: " + ex.getMessage()); |
| | | } |
| | | } |
| | | } |
| | |
| | | ClassLoader urlCL = null; |
| | | try { |
| | | url = getPath(c).toURL(); |
| | | log(Level.FINER, "url: " + url.getPath()); |
| | | finer("url: " + url.getPath()); |
| | | urlCL = new URLClassLoader(new URL[]{url}); |
| | | } catch (URISyntaxException ex) { |
| | | log(Level.SEVERE, ex.getMessage()); |
| | |
| | | public URI getPath(Class c) throws URISyntaxException { |
| | | //Class c = this.getClass(); |
| | | String className = c.getName(); |
| | | finer("this name: " + className); |
| | | finest("this name: " + className); |
| | | |
| | | int pos = className.indexOf(".class"); |
| | | if(pos > -1) { |
| | | String classNameWoExt = className.substring(0, pos); |
| | | } |
| | | String classNameWoPkg = className.substring(className.lastIndexOf(".") + 1); |
| | | finer("Class name: " + classNameWoPkg); |
| | | finest("Class name: " + classNameWoPkg); |
| | | String classPath = c.getResource(classNameWoPkg + ".class").getPath(); |
| | | pos = classPath.indexOf("!"); |
| | | String jarPath; |
| | |
| | | } else { |
| | | jarPath = classPath; |
| | | } |
| | | finer("path: " + jarPath); |
| | | finest("path: " + jarPath); |
| | | return new URI(jarPath); |
| | | } |
| | | |
| | | private void finest(String msg) { |
| | | log(Level.FINEST, msg); |
| | | } |
| | | |
| | | private void finer(String msg) { |
| | | log(Level.FINER, msg); |
| | | } |