All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.fireflysource.net.websocket.common.extension.WebSocketExtensionFactory Maven / Gradle / Ivy

There is a newer version: 5.0.2
Show newest version
package com.fireflysource.net.websocket.common.extension;


import com.fireflysource.common.string.StringUtils;
import com.fireflysource.net.websocket.common.exception.WebSocketException;
import com.fireflysource.net.websocket.common.model.Extension;
import com.fireflysource.net.websocket.common.model.ExtensionConfig;

public class WebSocketExtensionFactory extends ExtensionFactory {

    @Override
    public Extension newInstance(ExtensionConfig config) {
        if (config == null) {
            return null;
        }

        String name = config.getName();
        if (!StringUtils.hasText(name)) {
            return null;
        }

        Class extClass = getExtension(name);
        if (extClass == null) {
            return null;
        }

        try {
            return extClass.getConstructor().newInstance();
        } catch (Exception e) {
            throw new WebSocketException("Cannot instantiate extension: " + extClass, e);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy