KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > compiler > model > StrutsElementSupport


1 /*
2  * Copyright 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  * $Header:$
17  */

18 package org.apache.beehive.netui.compiler.model;
19
20 import org.w3c.dom.Node JavaDoc;
21 import org.apache.xmlbeans.XmlObject;
22 import org.apache.xmlbeans.XmlCursor;
23
24 import java.util.HashMap JavaDoc;
25
26 /**
27  * Defines general support for elements that
28  */

29 public abstract class StrutsElementSupport
30 {
31     private String JavaDoc _description;
32     private HashMap JavaDoc _properties = new HashMap JavaDoc();
33     private String JavaDoc _displayName;
34     private Icon _icon;
35     private StrutsApp _parentApp;
36     private String JavaDoc _comment;
37     private String JavaDoc _className;
38
39     public StrutsElementSupport( StrutsApp parentApp )
40     {
41         _parentApp = parentApp;
42     }
43
44     protected StrutsApp getParentApp()
45     {
46         return _parentApp;
47     }
48
49     public void setDescription( String JavaDoc description )
50         { _description = description; }
51
52     public String JavaDoc getDescription()
53         { return _description; }
54
55     public void setProperty( String JavaDoc name, String JavaDoc value )
56         { _properties.put( name, value ); }
57
58     public String JavaDoc getProperty( String JavaDoc name )
59         { return ( String JavaDoc ) _properties.get( name ); }
60
61     public void setDisplayName( String JavaDoc displayName )
62         { _displayName = displayName; }
63
64     public String JavaDoc getDisplayName()
65         { return _displayName; }
66
67     public void setIcon( Icon icon )
68         { _icon = icon; }
69
70     public Icon getIcon()
71         { return _icon; }
72
73     public String JavaDoc getClassName()
74     {
75         return _className;
76     }
77
78     public void setClassName( String JavaDoc className )
79     {
80         _className = className;
81     }
82
83     public void setComment( String JavaDoc comment )
84     {
85         _comment = comment;
86     }
87     
88     public String JavaDoc getComment()
89     {
90         return _comment;
91     }
92
93     class Icon
94     {
95         String JavaDoc smallIconLocation;
96         String JavaDoc largeIconLocation;
97
98         /**
99          * Creates an object representing icon locations for certain types of
100          * elements in the struts-config.xml file.
101          * @param smallIconLocation the location of a small icon
102          * relative to the stuts config file
103          */

104         public Icon( String JavaDoc smallIconLocation )
105         {
106             this( smallIconLocation, null );
107         }
108
109         /**
110          * Creates an object representing icon locations for certain types of
111          * elements in the struts-config.xml file.
112          * @param smallIconLocation the location of a small icon
113          * relative to the stuts config file
114          * @param largeIconLocation the location of a large (32x32) icon
115          * relative to the stuts-config.xml file.
116          */

117         public Icon( String JavaDoc smallIconLocation, String JavaDoc largeIconLocation )
118         {
119             this.smallIconLocation = smallIconLocation;
120             this.largeIconLocation = largeIconLocation;
121         }
122     }
123
124     public static String JavaDoc getAttr( Node JavaDoc node, String JavaDoc name )
125     {
126         Node JavaDoc attr = node.getAttributes().getNamedItem( name );
127         return ( attr != null ? attr.getNodeValue() : null );
128     }
129
130     public static boolean getAttrBool( Node JavaDoc node, String JavaDoc name )
131     {
132         String JavaDoc val = getAttr( node, name );
133         return ( val != null && val.equalsIgnoreCase( "true" ) ); // NOI18N
134
}
135     
136     protected void addComment( XmlObject xb )
137     {
138         if ( _comment != null )
139         {
140             XmlCursor curs = xb.newCursor();
141             curs.insertComment( " " + _comment + " " );
142         }
143     }
144     
145     protected void setParentApp( StrutsApp parentApp )
146     {
147         _parentApp = parentApp;
148     }
149 }
150
Popular Tags