Github user mike-jumper commented on a diff in the pull request:

    
https://github.com/apache/incubator-guacamole-client/pull/184#discussion_r143105757
  
    --- Diff: 
guacamole/src/main/java/org/apache/guacamole/extension/ListenerFactory.java ---
    @@ -0,0 +1,256 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *   http://www.apache.org/licenses/LICENSE-2.0
    + *
    + *  Unless required by applicable law or agreed to in writing,
    + *  software distributed under the License is distributed on an
    + *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + *  KIND, either express or implied.  See the License for the
    + *  specific language governing permissions and limitations
    + *  under the License.
    + */
    +
    +package org.apache.guacamole.extension;
    +
    +import org.apache.guacamole.GuacamoleException;
    +import org.apache.guacamole.GuacamoleSecurityException;
    +import org.apache.guacamole.net.event.AuthenticationFailureEvent;
    +import org.apache.guacamole.net.event.AuthenticationSuccessEvent;
    +import org.apache.guacamole.net.event.TunnelCloseEvent;
    +import org.apache.guacamole.net.event.TunnelConnectEvent;
    +import org.apache.guacamole.net.event.listener.*;
    +
    +import java.util.ArrayList;
    +import java.util.Collections;
    +import java.util.List;
    +
    +/**
    + * A factory that reflectively instantiates Listener objects for a given
    + * provider class.
    + */
    +class ListenerFactory {
    +
    +    /**
    +     * Creates all listeners represented by an instance of the given 
provider class.
    +     * <p>
    +     * If a provider class implements the simple Listener interface, that 
is the
    +     * only listener type that will be returned. Otherwise, a list of 
Listener
    +     * objects that adapt the legacy listener interfaces will be returned.
    +     *
    +     * @param providerClass
    +     *      a class that represents a listener provider
    +     *
    +     * @return
    +     *      list of listeners represented by the given provider class
    +     */
    +    static List<Listener> createListeners(Class<?> providerClass) {
    +
    +        Object provider = ProviderFactory.newInstance("listener", 
providerClass);
    +
    +        if (provider instanceof Listener) {
    +            return Collections.singletonList((Listener) provider);
    +        }
    +
    +        return createListenerAdapters(provider);
    +
    +    }
    +
    +    @SuppressWarnings("deprecation")
    +    private static List<Listener> createListenerAdapters(Object provider) {
    +
    +        final List<Listener> listeners = new ArrayList<Listener>();
    +
    +        if (provider instanceof AuthenticationSuccessListener) {
    +            listeners.add(new AuthenticationSuccessListenerAdapter(
    +                    (AuthenticationSuccessListener) provider));
    +        }
    +
    +        if (provider instanceof AuthenticationFailureListener) {
    +            listeners.add(new AuthenticationFailureListenerAdapter(
    +                    (AuthenticationFailureListener) provider));
    +        }
    +
    +        if (provider instanceof TunnelConnectListener) {
    +            listeners.add(new TunnelConnectListenerAdapter(
    +                    (TunnelConnectListener) provider));
    +        }
    +
    +        if (provider instanceof TunnelCloseListener) {
    +            listeners.add(new TunnelCloseListenerAdapter(
    +                    (TunnelCloseListener) provider));
    +        }
    +
    +        return listeners;
    +
    +    }
    +
    +    /**
    +     * An adapter the allows an AuthenticationSuccessListener to be used
    +     * as an ordinary Listener.
    +     */
    +    @SuppressWarnings("deprecation")
    +    private static class AuthenticationSuccessListenerAdapter implements 
Listener {
    +
    +        private final AuthenticationSuccessListener delegate;
    +
    +        /**
    +         * Constructs a new adapter.
    +         *
    +         * @param delegate
    +         *      the delegate listener
    --- End diff --
    
    Should be sentence case, plus a period.


---

Reply via email to