001: package org.drools.lang.descr;
002:
003: import java.util.Iterator;
004: import java.util.List;
005:
006: /*
007: * Copyright 2005 JBoss Inc
008: *
009: * Licensed under the Apache License, Version 2.0 (the "License");
010: * you may not use this file except in compliance with the License.
011: * You may obtain a copy of the License at
012: *
013: * http://www.apache.org/licenses/LICENSE-2.0
014: *
015: * Unless required by applicable law or agreed to in writing, software
016: * distributed under the License is distributed on an "AS IS" BASIS,
017: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018: * See the License for the specific language governing permissions and
019: * limitations under the License.
020: */
021:
022: public class PatternDescr extends BaseDescr implements Cloneable {
023: /**
024: *
025: */
026: private static final long serialVersionUID = 400L;
027: private String objectType;
028: private String identifier;
029: private ConditionalElementDescr constraint = new AndDescr();
030: private int leftParentCharacter = -1;
031: private int rightParentCharacter = -1;
032: private PatternSourceDescr source;
033:
034: public PatternDescr() {
035: this (null, null);
036: }
037:
038: public PatternDescr(final String objectType) {
039: this (objectType, null);
040: }
041:
042: public PatternDescr(final String objectType, final String identifier) {
043: this .objectType = objectType;
044: this .identifier = identifier;
045: }
046:
047: public void setIdentifier(final String identifier) {
048: this .identifier = identifier;
049: }
050:
051: public void setObjectType(final String objectType) {
052: this .objectType = objectType;
053: }
054:
055: public String getObjectType() {
056: return this .objectType;
057: }
058:
059: public String getIdentifier() {
060: return this .identifier;
061: }
062:
063: public List getDescrs() {
064: return this .constraint.getDescrs();
065: }
066:
067: public void addConstraint(BaseDescr base) {
068: this .constraint.addDescr(base);
069: }
070:
071: public ConditionalElementDescr getConstraint() {
072: return this .constraint;
073: }
074:
075: public boolean isInternalFact() {
076: return this .getSource() != null
077: && this .getSource() instanceof CollectDescr;
078: }
079:
080: public String toString() {
081: return "[Pattern: id=" + this .identifier + "; objectType="
082: + this .objectType + "]";
083: }
084:
085: /**
086: * @return the leftParentCharacter
087: */
088: public int getLeftParentCharacter() {
089: return this .leftParentCharacter;
090: }
091:
092: /**
093: * @param leftParentCharacter the leftParentCharacter to set
094: */
095: public void setLeftParentCharacter(final int leftParentCharacter) {
096: this .leftParentCharacter = leftParentCharacter;
097: }
098:
099: /**
100: * @return the rightParentCharacter
101: */
102: public int getRightParentCharacter() {
103: return this .rightParentCharacter;
104: }
105:
106: /**
107: * @param rightParentCharacter the rightParentCharacter to set
108: */
109: public void setRightParentCharacter(final int rightParentCharacter) {
110: this .rightParentCharacter = rightParentCharacter;
111: }
112:
113: public PatternSourceDescr getSource() {
114: return source;
115: }
116:
117: public void setSource(PatternSourceDescr source) {
118: this .source = source;
119: }
120:
121: public Object clone() {
122: PatternDescr clone = new PatternDescr(this .objectType,
123: this .identifier);
124: clone.setLeftParentCharacter(this .leftParentCharacter);
125: clone.setRightParentCharacter(this .rightParentCharacter);
126: clone.setSource(this .source);
127: clone.setStartCharacter(this .getStartCharacter());
128: clone.setEndCharacter(this .getEndCharacter());
129: clone.setLocation(this .getLine(), this .getColumn());
130: clone.setEndLocation(this .getEndLine(), this .getEndColumn());
131: clone.setText(this .getText());
132: for (Iterator it = this .getDescrs().iterator(); it.hasNext();) {
133: clone.addConstraint((BaseDescr) it.next());
134: }
135: return clone;
136: }
137: }
|