001/** 
002 * Copyright (c) 2011, Regents of the University of Colorado 
003 * All rights reserved.
004 * 
005 * Redistribution and use in source and binary forms, with or without
006 * modification, are permitted provided that the following conditions are met:
007 * 
008 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 
009 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 
010 * Neither the name of the University of Colorado at Boulder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 
011 * 
012 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
013 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
014 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
015 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
016 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
017 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
018 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
019 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
020 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
021 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
022 * POSSIBILITY OF SUCH DAMAGE. 
023 */
024package org.cleartk.util;
025
026import java.io.File;
027import java.lang.reflect.Type;
028import java.util.List;
029
030import org.apache.uima.resource.ResourceInitializationException;
031
032/**
033 * <br>
034 * Copyright (c) 2011, Regents of the University of Colorado <br>
035 * All rights reserved.
036 */
037public class CleartkInitializationException extends ResourceInitializationException {
038
039  private static final String DEFAULT_RESOURCE_BUNDLE = "org.cleartk.util.CleartkExceptions";
040
041  private static final String KEY_PREFIX = CleartkInitializationException.class.getName() + ".";
042
043  private static final long serialVersionUID = 1L;
044
045  public static CleartkInitializationException fileNotFound(File file) {
046    String key = KEY_PREFIX + "fileNotFound";
047    return new CleartkInitializationException(DEFAULT_RESOURCE_BUNDLE, key, file.getPath());
048  }
049
050  public static CleartkInitializationException incompatibleTypeParameterAndType(
051      Object object1,
052      String typeParamName1,
053      Type typeParamValue1,
054      Class<?> class2) {
055    String key = KEY_PREFIX + "incompatibleTypeParameterAndType";
056    String class1Name = object1.getClass().getName();
057    return new CleartkInitializationException(
058        DEFAULT_RESOURCE_BUNDLE,
059        key,
060        class1Name,
061        typeParamName1,
062        typeParamValue1,
063        class2.getName());
064  }
065
066  public static CleartkInitializationException incompatibleTypeParameters(
067      Object object1,
068      String typeParamName1,
069      Type typeParamValue1,
070      Object object2,
071      String typeParamName2,
072      Type typeParamValue2) {
073    String key = KEY_PREFIX + "incompatibleTypeParameters";
074    String class1 = object1.getClass().getName();
075    String class2 = object2.getClass().getName();
076    return new CleartkInitializationException(
077        DEFAULT_RESOURCE_BUNDLE,
078        key,
079        class1,
080        typeParamName1,
081        typeParamValue1 == null ? null : typeParamValue1.toString().replaceFirst("^class ", ""),
082        class2,
083        typeParamName2,
084        typeParamValue2 == null ? null : typeParamValue2.toString().replaceFirst("^class ", ""));
085  }
086
087  public static CleartkInitializationException invalidParameterValueSelectFrom(
088      String paramName,
089      List<?> expectedValues,
090      Object actualValue) {
091    String key = KEY_PREFIX + "invalidParameterValueSelectFrom";
092    return new CleartkInitializationException(
093        DEFAULT_RESOURCE_BUNDLE,
094        key,
095        paramName,
096        expectedValues,
097        actualValue);
098  }
099
100  public static CleartkInitializationException neitherParameterSet(
101      String param1,
102      Object value1,
103      String param2,
104      Object value2) {
105    String key = KEY_PREFIX + "neitherParameterSet";
106    return new CleartkInitializationException(
107        DEFAULT_RESOURCE_BUNDLE,
108        key,
109        param1,
110        value1,
111        param2,
112        value2);
113  }
114
115  public static CleartkInitializationException notExactlyOneParameterSet(
116      String param1,
117      Object value1,
118      String param2,
119      Object value2) {
120    String key = KEY_PREFIX + "notExactlyOneParameterSet";
121    return new CleartkInitializationException(
122        DEFAULT_RESOURCE_BUNDLE,
123        key,
124        param1,
125        value1,
126        param2,
127        value2);
128  }
129
130  public static CleartkInitializationException notSingleCharacter(String paramName, Object value) {
131    String key = KEY_PREFIX + "notSingleCharacter";
132    return new CleartkInitializationException(DEFAULT_RESOURCE_BUNDLE, key, paramName, value);
133  }
134
135  public static CleartkInitializationException parameterLessThan(
136      String paramName,
137      Object minExpectedValue,
138      Object actualValue) {
139    String key = KEY_PREFIX + "parameterLessThan";
140    return new CleartkInitializationException(
141        DEFAULT_RESOURCE_BUNDLE,
142        key,
143        paramName,
144        minExpectedValue,
145        actualValue);
146  }
147
148  public CleartkInitializationException(
149      String resourceBundleName,
150      String messageKey,
151      Object... arguments) {
152    super(resourceBundleName, messageKey, arguments);
153  }
154
155  public CleartkInitializationException(
156      Throwable cause,
157      String resourceBundleName,
158      String messageKey,
159      Object... arguments) {
160    super(resourceBundleName, messageKey, arguments, cause);
161  }
162
163}