001: /*--------------------------------------------------------------------------*
002: | Copyright (C) 2006 Christopher Kohlhaas |
003: | |
004: | This program is free software; you can redistribute it and/or modify |
005: | it under the terms of the GNU General Public License as published by the |
006: | Free Software Foundation. A copy of the license has been included with |
007: | these distribution in the COPYING file, if not go to www.fsf.org |
008: | |
009: | As a special exception, you are granted the permissions to link this |
010: | program with every library, which license fulfills the Open Source |
011: | Definition as published by the Open Source Initiative (OSI). |
012: *--------------------------------------------------------------------------*/
013: package org.rapla.entities.dynamictype;
014:
015: import java.util.Iterator;
016:
017: /** <p>A new ClassificationFilter for a classifications belonging to the
018: same DynamicType can be created by the newClassificationFilter of
019: the corresponding DynamicType object.
020: </p>
021:
022: <p>You can set rules for the attributes of the DynamicType. A
023: Classification (object implementing Classifiable) is matched by
024: the filter when the conditions for each attribute-rule are
025: matched (AND - function).</p>
026:
027: <p>A condition is an array of size 2, the first field contains the
028: operator of the condition and the second the test value.
029: When an attribute-rule has more than one condition, at least
030: one of the conditions must be matched (OR - function ) .
031: </p>
032: <p>
033: The following Example matches all classifications
034: with a title-value that contains either "rapla" or "sourceforge"
035: ,a size-value that is > 5 and a category-department-value that
036: is either the departmentA or the departmentB.
037: </p>
038:
039: <pre>
040: DynamicType eventType = facade.getDynamicType("event");
041: ClassificationFilter f = eventType.newClassificationFilter();
042: f.addRule(
043: "title"
044: ,new Object {
045: {"contains", "rapla"}
046: ,{"contains", "sourceforge"}
047: });
048: f.addRule(
049: "size"
050: ,new Object{
051: {">", new Integer(5)}
052: });
053:
054: Category departemntCategory = facade.getRootCategory().getCategory("departments");
055: Category departmentA = departmentCategory.getCategory("departmentA");
056: Category departmentB = departmentCategory.getCategory("departmentB");
057: f.addRule(
058: "department"
059: ,new Object{
060: {"=", departmentA}
061: ,{ "=", departmentB}
062: });
063: </pre>
064:
065: @see Classification
066: */
067: public interface ClassificationFilter extends Cloneable {
068: DynamicType getType();
069:
070: /** Defines a rule for the passed attribute.
071: */
072: void setRule(int index, String attributeName, Object[][] conditions);
073:
074: void setRule(int index, Attribute attribute, Object[][] conditions);
075:
076: /** appends a rule.
077: * @see #setRule*/
078: void addRule(String attributeName, Object[][] conditions);
079:
080: /** shortcut to
081: * <pre>
082: * f.addRule(
083: attributeName
084: ,new Object{
085: {"=", object}}
086: });
087: * </pre>
088: * @param attributeName
089: * @param object
090: */
091: void addEqualsRule(String attributeName, Object object);
092:
093: /** shortcut to
094: * <pre>
095: * f.addRule(
096: attributeName
097: ,new Object{
098: {"is", object}}
099: });
100: * </pre>
101: * @param attributeName
102: * @param object
103: */
104: void addIsRule(String attributeName, Object object);
105:
106: int ruleSize();
107:
108: Iterator ruleIterator();
109:
110: void removeAllRules();
111:
112: void removeRule(int index);
113:
114: boolean matches(Classification classification);
115:
116: Object clone();
117:
118: final ClassificationFilter[] CLASSIFICATIONFILTER_ARRAY = new ClassificationFilter[0];
119:
120: ClassificationFilter[] toArray();
121: }
|