KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > treeprocessor > CategoryNode


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;
17
18 import java.util.HashMap JavaDoc;
19 import java.util.Map JavaDoc;
20
21 import org.apache.cocoon.ProcessingException;
22 import org.apache.cocoon.environment.Environment;
23
24 /**
25  * A generic container node that just invokes its children.
26  *
27  * @author <a HREF="mailto:sylvain@apache.org">Sylvain Wallez</a>
28  * @version CVS $Id: CategoryNode.java 30932 2004-07-29 17:35:38Z vgritsenko $
29  */

30
31 public final class CategoryNode extends AbstractParentProcessingNode {
32
33     /** The name of this category */
34     private String JavaDoc categoryName;
35
36     /** The Map of named nodes in this category */
37     private Map JavaDoc nodes;
38
39     public void setCategory(String JavaDoc categoryName, Map JavaDoc nodes) {
40         this.categoryName = categoryName;
41         this.nodes = (nodes != null) ? nodes : new HashMap JavaDoc(0);
42     }
43
44     public final boolean invoke(Environment env, InvokeContext context) throws Exception JavaDoc {
45         String JavaDoc msg = "Cannot invoke " + this.categoryName + " at " + getLocation();
46         throw new ProcessingException(msg);
47     }
48
49     public final ProcessingNode getNodeByName(String JavaDoc name) throws Exception JavaDoc {
50         ProcessingNode node = (ProcessingNode)nodes.get(name);
51         if (node == null) {
52             String JavaDoc msg = "Unknown " + this.categoryName + " named '" + name + "' at " + getLocation();
53             throw new ProcessingException(msg);
54         }
55
56         return node;
57     }
58
59     public final boolean invokeByName(String JavaDoc name, Environment env, InvokeContext context)
60       throws Exception JavaDoc {
61
62         return getNodeByName(name).invoke(env, context);
63     }
64 }
65
Popular Tags