001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  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
019package org.apache.hadoop.lib.server;
020
021import org.apache.hadoop.lib.lang.XException;
022
023/**
024 * Exception thrown by the {@link Server} class.
025 */
026public class ServerException extends XException {
027
028  /**
029   * Error codes use by the {@link Server} class.
030   */
031  public static enum ERROR implements XException.ERROR {
032    S01("Dir [{0}] does not exist"),
033    S02("[{0}] is not a directory"),
034    S03("Could not load file from classpath [{0}], {1}"),
035    S04("Service [{0}] does not implement declared interface [{1}]"),
036    S05("[{0}] is not a file"),
037    S06("Could not load file [{0}], {1}"),
038    S07("Could not instanciate service class [{0}], {1}"),
039    S08("Could not load service classes, {0}"),
040    S09("Could not set service [{0}] programmatically -server shutting down-, {1}"),
041    S10("Service [{0}] requires service [{1}]"),
042    S11("Service [{0}] exception during status change to [{1}] -server shutting down-, {2}");
043
044    private String msg;
045
046    /**
047     * Constructor for the error code enum.
048     *
049     * @param msg message template.
050     */
051    private ERROR(String msg) {
052      this.msg = msg;
053    }
054
055    /**
056     * Returns the message template for the error code.
057     *
058     * @return the message template for the error code.
059     */
060    @Override
061    public String getTemplate() {
062      return msg;
063    }
064  }
065
066  /**
067   * Constructor for sub-classes.
068   *
069   * @param error error code for the XException.
070   * @param params parameters to use when creating the error message
071   * with the error code template.
072   */
073  protected ServerException(XException.ERROR error, Object... params) {
074    super(error, params);
075  }
076
077  /**
078   * Creates an server exception using the specified error code.
079   * The exception message is resolved using the error code template
080   * and the passed parameters.
081   *
082   * @param error error code for the XException.
083   * @param params parameters to use when creating the error message
084   * with the error code template.
085   */
086  public ServerException(ERROR error, Object... params) {
087    super(error, params);
088  }
089
090}