001: /*
002: * Copyright 2005 JBoss Inc
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.drools.lang.dsl;
018:
019: import org.drools.compiler.DroolsError;
020:
021: /**
022: * MappingError
023: * A class to represent errors found in a DSL mapping
024: *
025: * @author <a href="mailto:tirelli@post.com">Edson Tirelli</a>
026: *
027: * Created: 11/04/2006
028: */
029: public class MappingError extends DroolsError {
030: public static final int TEMPLATE_UNKNOWN = 0;
031: public static final int TEMPLATE_NATURAL = 1;
032: public static final int TEMPLATE_TARGET = 2;
033:
034: public static final int ERROR_UNUSED_TOKEN = 21;
035: public static final int ERROR_UNDECLARED_TOKEN = 22;
036: public static final int ERROR_INVALID_TOKEN = 23;
037: public static final int ERROR_UNMATCHED_BRACES = 24;
038:
039: private final int errorCode;
040: private final int template;
041: private final int offset;
042: private final String token;
043: private String templateText;
044: private final int[] line;
045:
046: public MappingError(final int errorCode, final int template,
047: final int offset, final String token,
048: final String templateText, final int line) {
049: this .errorCode = errorCode;
050: this .template = template;
051: this .token = token;
052: this .offset = offset;
053: this .templateText = templateText;
054: this .line = new int[] { line };
055: }
056:
057: /**
058: * Returns this error code
059: * @return
060: */
061: public int getErrorCode() {
062: return this .errorCode;
063: }
064:
065: public int[] getErrorLines() {
066: return this .line;
067: }
068:
069: /**
070: * @return the offset
071: */
072: public int getOffset() {
073: return this .offset;
074: }
075:
076: /**
077: * @return the template
078: */
079: public int getTemplate() {
080: return this .template;
081: }
082:
083: /**
084: * @return the original content.
085: */
086: public String getTemplateText() {
087: return this .templateText;
088: }
089:
090: /**
091: * @inheritDoc
092: *
093: * @see org.drools.compiler.DroolsError#getMessage()
094: */
095: public String getMessage() {
096: switch (this .errorCode) {
097: case ERROR_UNUSED_TOKEN:
098: return "Warning, the token " + this .token
099: + " not used in the mapping.";
100: case ERROR_UNDECLARED_TOKEN:
101: return "Warning, the token "
102: + this .token
103: + " not found in the expression. (May not be a problem).";
104: case ERROR_INVALID_TOKEN:
105: return "Invalid token declaration at offset " + this .offset
106: + ": " + this .token;
107: case ERROR_UNMATCHED_BRACES:
108: return "Unexpected } found at offset " + this .offset;
109: default:
110: return "Unkown error at offset: " + this.offset;
111: }
112: }
113: }
|