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

org.drools.impl.adapters.KnowledgePackageAdapter Maven / Gradle / Ivy

Go to download

The Drools and jBPM public API which is backwards compatible between releases.

There is a newer version: 6.5.0.Final
Show newest version
/*
 * Copyright 2015 JBoss Inc
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * 
 *      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.drools.impl.adapters;

import org.drools.definition.process.Process;
import org.drools.definition.rule.Global;
import org.drools.definition.rule.Query;
import org.drools.definition.rule.Rule;
import org.drools.definition.type.FactType;
import org.kie.internal.definition.KnowledgePackage;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import static org.drools.impl.adapters.FactTypeAdapter.adaptFactTypes;
import static org.drools.impl.adapters.GlobalAdapter.adaptGlobals;
import static org.drools.impl.adapters.ProcessAdapter.adaptProcesses;
import static org.drools.impl.adapters.QueryAdapter.adaptQueries;
import static org.drools.impl.adapters.RuleAdapter.adaptRules;

public class KnowledgePackageAdapter implements org.drools.definition.KnowledgePackage {

    private final KnowledgePackage delegate;

    public KnowledgePackageAdapter(KnowledgePackage delegate) {
        this.delegate = delegate;
    }

    public String getName() {
        return delegate.getName();
    }

    public Collection getRules() {
        return adaptRules(delegate.getRules());
    }

    public Collection getProcesses() {
        return adaptProcesses(delegate.getProcesses());
    }

    public Collection getFactTypes() {
        return adaptFactTypes(delegate.getFactTypes());
    }

    public Collection getQueries() {
        return adaptQueries(delegate.getQueries());
    }

    public Collection getFunctionNames() {
        return delegate.getFunctionNames();
    }

    public Collection getGlobalVariables() {
        return adaptGlobals(delegate.getGlobalVariables());
    }

    public KnowledgePackage getDelegate() {
        return delegate;
    }

    public static List adaptKnowledgePackages(Collection pkgs) {
        List result = new ArrayList();
        for (KnowledgePackage pkg : pkgs) {
            result.add(new KnowledgePackageAdapter(pkg));
        }
        return result;
    }

    public static Collection fromKiePackages(Collection pkgs) {
        List result = new ArrayList();
        for (org.drools.definition.KnowledgePackage pkg : pkgs) {
            result.add(((KnowledgePackageAdapter)pkg).getDelegate());
        }
        return result;
    }

    @Override
    public int hashCode() {
        return delegate.hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        return obj instanceof KnowledgePackageAdapter && delegate.equals(((KnowledgePackageAdapter)obj).delegate);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy