Source Code Cross Referenced for Bean.java in  » Web-Framework » struts-2.0.11 » org » apache » struts2 » components » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Framework » struts 2.0.11 » org.apache.struts2.components 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: Bean.java 497654 2007-01-19 00:21:57Z rgielen $
003:         *
004:         * Licensed to the Apache Software Foundation (ASF) under one
005:         * or more contributor license agreements.  See the NOTICE file
006:         * distributed with this work for additional information
007:         * regarding copyright ownership.  The ASF licenses this file
008:         * to you under the Apache License, Version 2.0 (the
009:         * "License"); you may not use this file except in compliance
010:         * with the License.  You may obtain a copy of the License at
011:         *
012:         *  http://www.apache.org/licenses/LICENSE-2.0
013:         *
014:         * Unless required by applicable law or agreed to in writing,
015:         * software distributed under the License is distributed on an
016:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017:         * KIND, either express or implied.  See the License for the
018:         * specific language governing permissions and limitations
019:         * under the License.
020:         */
021:        package org.apache.struts2.components;
022:
023:        import java.io.Writer;
024:
025:        import org.apache.commons.logging.Log;
026:        import org.apache.commons.logging.LogFactory;
027:        import org.apache.struts2.views.annotations.StrutsTag;
028:        import org.apache.struts2.views.annotations.StrutsTagAttribute;
029:
030:        import com.opensymphony.xwork2.inject.Inject;
031:        import com.opensymphony.xwork2.util.ClassLoaderUtil;
032:        import com.opensymphony.xwork2.ObjectFactory;
033:        import com.opensymphony.xwork2.util.OgnlUtil;
034:        import com.opensymphony.xwork2.util.ValueStack;
035:
036:        /**
037:         * <!-- START SNIPPET: javadoc -->
038:         * <p>Instantiates a class that conforms to the JavaBeans specification. This tag has a body which can contain
039:         * a number of {@link Param} elements to set any mutator methods on that class.</p>
040:         * <p/>
041:         * <p>If the id attribute is set on the BeanTag, it will place the instantiated bean into the
042:         * stack's Context.</p>
043:         * <p/>
044:         * <!-- END SNIPPET: javadoc -->
045:         *
046:         *
047:         * <!-- START SNIPPET: params -->
048:         * <ul>
049:         *      <li>id - the stack's context id (if supplied) that the created bean will be store under</li>
050:         *      <li>name* - the class name of the bean to be instantiated (must respect JavaBean specification)</li>
051:         * </ul>
052:         * <!-- END SNIPPET: params -->
053:         *
054:         *
055:         * <p>Examples:</p>
056:         * <p/>
057:         * <pre>
058:         * <!-- START SNIPPET: examples -->
059:         * &lt;-- in freemarker form --&gt;
060:         * [@s.bean name="org.apache.struts2.example.counter.SimpleCounter" id="counter"]
061:         *   [s:param name="foo" value="BAR"/]
062:         *   The value of foo is : [s:property value="foo"/], when inside the bean tag.<br />
063:         * [/s:bean]
064:         *
065:         * &lt;-- in jsp form --&gt;
066:         * &lt;s:bean name="org.apache.struts2.example.counter.SimpleCounter" id="counter"&gt;
067:         *   &lt;s:param name="foo" value="BAR" /&gt;
068:         *   The value of foot is : &lt;s:property value="foo"/&gt;, when inside the bean tag &lt;br /&gt;
069:         * &lt;/s:bean&gt;
070:         * <!-- END SNIPPET: examples -->
071:         * </pre>
072:         * <p/>
073:         *
074:         * <!-- START SNIPPET: examplesdescription -->
075:         * <p>This example instantiates a bean called SimpleCounter and sets the foo property (setFoo('BAR')). The
076:         * SimpleCounter object is then pushed onto the Valuestack, which means that we can call its accessor methods (getFoo())
077:         * with the Property tag and get their values.</p>
078:         * <p/>
079:         * <p>In the above example, the id has been set to a value of <i>counter</i>. This means that the SimpleCounter class
080:         * will be placed into the stack's context. You can access the SimpleCounter class using a Struts tag:</p>
081:         * <p/>
082:         * <pre>
083:         * &lt;-- jsp form --&gt;
084:         * &lt;s:property value="#counter" /&gt;
085:         *
086:         * &lt;-- freemarker form --&gt;
087:         * [s:property value="#counter.foo"/]
088:         * </pre>
089:         * <p/>
090:         * <p>In the property tag example, the <i>#</i> tells Ognl to search the context for the SimpleCounter class which has
091:         * an id(key) of <i>counter</i></p>
092:         * <!-- END SNIPPET: examplesdescription -->
093:         *
094:         * @see Param
095:         */
096:        @StrutsTag(name="bean",tldTagClass="org.apache.struts2.views.jsp.BeanTag",description="Instantiate a JavaBean and place it in the context")
097:        public class Bean extends Component {
098:            protected static Log log = LogFactory.getLog(Bean.class);
099:
100:            protected Object bean;
101:            protected String name;
102:            protected ObjectFactory objectFactory;
103:
104:            public Bean(ValueStack stack) {
105:                super (stack);
106:            }
107:
108:            @Inject
109:            public void setObjectFactory(ObjectFactory objectFactory) {
110:                this .objectFactory = objectFactory;
111:            }
112:
113:            public boolean start(Writer writer) {
114:                boolean result = super .start(writer);
115:
116:                ValueStack stack = getStack();
117:
118:                try {
119:                    String beanName = findString(name, "name",
120:                            "Bean name is required. Example: com.acme.FooBean");
121:                    bean = objectFactory.buildBean(ClassLoaderUtil.loadClass(
122:                            beanName, getClass()), stack.getContext());
123:                } catch (Exception e) {
124:                    log.error("Could not instantiate bean", e);
125:
126:                    return false;
127:                }
128:
129:                // push bean on stack
130:                stack.push(bean);
131:
132:                // store for reference later
133:                if (getId() != null) {
134:                    getStack().getContext().put(getId(), bean);
135:                }
136:
137:                return result;
138:            }
139:
140:            public boolean end(Writer writer, String body) {
141:                ValueStack stack = getStack();
142:                stack.pop();
143:
144:                return super .end(writer, body);
145:            }
146:
147:            public void addParameter(String key, Object value) {
148:                OgnlUtil.setProperty(key, value, bean, getStack().getContext());
149:            }
150:
151:            @StrutsTagAttribute(description="The class name of the bean to be instantiated (must respect JavaBean specification)",required=true)
152:            public void setName(String name) {
153:                this.name = name;
154:            }
155:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.