[jboss-svn-commits] JBL Code SVN: r33758 - in labs/jbossrules/trunk: drools-core/src/main/java/org/drools/definitions/rule/impl and 3 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Jul 7 11:13:29 EDT 2010
Author: tirelli
Date: 2010-07-07 11:13:28 -0400 (Wed, 07 Jul 2010)
New Revision: 33758
Modified:
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/definition/rule/Rule.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/definitions/rule/impl/RuleImpl.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/impl/SerializedRule.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Rule.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/runtime/rule/impl/SerializedRule.java
Log:
Adjusting metadata methods for rule
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/definition/rule/Rule.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/definition/rule/Rule.java 2010-07-07 15:05:00 UTC (rev 33757)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/definition/rule/Rule.java 2010-07-07 15:13:28 UTC (rev 33758)
@@ -1,18 +1,53 @@
package org.drools.definition.rule;
import java.util.Collection;
+import java.util.Map;
import org.drools.definition.KnowledgeDefinition;
+/**
+ * Public Rule interface for runtime rule inspection.
+ */
public interface Rule
extends
KnowledgeDefinition {
-
+
+ /**
+ * Returns the package name (namespace) this rule is tied to.
+ *
+ * @return the package name.
+ */
String getPackageName();
+ /**
+ * Returns this rule's name.
+ *
+ * @return the rule name
+ */
String getName();
+ /**
+ * This method is deprecated. Please use {@link Rule#getMetaAttributes()} instead.
+ *
+ * @return a collection with all the meta attribute keys associated with this Rule.
+ * @deprecated
+ */
+ @Deprecated
Collection<String> listMetaAttributes();
- String getMetaAttribute(final String identifier);
+ /**
+ * Returns an immutable Map<String key, String value> of all meta attributes associated with this rule object.
+ *
+ * @return an immutable Map<String key, String value> of meta attributes.
+ */
+ Map<String, String> getMetaAttributes();
+
+ /**
+ * Returns the value of the meta attribute identified by the "key"
+ *
+ * @param key the meta attribute key
+ *
+ * @return the meta attribute value or null if there is no value for that key.
+ */
+ String getMetaAttribute(final String key);
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/definitions/rule/impl/RuleImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/definitions/rule/impl/RuleImpl.java 2010-07-07 15:05:00 UTC (rev 33757)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/definitions/rule/impl/RuleImpl.java 2010-07-07 15:13:28 UTC (rev 33758)
@@ -1,6 +1,7 @@
package org.drools.definitions.rule.impl;
import java.util.Collection;
+import java.util.Map;
import org.drools.rule.Rule;
@@ -23,7 +24,14 @@
return this.rule.getMetaAttribute( identifier );
}
+ @Deprecated
public Collection<String> listMetaAttributes() {
return this.rule.getMetaAttributes().keySet();
}
+
+ public Map<String, String> getMetaAttributes() {
+ return this.rule.getMetaAttributes();
+ }
+
+
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/impl/SerializedRule.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/impl/SerializedRule.java 2010-07-07 15:05:00 UTC (rev 33757)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/impl/SerializedRule.java 2010-07-07 15:13:28 UTC (rev 33758)
@@ -5,6 +5,7 @@
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -57,8 +58,13 @@
return this.metaAttributes.get( identifier );
}
+ @Deprecated
public Collection<String> listMetaAttributes() {
return this.metaAttributes.keySet();
+ }
+
+ public Map<String, String> getMetaAttributes() {
+ return Collections.unmodifiableMap( this.metaAttributes );
}
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Rule.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Rule.java 2010-07-07 15:05:00 UTC (rev 33757)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Rule.java 2010-07-07 15:13:28 UTC (rev 33758)
@@ -22,6 +22,7 @@
import java.io.ObjectOutput;
import java.util.Calendar;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@@ -80,7 +81,7 @@
/** The Rule is dirty after patterns have been added */
private boolean dirty;
- private Map declarations;
+ private Map<String, Declaration> declarations;
private Declaration[] declarationArray;
private GroupElement lhsRoot;
@@ -164,6 +165,7 @@
out.writeObject( resource );
}
+ @SuppressWarnings("unchecked")
public void readExternal(ObjectInput in) throws IOException,
ClassNotFoundException {
pkg = (String) in.readObject();
@@ -172,7 +174,7 @@
salience = (Salience) in.readObject();
dirty = in.readBoolean();
- declarations = (Map) in.readObject();
+ declarations = (Map<String, Declaration>) in.readObject();
declarationArray = (Declaration[]) in.readObject();
lhsRoot = (GroupElement) in.readObject();
dialect = (String) in.readObject();
@@ -425,14 +427,15 @@
* @return The declaration or <code>null</code> if no declaration matches
* the <code>identifier</code>.
*/
+ @SuppressWarnings("unchecked")
public Declaration getDeclaration(final String identifier) {
if ( this.dirty || (this.declarations == null) ) {
- this.declarations = this.getExtendedLhs( this,
- null ).getOuterDeclarations();
+ this.declarations = (Map<String, Declaration>) this.getExtendedLhs( this,
+ null ).getOuterDeclarations();
this.declarationArray = (Declaration[]) this.declarations.values().toArray( new Declaration[this.declarations.values().size()] );
this.dirty = false;
}
- return (Declaration) this.declarations.get( identifier );
+ return this.declarations.get( identifier );
}
/**
@@ -463,10 +466,11 @@
* @return The Set of <code>Declarations</code> in order which specify the
* <i>root fact objects</i>.
*/
+ @SuppressWarnings("unchecked")
public Declaration[] getDeclarations() {
if ( this.dirty || (this.declarationArray == null) ) {
- this.declarations = this.getExtendedLhs( this,
- null ).getOuterDeclarations();
+ this.declarations = (Map<String, Declaration>) this.getExtendedLhs( this,
+ null ).getOuterDeclarations();
this.declarationArray = (Declaration[]) this.declarations.values().toArray( new Declaration[this.declarations.values().size()] );
this.dirty = false;
}
@@ -716,13 +720,14 @@
}
public Map<String, String> getMetaAttributes() {
- return metaAttributes;
+ return Collections.unmodifiableMap( metaAttributes );
}
public String getMetaAttribute(final String identifier) {
return (String) this.metaAttributes.get( identifier );
}
+ @Deprecated
public Collection<String> listMetaAttributes() {
return this.metaAttributes.keySet();
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/runtime/rule/impl/SerializedRule.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/runtime/rule/impl/SerializedRule.java 2010-07-07 15:05:00 UTC (rev 33757)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/runtime/rule/impl/SerializedRule.java 2010-07-07 15:13:28 UTC (rev 33758)
@@ -5,6 +5,7 @@
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -25,11 +26,7 @@
public SerializedRule(Rule rule) {
this.name = rule.getName();
this.packageName = rule.getPackageName();
- Collection<String> identifiers = rule.listMetaAttributes();
- this.metaAttributes = new HashMap<String, String>(identifiers.size());
- for ( String identifier : identifiers ) {
- this.metaAttributes.put( identifier, rule.getMetaAttribute( identifier ) );
- }
+ this.metaAttributes = new HashMap<String, String>( rule.getMetaAttributes() );
}
public void writeExternal(ObjectOutput out) throws IOException {
@@ -38,6 +35,7 @@
out.writeObject( this.metaAttributes );
}
+ @SuppressWarnings("unchecked")
public void readExternal(ObjectInput in) throws IOException,
ClassNotFoundException {
name = in.readUTF();
@@ -61,4 +59,7 @@
return this.metaAttributes.keySet();
}
+ public Map<String, String> getMetaAttributes() {
+ return Collections.unmodifiableMap( this.metaAttributes );
+ }
}
More information about the jboss-svn-commits
mailing list