001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018package org.apache.log4j.pattern;
019
020
021/**
022 *
023 * Base class for other pattern converters which can return only parts of their name.
024 *
025 * @author Ceki Gülcü
026 * @author Curt Arnold
027 *
028 */
029public abstract class NamePatternConverter
030  extends LoggingEventPatternConverter {
031  /**
032   * Abbreviator.
033   */
034  private final NameAbbreviator abbreviator;
035
036  /**
037   * Constructor.
038   * @param name name of converter.
039   * @param style style name for associated output.
040   * @param options options, may be null, first element will be interpreted as an abbreviation pattern.
041   */
042  protected NamePatternConverter(
043    final String name, final String style, final String[] options) {
044    super(name, style);
045
046    if ((options != null) && (options.length > 0)) {
047      abbreviator = NameAbbreviator.getAbbreviator(options[0]);
048    } else {
049      abbreviator = NameAbbreviator.getDefaultAbbreviator();
050    }
051  }
052
053  /**
054   * Abbreviate name in string buffer.
055   * @param nameStart starting position of name to abbreviate.
056   * @param buf string buffer containing name.
057   */
058  protected final void abbreviate(final int nameStart, final StringBuffer buf) {
059    abbreviator.abbreviate(nameStart, buf);
060  }
061}