天天看點

Tapestry靈魂——位元組碼生成

<script type="text/javascript"> document.location.href="http://blog.csdn.net/mindhawk/archive/2006/12/16/1445012.aspx" target="_blank" rel="external nofollow" ; </script>

    Tapestry最大的的一個特點就是通過位元組碼生成在運作時動态的建立頁面的執行個體。這也是整個架構能有如此活力的基礎。通過運作時的代碼生成不僅使說明(specification),模闆(template)和類結合起來形成一個統一的整體,更主要的是使程式員得到了極大的解放。所有重複性的,易出錯的煩瑣工作都有架構負責,動态的将必須的資訊賦給頁面。程式員需要的僅僅是關心一些最為基本的設定。

    Tapestry4對這個生成的過程作了一個較大的調整。和其它改進類似,頁面生成也是通過HiveMind來組織的。将各種不同的生成政策使用接口分離開,然後再通過HiveMind的服務和配置組織在一起。

    與代碼生成有關的主要對象大緻可以分為三類。第一個是工廠方法,負責共的生成排程緩存的工作。另一類是基本生成工作類(enhance),負責各種不同的類型的代碼生成工作。最後一個是對基本生成工作類的一個擴充,主要用于生成注入屬性的位元組碼。至于如何實際生成位元組碼可以參見javassist。

    工廠方法(ComponentConstructorFactory):整個項目隻有一個執行個體,主要是提供一個統一的服務接口。

    基本生成類(EnhancementWorker):通過HiveMind組成成了一個責任鍊的形式(四人幫的 chain 模式),生成時會逐個調用各個實作類生成具體位元組碼。

    注入擴充類(InjectEnhancementWorker):這個擴充由一個基本生成類調用。由key/value的形式儲存組織,使用者可以根據自己的需要添加實作。key是該擴充的名稱,value是具體的實作類。

Tapestry靈魂——位元組碼生成

    上圖沒有列出所有的實作類。EnhancementWorker接口的主要實作有十多類,分别負責資源資訊(InjectMessagesWorker)、說明(InjectSpecificationWorker)、定義屬性(SpecifiedPropertyWorker)、參數(ParameterPropertyWorker)、注入配置設定(DispatchToInjectWorker)、元件(InjectComponentWorker)、Bean(InjectBeanWorker)、Asset(InjectAssetWorker)、抽象屬性(AbstractPropertyWorker)、頁面的接口(pageBeginRender等五類接口,InjectPageDetachListenerWorker,InjectPageAttachListenerWorker,InjectPageValidateListenerWorker,InjectPageBeginRenderListenerWorker,InjectPageEndRenderListenerWorker)等的生成工作。這十多個類的組成一個有序的 chain,抽象屬性是這個序列的分水嶺。大體順序與我上面提到的一緻,在抽象屬性前的為一個集合,每一個都必須在抽象屬性之前,但是他們之間沒有順序的限定。抽象屬性之後的是一個集合。AnnotationEnhancementWorker 比較特殊,隻有在java5以上才有效,它實際上是其它EnhancementWorker的一個排程。如果存在它會排在這個 chain 的最前面。

    注入配置設定(DispatchToInjectWorker)有它自己另外一套的配置,主要使用者便于使用者擴充注入的屬性。架構提供的主要有六類。InjectMetaWorker,InjectObjectWorker,InjectPageWorker,InjectScriptWorker,InjectStateFlagWorker,InjectStateWorker。

以下是我編寫的一個簡單的元件,包含了其中所有的典型的生成位元組碼,并注明了是由誰生成的(因為考慮到複用,有些屬性由第一個生成該屬性的生成類完成):

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

