001: package org.drools.jsr94.rules.admin;
002:
003: /*
004: * Copyright 2005 JBoss Inc
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: import java.util.HashMap;
020: import java.util.Map;
021:
022: import javax.rules.admin.Rule;
023:
024: /**
025: * The Drools implementation of the <code>Rule</code> interface which provides
026: * access to simple metadata for a rule. Related <code>Rule</code>
027: * instances are assembled into <code>RuleExecutionSet</code>s, which in
028: * turn, can be executed by a rules engine via the <code>RuleSession</code>
029: * interface.
030: *
031: * @see Rule
032: *
033: * @author N. Alex Rupp (n_alex <at>codehaus.org)
034: * @author <a href="mailto:thomas.diesler@softcon-itec.de">thomas diesler </a>
035: * @author <a href="mailto:michael.frandsen@syngenio.de">michael frandsen </a>
036: */
037: public class RuleImpl implements Rule {
038: /**
039: *
040: */
041: private static final long serialVersionUID = 400L;
042:
043: /** The name of this rule. */
044: private String name;
045:
046: /** A description of the rule or null if no description is specified. */
047: private String description;
048:
049: /** A <code>Map</code> of user-defined and Drools-defined properties. */
050: private final Map properties = new HashMap();
051:
052: /**
053: * The <code>org.drools.rule.Rule</code> that lies at the core of
054: * this <code>javax.rules.admin.Rule</code> object.
055: */
056: private org.drools.rule.Rule rule;
057:
058: /**
059: * Creates a <code>RuleImpl</code> object by wrapping an
060: * <code>org.drools.rule.Rule</code> object.
061: *
062: * @param rule the <code>org.drools.rule.Rule</code> object to be wrapped.
063: */
064: RuleImpl(final org.drools.rule.Rule rule) {
065: this .rule = rule;
066: this .name = rule.getName();
067: this .description = rule.getName();// the name of a rule is the only description
068: }
069:
070: /**
071: * Returns the <code>org.drools.rule.Rule</code> that lies at the core of
072: * this <code>javax.rules.admin.Rule</code> object. This method is package
073: * private.
074: *
075: * @return <code>org.drools.rule.Rule</code> at the core of this object.
076: */
077: org.drools.rule.Rule getRule() {
078: return this .rule;
079: }
080:
081: /* Rule interface methods */
082:
083: /**
084: * Get the name of this rule.
085: *
086: * @return The name of this rule.
087: */
088: public String getName() {
089: return this .name;
090: }
091:
092: /**
093: * Get a description of the rule.
094: *
095: * @return A description of the rule or null of no description is specified.
096: */
097: public String getDescription() {
098: return this .description;
099: }
100:
101: /**
102: * Get a user-defined or Drools-defined property.
103: *
104: * @param key the key to use to retrieve the property
105: *
106: * @return the value bound to the key or <code>null</code>
107: */
108: public Object getProperty(final Object key) {
109: // TODO certain keys should reference internal rule accessor methods
110: return this .properties.get(key);
111: }
112:
113: /**
114: * Set a user-defined or Drools-defined property.
115: *
116: * @param key the key for the property value
117: * @param value the value to associate with the key
118: */
119: public void setProperty(final Object key, final Object value) {
120: // TODO certain keys should alter internal rule accessor methods
121: this.properties.put(key, value);
122: }
123: }
|