KickJava   Java API By Example, From Geeks To Geeks.

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


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.avalon.framework.thread.ThreadSafe;
21 import org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNodeBuilder;
22 import org.apache.cocoon.components.treeprocessor.ProcessingNode;
23
24 /**
25  *
26  * @author <a HREF="mailto:sylvain@apache.org">Sylvain Wallez</a>
27  * @version CVS $Id: ActionSetNodeBuilder.java 30932 2004-07-29 17:35:38Z vgritsenko $
28  */

29
30 public class ActionSetNodeBuilder extends AbstractParentProcessingNodeBuilder implements ThreadSafe {
31     
32     /** The TreeBuilder attribute indicating that an ActionSet is being built */
33     public static final String JavaDoc IN_ACTION_SET = ActionSetNodeBuilder.class.getName() + "/inActionSet";
34
35     public ProcessingNode buildNode(Configuration config) throws Exception JavaDoc {
36
37         String JavaDoc actionSetName = config.getAttribute("name");
38
39         Configuration[] childrenConfig = config.getChildren();
40         // Inform other builders that we're in an action-set
41
this.treeBuilder.setAttribute(IN_ACTION_SET, Boolean.TRUE);
42         
43         // Get the child actions
44
ProcessingNode[] nodes = this.buildChildNodes(config);
45         
46         // And get their names
47
String JavaDoc[] actions = new String JavaDoc[nodes.length];
48         for (int i = 0; i < childrenConfig.length; i++) {
49             Configuration childConfig = childrenConfig[i];
50             String JavaDoc name = childConfig.getName();
51
52             if ("act".equals(name)) {
53                 actions[i] = childConfig.getAttribute("action", null);
54             } else {
55                 // Unknown element
56
String JavaDoc msg = "Unknown element " + name + " in action-set at " + childConfig.getLocation();
57                 throw new ConfigurationException(msg);
58             }
59         }
60
61         ActionSetNode node = new ActionSetNode(actionSetName, nodes, actions);
62         this.treeBuilder.setupNode(node, config);
63
64         // Inform other builders that we're no more in an action-set
65
this.treeBuilder.setAttribute(IN_ACTION_SET, null);
66
67         return node;
68     }
69 }
70
Popular Tags