public   class  $Enhance_21  extends  com.kft.tapestry.components.Enhance  ... {

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    private org.apache.tapestry.services.ComponentMessagesSource _$componentMessagesSource;

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    private org.apache.hivemind.Messages _$messages;

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    private org.apache.tapestry.spec.IComponentSpecification _$specification;

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    private java.lang.String _$sessionProperty;

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    private java.lang.String _$sessionProperty$default;

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    private java.lang.String _$specifiedProperty;

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    private java.lang.String _$specifiedProperty$default;

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    private java.lang.String _$parameter;

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    private java.lang.String _$parameter$Default;

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    private boolean _$parameter$Cached;

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    private java.lang.Class _class$java$lang$String;

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    private org.apache.tapestry.services.ComponentPropertySource _$componentPropertySource;

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    private org.apache.tapestry.coerce.ValueConverter _$valueConverter;

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    private org.apache.tapestry.engine.IEngineService _$injectObject;

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    private org.apache.tapestry.enhance.DeferredScript _$script;

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    private java.lang.Object _$injectState;

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    private org.apache.tapestry.engine.state.ApplicationStateManager _$applicationStateManager;

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    private java.lang.Class _class$org$apache$tapestry$components$Insert;

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    private org.apache.hivemind.Location _$injectComponent$location;

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    private org.apache.tapestry.components.Insert _$injectComponent;

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    private java.lang.String _$abstractProperty;

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    private java.lang.String _$abstractProperty$defaultValue;

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    public $Enhance_21(org.apache.tapestry.services.ComponentMessagesSource $1,

Tapestry靈魂——位元組碼生成

            org.apache.tapestry.spec.IComponentSpecification $2, java.lang.Class $3,

Tapestry靈魂——位元組碼生成

            org.apache.tapestry.services.ComponentPropertySource $4,

Tapestry靈魂——位元組碼生成

            org.apache.tapestry.coerce.ValueConverter $5,

Tapestry靈魂——位元組碼生成

            org.apache.tapestry.engine.IEngineService $6,

Tapestry靈魂——位元組碼生成

            org.apache.tapestry.enhance.DeferredScript $7,

Tapestry靈魂——位元組碼生成

            org.apache.tapestry.engine.state.ApplicationStateManager $8, java.lang.Class $9,

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

            org.apache.hivemind.Location $10) ...{

Tapestry靈魂——位元組碼生成

        // InjectMessagesWorker

Tapestry靈魂——位元組碼生成

        _$componentMessagesSource = $1;

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

        // InjectSpecificationWorker

Tapestry靈魂——位元組碼生成

        _$specification = $2;

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

        // ParameterPropertyWorker or other(公用屬性隻需生成一次,由最先生成的完成)

Tapestry靈魂——位元組碼生成

        _class$java$lang$String = $3;

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

        // DispatchToInjectWorker & InjectMetaWorker

Tapestry靈魂——位元組碼生成

        _$componentPropertySource = $4;

Tapestry靈魂——位元組碼生成

        _$valueConverter = $5;

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

        // DispatchToInjectWorker & InjectObjectWorker

Tapestry靈魂——位元組碼生成

        _$injectObject = $6;

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

        // DispatchToInjectWorker & InjectScriptWorker

Tapestry靈魂——位元組碼生成

        _$script = $7;

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

        // DispatchToInjectWorker & (InjectStateWorker or InjectStateFlagWorker)

Tapestry靈魂——位元組碼生成

        _$applicationStateManager = $8;

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

        // InjectComponentWorker

Tapestry靈魂——位元組碼生成

        _class$org$apache$tapestry$components$Insert = $9;

Tapestry靈魂——位元組碼生成

        _$injectComponent$location = $10;

Tapestry靈魂——位元組碼生成

    }

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    public void cleanupAfterRender(org.apache.tapestry.IRequestCycle $1) ...{

Tapestry靈魂——位元組碼生成

        super.cleanupAfterRender($1);

Tapestry靈魂——位元組碼生成

        org.apache.tapestry.IBinding parameterBinding = getBinding("parameter");

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

        if (_$parameter$Cached && !parameterBinding.isInvariant()) ...{

Tapestry靈魂——位元組碼生成

            _$parameter$Cached = false;

Tapestry靈魂——位元組碼生成

            _$parameter = _$parameter$Default;

Tapestry靈魂——位元組碼生成

        }

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    }

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    public org.apache.tapestry.components.Insert getInjectComponent() ...{

Tapestry靈魂——位元組碼生成

        return _$injectComponent;

Tapestry靈魂——位元組碼生成

    }

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    public void setSpecifiedProperty(java.lang.String $1) ...{

Tapestry靈魂——位元組碼生成

        _$specifiedProperty = $1;

Tapestry靈魂——位元組碼生成

    }

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    public boolean isInjectStateFlag() ...{

Tapestry靈魂——位元組碼生成

        return _$applicationStateManager.exists("visit");

Tapestry靈魂——位元組碼生成

    }

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    public org.apache.tapestry.IPage getInjectPage() ...{

Tapestry靈魂——位元組碼生成

        return getPage().getRequestCycle().getPage("Home");

Tapestry靈魂——位元組碼生成

    }

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    public org.apache.tapestry.IAsset getAsset() ...{

Tapestry靈魂——位元組碼生成

        return getAsset("$template");

Tapestry靈魂——位元組碼生成

    }

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    public org.apache.tapestry.spec.IComponentSpecification getSpecification() ...{

Tapestry靈魂——位元組碼生成

        return _$specification;

Tapestry靈魂——位元組碼生成

    }

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    public java.lang.String getInjectMeta() ...{

Tapestry靈魂——位元組碼生成

        java.lang.String meta = _$componentPropertySource.getComponentProperty(this, "meta");

Tapestry靈魂——位元組碼生成

        return (java.lang.String) _$valueConverter.coerceValue(meta, _class$java$lang$String);

Tapestry靈魂——位元組碼生成

    }

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    public org.apache.tapestry.engine.IEngineService getInjectObject() ...{

Tapestry靈魂——位元組碼生成

        return _$injectObject;

Tapestry靈魂——位元組碼生成

    }

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    public org.apache.hivemind.Messages getMessages() ...{

Tapestry靈魂——位元組碼生成

        if (_$messages == null)

Tapestry靈魂——位元組碼生成

            _$messages = _$componentMessagesSource.getMessages(this);

Tapestry靈魂——位元組碼生成

        return _$messages;

Tapestry靈魂——位元組碼生成

    }

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    public void setAbstractProperty(java.lang.String $1) ...{

Tapestry靈魂——位元組碼生成

        _$abstractProperty = $1;

Tapestry靈魂——位元組碼生成

    }

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    public pojo.Bean getBean() ...{

Tapestry靈魂——位元組碼生成

        return (pojo.Bean) getBeans().getBean("bean");

Tapestry靈魂——位元組碼生成

    }

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    public java.lang.String getSpecifiedProperty() ...{

Tapestry靈魂——位元組碼生成

        return _$specifiedProperty;

Tapestry靈魂——位元組碼生成

    }

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    public java.lang.String getParameter() ...{

Tapestry靈魂——位元組碼生成

        if (_$parameter$Cached)

Tapestry靈魂——位元組碼生成

            return _$parameter;

Tapestry靈魂——位元組碼生成

        org.apache.tapestry.IBinding binding = getBinding("parameter");

Tapestry靈魂——位元組碼生成

        if (binding == null)

Tapestry靈魂——位元組碼生成

            return _$parameter$Default;

Tapestry靈魂——位元組碼生成

        java.lang.String result = (java.lang.String) binding.getObject(_class$java$lang$String);

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

        if (isRendering() || binding.isInvariant()) ...{

Tapestry靈魂——位元組碼生成

            _$parameter = result;

Tapestry靈魂——位元組碼生成

            _$parameter$Cached = true;

Tapestry靈魂——位元組碼生成

        }

Tapestry靈魂——位元組碼生成

        return result;

Tapestry靈魂——位元組碼生成

    }

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    public java.lang.Object getInjectState() ...{

Tapestry靈魂——位元組碼生成

        if (_$injectState == null)

Tapestry靈魂——位元組碼生成

            _$injectState = (java.lang.Object) _$applicationStateManager.get("visit");

Tapestry靈魂——位元組碼生成

        return _$injectState;

Tapestry靈魂——位元組碼生成

    }

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    public java.lang.String getAbstractProperty() ...{

Tapestry靈魂——位元組碼生成

        return _$abstractProperty;

Tapestry靈魂——位元組碼生成

    }

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    public void finishLoad(org.apache.tapestry.IRequestCycle $1,

Tapestry靈魂——位元組碼生成

            org.apache.tapestry.engine.IPageLoader $2,

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

            org.apache.tapestry.spec.IComponentSpecification $3) ...{

Tapestry靈魂——位元組碼生成

        super.finishLoad($1, $2, $3);

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

        // SpecifiedPropertyWorker

Tapestry靈魂——位元組碼生成

        _$sessionProperty$default = _$sessionProperty;

Tapestry靈魂——位元組碼生成

        _$specifiedProperty$default = _$specifiedProperty;

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

        // InjectComponentWorker

Tapestry靈魂——位元組碼生成

        _$injectComponent = (org.apache.tapestry.components.Insert) org.apache.tapestry.TapestryUtils

Tapestry靈魂——位元組碼生成

                .getComponent(this, "injectComponent",

Tapestry靈魂——位元組碼生成

                        _class$org$apache$tapestry$components$Insert, _$injectComponent$location);

Tapestry靈魂——位元組碼生成

        _$abstractProperty$defaultValue = _$abstractProperty;

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

        // InjectPageDetachListenerWorker

Tapestry靈魂——位元組碼生成

        getPage().addPageDetachListener(this);

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

        // InjectPageAttachListenerWorker

Tapestry靈魂——位元組碼生成

        getPage().addPageAttachListener(this);

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

        // InjectPageValidateListenerWorker

Tapestry靈魂——位元組碼生成

        getPage().addPageValidateListener(this);

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

        // InjectPageBeginRenderListenerWorker

Tapestry靈魂——位元組碼生成

        getPage().addPageBeginRenderListener(this);

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

        // InjectPageEndRenderListenerWorker

Tapestry靈魂——位元組碼生成

        getPage().addPageEndRenderListener(this);

Tapestry靈魂——位元組碼生成

    }

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    public void setInjectState(java.lang.Object $1) ...{

Tapestry靈魂——位元組碼生成

        _$applicationStateManager.store("visit", $1);

Tapestry靈魂——位元組碼生成

        _$injectState = $1;

Tapestry靈魂——位元組碼生成

    }

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    public java.lang.String getSessionProperty() ...{

Tapestry靈魂——位元組碼生成

        return _$sessionProperty;

Tapestry靈魂——位元組碼生成

    }

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    public void setSessionProperty(java.lang.String $1) ...{

Tapestry靈魂——位元組碼生成

        org.apache.tapestry.Tapestry.fireObservedChange(this, "sessionProperty", $1);

Tapestry靈魂——位元組碼生成

        _$sessionProperty = $1;

Tapestry靈魂——位元組碼生成

    }

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    public void setParameter(java.lang.String $1) ...{

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

        if (!isInActiveState()) ...{

Tapestry靈魂——位元組碼生成

            _$parameter$Default = $1;

Tapestry靈魂——位元組碼生成

            return;

Tapestry靈魂——位元組碼生成

        }

Tapestry靈魂——位元組碼生成

        org.apache.tapestry.IBinding binding = getBinding("parameter");

Tapestry靈魂——位元組碼生成

        if (binding == null)

Tapestry靈魂——位元組碼生成

            throw new org.apache.hivemind.ApplicationRuntimeException(

Tapestry靈魂——位元組碼生成

                    "Parameter 'parameter' is not bound and can not be updated.");

Tapestry靈魂——位元組碼生成

        binding.setObject($1);

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

        if (isRendering()) ...{

Tapestry靈魂——位元組碼生成

            _$parameter = $1;

Tapestry靈魂——位元組碼生成

            _$parameter$Cached = true;

Tapestry靈魂——位元組碼生成

        }

Tapestry靈魂——位元組碼生成

    }

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    public void pageDetached(org.apache.tapestry.event.PageEvent $1) ...{

Tapestry靈魂——位元組碼生成

        super.pageDetached($1);

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

        // SpecifiedPropertyWorker

Tapestry靈魂——位元組碼生成

        _$sessionProperty = _$sessionProperty$default;

Tapestry靈魂——位元組碼生成

        _$specifiedProperty = _$specifiedProperty$default;

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

        // DispatchToInjectWorker & InjectStateWorker

Tapestry靈魂——位元組碼生成

        _$injectState = null;

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

        // AbstractPropertyWorker

Tapestry靈魂——位元組碼生成

        _$abstractProperty = _$abstractProperty$defaultValue;

Tapestry靈魂——位元組碼生成

    }

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    public org.apache.tapestry.IScript getInjectScript() ...{

Tapestry靈魂——位元組碼生成

        return _$script.getScript();

Tapestry靈魂——位元組碼生成

    }

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

}

