KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > treeprocessor > sitemap > ActNodeBuilder


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

16 package org.apache.cocoon.components.treeprocessor.sitemap;
17
18 import org.apache.avalon.framework.configuration.Configuration;
19 import org.apache.avalon.framework.configuration.ConfigurationException;
20 import org.apache.cocoon.acting.Action;
21 import org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNodeBuilder;
22 import org.apache.cocoon.components.treeprocessor.CategoryNode;
23 import org.apache.cocoon.components.treeprocessor.CategoryNodeBuilder;
24 import org.apache.cocoon.components.treeprocessor.LinkedProcessingNodeBuilder;
25 import org.apache.cocoon.components.treeprocessor.ProcessingNode;
26 import org.apache.cocoon.components.treeprocessor.variables.VariableResolverFactory;
27
28 /**
29  *
30  * @author <a HREF="mailto:sylvain@apache.org">Sylvain Wallez</a>
31  * @version CVS $Id: ActNodeBuilder.java 30932 2004-07-29 17:35:38Z vgritsenko $
32  */

33 public class ActNodeBuilder extends AbstractParentProcessingNodeBuilder
34                             implements LinkedProcessingNodeBuilder {
35
36     private ActSetNode actSetNode;
37     private String JavaDoc actSetName;
38
39     public ProcessingNode buildNode(Configuration config) throws Exception JavaDoc {
40         
41         boolean inActionSet = this.treeBuilder.getAttribute(ActionSetNodeBuilder.IN_ACTION_SET) != null;
42
43         // Is it an action-set call ?
44
this.actSetName = config.getAttribute("set", null);
45         if (actSetName == null) {
46             
47             if (inActionSet) {
48                 // Check that children are only parameters or actions
49
Configuration children[] = config.getChildren();
50                 for (int i = 0; i < children.length; i++) {
51                     String JavaDoc name = children[i].getName();
52                     if (!"act".equals(name) && !"parameter".equals(name)) {
53                         throw new ConfigurationException("An action set can only contain actions and not '"
54                             + name + "' at " + children[i].getLocation());
55                     }
56                 }
57             }
58
59             String JavaDoc name = config.getAttribute("name", null);
60             String JavaDoc source = config.getAttribute("src", null);
61             String JavaDoc type = this.treeBuilder.getTypeForStatement(config, Action.ROLE + "Selector");
62
63             ActTypeNode actTypeNode = new ActTypeNode(
64                 type,
65                 VariableResolverFactory.getResolver(source, this.manager),
66                 name,
67                 inActionSet
68             );
69             this.treeBuilder.setupNode(actTypeNode, config);
70
71             actTypeNode.setChildren(buildChildNodes(config));
72
73             return actTypeNode;
74
75         } else {
76
77             if (inActionSet) {
78                 throw new ConfigurationException("Cannot call an action set from an action set at " + config.getLocation());
79             }
80
81             // Action set call
82
if (config.getAttribute("src", null) != null) {
83                 getLogger().warn("The 'src' attribute is ignored for action-set call at " + config.getLocation());
84             }
85             this.actSetNode = new ActSetNode();
86             this.treeBuilder.setupNode(this.actSetNode, config);
87
88             this.actSetNode.setChildren(buildChildNodes(config));
89
90             return this.actSetNode;
91         }
92     }
93
94     public void linkNode() throws Exception JavaDoc {
95
96         if (this.actSetNode != null) {
97             // Link action-set call to the action set
98
CategoryNode actionSets = CategoryNodeBuilder.getCategoryNode(this.treeBuilder, "action-sets");
99
100             if (actionSets == null)
101                 throw new ConfigurationException("This sitemap contains no action sets. Cannot call at " + actSetNode.getLocation());
102
103             ActionSetNode actionSetNode = (ActionSetNode)actionSets.getNodeByName(this.actSetName);
104
105             this.actSetNode.setActionSet(actionSetNode);
106         }
107     }
108 }
109
Popular Tags