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,
013    software distributed under the License is distributed on an
014    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015    KIND, either express or implied.  See the License for the
016    specific language governing permissions and limitations
017    under the License.
018 */
019package org.apache.wiki.api.spi;
020
021import org.apache.wiki.api.core.Engine;
022
023import javax.servlet.ServletConfig;
024import javax.servlet.ServletContext;
025import java.util.Properties;
026
027
028public class EngineDSL {
029
030    private final EngineSPI engineSPI;
031
032    EngineDSL( final EngineSPI engineSPI ) {
033        this.engineSPI = engineSPI;
034    }
035
036    /**
037     * Locate, or build if necessary, a configured {@link Engine} instance.
038     *
039     * @param config servlet config holding the {@link Engine} instance.
040     * @return a configured {@link Engine} instance.
041     */
042    public Engine find( final ServletConfig config ) {
043        return find( config.getServletContext(), null );
044    }
045
046    /**
047     * Locate, or build if necessary, a configured {@link Engine} instance.
048     *
049     * @param config servlet config holding the {@link Engine} instance.
050     * @param props Engine configuration properties.
051     * @return a configured {@link Engine} instance.
052     */
053    public Engine find( final ServletConfig config, final Properties props ) {
054        return find( config.getServletContext(), props );
055    }
056
057    /**
058     * Locate, or build if necessary, a configured {@link Engine} instance.
059     *
060     * @param context servlet context holding the {@link Engine} instance.
061     * @param props Engine configuration properties.
062     * @return a configured {@link Engine} instance.
063     */
064    public Engine find( final ServletContext context, final Properties props ) {
065        return engineSPI.find( context, props );
066    }
067
068}