Your browser does not support JavaScript and this site utilizes JavaScript to build content and provide links to additional information. You should either enable JavaScript in your browser settings or use a browser that supports JavaScript in order to take full advantage of this site.
1 16 17 18 package org.apache.taglibs.jndi; 19 20 import javax.servlet.jsp.*; 21 import javax.servlet.jsp.tagext.*; 22 import javax.naming.*; 23 import java.io.*; 24 25 30 public class LookupTag extends TagSupport { 31 32 private Context context; 33 private String contextRef; 34 private String name = ""; 35 private int scope = PageContext.PAGE_SCOPE; 36 private String type = "java.lang.Object"; 37 private Name nameObject; 38 39 40 41 public LookupTag() { 42 } 43 44 47 public Context getContext() { 48 return context; 49 } 50 51 55 public void setContext(Context context) { 56 this.context = context; 57 } 58 59 63 public void setContextRef(String contextRef) { 64 this.contextRef = contextRef; 65 } 66 67 71 public void setScope(String scope) { 72 this.scope = decodeScope(scope); 73 } 74 75 79 public String getType() { 80 return type; 81 } 82 83 87 public void setType(String type) { 88 this.type = type; 89 } 90 91 95 public String getName() { 96 return name; 97 } 98 99 103 public void setName(String name) { 104 this.name = name; 105 } 106 107 111 public Name getNameObject() { 112 return nameObject; 113 } 114 115 119 public void setNameObject(Name nameObject) { 120 this.nameObject = nameObject; 121 } 122 123 public int doStartTag() throws JspException { 124 return SKIP_BODY; 125 } 126 127 public int doEndTag() throws JspException { 128 if( contextRef != null ) { 129 context = null; 130 Object o = pageContext.findAttribute(contextRef); 131 if (o instanceof Context) { 132 context = (Context)o; 133 } 134 } 135 if (context == null) { 136 throw new JspException("context not set in a lookup invocation"); 137 } 138 Object o; 139 try { 140 if (nameObject != null) { 141 o = context.lookup(nameObject); 142 } else { 143 o = context.lookup(name); 144 } 145 if (Class.forName(type).isInstance(o)) { 146 pageContext.setAttribute(getId(), o, scope); 147 } 148 } catch (NamingException ne) { 149 throw new JspException(ne.toString()); 150 } catch (ClassNotFoundException cnfe) { 151 } 155 156 return EVAL_PAGE; 157 } 158 159 static int decodeScope(String scope) { 160 if (scope.equalsIgnoreCase("request")) { 161 return PageContext.REQUEST_SCOPE; 162 } else if (scope.equalsIgnoreCase("session")) { 163 return PageContext.SESSION_SCOPE; 164 } else if (scope.equalsIgnoreCase("application")) { 165 return PageContext.APPLICATION_SCOPE; 166 } else { 167 return PageContext.PAGE_SCOPE; 168 } 169 } 170 } 171
| Popular Tags
|