001package org.apache.maven.doxia.parser.module;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *   http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022/**
023 * An abstract base class that implements the ParserModule interface.
024 *
025 * @since 1.6
026 */
027public abstract class AbstractParserModule
028    implements ParserModule
029{
030    /** The source directory. */
031    private final String sourceDirectory;
032
033    /** The supported file extensions. */
034    private final String[] extensions;
035
036    /** The default file extension. */
037    private final String parserId;
038
039    /**
040     * Constructor with null.
041     */
042    public AbstractParserModule()
043    {
044        this( null, null, (String[]) null );
045    }
046
047    /**
048     * Constructor with same value for everything: source directory and file extension equal parserId.
049     */
050    public AbstractParserModule( String parserId )
051    {
052        this( parserId, parserId, parserId );
053    }
054
055    /**
056     * Constructor with same value for parser id and source directory.
057     */
058    public AbstractParserModule( String parserId, String extension )
059    {
060        this( parserId, parserId, new String[] { extension } );
061    }
062
063    /**
064     * @param sourceDirectory not null
065     * @param extension not null
066     * @param parserId not null
067     * @since 1.1.1
068     * @deprecated can cause confusion with constructor with multiple extensions
069     */
070    protected AbstractParserModule( String sourceDirectory, String extension, String parserId )
071    {
072        super();
073        this.sourceDirectory = sourceDirectory;
074        this.extensions = new String[] { extension };
075        this.parserId = parserId;
076    }
077
078    /**
079     * @param sourceDirectory not null
080     * @param parserId not null (usually equals sourceDirectory)
081     * @param extensions not null
082     * @since 1.7
083     */
084    protected AbstractParserModule( String sourceDirectory, String parserId, String... extensions )
085    {
086        super();
087        this.sourceDirectory = sourceDirectory;
088        this.extensions = extensions;
089        this.parserId = parserId;
090    }
091
092    /** {@inheritDoc} */
093    public String getSourceDirectory()
094    {
095        return sourceDirectory;
096    }
097
098    /** {@inheritDoc} */
099    public String[] getExtensions()
100    {
101        return extensions;
102    }
103
104    /** {@inheritDoc} */
105    public String getParserId()
106    {
107        return parserId;
108    }
109}