KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > structure > ActionNode


1 /*
2  * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/structure/ActionNode.java,v 1.10 2004/08/09 12:05:29 unico Exp $
3  * $Revision: 1.10 $
4  * $Date: 2004/08/09 12:05:29 $
5  *
6  * ====================================================================
7  *
8  * Copyright 1999-2002 The Apache Software Foundation
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */

23
24 package org.apache.slide.structure;
25
26 import java.util.Vector JavaDoc;
27 import org.apache.slide.content.NodeProperty.NamespaceCache;
28 import org.jdom.Namespace;
29
30 /**
31  * Action node class. The namespace is used to distinguish actions with the
32  * same simple name.
33  *
34  * Although this class has a <code>namespace</code> attribute the equality of
35  * two <code>ActionNode</code>s can still be determined by comparing their
36  * URIs. Therefore this class does not override <code>equals(Object)</code>
37  * from <code>ObjectNode</code>.
38  *
39  * @version $Revision: 1.10 $
40  */

41 public class ActionNode extends ObjectNode {
42     
43     /** generic actions */
44     public static final String JavaDoc DEFAULT_URI = "default";
45     public static final String JavaDoc ALL_URI = "all";
46
47     public static final ActionNode DEFAULT = new ActionNode(DEFAULT_URI, NamespaceCache.DEFAULT_NAMESPACE);
48     public static final ActionNode ALL = new ActionNode(ALL_URI, NamespaceCache.DEFAULT_NAMESPACE);
49     
50     /**
51      * The namespace of the action.
52      */

53     private Namespace namespace;
54     
55     // ----------------------------------------------------------- Constructors
56

57     
58     /**
59      * Constructor.
60      */

61     public ActionNode() {
62         super();
63     }
64     
65     /**
66      * Default constructor.
67      */

68     public ActionNode(String JavaDoc uri) {
69         super(uri);
70     }
71         
72     /**
73      * Default constructor.
74      */

75     public ActionNode(String JavaDoc uri, Vector JavaDoc children, Vector JavaDoc links) {
76         super(uri, children, links);
77     }
78     
79     public ActionNode(String JavaDoc uuri, Vector JavaDoc bindings, Vector JavaDoc parentBindings, Vector JavaDoc links) {
80         super(uuri, bindings, parentBindings, links);
81     }
82     
83     /**
84      * Create an <code>ActionNode</code> with a namespace extracted from the
85      * <code>privilege-namespace</code> property.
86      *
87      * @param uri The Slide-internal URI of the ActionNode.
88      * @param namespace The namespace of the action.
89      */

90     public ActionNode(String JavaDoc uri, Namespace namespace) {
91         super(uri);
92         this.namespace = namespace;
93     }
94
95     /**
96      * Create an <code>ActionNode</code> without a namespace. If retrieval of
97      * the namespace is attempted on the result an exception will be thrown.
98      *
99      * This method is not required to return a unique instance each time it is
100      * invoked.
101      *
102      * @param actionUri The URI which uniquely identifies the <code>ActionNode</code>.
103      * @return An <code>ActionNode</code> without a namespace.
104      */

105     public static ActionNode getActionNode(String JavaDoc actionUri) {
106         if (ActionNode.ALL_URI.equals(actionUri)) {
107             return ActionNode.ALL;
108         }
109         return new ActionNode(actionUri);
110     }
111     
112     /**
113      * Create an ActionNode with a namespace.
114      *
115      * This method is not required to return a unique instance each time it is
116      * invoked.
117      *
118      * @param The URI which uniquely identifies the <code>ActionNode</code>.
119      * @param namespace The namespace of the <code>ActionNode</code>.
120      * @return An <code>ActionNode</code> with a namespace.
121      */

122     public static ActionNode getActionNode(String JavaDoc actionUri, Namespace namespace) {
123         if (ActionNode.ALL_URI.equals(actionUri) && NamespaceCache.DEFAULT_NAMESPACE.equals(namespace)) {
124             return ActionNode.ALL;
125         }
126         return new ActionNode(actionUri, namespace);
127     }
128
129     /**
130      * Get the namespace. If the <code>ActionNode</code> was constructed
131      * without a namespace, an exception will be thrown.
132      *
133      * @return The namespace of the <code>ActionNode</code>.
134      * @throws IllegalStateException The <code>ActionNode</code> was
135      * constructed without a namespace.
136      */

137     public Namespace getNamespace() {
138         if (this.namespace == null) {
139             throw new IllegalStateException JavaDoc("Namespace retrieved without being specified");
140         }
141         return this.namespace;
142     }
143 }
144
Popular Tags