001: package org.drools.rule;
002:
003: /*
004: * Copyright 2005 JBoss Inc
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: /**
020: * Indicates an attempt to add a <code>Rule</code> to a <code>Package</code>
021: * that already contains a <code>Rule</code> with the same name.
022: *
023: * @see Rule
024: * @see Package
025: *
026: * @author <a href="mailto:bob@eng.werken.com">bob mcwhirter </a>
027: */
028: public class DuplicateRuleNameException extends
029: RuleConstructionException {
030: /**
031: *
032: */
033: private static final long serialVersionUID = 400L;
034:
035: /** The rule-set. */
036: private Package pkg;
037:
038: /** The member rule. */
039: private Rule originalRule;
040:
041: /** The conflicting rule. */
042: private Rule conflictingRule;
043:
044: /**
045: * @see java.lang.Exception#Exception()
046: *
047: * @param pkg
048: * The <code>Package</code>.
049: * @param originalRule
050: * The <code>Rule</code> already in the <code>Package</code>.
051: * @param conflictingRule
052: * The new, conflicting <code>Rule</code>.
053: */
054: public DuplicateRuleNameException(final Package pkg,
055: final Rule originalRule, final Rule conflictingRule) {
056: super (createMessage(pkg, conflictingRule));
057: this .pkg = pkg;
058: this .originalRule = originalRule;
059: this .conflictingRule = conflictingRule;
060: }
061:
062: /**
063: * @see java.lang.Exception#Exception(Throwable cause)
064: *
065: * @param pkg
066: * The <code>Package</code>.
067: * @param originalRule
068: * The <code>Rule</code> already in the <code>Package</code>.
069: * @param conflictingRule
070: * The new, conflicting <code>Rule</code>.
071: */
072: public DuplicateRuleNameException(final Package pkg,
073: final Rule originalRule, final Rule conflictingRule,
074: final Throwable cause) {
075: super (createMessage(pkg, conflictingRule), cause);
076: this .pkg = pkg;
077: this .originalRule = originalRule;
078: this .conflictingRule = conflictingRule;
079: }
080:
081: /**
082: * Retrieve the <code>Package</code>.
083: *
084: * @return The <code>Package</code>.
085: */
086: public Package getPackage() {
087: return this .pkg;
088: }
089:
090: /**
091: * Retrieve the original <code>Rule</code> in the <code>Package</code>.
092: *
093: * @return The <code>Rule</code>.
094: */
095: public Rule getOriginalRule() {
096: return this .originalRule;
097: }
098:
099: /**
100: * Retrieve the new conflicting <code>Rule</code>.
101: *
102: * @return The <code>Rule</code>.
103: */
104: public Rule getConflictingRule() {
105: return this .conflictingRule;
106: }
107:
108: private static String createMessage(final Package pkg,
109: final Rule rule) {
110: return "Package "
111: + ((pkg.getName() != null) ? pkg.getName()
112: : "<no-name>")
113: + " already contains rule with name " + rule.getName();
114: }
115: }
|