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

com.fluxtion.api.SepContext Maven / Gradle / Ivy

/* 
 * Copyright (C) 2018 V12 Technology Ltd.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the Server Side Public License, version 1,
 * as published by MongoDB, Inc.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * Server Side Public License for more details.
 *
 * You should have received a copy of the Server Side Public License
 * along with this program.  If not, see 
 * .
 */
package com.fluxtion.api;

import java.util.ServiceLoader;

/**
 * Service providing buildtime access to constructing a SEP.
 *
 * @author V12 Technology Ltd.
 */
public interface SepContext {

     T add(T node);

     T[] add(T... nodes);

     T add(T node, String privateId);

     T addPublic(T node, String publicId);

     T addOrReuse(T node);

     T[] addOrReuse(T... nodes);

     T addOrReuse(T node, String privateId);

     T addPublicOrReuse(T node, String publicId);

    SepContext NULL_CONTEXT = new SepContext() {
        @Override
        public  T add(T node) {
            return node;
        }

        @Override
        public  T[] add(T... nodes) {
            return nodes;
        }

        @Override
        public  T[] addOrReuse(T... nodes) {
            return nodes;
        }

        @Override
        public  T addPublic(T node, String publicId) {
            return node;
        }

        @Override
        public  T add(T node, String privateId) {
            return node;
        }

        @Override
        public  T addOrReuse(T node) {
            return node;
        }

        @Override
        public  T addOrReuse(T node, String privateId) {
            return node;
        }

        @Override
        public  T addPublicOrReuse(T node, String publicId) {
            return node;
        }

    };

    static SepContext service() {
        ServiceLoader load = ServiceLoader.load(SepContext.class, SepContext.class.getClassLoader());
        if (load.iterator().hasNext()) {
            return load.iterator().next();
        } else {
            load = ServiceLoader.load(SepContext.class);
            if (load.iterator().hasNext()) {
                return load.iterator().next();
            } else {
                return NULL_CONTEXT;
            }
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy