work webstart

This commit is contained in:
7u83 2017-03-21 07:43:45 +01:00
parent 9fa4fdbf2a
commit 589b75800f

View File

@ -25,6 +25,7 @@
*/ */
package sesim; package sesim;
import gui.Globals;
import java.io.File; import java.io.File;
import java.io.FileFilter; import java.io.FileFilter;
import java.io.FileInputStream; import java.io.FileInputStream;
@ -49,6 +50,20 @@ import java.util.logging.Logger;
*/ */
public class AutoTraderLoader { public class AutoTraderLoader {
private ArrayList <String>pathlist;
private ArrayList<Class<AutoTraderInterface>> traders_cache;
public AutoTraderLoader(ArrayList <String> pathlist){
setPathList(pathlist);
}
public final void setPathList(ArrayList <String> pathlist){
this.pathlist=pathlist;
this.traders_cache=null;
}
/** /**
* Check if a given class can instaciated as AutoTrader. * Check if a given class can instaciated as AutoTrader.
* *
@ -60,13 +75,18 @@ public class AutoTraderLoader {
return false; return false;
} }
System.out.printf("Trav. modifiers\n");
do { do {
for (Class<?> i : cls.getInterfaces()) { for (Class<?> i : cls.getInterfaces()) {
Globals.LOGGER.info(String.format("Interface: %s", i.getCanonicalName()));
String cn = AutoTraderInterface.class.getCanonicalName();
Globals.LOGGER.info(String.format("Interface1: %s", cn));
// if (i == (AutoTraderInterface.class)) {
if (cn.endsWith(i.getCanonicalName())){
Globals.LOGGER.info("YEEEEA");
System.out.printf("Interface: %s\n", i.getCanonicalName());
if (i.equals(AutoTraderInterface.class)) {
System.out.printf("Yea! An autotrader\n");
return true; return true;
} }
} }
@ -77,7 +97,12 @@ public class AutoTraderLoader {
Class<AutoTraderInterface> loadAutoTraderClass(String filename, String classname) { Class<AutoTraderInterface> loadAutoTraderClass(String filename, String classname) {
System.out.printf("Comming in width %s %s\n", filename, classname); System.out.printf("Comming in width %s %s\n", filename, classname);
Globals.LOGGER.info(String.format("Comming in width %s %s\n", filename, classname));
if (classname == null) { if (classname == null) {
System.out.printf("Calssname is null\n"); System.out.printf("Calssname is null\n");
@ -95,27 +120,64 @@ public class AutoTraderLoader {
Logger.getLogger(AutoTraderLoader.class.getName()).log(Level.SEVERE, null, ex); Logger.getLogger(AutoTraderLoader.class.getName()).log(Level.SEVERE, null, ex);
} }
Globals.LOGGER.info(String.format("URL: %s", url.toString()));
URL[] urls = new URL[]{url}; URL[] urls = new URL[]{url};
// Create a new class loader with the directory // Create a new class loader with the directory
ClassLoader cl = new URLClassLoader(urls); ClassLoader cl = new URLClassLoader(urls);
try { try {
Class<?> cls = cl.loadClass(clnam); Globals.LOGGER.info("try cl");
System.out.printf("Check Class: %s\n", cls.getCanonicalName()); // Class<?> cls = cl.loadClass(clnam);
if (isAutoTrader(cls)) { Class<?>c = cl.loadClass(clnam);
return (Class<AutoTraderInterface>) cls; if (c==null){
Globals.LOGGER.info("loader c was null");
}
Globals.LOGGER.info("Ccast");
Class<AutoTraderInterface> cls = (Class<AutoTraderInterface>)c; // cl.loadClass(clnam);
return cls;
/* if (cls == null){
} }
System.out.printf("Check Class: %s\n", cls.getCanonicalName());
Globals.LOGGER.info(String.format("Class prope %s", cls.getCanonicalName()));
if (isAutoTrader(cls)) {
Class<AutoTraderInterface> claa;
claa = (Class<AutoTraderInterface>) cls;
if (claa==null){
Globals.LOGGER.info("claa = null");
}
Globals.LOGGER.info("return ok");
return claa;
//return (Class<AutoTraderInterface>) cls;
//return (Class<AutoTraderInterface>) cls;
}
*/
} catch (ClassNotFoundException ex) { } catch (ClassNotFoundException ex) {
// something wnet wrong, but we ignore it // something wnet wrong, but we ignore it
System.out.printf("Class not found\n"); System.out.printf("Class not found\n");
Globals.LOGGER.info("Class not loadable");
} }
return null; return null;
} }
ArrayList<Class<AutoTraderInterface>> traders_cache = null;
/* public ArrayList<Class<AutoTraderInterface>> getTradersX() {
String[] a = System.getProperty("java.class.path").split(System.getProperty("path.separator"));
this.pathlist=new ArrayList<>(Arrays.asList(a));
return getTraders0();
}
*/
public ArrayList<Class<AutoTraderInterface>> getTraders() { public ArrayList<Class<AutoTraderInterface>> getTraders() {
@ -123,20 +185,20 @@ public class AutoTraderLoader {
return traders_cache; return traders_cache;
} }
int curlen = 0;
ArrayList<Class<AutoTraderInterface>> traders; ArrayList<Class<AutoTraderInterface>> traders;
traders = new ArrayList<>(); traders = new ArrayList<>();
String cp = System.getProperty("java.class.path");
System.out.printf("Calss Pass: %s\n", cp);
for (String classpathEntry : System.getProperty("java.class.path").split(System.getProperty("path.separator"))) {
for (String classpathEntry : pathlist) {
Globals.LOGGER.info(String.format("Here we ar looking now %s", classpathEntry));
Consumer<? super Path> pf = (Object t) -> { Consumer<? super Path> pf = (Object t) -> {
String fn = ((Path) t).toString(); String fn = ((Path) t).toString();
System.out.printf("Checking out file %s\n", fn); // System.out.printf("Checking out file %s\n", fn);
Globals.LOGGER.info(String.format("Checking out file %s\n", fn));
if (fn.toLowerCase().endsWith(".class")) { if (fn.toLowerCase().endsWith(".class")) {
String cl = fn.substring(classpathEntry.length()); String cl = fn.substring(classpathEntry.length());
@ -150,24 +212,33 @@ public class AutoTraderLoader {
} }
if (fn.toLowerCase().endsWith(".jar")) { if (fn.toLowerCase().endsWith(".jar")) {
System.out.printf("Its a jar!\n"); System.out.printf("Its a jar!\n");
Globals.LOGGER.info("Its a jar");
JarInputStream is = null; JarInputStream is = null;
try { try {
File jar = new File(fn); File jar = new File(fn);
is = new JarInputStream(new FileInputStream(jar)); is = new JarInputStream(new FileInputStream(jar));
JarEntry entry; JarEntry entry;
Globals.LOGGER.info("starting entries");
while ((entry = is.getNextJarEntry()) != null) { while ((entry = is.getNextJarEntry()) != null) {
Globals.LOGGER.info(String.format("Jar entry: %s", entry));
if (entry.getName().endsWith(".class")) { if (entry.getName().endsWith(".class")) {
System.out.printf("Entry: %s\n", entry.getName()); System.out.printf("Entry: %s\n", entry.getName());
String fn0 = entry.getName(); String fn0 = entry.getName();
Class<AutoTraderInterface> cls = loadAutoTraderClass(fn, "/"+entry.getName()); Class<AutoTraderInterface> cls = loadAutoTraderClass(fn, "/"+entry.getName());
if (cls != null) { if (cls != null) {
traders.add(cls); traders.add(cls);
} }
Globals.LOGGER.info("clas was null");
} }
} }
} catch (IOException ex) { } catch (IOException ex) {
Globals.LOGGER.info("ioeception");
Logger.getLogger(AutoTraderLoader.class.getName()).log(Level.SEVERE, null, ex); Logger.getLogger(AutoTraderLoader.class.getName()).log(Level.SEVERE, null, ex);
} finally { } finally {
try { try {
@ -196,6 +267,7 @@ public class AutoTraderLoader {
public ArrayList<String> getDefaultStrategyNames(boolean devel) { public ArrayList<String> getDefaultStrategyNames(boolean devel) {
ArrayList<Class<AutoTraderInterface>> trclasses; ArrayList<Class<AutoTraderInterface>> trclasses;
trclasses = this.getTraders(); trclasses = this.getTraders();
ArrayList<String> ret = new ArrayList<>(); ArrayList<String> ret = new ArrayList<>();
trclasses = getTraders(); trclasses = getTraders();