mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
Read event listeners from properties.
This commit is contained in:
@@ -8,6 +8,8 @@ import java.util.Iterator;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import net.sourceforge.guacamole.GuacamoleException;
|
||||
import net.sourceforge.guacamole.net.basic.GuacamoleClassLoader;
|
||||
import net.sourceforge.guacamole.net.basic.properties.BasicGuacamoleProperties;
|
||||
import net.sourceforge.guacamole.properties.GuacamoleProperties;
|
||||
|
||||
/**
|
||||
* A collection which iterates over instances of all listeners defined in
|
||||
@@ -55,10 +57,13 @@ public class SessionListenerCollection extends AbstractCollection {
|
||||
listeners = new ArrayList();
|
||||
try {
|
||||
|
||||
// TODO: Retrieve list of listener classnames from properties
|
||||
Class listenerClass = GuacamoleClassLoader.getInstance().loadClass(
|
||||
"net.sourceforge.guacamole.test.GenericLoggingListener"
|
||||
);
|
||||
// Get all listener classes from properties
|
||||
Collection<Class> listenerClasses =
|
||||
GuacamoleProperties.getProperty(BasicGuacamoleProperties.EVENT_LISTENERS);
|
||||
|
||||
// Add an instance of each class to the list
|
||||
if (listenerClasses != null) {
|
||||
for (Class listenerClass : listenerClasses) {
|
||||
|
||||
// Instantiate listener
|
||||
Object listener = listenerClass.getConstructor().newInstance();
|
||||
@@ -67,8 +72,8 @@ public class SessionListenerCollection extends AbstractCollection {
|
||||
listeners.add(listener);
|
||||
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
throw new GuacamoleException("Could not find listener class.", e);
|
||||
}
|
||||
|
||||
}
|
||||
catch (InstantiationException e) {
|
||||
throw new GuacamoleException("Listener class is abstract.", e);
|
||||
|
@@ -54,4 +54,14 @@ public class BasicGuacamoleProperties {
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* The comma-separated list of all classes to use as event listeners.
|
||||
*/
|
||||
public static final EventListenersProperty EVENT_LISTENERS = new EventListenersProperty() {
|
||||
|
||||
@Override
|
||||
public String getName() { return "event-listeners"; }
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,68 @@
|
||||
package net.sourceforge.guacamole.net.basic.properties;
|
||||
|
||||
/*
|
||||
* Guacamole - Clientless Remote Desktop
|
||||
* Copyright (C) 2010 Michael Jumper
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import net.sourceforge.guacamole.GuacamoleException;
|
||||
import net.sourceforge.guacamole.net.basic.GuacamoleClassLoader;
|
||||
import net.sourceforge.guacamole.properties.GuacamoleProperty;
|
||||
|
||||
/**
|
||||
* A GuacamoleProperty whose value is a comma-separated list of class names,
|
||||
* where each class will be used as a listener for events.
|
||||
*
|
||||
* @author Michael Jumper
|
||||
*/
|
||||
public abstract class EventListenersProperty implements GuacamoleProperty<Collection<Class>> {
|
||||
|
||||
@Override
|
||||
public Collection<Class> parseValue(String classNameList) throws GuacamoleException {
|
||||
|
||||
// If no property provided, return null.
|
||||
if (classNameList == null)
|
||||
return null;
|
||||
|
||||
// Parse list
|
||||
String[] classNames = classNameList.split(",[\\s]*");
|
||||
|
||||
// Fill list of classes
|
||||
Collection<Class> listeners = new ArrayList<Class>();
|
||||
try {
|
||||
|
||||
// Load all classes in list
|
||||
for (String className : classNames) {
|
||||
Class clazz = GuacamoleClassLoader.getInstance().loadClass(className);
|
||||
listeners.add(clazz);
|
||||
}
|
||||
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
throw new GuacamoleException("Listener class not found.", e);
|
||||
}
|
||||
catch (SecurityException e) {
|
||||
throw new GuacamoleException("Security settings prevent loading of listener class.", e);
|
||||
}
|
||||
|
||||
return listeners;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user