Package org.apache.tapestry.bean

Source Code of org.apache.tapestry.bean.FieldBeanInitializer

/* $$ 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.bean;

import java.lang.reflect.Field;

import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.hivemind.ClassResolver;
import org.apache.tapestry.IBeanProvider;
import org.apache.tapestry.Tapestry;

/**
*  Initializes a bean with the value of a public static field.
*
@author Howard Lewis Ship
@since 1.0.8
*
**/

public class FieldBeanInitializer extends AbstractBeanInitializer
{public static com.cortexeb.tools.clover.d __CLOVER_47_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);
    protected String _fieldName;
    protected Object _fieldValue;
    private boolean _fieldResolved = false;

    public synchronized void setBeanProperty(IBeanProvider provider, Object bean)
    {try { __CLOVER_47_0.M[284]++;
        __CLOVER_47_0.S[1115]++;ClassResolver resolver = provider.getClassResolver();

        __CLOVER_47_0.S[1116]++;if ((((!_fieldResolved) && (++__CLOVER_47_0.CT[218] != 0)) || (++__CLOVER_47_0.CF[218] == 0))){
            __CLOVER_47_0.S[1117]++;resolveField(resolver);}

        __CLOVER_47_0.S[1118]++;setBeanProperty(bean, _fieldValue);
    } finally { }}

    private void resolveField(ClassResolver resolver)
    {try { __CLOVER_47_0.M[285]++;
        __CLOVER_47_0.S[1119]++;if ((((_fieldResolved) && (++__CLOVER_47_0.CT[219] != 0)) || (++__CLOVER_47_0.CF[219] == 0))){
            __CLOVER_47_0.S[1120]++;return;}

        // This is all copied out of of FieldBinding!!

        __CLOVER_47_0.S[1121]++;int dotx = _fieldName.lastIndexOf('.');

        __CLOVER_47_0.S[1122]++;if ((((dotx < 0) && (++__CLOVER_47_0.CT[220] != 0)) || (++__CLOVER_47_0.CF[220] == 0))){
            __CLOVER_47_0.S[1123]++;throw new ApplicationRuntimeException(
                Tapestry.format("invalid-field-name", _fieldName));}

        __CLOVER_47_0.S[1124]++;String className = _fieldName.substring(0, dotx);
        __CLOVER_47_0.S[1125]++;String simpleFieldName = _fieldName.substring(dotx + 1);

        // Simple class names are assumed to be in the java.lang package.

        __CLOVER_47_0.S[1126]++;if ((((className.indexOf('.') < 0) && (++__CLOVER_47_0.CT[221] != 0)) || (++__CLOVER_47_0.CF[221] == 0))){
            __CLOVER_47_0.S[1127]++;className = "java.lang." + className;}

        __CLOVER_47_0.S[1128]++;Class targetClass = null;

        __CLOVER_47_0.S[1129]++;try
        {
            __CLOVER_47_0.S[1130]++;targetClass = resolver.findClass(className);
        }
        catch (Throwable t)
        {
            __CLOVER_47_0.S[1131]++;throw new ApplicationRuntimeException(
                Tapestry.format("unable-to-resolve-class", className),
                t);
        }

        __CLOVER_47_0.S[1132]++;Field field = null;

        __CLOVER_47_0.S[1133]++;try
        {
            __CLOVER_47_0.S[1134]++;field = targetClass.getField(simpleFieldName);
        }
        catch (NoSuchFieldException ex)
        {
            __CLOVER_47_0.S[1135]++;throw new ApplicationRuntimeException(
                Tapestry.format("field-not-defined", _fieldName),
                ex);
        }

        // Get the value of the field.  null means look for it as a static
        // variable.

        __CLOVER_47_0.S[1136]++;try
        {
            __CLOVER_47_0.S[1137]++;_fieldValue = field.get(null);
        }
        catch (IllegalAccessException ex)
        {
            __CLOVER_47_0.S[1138]++;throw new ApplicationRuntimeException(
                Tapestry.format("illegal-field-access", _fieldName),
                ex);
        }
        catch (NullPointerException ex)
        {
            __CLOVER_47_0.S[1139]++;throw new ApplicationRuntimeException(
                Tapestry.format("field-is-instance", _fieldName),
                ex);
        }

        __CLOVER_47_0.S[1140]++;_fieldResolved = true;
    } finally { }}

}
TOP

Related Classes of org.apache.tapestry.bean.FieldBeanInitializer

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.