Remove trailing whitespace.
[guacamole.git] / src / main / java / net / sourceforge / guacamole / net / basic / properties / EventListenersProperty.java
1 package net.sourceforge.guacamole.net.basic.properties;
2
3 /*
4  *  Guacamole - Clientless Remote Desktop
5  *  Copyright (C) 2010  Michael Jumper
6  *
7  *  This program is free software: you can redistribute it and/or modify
8  *  it under the terms of the GNU Affero General Public License as published by
9  *  the Free Software Foundation, either version 3 of the License, or
10  *  (at your option) any later version.
11  *
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU Affero General Public License for more details.
16  *
17  *  You should have received a copy of the GNU Affero General Public License
18  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import net.sourceforge.guacamole.GuacamoleException;
24 import net.sourceforge.guacamole.net.basic.GuacamoleClassLoader;
25 import net.sourceforge.guacamole.properties.GuacamoleProperty;
26
27 /**
28  * A GuacamoleProperty whose value is a comma-separated list of class names,
29  * where each class will be used as a listener for events.
30  *
31  * @author Michael Jumper
32  */
33 public abstract class EventListenersProperty implements GuacamoleProperty<Collection<Class>> {
34
35     @Override
36     public Collection<Class> parseValue(String classNameList) throws GuacamoleException {
37
38         // If no property provided, return null.
39         if (classNameList == null)
40             return null;
41
42         // Parse list
43         String[] classNames = classNameList.split(",[\\s]*");
44
45         // Fill list of classes
46         Collection<Class> listeners = new ArrayList<Class>();
47         try {
48
49             // Load all classes in list
50             for (String className : classNames) {
51                 Class clazz = GuacamoleClassLoader.getInstance().loadClass(className);
52                 listeners.add(clazz);
53             }
54
55         }
56         catch (ClassNotFoundException e) {
57             throw new GuacamoleException("Listener class not found.", e);
58         }
59         catch (SecurityException e) {
60             throw new GuacamoleException("Security settings prevent loading of listener class.", e);
61         }
62
63         return listeners;
64
65     }
66
67 }
68