1 /*
2 * ModeShape (http://www.modeshape.org)
3 * See the COPYRIGHT.txt file distributed with this work for information
4 * regarding copyright ownership. Some portions may be licensed
5 * to Red Hat, Inc. under one or more contributor license agreements.
6 * See the AUTHORS.txt file in the distribution for a full listing of
7 * individual contributors.
8 *
9 * ModeShape is free software. Unless otherwise indicated, all code in ModeShape
10 * is licensed to you under the terms of the GNU Lesser General Public License as
11 * published by the Free Software Foundation; either version 2.1 of
12 * the License, or (at your option) any later version.
13 *
14 * ModeShape is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this software; if not, write to the Free
21 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
23 */
24 package org.modeshape.sequencer.ddl;
25
26 import org.modeshape.common.text.ParsingException;
27 import org.modeshape.common.text.Position;
28 import org.modeshape.sequencer.ddl.DdlConstants.Problems;
29
30 /**
31 * A special form of {@link Problems} that is also a {@link ParsingException}.
32 */
33 public class DdlParserProblem extends ParsingException implements DdlConstants.Problems {
34 private static final long serialVersionUID = 2010539270968770893L;
35
36 private int level = OK;
37 private String unusedSource;
38
39 /**
40 * @param position
41 */
42 public DdlParserProblem( Position position ) {
43 super(position);
44
45 }
46
47 /**
48 * @param level
49 * @param position
50 * @param message
51 * @param cause
52 */
53 public DdlParserProblem( int level,
54 Position position,
55 String message,
56 Throwable cause ) {
57 super(position, message, cause);
58 this.level = level;
59 }
60
61 /**
62 * @param level
63 * @param position
64 * @param message
65 */
66 public DdlParserProblem( int level,
67 Position position,
68 String message ) {
69 super(position, message);
70 this.level = level;
71 }
72
73 /**
74 * @return the unused statement string
75 */
76 public String getUnusedSource() {
77 return this.unusedSource;
78 }
79
80 /**
81 * @param unusedSource
82 */
83 public void setUnusedSource( String unusedSource ) {
84 if (unusedSource == null) {
85 unusedSource = "";
86 }
87 this.unusedSource = unusedSource;
88 }
89
90 public void appendSource( boolean addSpaceBefore,
91 String value ) {
92 if (addSpaceBefore) {
93 this.unusedSource = this.unusedSource + DdlConstants.SPACE;
94 }
95 this.unusedSource = this.unusedSource + value;
96 }
97
98 public void appendSource( boolean addSpaceBefore,
99 String value,
100 String... additionalStrs ) {
101 if (addSpaceBefore) {
102 this.unusedSource = this.unusedSource + DdlConstants.SPACE;
103 }
104 this.unusedSource = this.unusedSource + value;
105 }
106
107 /**
108 * @return level
109 */
110 public int getLevel() {
111 return level;
112 }
113
114 /**
115 * @param level Sets level to the specified value.
116 */
117 public void setLevel( int level ) {
118 this.level = level;
119 }
120
121 /**
122 * {@inheritDoc}
123 *
124 * @see java.lang.Throwable#toString()
125 */
126 @Override
127 public String toString() {
128 if (this.level == WARNING) {
129 return ("WARNING: " + super.toString());
130 } else if (this.level == ERROR) {
131 return ("ERROR: " + super.toString());
132 }
133
134 return super.toString();
135 }
136
137 }