下面是這個元件的java類:

Tapestry靈魂——位元組碼生成

package  com.kft.tapestry.components;

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

import  org.apache.tapestry.BaseComponent;

Tapestry靈魂——位元組碼生成

import  org.apache.tapestry.IAsset;

Tapestry靈魂——位元組碼生成

import  org.apache.tapestry.IPage;

Tapestry靈魂——位元組碼生成

import  org.apache.tapestry.IScript;

Tapestry靈魂——位元組碼生成

import  org.apache.tapestry.components.Insert;

Tapestry靈魂——位元組碼生成

import  org.apache.tapestry.engine.IEngineService;

Tapestry靈魂——位元組碼生成

import  org.apache.tapestry.engine.PageService;

Tapestry靈魂——位元組碼生成

import  org.apache.tapestry.event.PageAttachListener;

Tapestry靈魂——位元組碼生成

import  org.apache.tapestry.event.PageBeginRenderListener;

Tapestry靈魂——位元組碼生成

import  org.apache.tapestry.event.PageDetachListener;

Tapestry靈魂——位元組碼生成

import  org.apache.tapestry.event.PageEndRenderListener;

Tapestry靈魂——位元組碼生成

import  org.apache.tapestry.event.PageEvent;

Tapestry靈魂——位元組碼生成

import  org.apache.tapestry.event.PageValidateListener;

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

import  pojo.Bean;

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

public   abstract   class  Enhance  extends  BaseComponent  implements  PageBeginRenderListener,

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

        PageEndRenderListener, PageAttachListener, PageDetachListener, PageValidateListener  ... {

Tapestry靈魂——位元組碼生成

    public abstract String getAbstractProperty();

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    public abstract String getSpecifiedProperty();

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    public abstract String getSessionProperty();

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    public abstract String getParameter();

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    public abstract Insert getInjectComponent();

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    public abstract Bean getBean();

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    public abstract IAsset getAsset();

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    public abstract IPage getInjectPage();

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    public abstract String getInjectMeta();

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    public abstract IEngineService getInjectObject();

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    public abstract IScript getInjectScript();

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    public abstract Object getInjectState();

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    public abstract boolean isInjectStateFlag();

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    public void pageAttached(PageEvent event) ...{

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    }

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    public void pageBeginRender(PageEvent event) ...{

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    }

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    public void pageValidate(PageEvent event) ...{

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    }

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    public void pageDetached(PageEvent event) ...{

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

    }

Tapestry靈魂——位元組碼生成

}

Tapestry靈魂——位元組碼生成

下面是該元件的說明檔案:

Tapestry靈魂——位元組碼生成

