001/* $Id: DigesterLoaderBuilder.java 992099 2010-09-02 20:09:12Z simonetripodi $
002 *
003 * Licensed to the Apache Software Foundation (ASF) under one or more
004 * contributor license agreements.  See the NOTICE file distributed with
005 * this work for additional information regarding copyright ownership.
006 * The ASF licenses this file to You under the Apache License, Version 2.0
007 * (the "License"); you may not use this file except in compliance with
008 * 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 */
018package org.apache.commons.digester.annotations;
019
020import org.apache.commons.digester.annotations.internal.DefaultAnnotationRuleProviderFactory;
021import org.apache.commons.digester.annotations.spi.AnnotationRuleProviderFactory;
022
023/**
024 * {@link DigesterLoader} builder implementation.
025 *
026 * @since 2.1
027 */
028public final class DigesterLoaderBuilder {
029
030    /**
031     * Builds a new {@link DigesterLoader} using the default SPI
032     * implementations.
033     *
034     * @return a new {@link DigesterLoader} using the default SPI
035     *         implementations.
036     */
037    public static DigesterLoader byDefaultFactories() {
038        return new DigesterLoaderBuilder()
039                    .useDefaultAnnotationRuleProviderFactory()
040                    .useDefaultDigesterLoaderHandlerFactory();
041    }
042
043    /**
044     * Builds a new {@link DigesterLoader} using the default
045     * {@link AnnotationRuleProviderFactory} implementation.
046     *
047     * @return the next chained builder.
048     * @see DefaultAnnotationRuleProviderFactory
049     */
050    public FromAnnotationRuleProviderFactory useDefaultAnnotationRuleProviderFactory() {
051        return this.useAnnotationRuleProviderFactory(new DefaultAnnotationRuleProviderFactory());
052    }
053
054    /**
055     * Builds a new {@link DigesterLoader} using the user defined
056     * {@link AnnotationRuleProviderFactory} implementation.
057     *
058     * @param annotationRuleProviderFactory the user defined
059     *        {@link AnnotationRuleProviderFactory} implementation.
060     * @return the next chained builder.
061     */
062    public FromAnnotationRuleProviderFactory
063            useAnnotationRuleProviderFactory(AnnotationRuleProviderFactory annotationRuleProviderFactory) {
064        if (annotationRuleProviderFactory == null) {
065            throw new IllegalArgumentException("Parameter 'annotationRuleProviderFactory' must be not null");
066        }
067        return new FromAnnotationRuleProviderFactory(annotationRuleProviderFactory);
068    }
069
070}