001: package org.ofbiz.rules.engine;
002:
003: /**
004: * <p><b>Title:</b> Query
005: * <p><b>Description:</b> None
006: * <p>Copyright (c) 1999 Steven J. Metsker.
007: * <p>Copyright (c) 2001 The Open For Business Project - www.ofbiz.org
008: *
009: * <p>Permission is hereby granted, free of charge, to any person obtaining a
010: * copy of this software and associated documentation files (the "Software"),
011: * to deal in the Software without restriction, including without limitation
012: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
013: * and/or sell copies of the Software, and to permit persons to whom the
014: * Software is furnished to do so, subject to the following conditions:
015: *
016: * <p>The above copyright notice and this permission notice shall be included
017: * in all copies or substantial portions of the Software.
018: *
019: * <p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
020: * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
021: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
022: * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
023: * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
024: * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
025: * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
026: *
027: * <br>
028: * <p>A Query is a dynamic rule that stands outside of a program
029: * and proves itself by referring to a program.
030: *
031: * @author Steven J. Metsker
032: * @version 1.0
033: */
034: public class Query extends DynamicRule {
035:
036: /**
037: * Create a query from the given structures, to prove itself
038: * against the given axiom source.
039: *
040: * @param AxiomSource the source to prove against
041: *
042: * @param Structures the structures to prove
043: */
044: public Query(AxiomSource as, Structure[] structures) {
045: this (as, new Scope(structures), structures);
046: }
047:
048: /**
049: * Create a query from the given rule's structures, to prove
050: * itself against the given axiom source.
051: *
052: * @param AxiomSource the source to prove against
053: *
054: * @param Rule the rule that contains structures to prove
055: */
056: public Query(AxiomSource as, Rule rule) {
057: this (as, rule.structures);
058: }
059:
060: /**
061: * This constructor ensures that the structures in the query
062: * are all "provable", meaning that they are capable of
063: * proving themselves. Structures cannot achieve this, but
064: * they can produce consulting versions of themselves, given
065: * an axiom source. Evalutations and comparisons are
066: * provable in themselves, and will ignore the axiom
067: * source.
068: */
069: protected Query(AxiomSource as, Scope scope, Structure[] structures) {
070: super (as, scope, provableStructures(as, scope, structures));
071: }
072:
073: /**
074: * Create a query from the given structure, to prove itself
075: * against the given axiom source.
076: *
077: * @param AxiomSource the source to prove against
078: *
079: * @param Structures the structure to prove
080: */
081: public Query(AxiomSource as, Structure structure) {
082: this (as, new Structure[] { structure });
083: }
084:
085: /**
086: * Create a query from the given structure, to prove itself
087: * without any axiom source.
088: *
089: * For example new Query(new Comparison())
090: *
091: * @param AxiomSource the source to prove against
092: *
093: * @param Structure the structure to prove
094: */
095: public Query(Structure structure) {
096: this (null, new Scope(), new Structure[] { structure });
097: }
098:
099: /**
100: * Returns a string representation of this query.
101: *
102: * @return a string representation of this query.
103: */
104: public String toString() {
105: StringBuffer buf = new StringBuffer();
106:
107: for (int i = 0; i < structures.length; i++) {
108: if (i > 0) {
109: buf.append(", ");
110: }
111: buf.append(structures[i].toString());
112: }
113: return buf.toString();
114: }
115: }
|