<? xml version="1.0" ?>

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

<! DOCTYPE component-specification PUBLIC

Tapestry靈魂——位元組碼生成

  "-//Apache Software Foundation//Tapestry Specification 4.0//EN"

Tapestry靈魂——位元組碼生成

  "http://jakarta.apache.org/tapestry/dtd/Tapestry_4_0.dtd" >

Tapestry靈魂——位元組碼生成

< component-specification  class ="com.kft.tapestry.components.Enhance" >

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

     < bean  name ="bean"  class ="pojo.Bean"  property ="bean" />

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

     < property  name ="specifiedProperty" />

Tapestry靈魂——位元組碼生成

     < property  name ="sessionProperty"  persist ="session" />

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

     < parameter  name ="parameter" />

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

     < component  id ="injectComponent"  type ="Insert"  property ="injectComponent" >

Tapestry靈魂——位元組碼生成

         < binding  name ="value"  value ="literal:mindhawk" />

Tapestry靈魂——位元組碼生成

     </ component >

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

     < asset  name ="$template"  path ="context:WEB-INF/component/Enhance.html"  property ="asset" />

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

     < inject  property ="injectPage"  type ="page"  object ="Home" />

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

     < meta  key ="meta"  value ="meta" />

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

     < inject  property ="injectMeta"  type ="meta"  object ="meta" />

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

     < inject  property ="injectObject"  object ="engine-service:page" />

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

     < inject  property ="injectScript"  type ="script"  object ="Enhance.script" />

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

     < inject  property ="injectState"  type ="state"  object ="visit" />

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

     < inject  property ="injectStateFlag"  type ="state-flag"  object ="visit" />

Tapestry靈魂——位元組碼生成
Tapestry靈魂——位元組碼生成

</ component-specification >

Tapestry靈魂——位元組碼生成

模版檔案很簡單,不會對生成的代碼有影響,這裡就不列出來了。

繼續閱讀