Source Code Cross Referenced for ContextTag.java in  » Portal » Open-Portal » com » sun » portal » wireless » taglibs » base » 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 » Portal » Open Portal » com.sun.portal.wireless.taglibs.base 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * $Id: ContextTag.java,v 1.22 2005/10/18 22:28:22 js143762 Exp $
003:         * Copyright 2002 Sun Microsystems, Inc. All
004:         * rights reserved. Use of this product is subject
005:         * to license terms. Federal Acquisitions:
006:         * Commercial Software -- Government Users
007:         * Subject to Standard License Terms and
008:         * Conditions.
009:         *
010:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011:         * are trademarks or registered trademarks of Sun Microsystems,
012:         * Inc. in the United States and other countries.
013:         */package com.sun.portal.wireless.taglibs.base;
014:
015:        import java.util.*;
016:        import java.util.logging.Logger;
017:        import java.util.logging.Level;
018:
019:        import javax.servlet.jsp.*;
020:        import javax.servlet.http.*;
021:        import javax.servlet.jsp.tagext.*;
022:
023:        import com.sun.ssoadapter.*;
024:        import com.sun.ssoadapter.config.*;
025:        import com.sun.portal.wireless.taglibs.util.UtilContext;
026:        import com.sun.portal.wireless.util.SSOAdapterPrivate;
027:        import com.sun.portal.wireless.util.AppConfigConstants;
028:        import com.sun.portal.log.common.PortalLogger;
029:
030:        /**
031:         * The ContextTag abstract class supports tags which
032:         * represent a context for a service.
033:         * 
034:         * Subclasses must implement the findContext() method.
035:         * 
036:         * Cooperating classes either look for the context
037:         * in the pageContext with the appropriate name
038:         * or use the getContext() method if this is
039:         * a parent tag.
040:         * 
041:         * There are no default attributes for this tag.
042:         * 
043:         * @version 1.0
044:         * @see Context
045:         */
046:        public abstract class ContextTag extends BeanTag {
047:
048:            private static final String CONFIG_NAME_VECTOR_KEY = "configNameVector";
049:
050:            private String configName = null;
051:            private String testString = null;
052:            private boolean testBoolean = false;
053:            private String reset = null;
054:            //When true, clean up (reset) context, closing connections, and don't reestablish
055:            private boolean close = false;
056:
057:            // Create a logger for this class
058:            private static Logger debugLogger = PortalLogger
059:                    .getLogger(ContextTag.class);
060:
061:            /**
062:             * Find the context this tag represents.
063:             * 
064:             * Subclasses must implement this method which
065:             * should return the appropriate context for
066:             * this session.
067:             * 
068:             * @return the context
069:             */
070:            public abstract Context findContext() throws Exception;
071:
072:            /**
073:             * Remove the context this tag represents from all places
074:             *	it is referred from.
075:             * 
076:             * Subclasses must implement this method which
077:             * should remove the appropriate context.
078:             * 
079:             */
080:            public abstract void reset();
081:
082:            /**
083:             * Return the context as a bean
084:             * 
085:             * @return the context
086:             */
087:            public Object newBean() throws Exception {
088:                return findContext();
089:            }
090:
091:            /**
092:             * Return the context as a bean
093:             * 
094:             * @return the context
095:             */
096:            public Object findBean() throws Exception {
097:                return findContext();
098:            }
099:
100:            /**
101:             * Make the context available.
102:             * If no context is found then throw JspException.
103:             * 
104:             * @return EVAL_BODY_INCLUDE
105:             * @exception JspException
106:             */
107:            public int doStartTag() throws JspException {
108:                Context context = null;
109:
110:                try {
111:                    context = findContext();
112:                    //If we are closing the context, reset (close all connections),
113:                    //and don't re-establish a new context(find)
114:                    if (close) {
115:                        if (context != null) {
116:                            context.closeConnection();
117:                            reset();
118:                        }
119:                        return EVAL_BODY_INCLUDE;
120:                    }
121:
122:                    if ((reset != null) && (context != null)) {
123:                        reset();
124:                        context = findContext();
125:                    }
126:
127:                } catch (JspException e) {
128:                    throw e;
129:                } catch (Exception e) {
130:                    if (testString == null) {
131:                        debugLogger.log(Level.FINE, "PSMA_CSPWTB0001", e);
132:                        throw new JspException(this .getClass().getName()
133:                                + ".doStartTag(): " + e);
134:                    }
135:                }
136:
137:                if (context == null) {
138:                    if (testString == null) {
139:                        debugLogger.fine("PSMA_CSPWTB0014");
140:                        throw new JspException(this .getClass().getName()
141:                                + ".doStartTag(): No context available");
142:                    } else {
143:                        return testBoolean ? SKIP_BODY : EVAL_BODY_INCLUDE;
144:                    }
145:                }
146:
147:                if (testString != null) {
148:                    boolean available = false;
149:                    try {
150:                        SSOAdapter ssoAdapter = context.getSSOAdapter();
151:                        available = (ssoAdapter.getConnection() != null);
152:                    } catch (Exception e) {
153:                        available = false;
154:                    }
155:                    if (available) {
156:                        return testBoolean ? EVAL_BODY_INCLUDE : SKIP_BODY;
157:                    } else {
158:                        return testBoolean ? SKIP_BODY : EVAL_BODY_INCLUDE;
159:                    }
160:                }
161:
162:                return EVAL_BODY_INCLUDE;
163:            }
164:
165:            /*
166:             * Try to ensure that a useable configName is chosen.
167:             */
168:            protected void computeConfigName(PageContext pageContext,
169:                    String configNameKey, String ssoAdapterKey,
170:                    String configType) {
171:                ConfigurationFactory factory = ConfigurationFactory
172:                        .getInstance(SSOAdapterPrivate.SSO_SERVICE_NAME,
173:                                SSOAdapterPrivate.SSO_ATTR_CONFIGURATIONS_NAME);
174:
175:                if (configName == null) {
176:
177:                    //get the configName from Page
178:                    configName = getConfigNameFromPage(pageContext,
179:                            configNameKey);
180:
181:                    if (configName == null) {
182:
183:                        //get the configName from session
184:                        configName = getConfigNameFromSession(pageContext,
185:                                configNameKey);
186:
187:                        if (configName == null) {
188:
189:                            Vector configNameVector = (Vector) pageContext
190:                                    .getAttribute(CONFIG_NAME_VECTOR_KEY);
191:
192:                            if (configNameVector == null) {
193:                                Enumeration configEnum = factory
194:                                        .getConfigurationNames(new SSOAdapterSession(
195:                                                (HttpServletRequest) pageContext
196:                                                        .getRequest()));
197:                                if (configEnum == null) {
198:                                    return;
199:                                }
200:                                configNameVector = new Vector(3, 3);
201:                                while (configEnum.hasMoreElements()) {
202:                                    configNameVector.add(configEnum
203:                                            .nextElement());
204:                                }
205:                                pageContext.setAttribute(
206:                                        CONFIG_NAME_VECTOR_KEY,
207:                                        configNameVector);
208:                            }
209:
210:                            // Pick 1st config of matching type...
211:                            // ... and which is useable...
212:
213:                            SSOAdapterFactory ssoFactory = SSOAdapterFactory
214:                                    .getInstance();
215:                            HttpServletRequest request = (HttpServletRequest) pageContext
216:                                    .getRequest();
217:
218:                            for (int i = 0; i < configNameVector.size(); i++) {
219:                                Configuration conf;
220:                                try {
221:                                    configName = (String) configNameVector
222:                                            .get(i);
223:                                    conf = factory.readConfiguration(
224:                                            configName, true,
225:                                            new SSOAdapterSession(request));
226:                                    String type = conf.getProperty("type");
227:
228:                                    if (type != null && type.length() != 0
229:                                            && type.equals(configType)) {
230:                                        //
231:                                        // Test usability of candidate...
232:                                        //
233:                                        SSOAdapter ssoAdapter = ssoFactory
234:                                                .getSSOAdapter(
235:                                                        configName,
236:                                                        new SSOAdapterSession(
237:                                                                request,
238:                                                                null,
239:                                                                null,
240:                                                                AppConfigConstants.MAP_INSTANCE_NAME));
241:                                        Object conn = ssoAdapter
242:                                                .getConnection();
243:                                        if (conn != null) {
244:                                            // DANGER:  The context impl had better pick this up, or we've
245:                                            // just created an orphaned connection of unknown duration.
246:                                            pageContext.setAttribute(
247:                                                    ssoAdapterKey, ssoAdapter);
248:                                            break;
249:                                        }
250:                                    }
251:
252:                                } catch (Exception e) {
253:                                }
254:                                configName = null;
255:                            }
256:
257:                            if (configName != null) {
258:                                setConfigNameOnSession(pageContext,
259:                                        configNameKey, configName);
260:                            }
261:                            pageContext.setAttribute(configNameKey, configName);
262:                        } else {
263:                            pageContext.setAttribute(configNameKey, configName);
264:                        }
265:                    }
266:
267:                } else {
268:                    pageContext.setAttribute(configNameKey, configName);
269:                    setConfigNameOnSession(pageContext, configNameKey,
270:                            configName);
271:                }
272:
273:                return;
274:            }
275:
276:            private String getConfigNameFromPage(PageContext pageContext,
277:                    String configNameKey) {
278:                return (String) pageContext.getAttribute(configNameKey);
279:            }
280:
281:            private String getConfigNameFromSession(PageContext pageContext,
282:                    String configNameKey) {
283:                String configName = null;
284:                try {
285:                    UtilContext uc = UtilContext.getContext(pageContext);
286:                    configName = (String) uc.getAttribute(configNameKey);
287:                } catch (Exception ex) {
288:                    debugLogger.fine("PSMA_CSPWTB0015");
289:                }
290:                return configName;
291:            }
292:
293:            private void setConfigNameOnSession(PageContext pageContext,
294:                    String configNameKey, String configName) {
295:                try {
296:                    UtilContext uc = UtilContext.getContext(pageContext);
297:                    uc.setAttribute(configNameKey, configName);
298:                } catch (Exception ex) {
299:                    debugLogger.fine("PSMA_CSPWTB0015");
300:                }
301:            }
302:
303:            /*
304:             * Process "config" attribute...
305:             */
306:            public void setConfig(String s) {
307:                configName = Util.evalAttribute(pageContext, null, s);
308:                if (configName.length() == 0) {
309:                    configName = null;
310:                }
311:            }
312:
313:            /*
314:             * Process "test" attribute...
315:             */
316:            public void setTest(String s) {
317:                testString = Util.evalAttribute(pageContext, null, s);
318:                testBoolean = Boolean.valueOf(testString).booleanValue();
319:            }
320:
321:            /**
322:             * Process "reset" attribute...
323:             */
324:            public void setReset(String s) {
325:                reset = Util.evalAttribute(pageContext, null, s);
326:                if (reset.length() == 0) {
327:                    reset = null;
328:                }
329:            }
330:
331:            /**
332:             * Cleanup
333:             */
334:            public void release() {
335:                configName = null;
336:                testString = null;
337:                testBoolean = false;
338:                super .release();
339:            }
340:
341:            /**
342:             * Process "close" attribute
343:             */
344:            public void setClose(String s) {
345:                String closeS = Util.evalAttribute(pageContext, null, s);
346:                if ((closeS != null) && (closeS.length() != 0)
347:                        && (!closeS.equalsIgnoreCase("false"))) {
348:                    close = true;
349:                }
350:            }
351:
352:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.