001/* 002 * ModeShape (http://www.modeshape.org) 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 */ 016package org.modeshape.sequencer.ddl; 017 018import org.modeshape.common.text.ParsingException; 019import org.modeshape.common.text.Position; 020import org.modeshape.sequencer.ddl.DdlConstants.Problems; 021 022/** 023 * A special form of {@link Problems} that is also a {@link ParsingException}. 024 */ 025public class DdlParserProblem extends ParsingException implements DdlConstants.Problems { 026 private static final long serialVersionUID = 2010539270968770893L; 027 028 private int level = OK; 029 private String unusedSource; 030 031 public DdlParserProblem( Position position ) { 032 super(position); 033 034 } 035 036 public DdlParserProblem( int level, 037 Position position, 038 String message, 039 Throwable cause ) { 040 super(position, message, cause); 041 this.level = level; 042 } 043 044 public DdlParserProblem( int level, 045 Position position, 046 String message ) { 047 super(position, message); 048 this.level = level; 049 } 050 051 /** 052 * @return the unused statement string 053 */ 054 public String getUnusedSource() { 055 return this.unusedSource; 056 } 057 058 public void setUnusedSource( String unusedSource ) { 059 if (unusedSource == null) { 060 unusedSource = ""; 061 } 062 this.unusedSource = unusedSource; 063 } 064 065 public void appendSource( boolean addSpaceBefore, 066 String value ) { 067 if (addSpaceBefore) { 068 this.unusedSource = this.unusedSource + DdlConstants.SPACE; 069 } 070 this.unusedSource = this.unusedSource + value; 071 } 072 073 public void appendSource( boolean addSpaceBefore, 074 String value, 075 String... additionalStrs ) { 076 if (addSpaceBefore) { 077 this.unusedSource = this.unusedSource + DdlConstants.SPACE; 078 } 079 this.unusedSource = this.unusedSource + value; 080 } 081 082 public int getLevel() { 083 return level; 084 } 085 086 /** 087 * @param level Sets level to the specified value. 088 */ 089 public void setLevel( int level ) { 090 this.level = level; 091 } 092 093 @Override 094 public String toString() { 095 if (this.level == WARNING) { 096 return ("WARNING: " + super.toString()); 097 } else if (this.level == ERROR) { 098 return ("ERROR: " + super.toString()); 099 } 100 101 return super.toString(); 102 } 103 104}