    001// Licensed to the Apache License, Version 2.0 (the "License");
    002// you may not use this file except in compliance with the License.
    003// You may obtain a copy of the License at
    004//
    005//     http://www.apache.org/licenses/LICENSE-2.0
    006//
    007// Unless required by applicable law or agreed to in writing, software
    008// distributed under the License is distributed on an "AS IS" BASIS,
    009// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    010// See the License for the specific language governing permissions and
    011// limitations under the License.
    012
    013package org.apache.tapestry5.internal;
    014
    015import org.apache.tapestry5.commons.RecursiveValue;
    016import org.apache.tapestry5.corelib.components.Recursive;
    017import org.apache.tapestry5.corelib.components.RecursiveBody;
    018import org.apache.tapestry5.dom.Element;
    019
    020/**
    021 * <p>
    022 * Class that makes the link between {@link Recursive} and {@link RecursiveBody}.
    023 * </p>
    024 * <p>
    025 * This was contributed by <a href="https://www.pubfactory.com">KGL PubFactory</a>.
    026 * </p>
    027 * @since 5.9.0
    028 */
    029final public class RecursiveContext
    030{
    031
    032    private final Provider provider;
    033
    034    public RecursiveContext(Provider provider)
    035    {
    036        this.provider = provider;
    037    }
    038
    039    public String getId()
    040    {
    041        return provider.getClientIdForCurrent();
    042    }
    043
    044    public RecursiveValue<?> getCurrent()
    045    {
    046        return provider.getCurrent();
    047    }
    048
    049    public Object getValue()
    050    {
    051        return provider.getCurrent().getValue();
    052    }
    053
    054    public void registerPlaceholder(Element element)
    055    {
    056        provider.registerPlaceholder(element);
    057    }
    058
    059    public static interface Provider
    060    {
    061        RecursiveValue<?> getCurrent();
    062
    063        String getClientIdForCurrent();
    064
    065        void registerPlaceholder(Element element);
    066    }
    067
    068}