Bug fixes
This commit is contained in:
parent
c22c866000
commit
a199165756
10 changed files with 171 additions and 55 deletions
|
|
@ -89,8 +89,9 @@ public class CompactLogFormatter extends Formatter{
|
|||
ret.append( data );
|
||||
ret.append( array[i] );
|
||||
}
|
||||
ret.append( '\n' );
|
||||
}
|
||||
ret.append( '\n' );
|
||||
|
||||
if( record.getThrown() != null ){
|
||||
StringOutputStream out = new StringOutputStream();
|
||||
record.getThrown().printStackTrace(new PrintStream(out));
|
||||
|
|
|
|||
31
src/zutil/osal/HALLinuxImpl.java
Normal file
31
src/zutil/osal/HALLinuxImpl.java
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright (c) 2015 Ziver
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.osal;
|
||||
|
||||
/**
|
||||
* Created by Ziver on 2015-04-07.
|
||||
*/
|
||||
public class HALLinuxImpl implements HardwareAbstractionLayer{
|
||||
|
||||
protected HALLinuxImpl(){}
|
||||
}
|
||||
29
src/zutil/osal/HardwareAbstractionLayer.java
Normal file
29
src/zutil/osal/HardwareAbstractionLayer.java
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Copyright (c) 2015 Ziver
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.osal;
|
||||
|
||||
/**
|
||||
* Created by Ziver on 2015-04-07.
|
||||
*/
|
||||
public interface HardwareAbstractionLayer {
|
||||
}
|
||||
|
|
@ -58,7 +58,7 @@ public abstract class OSAbstractionLayer {
|
|||
* @param cmd the command to run
|
||||
* @return first line of the command
|
||||
*/
|
||||
protected String getFirstLineFromCommand(String cmd) {
|
||||
protected static String getFirstLineFromCommand(String cmd) {
|
||||
String[] tmp = runCommand(cmd);
|
||||
if(tmp.length > 1)
|
||||
return tmp[0];
|
||||
|
|
@ -71,7 +71,7 @@ public abstract class OSAbstractionLayer {
|
|||
* @param cmd the command to run
|
||||
* @return a String list of the output of the command
|
||||
*/
|
||||
public String[] runCommand(String cmd) {
|
||||
public static String[] runCommand(String cmd) {
|
||||
ArrayList<String> ret = new ArrayList<String>();
|
||||
try {
|
||||
Runtime runtime = Runtime.getRuntime();
|
||||
|
|
@ -125,4 +125,6 @@ public abstract class OSAbstractionLayer {
|
|||
* @return the path to the global configuration folder e.g Linux: "/etc
|
||||
*/
|
||||
public abstract File getGlobalConfigPath();
|
||||
|
||||
public abstract HardwareAbstractionLayer getHAL();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@ import java.io.File;
|
|||
* User: Ziver
|
||||
*/
|
||||
public class OsalLinuxImpl extends OSAbstractionLayer {
|
||||
private static HALLinuxImpl hal;
|
||||
|
||||
@Override
|
||||
public OSType getOSType() {
|
||||
return OSType.Linux;
|
||||
|
|
@ -72,4 +74,11 @@ public class OsalLinuxImpl extends OSAbstractionLayer {
|
|||
public File getGlobalConfigPath() {
|
||||
return new File("/etc");
|
||||
}
|
||||
|
||||
@Override
|
||||
public HardwareAbstractionLayer getHAL() {
|
||||
if(hal == null)
|
||||
hal = new HALLinuxImpl();
|
||||
return hal;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,17 +30,17 @@ import java.io.File;
|
|||
public class OsalWindowsImpl extends OSAbstractionLayer {
|
||||
@Override
|
||||
public OSType getOSType() {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOSName() {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOSVersion() {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -55,16 +55,21 @@ public class OsalWindowsImpl extends OSAbstractionLayer {
|
|||
|
||||
@Override
|
||||
public String getUsername() {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getUserConfigPath() {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getGlobalConfigPath() {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HardwareAbstractionLayer getHAL() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -252,7 +252,7 @@ public class Templator {
|
|||
super.compile(str);
|
||||
}
|
||||
else if(obj instanceof Integer){
|
||||
if ((Integer) obj > 0)
|
||||
if ((Integer) obj != 0)
|
||||
super.compile(str);
|
||||
}
|
||||
else if(obj instanceof Iterable){
|
||||
|
|
@ -273,7 +273,7 @@ public class Templator {
|
|||
|
||||
// Reset map to parent object
|
||||
if(prevObj != null)
|
||||
set(".", obj);
|
||||
set(".", prevObj);
|
||||
else
|
||||
remove(".");
|
||||
}
|
||||
|
|
@ -326,31 +326,29 @@ public class Templator {
|
|||
|
||||
protected class TemplateDataAttribute implements TemplateEntity {
|
||||
private String tag;
|
||||
private String key;
|
||||
private String attrib;
|
||||
private String[] keys;
|
||||
|
||||
public TemplateDataAttribute(String tag){
|
||||
this.tag = tag;
|
||||
String[] s = tag.trim().split("\\.", 2);
|
||||
this.key = s[0];
|
||||
if(this.key.isEmpty()) // tag starts with "."
|
||||
this.key = ".";
|
||||
if(s.length > 1)
|
||||
this.attrib = s[1];
|
||||
this.keys = tag.trim().split("\\.");
|
||||
if(this.keys.length == 0)
|
||||
this.keys = new String[]{"."};
|
||||
if(this.keys[0].isEmpty()) // if tag starts with "."
|
||||
this.keys[0] = ".";
|
||||
}
|
||||
|
||||
|
||||
public Object getObject(){
|
||||
if (data.containsKey(tag))
|
||||
return data.get(tag);
|
||||
else if (data.containsKey(key) && data.get(key) != null) {
|
||||
if (attrib != null) {
|
||||
Object obj = getFieldValue(data.get(key), attrib);
|
||||
if(obj != null)
|
||||
return obj;
|
||||
else if (data.containsKey(keys[0]) && data.get(keys[0]) != null) {
|
||||
Object obj = data.get(keys[0]);
|
||||
for(int i=1; i<keys.length; ++i){
|
||||
obj = getFieldValue(obj, keys[i]);
|
||||
if(obj == null)
|
||||
return null;
|
||||
}
|
||||
else
|
||||
return data.get(key);
|
||||
return obj;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
@ -358,10 +356,14 @@ public class Templator {
|
|||
try {
|
||||
if(obj.getClass().isArray() && "length".equals(attrib))
|
||||
return Array.getLength(obj);
|
||||
for (Field field : obj.getClass().getDeclaredFields()) {
|
||||
if(field.getName().equals(attrib)) {
|
||||
field.setAccessible(true);
|
||||
return field.get(obj);
|
||||
else if(obj instanceof Collection && "length".equals(attrib))
|
||||
return ((Collection) obj).size();
|
||||
else {
|
||||
for (Field field : obj.getClass().getDeclaredFields()) {
|
||||
if (field.getName().equals(attrib)) {
|
||||
field.setAccessible(true);
|
||||
return field.get(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
}catch (IllegalAccessException e){
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ import java.net.URLClassLoader;
|
|||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
|
|
@ -51,28 +52,49 @@ public class PluginData {
|
|||
|
||||
|
||||
protected PluginData(DataNode data) throws ClassNotFoundException, MalformedURLException {
|
||||
classMap = new HashMap<Class, Class>();
|
||||
classMap = new HashMap<Class, Class>();
|
||||
objectMap = new HashMap<Class, Object>();
|
||||
|
||||
pluginVersion = data.getDouble("version");
|
||||
pluginName = data.getString("name");
|
||||
log.fine("Plugin: "+this);
|
||||
log.fine("Plugin: " + this);
|
||||
|
||||
DataNode node = data.get("interfaces");
|
||||
Iterator<String> intfIt = node.keyIterator();
|
||||
while (intfIt.hasNext()) {
|
||||
String intf = intfIt.next();
|
||||
log.finer("Plugin interface: "+ intf+" --> "+node.get(intf).getString());
|
||||
classMap.put(
|
||||
getClassByName(intf),
|
||||
getClassByName(node.get(intf).getString()));
|
||||
if(node.isMap())
|
||||
addInterfaces(node);
|
||||
else if(node.isList()) {
|
||||
Iterator<DataNode> intfs_it = node.iterator();
|
||||
while (intfs_it.hasNext()) {
|
||||
addInterfaces(intfs_it.next());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Class getClassByName(String name) throws ClassNotFoundException, MalformedURLException {
|
||||
return Class.forName(name);
|
||||
private void addInterfaces(DataNode node){
|
||||
Iterator<String> intf_it = node.keyIterator();
|
||||
while (intf_it.hasNext()) {
|
||||
String pluginIntf = intf_it.next();
|
||||
String className = node.get(pluginIntf).getString();
|
||||
try {
|
||||
Class.forName(className); // Check if class is available, will throw exception if class is not found
|
||||
log.finer("Plugin interface: " + pluginIntf + " --> " + className);
|
||||
classMap.put(
|
||||
getClassByName(pluginIntf),
|
||||
getClassByName(className));
|
||||
}catch (Exception e){
|
||||
log.finer("Plugin interface: " + pluginIntf + " --> (Not Available) " + className);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Class getClassByName(String name) {
|
||||
try {
|
||||
return Class.forName(name);
|
||||
}catch (Exception e){
|
||||
log.log(Level.WARNING, null, e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public double getVersion(){
|
||||
return pluginVersion;
|
||||
}
|
||||
|
|
@ -84,11 +106,11 @@ public class PluginData {
|
|||
if(classMap.containsKey(intf)) {
|
||||
try {
|
||||
Class subClass = classMap.get(intf);
|
||||
if (objectMap.containsKey(subClass))
|
||||
objectMap.put(intf, subClass.newInstance());
|
||||
if (!objectMap.containsKey(subClass))
|
||||
objectMap.put(subClass, subClass.newInstance());
|
||||
return (T) objectMap.get(subClass);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.log(Level.WARNING, null, e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -25,9 +25,7 @@ package zutil.plugin;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.*;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.sun.xml.internal.stream.util.ReadOnlyIterator;
|
||||
|
|
@ -97,11 +95,26 @@ public class PluginManager<T> implements Iterable<PluginData>{
|
|||
public Iterator<PluginData> iterator() {
|
||||
return plugins.values().iterator();
|
||||
}
|
||||
|
||||
public <T> Iterator<T> iterator(Class<T> intf) {
|
||||
return new PluginInterfaceIterator<T>(plugins.values().iterator(), intf);
|
||||
}
|
||||
|
||||
public ArrayList<PluginData> toArray() {
|
||||
ArrayList<PluginData> list = new ArrayList<PluginData>();
|
||||
Iterator<PluginData> it = iterator();
|
||||
while(it.hasNext())
|
||||
list.add(it.next());
|
||||
return list;
|
||||
}
|
||||
public <T> ArrayList<T> toArray(Class<T> intf) {
|
||||
ArrayList<T> list = new ArrayList<T>();
|
||||
Iterator<T> it = iterator(intf);
|
||||
while(it.hasNext())
|
||||
list.add(it.next());
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
public class PluginInterfaceIterator<T> implements Iterator<T> {
|
||||
private Class<T> intf;
|
||||
private Iterator<PluginData> it;
|
||||
|
|
@ -129,7 +142,9 @@ public class PluginManager<T> implements Iterable<PluginData>{
|
|||
public T next() {
|
||||
if(!hasNext())
|
||||
throw new NoSuchElementException();
|
||||
return next.getObject(intf);
|
||||
T tmp = next.getObject(intf);
|
||||
next = null;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
{
|
||||
version = 1.0,
|
||||
name = "Nice name of Plugin"
|
||||
interfaces = {
|
||||
"plugin.interface.class" = "plugin.implementation.class",
|
||||
"wa.server.plugin.WAFrontend" = "wa.server.plugin.apache.ApacheFrontend",
|
||||
}
|
||||
interfaces = [
|
||||
{"plugin.interface.class" = "plugin.implementation.class"},
|
||||
{"wa.server.plugin.WAFrontend" = "wa.server.plugin.apache.ApacheFrontend"},
|
||||
]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue