KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > pageload > QueuedInheritInformalBindings


1 // Copyright 2004, 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.tapestry.pageload;
16
17 import java.util.Iterator JavaDoc;
18
19 import org.apache.tapestry.IBinding;
20 import org.apache.tapestry.IComponent;
21 import org.apache.tapestry.spec.IComponentSpecification;
22
23 /**
24  * Used to defer connection of inherited informal bindings.
25  *
26  * @author Howard Lewis Ship
27  * @since 4.0
28  */

29 class QueuedInheritInformalBindings implements IQueuedInheritedBinding
30 {
31     private IComponent _component;
32
33     QueuedInheritInformalBindings(IComponent component)
34     {
35         _component = component;
36     }
37
38     public void connect()
39     {
40
41         IComponent container = _component.getContainer();
42
43         for (Iterator JavaDoc it = container.getBindingNames().iterator(); it.hasNext();)
44         {
45             String JavaDoc bindingName = (String JavaDoc) it.next();
46             connectInformalBinding(container, _component, bindingName);
47         }
48     }
49
50     private void connectInformalBinding(
51         IComponent container,
52         IComponent component,
53         String JavaDoc bindingName)
54     {
55         IComponentSpecification componentSpec = component.getSpecification();
56         IComponentSpecification containerSpec = container.getSpecification();
57
58         // check if binding already exists in the component
59
if (component.getBinding(bindingName) != null)
60             return;
61
62         // check if parameter is informal for the component
63
if (componentSpec.getParameter(bindingName) != null
64             || componentSpec.isReservedParameterName(bindingName))
65             return;
66
67         // check if parameter is informal for the container
68
if (containerSpec.getParameter(bindingName) != null
69             || containerSpec.isReservedParameterName(bindingName))
70             return;
71
72         // if everything passes, establish binding
73
IBinding binding = container.getBinding(bindingName);
74         component.setBinding(bindingName, binding);
75     }
76 }
Popular Tags