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

org.drools.jsr94.rules.admin.RuleImpl Maven / Gradle / Ivy

/*
 * Copyright 2005 Red Hat, Inc. and/or its affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      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.jsr94.rules.admin;


import java.util.HashMap;
import java.util.Map;

import javax.rules.admin.Rule;

/**
 * The Drools implementation of the Rule interface which provides
 * access to simple metadata for a rule. Related Rule
 * instances are assembled into RuleExecutionSets, which in
 * turn, can be executed by a rules engine via the RuleSession
 * interface.
 *
 * @see Rule
 */
public class RuleImpl
    implements
    Rule {
    private static final long    serialVersionUID = 510l;

    /** The name of this rule. */
    private String               name;

    /** A description of the rule or null if no description is specified. */
    private String               description;

    /** A Map of user-defined and Drools-defined properties. */
    private final Map            properties       = new HashMap();

    /**
     * The org.kie.rule.Rule that lies at the core of
     * this javax.rules.admin.Rule object.
     */
    private org.drools.core.definitions.rule.impl.RuleImpl rule;

    /**
     * Creates a RuleImpl object by wrapping an
     * org.kie.rule.Rule object.
     *
     * @param rule the org.kie.rule.Rule object to be wrapped.
     */
    RuleImpl(final org.drools.core.definitions.rule.impl.RuleImpl rule) {
        this.rule = rule;
        this.name = rule.getName();
        this.description = rule.getName();// the name of a rule is the only description
    }

    /**
     * Returns the org.kie.rule.Rule that lies at the core of
     * this javax.rules.admin.Rule object. This method is package
     * private.
     *
     * @return org.kie.rule.Rule at the core of this object.
     */
    org.drools.core.definitions.rule.impl.RuleImpl getRule() {
        return this.rule;
    }

    /* Rule interface methods */

    /**
     * Get the name of this rule.
     *
     * @return The name of this rule.
     */
    public String getName() {
        return this.name;
    }

    /**
     * Get a description of the rule.
     *
     * @return A description of the rule or null of no description is specified.
     */
    public String getDescription() {
        return this.description;
    }

    /**
     * Get a user-defined or Drools-defined property.
     *
     * @param key the key to use to retrieve the property
     *
     * @return the value bound to the key or null
     */
    public Object getProperty(final Object key) {
        // TODO certain keys should reference internal rule accessor methods
        return this.properties.get( key );
    }

    /**
     * Set a user-defined or Drools-defined property.
     *
     * @param key the key for the property value
     * @param value the value to associate with the key
     */
    public void setProperty(final Object key,
                            final Object value) {
        // TODO certain keys should alter internal rule accessor methods
        this.properties.put( key,
                             value );
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy