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

com.firefly.codec.websocket.model.extension.WebSocketExtensionFactory Maven / Gradle / Ivy

There is a newer version: 5.0.0-dev6
Show newest version
package com.firefly.codec.websocket.model.extension;

import com.firefly.codec.websocket.exception.WebSocketException;
import com.firefly.codec.websocket.model.Extension;
import com.firefly.codec.websocket.model.ExtensionConfig;
import com.firefly.utils.StringUtils;

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.newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            throw new WebSocketException("Cannot instantiate extension: " + extClass, e);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy