001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019: package org.openharmonise.vfs.search;
020:
021: import java.util.ArrayList;
022: import java.util.List;
023:
024: /**
025: * Groups conditions in either an AND or OR group. The conditions can be
026: * property conditions, content conditions or other condition groups.
027: *
028: * @author Matthew Large
029: * @version $Revision: 1.1 $
030: *
031: */
032: public class ConditionGroup {
033:
034: /**
035: * AND group type identifier.
036: */
037: public static final String AND = "and";
038:
039: /**
040: * OR group type identifier.
041: */
042: public static final String OR = "or";
043:
044: /**
045: * Group type of this condition group.
046: */
047: private String m_sType = ConditionGroup.AND;
048:
049: /**
050: * List of {@link PropertyCondition} objects.
051: */
052: private ArrayList m_aPropertyConditions = new ArrayList(3);
053:
054: /**
055: * List of {@link ContentCondition} objects.
056: */
057: private ArrayList m_aContentConditions = new ArrayList(3);
058:
059: /**
060: * List of {@link ConditionGroup} objects.
061: */
062: private ArrayList m_aConditionGroups = new ArrayList(3);
063:
064: /**
065: * Constructs a new condition group.
066: *
067: * @param sType Either 'and' or 'or'
068: * @see ConditionGroup#AND
069: * @see ConditionGroup#OR
070: */
071: public ConditionGroup(String sType) {
072: super ();
073: this .m_sType = sType;
074: }
075:
076: /**
077: * Returns the type of this ConditionGroup.
078: *
079: * @return String, either 'and' or 'or'
080: * @see ConditionGroup#AND
081: * @see ConditionGroup#OR
082: */
083: public String getType() {
084: return this .m_sType;
085: }
086:
087: /**
088: * Adds a content condition.
089: *
090: * @param cond ContentConditon to be added
091: */
092: public void addContentCondition(ContentCondition cond) {
093: this .m_aContentConditions.add(cond);
094: }
095:
096: /**
097: * Adds a property condition.
098: *
099: * @param cond PropertyCondition to be added
100: */
101: public void addPropertyCondition(PropertyCondition cond) {
102: this .m_aPropertyConditions.add(cond);
103: }
104:
105: /**
106: * Adds a sub condition group.
107: *
108: * @param group ConditionGroup to be added
109: */
110: public void addConditionGroup(ConditionGroup group) {
111: this .m_aConditionGroups.add(group);
112: }
113:
114: /**
115: * Returns the content conditions.
116: *
117: * @return List of {@link ContentCondition} objects
118: */
119: public List getContentConditions() {
120: return (List) this .m_aContentConditions.clone();
121: }
122:
123: /**
124: * Returns the property conditions.
125: *
126: * @return List of {@link PropertyCondition} objects
127: */
128: public List getPropertyConditions() {
129: return (List) this .m_aPropertyConditions.clone();
130: }
131:
132: /**
133: * Returns the sub condition groups.
134: *
135: * @return List of {@link ConditionGroup} objects
136: */
137: public List getConditionGroups() {
138: return (List) this.m_aConditionGroups.clone();
139: }
140:
141: }
|