static {
if(loader == null) {
loader = createDummy();
loader.register(loader.new DT_SERIALIZEDDATA().getDescriptions());
loader.register(loader.new DT_CLASSDATA().getDescriptions());
URL url = loader.getResource("datatypes/viewer");
if(url != null) loader.scan(url, true);
url = loader.getResource("datatypes/codecs");
if(url != null) loader.scan(url, true);
try {
url = new File(home + sp + "classes" + sp + "datatypes" + sp + "viewer").toURL();
if(url != null) loader.scan(url, true);
url = new File(home + sp + "classes" + sp + "datatypes" + sp + "codecs").toURL();
if(url != null) loader.scan(url, true);
} catch (MalformedURLException e) {
}
int sizeold = failCache.size() + 1;
while(!failCache.isEmpty() && failCache.size() != sizeold) {
sizeold = failCache.size();
HashMap tmp = (HashMap) failCache.clone();
Iterator it = tmp.entrySet().iterator();
while(it.hasNext()) {
Map.Entry e = (Map.Entry) it.next();
String key = (String) e.getKey();
byte[] value = (byte[]) e.getValue();
try {
Class c = loader.defineClass(key, value, 0, value.length);
DataType dd = (DataType) c.newInstance();
loader.register(dd.getDescriptions());
failCache.remove(key);
} catch (ClassCastException ee) {
failCache.remove(key);
} catch (InstantiationException ee) {
failCache.remove(key);
} catch (IllegalAccessException ee) {
} catch (LinkageError ee) {
if(ee.getMessage().indexOf("duplicate") != -1) {
try {
if(key.indexOf("$") == -1) {
DataType dd = (DataType) Class.forName(key, false, loader).newInstance();
loader.register(dd.getDescriptions());
}
failCache.remove(key);
} catch (NoClassDefFoundError eee) {
} catch (ClassNotFoundException eee) {
} catch (ClassCastException eee) {
} catch (InstantiationException eee) {
failCache.remove(key);
} catch (IllegalAccessException eee) {
}
}
}
}
}
}
}
//Ende init Datatype_Library...
private void scan(URL filename, boolean checked)
{
try {
DT_Viewer dtv = getFile(filename, true);
if(dtv.isDrawer()) {
String[] list = ((DIRECTORY) dtv).getDir();
for(int x = 0; x < list.length; x++) scan(new URL(dtv.base, list[x]), true);
} else if(BINARY.class.isInstance(dtv)) {
String tmp = dtv.base.getFile();
tmp = tmp.substring(tmp.indexOf("datatypes"));
int x;
if((x = tmp.indexOf(".class")) != - 1 && !tmp.contains("$")) {
Class c = Class.forName(tmp.substring(0, x).replace("/", "."));
DataType d = (DataType) c.newInstance();
register(d.getDescriptions());
} else if((x = tmp.indexOf(".jar")) != -1) {
addJar(dtv.base);
}
}
} catch (InstantiationException e) {
boolean bp = true;
} catch (LinkageError e) {
boolean bp = true;
} catch (IllegalAccessException e) {
boolean bp = true;
} catch (ClassNotFoundException e) {
boolean bp = true;
} catch (FileNotFoundException e) {
boolean bp = true;
} catch (IOException e) {
boolean bp = true;
}
}
//Ende URL-Scan
private final void addJar(URL jarbase)
{
try {
JarFile jf = new JarFile(new File(jarbase.toURI()));
DT_Viewer dtv = null;
for(Enumeration e = jf.entries(); e.hasMoreElements();) try {
JarEntry entry = (JarEntry) e.nextElement();
InputStream i = jf.getInputStream(entry);
ByteArrayOutputStream o = new ByteArrayOutputStream();
int x;
while((x = i.read()) != -1) o.write(x);
i.close();
o.close();
base = new URL(jarbase, entry.getName());
buf = o.toByteArray();
dtv = identify(buf, true);
if(dtv.isDrawer()) {
String[] list = ((DIRECTORY) dtv).getDir();
for(x = 0; x < list.length; x++) scan(new URL(dtv.base, list[x]), true);
} else if(BINARY.class.isInstance(dtv)) {
String tmp = dtv.base.getFile();
tmp = tmp.substring(tmp.lastIndexOf("datatypes"));
if((x = tmp.indexOf(".class")) != - 1) {
Class c = Class.forName(tmp.substring(0, x).replace("/", "."));
DataType d = (DataType) c.newInstance();
register(d.getDescriptions());
} else if((x = tmp.indexOf(".jar")) != -1) {
addJar(dtv.base);
}
}
} catch (InstantiationException ee) {
boolean bp = true;
} catch (ClassCastException ee) {
boolean bp = true;
} catch (IllegalAccessException ee) {
boolean bp = true;
} catch (ClassNotFoundException ee) {
defineClass(ee.getMessage(), ((BINARY) dtv).buf);
} catch (FileNotFoundException ee) {
boolean bp = true;
}
} catch (IOException e) {
boolean bp = true;
} catch (URISyntaxException e) {
boolean bp = true;
}
base = null;
buf = null;
}
//Ende Scan-JarFile
private final Class defineClass(String name, byte[] buffer)
{
// extract PackageName
String pname = (name.indexOf(".") != -1)? name.substring(0, name.lastIndexOf(".")) : "";
if(!pname.equals("")) try {
definePackage(pname, null, null, null, null, null, null, null);
} catch(IllegalArgumentException e) {
}
Class rc = null;
try {
rc = defineClass(name, buffer, 0, buffer.length);
} catch (NoClassDefFoundError e) {
failCache.put(name, buffer);
}
if(rc != null) try {
DataType d = (DataType) rc.newInstance();
register(d.getDescriptions());
} catch (ClassCastException e) {
} catch (IllegalAccessException e) {
boolean bp = true;
} catch (InstantiationException e) {
boolean bp = true;
} catch (NoClassDefFoundError e) {
failCache.put(name, buffer);
rc = null;
} catch (Throwable e) {
boolean bp = true;
}
return rc;
}
//Ende defineClass