Source Code Cross Referenced for JSPRenderingContainerProvider.java in  » Portal » Open-Portal » com » sun » portal » wireless » providers » containers » jsp » rendering » 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.providers.containers.jsp.rendering 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: JSPRenderingContainerProvider.java,v 1.16 2005/09/21 10:48:36 dg154973 Exp $
003:         * Copyright 2003 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:         */
014:
015:        package com.sun.portal.wireless.providers.containers.jsp.rendering;
016:
017:        import java.util.List;
018:        import java.util.Map;
019:        import java.util.ArrayList;
020:        import java.util.ResourceBundle;
021:        import java.util.MissingResourceException;
022:        import java.util.logging.Level;
023:        import java.util.logging.LogRecord;
024:        import java.util.logging.Logger;
025:        import java.io.File;
026:        import com.sun.portal.log.common.PortalLogger;
027:
028:        import javax.servlet.http.HttpServletRequest;
029:        import javax.servlet.http.HttpServletResponse;
030:
031:        import com.sun.portal.providers.context.ProviderContext;
032:        import com.sun.portal.providers.Provider;
033:        import com.sun.portal.providers.context.ContainerProviderContext;
034:        import com.sun.portal.providers.context.ProviderContextException;
035:        import com.sun.portal.providers.ProviderException;
036:        import com.sun.portal.wireless.providers.containers.jsp.WirelessJSPContainerProviderAdapter;
037:        import com.sun.portal.wireless.providers.containers.rendering.RenderingContainerProvider;
038:        import com.sun.portal.wireless.providers.containers.util.ChannelOrder;
039:        import com.sun.portal.wireless.providers.rendering.JSPRenderingProvider;
040:        import com.sun.portal.wireless.providers.rendering.RenderingUtil;
041:
042:        /**
043:         * This class provides default implementations of methods in the
044:         * ContainerProvider
045:         * interface implemented using a containerProviderContext object as the
046:         * persistent store and extends <code>JSPProvider</code> to facilitate
047:         * the execution of JSPs
048:         * <p>
049:         * For method details, see the descriptions in the
050:         * <code>ContainerProvider</code> interface.
051:         *
052:         * @see com.sun.portal.providers.context.ContainerProviderContext
053:         * @see com.sun.portal.providers.jsp.JSPProvider
054:         */
055:
056:        public class JSPRenderingContainerProvider extends
057:                WirelessJSPContainerProviderAdapter implements 
058:                RenderingContainerProvider {
059:
060:            public final static String PARALLEL_CHANNELS_INIT = "parallelChannelsInit";
061:            public final static String ERROR_CHANNEL = "errorChannel";
062:            public final static String WRAPPING_PROVIDER = "RenderingWrappingProvider";
063:            public final static String WRAPPING_STRING = "_Wrapped_";
064:            public final static String WRAPPED_CHANNEL_PROPERTY = "wrappedChannel";
065:            public final static String WRAPPED_CHANNELS = "_WrappedChannels";
066:            private ResourceBundle bundle = null;
067:            private List minimizedChannelsList = null;
068:
069:            private static Logger logger = PortalLogger
070:                    .getLogger(JSPRenderingContainerProvider.class);
071:
072:            public void init(String name, HttpServletRequest httpReq)
073:                    throws ProviderException {
074:
075:                // Parent's init
076:                super .init(name, httpReq);
077:
078:                //Get the provider resource bundle
079:                if (bundle == null) {
080:                    bundle = getResourceBundle();
081:                }
082:
083:                // See if we need to do parallel initialization
084:                ContainerProviderContext cpc = getContainerProviderContext();
085:                boolean isParallel = false;
086:                try {
087:                    isParallel = cpc.getBooleanProperty(getName(),
088:                            PARALLEL_CHANNELS_INIT);
089:                } catch (ProviderContextException e) {
090:                    throw new ProviderException(
091:                            "JSPRenderingContainerProvider.init()" + ": ", e);
092:                }
093:
094:                if (isParallel) {
095:                    cpc.initProviders(httpReq, name, getSelectedChannels(), 0);
096:                }
097:            }
098:
099:            /**
100:             * This method overrides <code>JSPProvider.getContent()</code> method. 
101:             * It gets the JSP content from <code>JSPProvider</code> and pass it to
102:             * <code>renderContent()</code> method. 
103:             * Based on a few checks, it will either return device specfic markup or
104:             * AML.
105:             *
106:             * @return    StringBuffer   holding the channel content that is markup
107:             *                           specific or AML.
108:             * @exception ProviderException If there was an error generating content. 
109:             *
110:             * @param req   An HttpServletRequest that contains information related to 
111:             *              this request for content.
112:             * @param res   An HttpServletResponse that allows the provider to 
113:             *              influence the overall response for the desktop page 
114:             *              (besides generating the content).
115:             * @see com.sun.portal.providers.jsp.JSPProvider#getContent
116:             **/
117:
118:            public StringBuffer getContent(HttpServletRequest req,
119:                    HttpServletResponse res) throws ProviderException {
120:                StringBuffer sb = null;
121:                try {
122:                    sb = super .getContent(req, res);
123:                    sb = renderContent(req, sb);
124:                } catch (Throwable e) {
125:                    if (logger.isLoggable(Level.SEVERE))
126:                        logger.log(Level.SEVERE, "", e);
127:                    return handleException(req, res);
128:                }
129:                return sb;
130:            }
131:
132:            /**
133:             * This method overrides <code>JSPProvider.getEdit()</code> method. It
134:             * gets the JSP edit page content from <code>JSPProvider</code> and pass
135:             * it to <code>renderContent()</code> method. 
136:             * Based on a few check, it will either return device specfic markup or AML
137:             *
138:             * @return    StringBuffer      holding the channel edit page that is 
139:             *                              markup specific or AML.
140:             * @exception ProviderException If there was an error generating content.
141:             *
142:             * @param req   An HttpServletRequest that contains information related to 
143:             *              this request for content.
144:             * @param res   An HttpServletResponse that allows the provider to 
145:             *              influence the overall response for the desktop page 
146:             *              (besides generating the content).
147:             * @see com.sun.portal.providers.jsp.JSPProvider#getEdit
148:             *
149:             **/
150:            public StringBuffer getEdit(HttpServletRequest req,
151:                    HttpServletResponse res) throws ProviderException {
152:                StringBuffer sb = null;
153:                try {
154:                    sb = super .getEdit(req, res);
155:                } catch (Throwable e) {
156:                    if (logger.isLoggable(Level.SEVERE))
157:                        logger.log(Level.SEVERE, "", e);
158:                    return handleException(req, res);
159:                }
160:                return renderEditContent(req, sb);
161:            }
162:
163:            /**
164:             * Exception handling method for the Rendering Container. This method
165:             * reads the error page and passes it through the rendering engine
166:             * and returns the resulting stringbuffer to the caller.
167:             * 
168:             * @return    StringBuffer holding the channel content that is markup 
169:             *            specific or AML.
170:             *
171:             * @param req  An HttpServletRequest that contains information related to 
172:             *             this request for content.
173:             * @param res  An HttpServletResponse that allows the provider to influence
174:             *             the overall response for desktop page 
175:             **/
176:
177:            protected StringBuffer handleException(HttpServletRequest req,
178:                    HttpServletResponse res) {
179:
180:                StringBuffer sb = null;
181:                ContainerProviderContext cpc = (ContainerProviderContext) getProviderContext();
182:                String defErrMsg = "JSPRenderingContainerProvider.handleException():"
183:                        + " Error while reading error page. Defaulting to base error page";
184:                String defErrPg = null;
185:                try {
186:                    defErrPg = bundle.getString("defaultError");
187:                } catch (MissingResourceException mre) {
188:                    defErrPg = "";
189:                }
190:                if (defErrPg == null) {
191:                    defErrPg = "";
192:                }
193:                try {
194:                    String errorCh = getStringProperty(ERROR_CHANNEL);
195:                    if ((errorCh != null) && (errorCh.length() != 0)) {
196:                        sb = cpc.getContent(req, res, null, errorCh);
197:                    } else {
198:                        logger.info("PSMA_CSPWPCJR0013");
199:                        // Default error page
200:                        sb = new StringBuffer(defErrPg);
201:                        sb = RenderingUtil.doRender(req, cpc, getName(), sb,
202:                                true, false);
203:                    }
204:                } catch (Throwable t) {
205:                    logger.log(Level.INFO, "PSMA_CSPWPCJR0013", t);
206:                    // Default error page
207:                    sb = new StringBuffer(defErrPg);
208:                    try {
209:                        sb = RenderingUtil.doRender(req, cpc, getName(), sb,
210:                                true, false);
211:                    } catch (Throwable t1) {
212:                        if (logger.isLoggable(Level.INFO))
213:                            logger.log(Level.INFO, "PSMA_CSPWPCJR0002", t1);
214:                        // Rendering is failing. Cannot do much. Return original 
215:                        //  string buffer. Device will get a compile error.
216:                        return sb;
217:                    }
218:                }
219:
220:                // Content coming back is rendered content as getContent which doesnt
221:                //  set the parent is called. Thus error channel renders itself.
222:                return sb;
223:            }
224:
225:            /**
226:             * This method is expected to be called from the Provider's 
227:             * <code>getContent()</code> methods after it creates its content
228:             *  StringBuffer. It calls 
229:             * <code>RenderingUtil.renderContent()</code> to render the content. The
230:             * return buffer can contain device specific markup (rendered) or remain
231:             * as AML document (not rendered).
232:             * 
233:             * @param req  An HttpServletRequest that contains information related to 
234:             *             this request for content.
235:             * @param sb   The StringBuffer representing the content obtained 
236:             *             from the JSPs.
237:             *
238:             * @return StringBuffer  The return content can be rendered or not rendered
239:             * @see com.sun.portal.wireless.providers.rendering.
240:             *  RenderingUtil#renderContent
241:             * @throws ProviderException
242:             */
243:
244:            protected StringBuffer renderContent(HttpServletRequest req,
245:                    StringBuffer sb) throws ProviderException {
246:                ContainerProviderContext cpc = getContainerProviderContext();
247:                return RenderingUtil.renderContent(req, cpc, getName(), sb);
248:            }
249:
250:            /**
251:             * This method is expected to be called from the Provider's 
252:             *  <code>getEdit()</code> methods after it creates its content 
253:             * StringBuffer. It calls <code>RenderingUtil.renderEditContent()</code> 
254:             * to render the content. The return buffer can contain device specific
255:             * markup (rendered) or remain as AML document (not rendered).
256:             * 
257:             * @param req  An HttpServletRequest that contains information related to 
258:             *             this request for content.
259:             * @param sb   The StringBuffer representing the content obtained 
260:             *             from the JSPs.
261:             *
262:             * @return StringBuffer  The return content can be rendered or not rendered
263:             * @see com.sun.portal.wireless.providers.rendering.
264:             *  RenderingUtil#renderContent
265:             * @throws ProviderException
266:             */
267:
268:            protected StringBuffer renderEditContent(HttpServletRequest req,
269:                    StringBuffer sb) throws ProviderException {
270:                ContainerProviderContext cpc = getContainerProviderContext();
271:                return RenderingUtil.renderEditContent(req, cpc, getName(), sb);
272:            }
273:
274:            /**
275:             * Get the most specific JSP path for the given channel name and
276:             * file name.  This method overrides the 
277:             * <code>JSPProvider.getMostSpecificJSPPath()</code> method and calls 
278:             * <code>RenderingUtils.getTemplateMostSpecificPath</code> to get the real
279:             *  path.
280:             *
281:             * @param pc   The ProviderContext.
282:             * @param name The channel name.
283:             * @param file The jsp file name.
284:             *
285:             * @return a <code>File</code>, the most specific path to the jsp.
286:             *
287:             * @exception  ProviderException if an error occurs in getting the path.
288:             * @see com.sun.portal.providers.jsp.JSPProvider#getMostSpecificJSPPath
289:             * @see com.sun.portal.wireless.providers.rendering.
290:             *  RenderingUtil#getTemplateMostSpecificPath
291:             **/
292:
293:            protected File getMostSpecificJSPPath(ProviderContext pc,
294:                    String name, String file) throws ProviderException {
295:                File jspPath = null;
296:                try {
297:                    jspPath = RenderingUtil.getTemplateMostSpecificPath(
298:                            (ContainerProviderContext) pc, name, file);
299:                } catch (ProviderContextException e) {
300:                    if (logger.isLoggable(Level.INFO))
301:                        logger.log(Level.INFO, "", e);
302:                }
303:
304:                return jspPath;
305:            }
306:
307:            /**
308:             * Get the existing JSP path for the given channel name and
309:             * file name.  This method overrides the 
310:             * <code>JSPProvider.getExistingJSPPath()</code> method and calls 
311:             * <code>RenderingUtils.getTemplatePath</code> to get the real path.
312:             *
313:             * @param pc   The ProviderContext.
314:             * @param name The channel name.
315:             * @param file The jsp file name.
316:             *
317:             * @return a <code>File</code>, the most specific path to the jsp.
318:             *
319:             * @exception  ProviderException if an error occurs in getting the path.
320:             * @see com.sun.portal.providers.jsp.JSPProvider#getExistingJSPPath
321:             * @see com.sun.portal.wireless.providers.rendering.
322:             *  RenderingUtil#getTemplatePath
323:             **/
324:
325:            protected File getExistingJSPPath(ProviderContext pc, String name,
326:                    String file) throws ProviderException {
327:                File jspPath = null;
328:                try {
329:                    jspPath = RenderingUtil.getTemplatePath(
330:                            (ContainerProviderContext) pc, name, file);
331:                } catch (ProviderContextException e) {
332:                    if (logger.isLoggable(Level.INFO))
333:                        logger.log(Level.INFO, "", e);
334:                }
335:
336:                return jspPath;
337:            }
338:
339:            /**
340:             * Returns an ordered list of existing presentable selected channels.
341:             *  Wrap any native channels if required.
342:             * @param req HttpServletRequest
343:             * @param onlyMovable should list only include movable channels
344:             * @return List ordered existing presentable selected channel names
345:             * @throws ProviderException
346:             */
347:            public List getWrappedOrderedSelectedChannels(
348:                    HttpServletRequest req, boolean onlyMovable)
349:                    throws ProviderException {
350:                ContainerProviderContext cpc = getContainerProviderContext();
351:                List selectedChannels = getSelectedChannels();
352:                // getSelectedChannels should never return null, but just in case
353:                if (selectedChannels == null) {
354:                    selectedChannels = new ArrayList();
355:                }
356:                if (selectedChannels.size() > 0) {
357:                    selectedChannels = ChannelOrder.order(selectedChannels,
358:                            getName(), cpc, onlyMovable);
359:                }
360:
361:                String channel = null;
362:                List newChannelList = new ArrayList();
363:
364:                for (int i = 0; i < selectedChannels.size(); i++) {
365:                    channel = (String) selectedChannels.get(i);
366:                    Provider p = cpc.getProvider(req, getName(), channel);
367:                    if (cpc.existsChannel(channel)) {
368:                        // Native channel exists
369:                        if (p.isPresentable(req)) {
370:                            // Disable the dynamic wrapping feature for anon desktop
371:                            if (cpc.isAuthless(req)) {
372:                                newChannelList.add(channel);
373:                            } else {
374:                                if ((p instanceof  JSPRenderingProvider)
375:                                        || (p instanceof  RenderingContainerProvider)) {
376:                                    // Channel is a rendering or wrapped channel.
377:                                    // Do nothing. Add the channel to the channel list.
378:                                    newChannelList.add(channel);
379:                                } else {
380:                                    String wrappedChannel = wrapChannel(channel);
381:                                    if (wrappedChannel != null) {
382:                                        newChannelList.add(wrappedChannel);
383:                                    }
384:                                }
385:                            }
386:                        }
387:                    } else {
388:                        // Native channel doesnt exist. Delete wrapped channel from DP
389:                        if (!cpc.isAuthless(req)) {
390:                            try {
391:                                cpc.removeChannel(channel);
392:
393:                                // Delete the wrapped channel from the _WrappedChannels
394:                                // collection
395:                                Map map = null;
396:                                List wrappedChannels = null;
397:                                if (cpc.existsCollectionProperty(getName(),
398:                                        WRAPPED_CHANNELS)) {
399:                                    // Read the _WrappedChannels Collection property.
400:                                    map = (Map) cpc.getCollectionProperty(
401:                                            getName(), WRAPPED_CHANNELS);
402:                                    if (map != null) {
403:                                        wrappedChannels = (List) map.values();
404:                                        wrappedChannels.remove(channel);
405:                                        if (logger.isLoggable(Level.FINEST))
406:                                            logger.log(Level.FINEST,
407:                                                    "PSMA_CSPWPCJR0003",
408:                                                    channel);
409:
410:                                        cpc.setCollectionProperty(getName(),
411:                                                WRAPPED_CHANNELS,
412:                                                wrappedChannels);
413:                                    }
414:                                }
415:                            } catch (ProviderContextException pce) {
416:                                if (logger.isLoggable(Level.WARNING))
417:                                    logger.log(Level.WARNING,
418:                                            "PSMA_CSPWPCJR0004", pce);
419:                            }
420:                        }
421:                    }
422:                }
423:
424:                // store minimized channel list for use by getMaximizedChannel
425:                minimizedChannelsList = newChannelList;
426:
427:                return newChannelList;
428:            }
429:
430:            /**
431:             * Returns an ordered list of existing presentable selected channels 
432:             * and movable channel names.
433:             *  Wrap any native channels if required.
434:             * @param req HttpServletRequest
435:             * @return List ordered existing presentable selected channel names
436:             * @throws ProviderException
437:             */
438:
439:            public List getWrappedOrderedSelectedChannels(HttpServletRequest req)
440:                    throws ProviderException {
441:
442:                // store minimized channel list for use by getMaximizedChannel
443:                minimizedChannelsList = getWrappedOrderedSelectedChannels(req,
444:                        false);
445:
446:                return minimizedChannelsList;
447:            }
448:
449:            /**
450:             * Returns the maximized channel specified by this request, or
451:             * <code>null</code> if none exists, or the channel is not presentable.
452:             * @param request the current request
453:             * @return the maximized channel
454:             * @throws ProviderException
455:             */
456:            public String getMaximizedChannel(HttpServletRequest request)
457:                    throws ProviderException {
458:                String maximizedChannel = null;
459:                String maximizedChannelParam = request
460:                        .getParameter(MAXIMIZEDCHANNEL);
461:
462:                if (maximizedChannelParam != null) {
463:                    List userChannels;
464:                    if (!getProviderContext().isAuthless(request)
465:                            && minimizedChannelsList != null) {
466:                        userChannels = minimizedChannelsList;
467:                    } else {
468:                        userChannels = getWrappedOrderedSelectedChannels(request);
469:                    }
470:                    try {
471:                        maximizedChannel = (String) userChannels.get(Integer
472:                                .parseInt(maximizedChannelParam));
473:                    } catch (Exception e) {
474:                        throw new ProviderException(getClass().getName()
475:                                + ".getMaximizedChannel(): ", e);
476:                    }
477:                }
478:                return maximizedChannel;
479:            }
480:
481:            /**
482:             * This method gets called only in case of authenticated desktop.
483:             * This method removes the wrapped channels for which there are the 
484:             * corresponding native channels have been deleted.
485:             * @param cpc ContainerProviderContext
486:             * @param req HttpServletRequest
487:             */
488:
489:            public void cleanUpWrappedChannels(ContainerProviderContext cpc) {
490:                Map map = null;
491:                List wrappedChannels = null;
492:
493:                try {
494:                    if (cpc.existsCollectionProperty(getName(),
495:                            WRAPPED_CHANNELS)) {
496:                        // Read the _WrappedChannels Collection property.
497:                        map = (Map) cpc.getCollectionProperty(getName(),
498:                                WRAPPED_CHANNELS);
499:                    }
500:                } catch (ProviderContextException pce) {
501:                    if (logger.isLoggable(Level.INFO)) {
502:                        LogRecord rec = new LogRecord(Level.INFO,
503:                                "PSMA_CSPWPCJR0005");
504:                        rec.setThrown(pce);
505:                        String[] param = { WRAPPED_CHANNELS };
506:                        rec.setParameters(param);
507:                        rec.setLoggerName(logger.getName());
508:                        logger.log(rec);
509:                    }
510:                }
511:                if (map != null) {
512:                    wrappedChannels = (List) map.values();
513:                    String channel = null;
514:                    for (int i = 0; i < wrappedChannels.size(); i++) {
515:                        channel = (String) wrappedChannels.get(i);
516:                        if (cpc.existsChannel(channel)) {
517:                            String wrapped_ch_prop = null;
518:                            try {
519:                                wrapped_ch_prop = cpc.getStringProperty(
520:                                        channel, WRAPPED_CHANNEL_PROPERTY);
521:                            } catch (ProviderContextException pce) {
522:                                // The channel exists,but the property 'wrappedchannel'
523:                                //  is not readable. 
524:                                if (logger.isLoggable(Level.INFO)) {
525:                                    LogRecord rec = new LogRecord(Level.INFO,
526:                                            "PSMA_CSPWPCJR0005");
527:                                    rec.setThrown(pce);
528:                                    String[] param = { WRAPPED_CHANNELS };
529:                                    rec.setParameters(param);
530:                                    rec.setLoggerName(logger.getName());
531:                                    logger.log(rec);
532:                                }
533:                            }
534:                            if (!cpc.existsChannel(wrapped_ch_prop)) {
535:                                // Native channel corresponding to the wrapped channel
536:                                // doesnt exist. Delete wrapped channel.
537:                                try {
538:                                    cpc.removeChannel(channel);
539:                                    wrappedChannels.remove(channel);
540:                                    if (logger.isLoggable(Level.FINEST))
541:                                        logger.log(Level.FINEST,
542:                                                "PSMA_CSPWPCJR0005", channel);
543:                                } catch (ProviderContextException pce) {
544:                                    if (logger.isLoggable(Level.SEVERE))
545:                                        logger.log(Level.SEVERE,
546:                                                "PSMA_CSPWPCJR0006", pce);
547:                                }
548:                            }
549:                        }
550:                    }
551:                    try {
552:                        cpc.setCollectionProperty(getName(), WRAPPED_CHANNELS,
553:                                wrappedChannels);
554:                    } catch (ProviderContextException pce) {
555:                        if (logger.isLoggable(Level.SEVERE))
556:                            logger.log(Level.SEVERE, "PSMA_CSPWPCJR0007", pce);
557:                    }
558:                }
559:            }
560:
561:            // This method gets called only in case of authenticated desktop.
562:            private String wrapChannel(String channel) {
563:
564:                ContainerProviderContext cpc = (ContainerProviderContext) getProviderContext();
565:                int idx = 0;
566:                String wrappedChannel = WRAPPING_STRING + channel;
567:                if (cpc.existsChannel(wrappedChannel)) {
568:                    // Check the 'wrappedChannel' property
569:                    String wrapped_ch_prop = null;
570:                    try {
571:                        wrapped_ch_prop = cpc.getStringProperty(wrappedChannel,
572:                                WRAPPED_CHANNEL_PROPERTY);
573:                    } catch (ProviderContextException pce) {
574:                        // The channel exists, but the property 'wrappedchannel' 
575:                        //  is not readable.
576:                        if (logger.isLoggable(Level.INFO)) {
577:                            LogRecord rec = new LogRecord(Level.INFO,
578:                                    "PSMA_CSPWPCJR0008");
579:                            String[] param = { wrappedChannel,
580:                                    WRAPPED_CHANNEL_PROPERTY };
581:                            rec.setParameters(param);
582:                            rec.setThrown(pce);
583:                            rec.setLoggerName(logger.getName());
584:                            logger.log(rec);
585:                        }
586:                    }
587:                    if (wrapped_ch_prop != null
588:                            && wrapped_ch_prop.equals(channel)) {
589:                        // wrappedChannel wraps the channel 'channel'
590:                        return wrappedChannel;
591:                    } else {
592:                        // Check if the wrapped channel is created with a numerical 
593:                        // suffix.
594:                        idx++;
595:                        String tmp = wrappedChannel + String.valueOf(idx);
596:                        while (cpc.existsChannel(tmp)) {
597:                            try {
598:                                wrapped_ch_prop = cpc.getStringProperty(tmp,
599:                                        WRAPPED_CHANNEL_PROPERTY);
600:                            } catch (ProviderContextException pce) {
601:                                // The channel exists,but the property 'wrappedchannel'
602:                                //  is not readable. 
603:                                if (logger.isLoggable(Level.INFO)) {
604:                                    LogRecord rec = new LogRecord(Level.INFO,
605:                                            "PSMA_CSPWPCJR0008");
606:                                    String[] param = { wrappedChannel,
607:                                            WRAPPED_CHANNEL_PROPERTY };
608:                                    rec.setParameters(param);
609:                                    rec.setThrown(pce);
610:                                    rec.setLoggerName(logger.getName());
611:                                    logger.log(rec);
612:                                }
613:                            }
614:                            // Check the 'wrappedChannel' property 
615:                            if (wrapped_ch_prop != null
616:                                    && wrapped_ch_prop.equals(channel)) {
617:                                // tmp wraps the channel 'channel'
618:                                return tmp;
619:                            }
620:                            idx++;
621:                            tmp = wrappedChannel + String.valueOf(idx);
622:                        }
623:                        // The wrapped channel doesnt exist, create a new wrapped 
624:                        // channel at the new index
625:                        try {
626:                            cpc.createChannel(tmp, WRAPPING_PROVIDER);
627:                            // Add the newly create channel to WrappedChannels list.
628:
629:                            if (cpc.existsCollectionProperty(getName(),
630:                                    WRAPPED_CHANNELS)) {
631:                                Map m = cpc.getCollectionProperty(getName(),
632:                                        WRAPPED_CHANNELS);
633:                                List wrappedChannels = new ArrayList(m.values());
634:                                wrappedChannels.add(tmp);
635:                                cpc.setCollectionProperty(getName(),
636:                                        WRAPPED_CHANNELS, wrappedChannels);
637:                            }
638:
639:                            if (logger.isLoggable(Level.FINEST))
640:                                logger.log(Level.FINEST, "PSMA_CSPWPCJR0009",
641:                                        tmp);
642:
643:                        } catch (ProviderContextException pce) {
644:                            if (logger.isLoggable(Level.SEVERE))
645:                                logger.log(Level.SEVERE, "PSMA_CSPWPCJR0010",
646:                                        pce);
647:                            return null;
648:                        }
649:
650:                        try {
651:                            cpc.setStringProperty(tmp,
652:                                    WRAPPED_CHANNEL_PROPERTY, channel);
653:                        } catch (ProviderContextException pce) {
654:                            if (logger.isLoggable(Level.SEVERE))
655:                                logger
656:                                        .log(Level.INFO, "PSMA_CSPWPCJR0011",
657:                                                pce);
658:                            return null;
659:                        }
660:                        return tmp;
661:                    }
662:                } else {
663:                    try {
664:                        cpc.createChannel(wrappedChannel, WRAPPING_PROVIDER);
665:                        // Add the newly create channel to WrappedChannels list.
666:
667:                        if (cpc.existsCollectionProperty(getName(),
668:                                WRAPPED_CHANNELS)) {
669:                            Map m = cpc.getCollectionProperty(getName(),
670:                                    WRAPPED_CHANNELS);
671:                            List wrappedChannels = new ArrayList(m.values());
672:                            wrappedChannels.add(wrappedChannel);
673:                            cpc.setCollectionProperty(getName(),
674:                                    WRAPPED_CHANNELS, wrappedChannels);
675:                        }
676:
677:                        if (logger.isLoggable(Level.FINEST))
678:                            logger.log(Level.FINEST, "PSMA_CSPWPCJR0012",
679:                                    wrappedChannel);
680:                    } catch (ProviderContextException pce) {
681:                        if (logger.isLoggable(Level.SEVERE))
682:                            logger.log(Level.SEVERE, "PSMA_CSPWPCJR0010", pce);
683:                        return null;
684:                    }
685:                    try {
686:                        cpc.setStringProperty(wrappedChannel,
687:                                WRAPPED_CHANNEL_PROPERTY, channel);
688:                    } catch (ProviderContextException pce) {
689:                        if (logger.isLoggable(Level.SEVERE))
690:                            logger.log(Level.SEVERE, "PSMA_CSPWPCJR0011", pce);
691:                        return null;
692:                    }
693:                }
694:                return wrappedChannel;
695:            }
696:        }
w___w__w___.j___av___a2___s__.__c_o__m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.