Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  // Copyright 2009 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.tapestry5.internal.pageload;
 
 
 
 import java.util.Map;
 
 {
 
     private final ComponentAssemblerSource assemblerSource;
 
     private final Locale locale;
 
     private final ComponentModel componentModel;
 
     private final Location location;
 
     private final Map<StringInstantiatormixinIdToInstantiator = CollectionFactory.newCaseInsensitiveMap();
     private final Map<StringString[]> mixinsIdToOrderConstraints = CollectionFactory.newCaseInsensitiveMap();

    
Maps parameter names (both simple, and qualified with the mixin id) to the corresponding QualifiedParameterName.
 
     private final Map<StringParameterBinderparameterNameToBinder = CollectionFactory.newCaseInsensitiveMap();
 
     // The id of the mixin to receive informal parameters.  If null, the component itself recieves them.
     // If the component doesn't support them, they are quietly dropped.
 
     private final String informalParametersMixinId;
 
     private Map<StringBooleanbound;

    

Parameters:
assemblerSource
instantiatorSource used to access component models
componentClassResolver used to convert mixin types to component models
componentClassName class name of embedded component
locale
embeddedModel embedded model (may be null for components defined in the template)
templateMixins list of mixins from the t:mixins element (possibly null)
location location of components element in its container's template
 
                                           ComponentInstantiatorSource instantiatorSource,
                                           ComponentClassResolver componentClassResolver,
                                           String componentClassName,
                                           Locale locale,
                                           EmbeddedComponentModel embeddedModel,
                                           String templateMixins,
                                           Location location)
     {
         this. = assemblerSource;
         this. = instantiatorSource;
         this. = locale;
         this. = location;
 
          = getModel(componentClassName);
 
         // Add the implementation mixins defined by the component model.
 
         for (String className : .getMixinClassNames())
         {
             addMixin(className,.getOrderForMixin(className));
         }
 
         // If there's an embedded model (i.e., there was an @Component annotation)
         // then it may define some mixins.
 
         if (embeddedModel != null)
         {
             for (String className : embeddedModel.getMixinClassNames())
            {
                addMixin(className,embeddedModel.getConstraintsForMixin(className));
            }
        }
        // And the template may include a t:mixins element to define yet more mixin.
        // Template strings specified as:
        for (String mixinDef : TapestryInternalUtils.splitAtCommas(templateMixins))
        {
            Orderable<Stringorder = TapestryInternalUtils.mixinTypeAndOrder(mixinDef);
            String className = componentClassResolver.resolveMixinTypeToClassName(order.getId());
            addMixin(className,order.getConstraints());
        }
    }
    private String prescanMixins()
    {
        // Mixin id found to support informal parameters
        String supportsInformals = null;
        for (Map.Entry<StringInstantiatorentry : .entrySet())
        {
            String mixinId = entry.getKey();
            ComponentModel mixinModel = entry.getValue().getModel();
            updateParameterNameToQualified(mixinIdmixinModel);
            if (supportsInformals == null && mixinModel.getSupportsInformalParameters())
                supportsInformals = mixinId;
        }
        // The component comes last and overwrites simple names from the others.
        return supportsInformals;
    }
    private void updateParameterNameToQualified(String mixinIdComponentModel model)
    {
        for (String parameterName : model.getParameterNames())
        {
            String defaultBindingPrefix = model.getParameterModel(parameterName).getDefaultBindingPrefix();
            ParameterBinderImpl binder = new ParameterBinderImpl(mixinIdparameterNamedefaultBindingPrefix);
            .put(parameterName,
                                      binder);
            if (mixinId != null)
                .put(mixinId + "." + parameterNamebinder);
        }
    }
    private void addMixin(String classNameString... order)
    {
        Instantiator mixinInstantiator = .getInstantiator(className);
        String mixinId = InternalUtils.lastTerm(className);
        if (.containsKey(mixinId))
            throw new TapestryException(
                    PageloadMessages.uniqueMixinRequired(mixinId),
                    null);
        .put(mixinIdmixinInstantiator);
        .put(mixinIdorder);
    }
    private ComponentModel getModel(String className)
    {
        return .getInstantiator(className).getModel();
    }
    {
    }
    public ParameterBinder createParameterBinder(String parameterName)
    {
        int dotx = parameterName.indexOf('.');
        if (dotx >= 0)
        {
            String mixinId = parameterName.substring(0, dotx);
            if (!.containsKey(mixinId))
            {
                throw new TapestryException(
                        PageloadMessages.mixinidForParamnotfound(parameterName.keySet()),
                        
                        null);
            }
        }
        else
        {
            // Unqualified parameter name. May be a reference not to a parameter of this component, but a published
            // parameter of a component embedded in this component. The ComponentAssembler for this component
            // will know.
            ParameterBinder binder = assembler.getBinder(parameterName);
            if (binder != nullreturn binder;
        }
        final ParameterBinder binder = .get(parameterName);
        if (binder != null)
            return binder;
        // Informal parameter: Is there a mixin for that?
        if ( != null)
            return new ParameterBinderImpl(parameterNamenull);
            return new ParameterBinderImpl(nullparameterNamenull);
        // Otherwise, informal parameter and not supported by the component or any mixin.
        return null;
    }
    public boolean isBound(String parameterName)
    {
        return InternalUtils.get(parameterName) != null;
    }
    public void setBound(String parameterName)
    {
        if ( == null)
             = CollectionFactory.newCaseInsensitiveMap();
        .put(parameterNametrue);
    }
    public void addMixinsToElement(ComponentPageElement newElement)
    {
        for (Map.Entry<StringInstantiatorentry : .entrySet())
        {
            String mixinId = entry.getKey();
            Instantiator instantiator = entry.getValue();
            newElement.addMixin(mixinIdinstantiator.get(mixinId));
        }
    }
    public Location getLocation()
    {
        return ;
    }
New to GrepCode? Check out our FAQ X