/**
   * @param model embededded model defining the new component, from an {@link
   *     org.apache.tapestry5.annotations.Component} annotation
   * @param loadingComponent the currently loading container component
   * @param newComponent the new child of the container whose parameters are being bound
   * @param newComponentBindings map of bindings for the new component (used to handle inheriting of
   *     informal parameters)
   */
  private void bindParametersFromModel(
      EmbeddedComponentModel model,
      ComponentPageElement loadingComponent,
      ComponentPageElement newComponent,
      Map<String, Binding> newComponentBindings) {
    for (String name : model.getParameterNames()) {
      String value = model.getParameterValue(name);

      String defaultBindingPrefix =
          determineDefaultBindingPrefix(newComponent, name, BindingConstants.PROP);

      Binding binding =
          findBinding(
              loadingComponent,
              newComponent,
              name,
              value,
              defaultBindingPrefix,
              newComponent.getLocation());

      if (binding != null) {
        newComponent.bindParameter(name, binding);

        // So that the binding can be shared if inherited by a subcomponent
        newComponentBindings.put(name, binding);
      }
    }
  }
  private void bindParameterFromTemplate(ComponentPageElement component, AttributeToken token) {
    String name = token.getName();
    ComponentResources resources = component.getComponentResources();

    // If already bound (i.e., from the component class, via @Component), then
    // ignore the value in the template. This may need improving to just ignore
    // the value if it is an unprefixed literal string.

    if (resources.isBound(name)) return;

    // Meta default of literal for the template.

    String defaultBindingPrefix =
        determineDefaultBindingPrefix(component, name, BindingConstants.LITERAL);

    Binding binding =
        findBinding(
            loadingElement,
            component,
            name,
            token.getValue(),
            defaultBindingPrefix,
            token.getLocation());

    if (binding != null) {
      component.bindParameter(name, binding);

      Map<String, Binding> bindingMap = componentIdToBindingMap.get(component.getCompleteId());
      bindingMap.put(name, binding);
    }
  }
  private void parameter(ParameterToken token) {
    ComponentPageElement element = activeElementStack.peek();
    String name = token.getName();

    BlockImpl block =
        new BlockImpl(
            token.getLocation(), String.format("Parmeter %s of %s", name, element.getCompleteId()));

    Binding binding = new LiteralBinding("block parameter " + name, block, token.getLocation());

    // TODO: Check that the t:parameter doesn't appear outside of an embedded component.

    element.bindParameter(name, binding);

    setupBlock(block);
  }
  /**
   * Invoked when a component's end tag is reached, to check and process informal parameters as per
   * the {@link org.apache.tapestry5.model.EmbeddedComponentModel#getInheritInformalParameters()}
   * flag.
   *
   * @param loadingComponent the container component that was loaded
   * @param model
   * @param newComponent
   * @param newComponentBindings
   */
  private void handleInformalParameters(
      ComponentPageElement loadingComponent,
      EmbeddedComponentModel model,
      ComponentPageElement newComponent,
      ComponentModel newComponentModel,
      Map<String, Binding> newComponentBindings) {

    Map<String, Binding> informals = loadingComponent.getInformalParameterBindings();

    for (String name : informals.keySet()) {
      if (newComponentModel.getParameterModel(name) != null) continue;

      Binding binding = informals.get(name);

      newComponent.bindParameter(name, binding);
      newComponentBindings.put(name, binding);
    }
  }