KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > webapp > taglib > ObjectTag


1 /*
2  * $Id: ObjectTag.java 5462 2005-08-05 18:35:48Z jonesde $
3  *
4  * Copyright (c) 2002-2003 The Open For Business Project - www.ofbiz.org
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  *
24  */

25 package org.ofbiz.webapp.taglib;
26
27 import javax.servlet.jsp.JspTagException JavaDoc;
28 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
29
30 import org.ofbiz.base.util.Debug;
31 import org.ofbiz.base.util.ObjectType;
32 import org.ofbiz.base.util.UtilValidate;
33
34 /**
35  * ObjectTag - Loads an object from the PageContext.
36  *
37  * @author <a HREF="mailto:jaz@ofbiz.org">Andy Zeneski</a>
38  * @version 1.0
39  * @created August 4, 2001
40  */

41 public class ObjectTag extends TagSupport JavaDoc {
42     
43     public static final String JavaDoc module = ObjectTag.class.getName();
44
45     protected Object JavaDoc element = null;
46     protected String JavaDoc name = null;
47     protected String JavaDoc property = null;
48     protected Class JavaDoc type = null;
49
50     public void setName(String JavaDoc name) {
51         this.name = name;
52     }
53
54     public void setProperty(String JavaDoc property) {
55         this.property = property;
56     }
57
58     public void setType(String JavaDoc type) throws ClassNotFoundException JavaDoc {
59         this.type = ObjectType.loadClass(type);
60     }
61
62     public String JavaDoc getName() {
63         return name;
64     }
65
66     public String JavaDoc getProperty() {
67         return property;
68     }
69
70     public Object JavaDoc getObject() {
71         return element;
72     }
73
74     public String JavaDoc getType() {
75         return type.getName();
76     }
77
78     public int doStartTag() throws JspTagException JavaDoc {
79         String JavaDoc realAttrName = property;
80
81         if (UtilValidate.isEmpty(realAttrName)) {
82             realAttrName = name;
83         }
84         element = pageContext.findAttribute(realAttrName);
85         if (element != null) {
86             pageContext.setAttribute(name, element);
87         } else {
88             Debug.logWarning("Did not find element in property. (" + property + ")", module);
89         }
90         return EVAL_BODY_INCLUDE;
91     }
92
93     public int doEndTag() {
94         return EVAL_PAGE;
95     }
96 }
97
98
Popular Tags