Product.java

/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 *  to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 *  with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package org.apache.creadur.whisker.out.velocity;

import java.io.IOException;
import java.io.Writer;

import org.apache.creadur.whisker.app.Result;
import org.apache.creadur.whisker.app.ResultWriterFactory;

/**
 * Products generated by velocity templates.
 */
public enum Product {

    /**
     * Produces a NOTICE report.
     */
    NOTICE("NOTICE", Result.NOTICE),
    /**
     * Produces a LICENSE report.
     */
    LICENSE("LICENSE", Result.LICENSE),
    /**
     * Produces a directories report.
     */
    DIRECTORIES_REPORT_TEMPLATE("DIRECTORIES", Result.DIRECTORIES_REPORT),
    /**
     * Produces a missing license report.
     */
    MISSING_LICENSE_REPORT_TEMPLATE(
            "MISSING-LICENSE", Result.MISSING_LICENSE_REPORT),
    /**
     * Produces an xml template.
     */
    XML_TEMPLATE("XML-TEMPLATE", Result.XML_TEMPLATE);

    /** Not null. */
    private final String template;
    /** Not null. */
    private final Result result;

    /**
     * Constructs a product.
     * @param template not null
     * @param result not null
     */
    Product(final String template, final Result result) {
        this.template = template;
        this.result = result;
    }

    /**
     * Gets the template name that generates this product.
     * @return not null
     */
    public String getTemplate() {
        return template;
    }

    /**
     * Gets result implemented by this product.
     * @return not null
     */
    public Result getResult() {
        return result;
    }

    /**
     * Builds writer for this product.
     * @param writerFactory not null
     * @return not null
     * @throws IOException when write fails
     */
    public Writer writerFrom(
            final ResultWriterFactory writerFactory) throws IOException {
        return writerFactory.writerFor(getResult());
    }
}