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

io.deephaven.appmode.DynamicApplication Maven / Gradle / Ivy

There is a newer version: 0.36.1
Show newest version
//
// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending
//
package io.deephaven.appmode;

import io.deephaven.annotations.SimpleStyle;
import org.immutables.value.Value.Check;
import org.immutables.value.Value.Immutable;
import org.immutables.value.Value.Parameter;

import java.util.Properties;

@Immutable
@SimpleStyle
public abstract class DynamicApplication implements ApplicationConfig {

    public static final String TYPE = "dynamic";

    public static DynamicApplication parse(Properties properties)
            throws ClassNotFoundException {
        // noinspection unchecked
        Class clazz =
                (Class) Class.forName(properties.getProperty("class"));
        return ImmutableDynamicApplication.of(clazz, ApplicationUtil.isEnabled(properties));
    }

    public static  DynamicApplication of(Class clazz, boolean isEnabled) {
        return ImmutableDynamicApplication.of(clazz, isEnabled);
    }

    @Parameter
    public abstract Class clazz();

    @Parameter
    public abstract boolean isEnabled();

    public final ApplicationState create(ApplicationState.Listener appStateListener)
            throws InstantiationException, IllegalAccessException {
        return clazz().newInstance().create(appStateListener);
    }

    @Override
    public final  V walk(V visitor) {
        visitor.visit(this);
        return visitor;
    }

    @Check
    final void checkClazz() {
        if (!ApplicationState.Factory.class.isAssignableFrom(clazz())) {
            throw new IllegalArgumentException(
                    String.format("clazz should extend '%s'", ApplicationState.Factory.class));
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy