Package org.apache.tapestry.services.impl

Source Code of org.apache.tapestry.services.impl.ApplicationSpecificationInitializer

/* $$ Clover has instrumented this file $$ */// Copyright 2004 The Apache Software Foundation
//
// Licensed 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.tapestry.services.impl;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServlet;

import org.apache.commons.logging.Log;
import org.apache.hivemind.Resource;
import org.apache.tapestry.parse.ISpecificationParser;
import org.apache.tapestry.resource.ContextResource;
import org.apache.tapestry.services.ApplicationGlobals;
import org.apache.tapestry.services.ApplicationInitializer;
import org.apache.tapestry.services.ClasspathResourceFactory;
import org.apache.tapestry.spec.ApplicationSpecification;
import org.apache.tapestry.spec.IApplicationSpecification;

/**
* Locates the application specification and informs the
* {@link org.apache.tapestry.services.ServletInfo} service about it.
*
* @author Howard Lewis Ship
* @since 3.1
*/
public class ApplicationSpecificationInitializer implements ApplicationInitializer
{public static com.cortexeb.tools.clover.d __CLOVER_300_0 = com.cortexeb.tools.clover.aq.getRecorder(new char[] {67,58,92,119,111,114,107,115,112,97,99,101,92,106,97,107,97,114,116,97,45,116,97,112,101,115,116,114,121,92,102,114,97,109,101,119,111,114,107,92,116,97,114,103,101,116,92,99,108,111,118,101,114,45,100,98},1096998272901L);
    private Log _log;
    private ClasspathResourceFactory _classpathResourceFactory;
    private ApplicationGlobals _globals;
    private ISpecificationParser _parser;

    public static final String APP_SPEC_PATH_PARAM =
        "org.apache.tapestry.application-specification";

    public void initialize(HttpServlet servlet)
    {try { __CLOVER_300_0.M[1437]++;
        __CLOVER_300_0.S[6977]++;IApplicationSpecification spec = null;

        __CLOVER_300_0.S[6978]++;Resource specResource = findApplicationSpecification(servlet);

        __CLOVER_300_0.S[6979]++;if ((((specResource == null) && (++__CLOVER_300_0.CT[1218] != 0)) || (++__CLOVER_300_0.CF[1218] == 0))){
        {
            __CLOVER_300_0.S[6980]++;_log.debug(ImplMessages.noApplicationSpecification(servlet));

            __CLOVER_300_0.S[6981]++;spec = constructStandinSpecification(servlet);
        }}
        else{
            __CLOVER_300_0.S[6982]++;spec = _parser.parseApplicationSpecification(specResource);}

        __CLOVER_300_0.S[6983]++;_globals.store(servlet, spec);
    } finally { }}

    private Resource findApplicationSpecification(HttpServlet servlet)
    {try { __CLOVER_300_0.M[1438]++;
        __CLOVER_300_0.S[6984]++;String path = servlet.getInitParameter(APP_SPEC_PATH_PARAM);

        __CLOVER_300_0.S[6985]++;if ((((path != null) && (++__CLOVER_300_0.CT[1219] != 0)) || (++__CLOVER_300_0.CF[1219] == 0))){
            __CLOVER_300_0.S[6986]++;return _classpathResourceFactory.newResource(path);}

        __CLOVER_300_0.S[6987]++;ServletContext context = servlet.getServletContext();
        __CLOVER_300_0.S[6988]++;String servletName = servlet.getServletName();
        __CLOVER_300_0.S[6989]++;String expectedName = servletName + ".application";

        __CLOVER_300_0.S[6990]++;Resource webInfLocation = new ContextResource(context, "/WEB-INF/");
        __CLOVER_300_0.S[6991]++;Resource webInfAppLocation = webInfLocation.getRelativeResource(servletName + "/");

        __CLOVER_300_0.S[6992]++;Resource result = check(webInfAppLocation, expectedName);
        __CLOVER_300_0.S[6993]++;if ((((result != null) && (++__CLOVER_300_0.CT[1220] != 0)) || (++__CLOVER_300_0.CF[1220] == 0))){
            __CLOVER_300_0.S[6994]++;return result;}

        __CLOVER_300_0.S[6995]++;return check(webInfLocation, expectedName);
    } finally { }}

    private Resource check(Resource resource, String name)
    {try { __CLOVER_300_0.M[1439]++;
        __CLOVER_300_0.S[6996]++;Resource result = resource.getRelativeResource(name);

        __CLOVER_300_0.S[6997]++;if ((((_log.isDebugEnabled()) && (++__CLOVER_300_0.CT[1221] != 0)) || (++__CLOVER_300_0.CF[1221] == 0))){
            __CLOVER_300_0.S[6998]++;_log.debug("Checking for existence of " + result);}

        __CLOVER_300_0.S[6999]++;if ((((result.getResourceURL() != null) && (++__CLOVER_300_0.CT[1222] != 0)) || (++__CLOVER_300_0.CF[1222] == 0))){
        {
            __CLOVER_300_0.S[7000]++;_log.debug("Found " + result);
            __CLOVER_300_0.S[7001]++;return result;
        }}

        __CLOVER_300_0.S[7002]++;return null;
    } finally { }}

    private IApplicationSpecification constructStandinSpecification(HttpServlet servlet)
    {try { __CLOVER_300_0.M[1440]++;
        __CLOVER_300_0.S[7003]++;ApplicationSpecification result = new ApplicationSpecification();

        __CLOVER_300_0.S[7004]++;Resource virtualLocation = new ContextResource(servlet.getServletContext(), "/WEB-INF/");

        __CLOVER_300_0.S[7005]++;result.setSpecificationLocation(virtualLocation);

        __CLOVER_300_0.S[7006]++;result.setName(servlet.getServletName());

        // result.setResourceResolver(_resolver);

        __CLOVER_300_0.S[7007]++;return result;
    } finally { }}

    public void setClasspathResourceFactory(ClasspathResourceFactory factory)
    {try { __CLOVER_300_0.M[1441]++;
        __CLOVER_300_0.S[7008]++;_classpathResourceFactory = factory;
    } finally { }}

    public void setLog(Log log)
    {try { __CLOVER_300_0.M[1442]++;
        __CLOVER_300_0.S[7009]++;_log = log;
    } finally { }}

    public void setGlobals(ApplicationGlobals globals)
    {try { __CLOVER_300_0.M[1443]++;
        __CLOVER_300_0.S[7010]++;_globals = globals;
    } finally { }}

    public void setParser(ISpecificationParser parser)
    {try { __CLOVER_300_0.M[1444]++;
        __CLOVER_300_0.S[7011]++;_parser = parser;
    } finally { }}

}
TOP

Related Classes of org.apache.tapestry.services.impl.ApplicationSpecificationInitializer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.