Source Code Cross Referenced for JBITreeAdaptorImpl.java in  » ESB » open-esb » com » sun » jbi » jsf » util » 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 » ESB » open esb » com.sun.jbi.jsf.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         *  Copyright 1997-2008 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         *  The contents of this file are subject to the terms of either the GNU
007:         *  General Public License Version 2 only ("GPL") or the Common Development
008:         *  and Distribution License("CDDL") (collectively, the "License").  You
009:         *  may not use this file except in compliance with the License. You can obtain
010:         *  a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011:         *  or glassfish/bootstrap/legal/LICENSE.txt.  See the License for the specific
012:         *  language governing permissions and limitations under the License.
013:         *
014:         *  When distributing the software, include this License Header Notice in each
015:         *  file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016:         *  Sun designates this particular file as subject to the "Classpath" exception
017:         *  as provided by Sun in the GPL Version 2 section of the License file that
018:         *  accompanied this code.  If applicable, add the following below the License
019:         *  Header, with the fields enclosed by brackets [] replaced by your own
020:         *  identifying information: "Portions Copyrighted [year]
021:         *  [name of copyright owner]"
022:         *
023:         *  Contributor(s):
024:         *
025:         *  If you wish your version of this file to be governed by only the CDDL or
026:         *  only the GPL Version 2, indicate your decision by adding "[Contributor]
027:         *  elects to include this software in this distribution under the [CDDL or GPL
028:         *  Version 2] license."  If you don't indicate a single choice of license, a
029:         *  recipient has the option to distribute your version of this file under
030:         *  either the CDDL, the GPL Version 2 or to extend the choice of license to
031:         *  its licensees as provided above.  However, if you add GPL Version 2 code
032:         *  and therefore, elected the GPL Version 2 license, then the option applies
033:         *  only if the new code is made subject to such option by the copyright
034:         *  holder.
035:         */
036:        package com.sun.jbi.jsf.util;
037:
038:        import com.sun.jbi.jsf.bean.JBIConfigBean;
039:        import com.sun.jbi.jsf.bean.ListBean;
040:        import com.sun.jbi.ui.common.JBIAdminCommands;
041:        import com.sun.jbi.ui.common.JBIComponentInfo;
042:        import com.sun.jbi.ui.common.ServiceAssemblyInfo;
043:        import com.sun.jbi.ui.common.ServiceUnitInfo;
044:        import com.sun.jsftemplating.component.factory.tree.DynamicTreeNodeFactory;
045:        import com.sun.jsftemplating.component.factory.tree.TreeAdaptor;
046:        import com.sun.jsftemplating.component.factory.tree.TreeAdaptorBase;
047:        import com.sun.jsftemplating.layout.descriptors.ComponentType;
048:        import com.sun.jsftemplating.layout.descriptors.LayoutComponent;
049:        import com.sun.jsftemplating.layout.descriptors.LayoutElement;
050:        import com.sun.webui.jsf.component.TreeNode;
051:        import java.util.ArrayList;
052:        import java.util.Arrays;
053:        import java.util.HashMap;
054:        import java.util.Iterator;
055:        import java.util.List;
056:        import java.util.Map;
057:        import java.util.logging.Logger;
058:        import javax.faces.component.UIComponent;
059:        import javax.faces.context.FacesContext;
060:
061:        /**
062:         * <p>
063:         *
064:         * The <code>JBITreeAdaptorImpl</code> implementation must have a 
065:         * <code>public static JBITreeAdaptorImpl getInstance(FacesContext,
066:         *  LayoutComponent, UIComponent)</code> method in order to get access to an
067:         * instance of the <code>JBITreeAdaptorImpl</code> instance.</p> <p>
068:         *
069:         * This class is used by <code>DynamicTreeNodeFactory</code>.</p>
070:         *
071:         * @author   Sun Microsystems Inc.
072:         */
073:        public class JBITreeAdaptorImpl extends TreeAdaptorBase implements 
074:                TreeAdaptor {
075:
076:            /**
077:             * <p>
078:             *
079:             * This method provides access to an <code>JBITreeAdaptorImpl</code>
080:             * instance. Each time it is invoked, it returns a new instance.</p>
081:             *
082:             * @param ctx     Description of Parameter
083:             * @param desc    Description of Parameter
084:             * @param parent  Description of Parameter
085:             * @return        The Instance value
086:             */
087:            public static TreeAdaptor getInstance(FacesContext ctx,
088:                    LayoutComponent desc, UIComponent parent) {
089:                TreeAdaptor result = new JBITreeAdaptorImpl(desc, parent);
090:                sLog.fine("JBITreeAdaptorImpl.getInstance(" + ctx + ", " + desc
091:                        + ", " + parent + "),result =" + result);
092:                return result;
093:            }
094:
095:            /**
096:             * <p>
097:             *
098:             * This constructor is by the wrapper.</p> <code>JBITreeAdaptorWrapper</code>
099:             */
100:            public JBITreeAdaptorImpl() {
101:                sLog.fine("JBITreeAdaptorImpl.<init>()");
102:            }
103:
104:            /**
105:             * <p>
106:             *
107:             * This constructor saves the <code>LayoutComponent</code> descriptor and
108:             * the <code>UIComponent</code> associated with this <code>TreeAdaptor</code>
109:             * . This constructor is used by the JBITreeAdaptorWrapper constructor.
110:             * </p>
111:             *
112:             * @param desc    Description of Parameter
113:             * @param parent  Description of Parameter
114:             */
115:            public JBITreeAdaptorImpl(LayoutComponent desc, UIComponent parent) {
116:                super (desc, parent);
117:                sLog.fine("JBITreeAdaptorImpl.<init>(" + desc + ", " + parent
118:                        + "), mJac=" + mJac + ", this=" + this );
119:            }
120:
121:            /**
122:             * 2/13/2007 <p>
123:             *
124:             * Returns child <code>TreeNode</code>s for the given <code>TreeNode</code>
125:             * model Object.</p>
126:             *
127:             * @param nodeObject  Description of Parameter
128:             * @return            The ChildTreeNodeObjects value
129:             */
130:            public List getChildTreeNodeObjects(Object nodeObject) {
131:                sLog.fine("JBITreeAdaptorImpl getChildTreeNodeObjects("
132:                        + nodeObject + "), mAdaptorListType="
133:                        + mAdaptorListType + ", this=" + this );
134:
135:                List result = null;
136:
137:                if (null != nodeObject) {
138:                    if (nodeObject.equals(mAdaptorListType)) {
139:                        ListBean listBean = BeanUtilities.getListBean();
140:                        String xmlQueryResults;
141:
142:                        if ("deployments".equals(mAdaptorListType)) {
143:                            xmlQueryResults = listBean
144:                                    .getListServiceAssemblies();
145:                            sLog
146:                                    .fine("JBITreeAdaptorImpl getChildTreeNodeObjects()"
147:                                            + ", xmlQueryResults="
148:                                            + xmlQueryResults);
149:                            List saInfoList = ServiceAssemblyInfo
150:                                    .readFromXmlTextWithProlog(xmlQueryResults);
151:
152:                            mChildren = saInfoList.toArray();
153:                        }
154:
155:                        else if ("bindingsEngines".equals(mAdaptorListType)) {
156:                            xmlQueryResults = listBean
157:                                    .getListBindingComponents();
158:                            sLog
159:                                    .fine("JBITreeAdaptorImpl getChildTreeNodeObjects()"
160:                                            + ", xmlQueryResults="
161:                                            + xmlQueryResults);
162:                            List bcCompInfoList = JBIComponentInfo
163:                                    .readFromXmlText(xmlQueryResults);
164:
165:                            xmlQueryResults = listBean.getListServiceEngines();
166:                            sLog
167:                                    .fine("JBITreeAdaptorImpl getChildTreeNodeObjects()"
168:                                            + ", xmlQueryResults="
169:                                            + xmlQueryResults);
170:                            List seCompInfoList = JBIComponentInfo
171:                                    .readFromXmlText(xmlQueryResults);
172:
173:                            List operableComponentsList = new ArrayList();
174:                            operableComponentsList.addAll(bcCompInfoList);
175:                            operableComponentsList.addAll(seCompInfoList);
176:
177:                            mChildren = operableComponentsList.toArray();
178:                        }
179:
180:                        else if ("libraries".equals(mAdaptorListType)) {
181:                            xmlQueryResults = listBean.getListSharedLibraries();
182:                            sLog
183:                                    .fine("JBITreeAdaptorImpl getChildTreeNodeObjects()"
184:                                            + ", xmlQueryResults="
185:                                            + xmlQueryResults);
186:                            List slCompInfoList = JBIComponentInfo
187:                                    .readFromXmlText(xmlQueryResults);
188:                            mChildren = slCompInfoList.toArray();
189:                        }
190:
191:                        if (mChildren != null) {
192:                            sLog
193:                                    .fine("JBITreeAdaptorImpl getChildTreeNodeObjects()"
194:                                            + ", mChildren.length="
195:                                            + mChildren.length);
196:                            result = Arrays.asList((Object[]) mChildren);
197:                        }
198:                    }
199:
200:                    else if (nodeObject instanceof  ServiceAssemblyInfo) {
201:                        String target = "server";
202:                        List suInfoList = new ArrayList();
203:                        ServiceAssemblyInfo saInfo = (ServiceAssemblyInfo) nodeObject;
204:                        String saName = saInfo.getName();
205:                        List infoList = saInfo.getServiceUnitInfoList();
206:                        Iterator<Object> it2 = infoList.iterator();
207:                        while (it2.hasNext()) {
208:                            Object suInfoObject = it2.next();
209:                            String compName = ((ServiceUnitInfo) suInfoObject)
210:                                    .getTargetName();
211:                            ServiceUnitInfoWrapper wrapper = new ServiceUnitInfoWrapper(
212:                                    (ServiceUnitInfo) suInfoObject, compName,
213:                                    saName, target);
214:                            suInfoList.add(wrapper);
215:                            wrapper.setQueryString("sa");
216:                        }
217:                        result = suInfoList;
218:                    }
219:
220:                    else if (nodeObject instanceof  JBIComponentInfo) {
221:                        JBIComponentInfo compInfo = (JBIComponentInfo) nodeObject;
222:                        String compName = compInfo.getName();
223:                        String compType = compInfo.getType();
224:                        String target = "server";
225:                        List saInfoList = null;
226:                        List suInfoList = new ArrayList();
227:                        if (!("shared-library".equals(compType))) {
228:                            sLog
229:                                    .fine("JBITreeAdaptorImpl.getChildTreeNodeObjects(): get SUs for compType="
230:                                            + compType
231:                                            + ", compName="
232:                                            + compName);
233:                            try {
234:                                String xml = mJac.listServiceAssemblies(
235:                                        compName, target);
236:                                saInfoList = ServiceAssemblyInfo
237:                                        .readFromXmlTextWithProlog(xml);
238:                                if (saInfoList != null) {
239:                                    Iterator<Object> it = saInfoList.iterator();
240:                                    while (it.hasNext()) {
241:                                        Object saInfoObject = it.next();
242:                                        String saName = ((ServiceAssemblyInfo) saInfoObject)
243:                                                .getName();
244:                                        List infoList = ((ServiceAssemblyInfo) saInfoObject)
245:                                                .getServiceUnitInfoList();
246:                                        Iterator<Object> it2 = infoList
247:                                                .iterator();
248:                                        while (it2.hasNext()) {
249:                                            Object suInfoObject = it2.next();
250:                                            String tgtName = ((ServiceUnitInfo) suInfoObject)
251:                                                    .getTargetName();
252:                                            if (tgtName.equals(compName)) {
253:                                                ServiceUnitInfoWrapper wrapper = new ServiceUnitInfoWrapper(
254:                                                        (ServiceUnitInfo) suInfoObject,
255:                                                        compName, saName,
256:                                                        target);
257:                                                wrapper.setQueryString("comp");
258:                                                suInfoList.add(wrapper);
259:                                            }
260:                                        }
261:                                    }
262:                                }
263:                            } catch (com.sun.jbi.ui.common.JBIRemoteException jbiRemoteEx) {
264:                                sLog
265:                                        .fine("JBITreeAdaptorImpl.getChildTreeNodeObjects()"
266:                                                + ", caught jbiRemoteEx="
267:                                                + jbiRemoteEx);
268:                            }
269:                        } else {
270:                            sLog
271:                                    .fine("JBITreeAdaptorImpl.getChildTreeNodeObjects() skip getting SUs for an SL");
272:                        }
273:
274:                        result = suInfoList;
275:
276:                    }
277:
278:                } else {
279:                    sLog
280:                            .fine("JBITreeAdaptorImpl getChildTreeNodeObjects, nodeObject="
281:                                    + nodeObject);
282:                }
283:                sLog.fine("JBITreeAdaptorImpl getChildTreeNodeObjects, result="
284:                        + result + ", this=" + this );
285:                return result;
286:            }
287:
288:            /**
289:             * <p>
290:             *
291:             * This method returns the "options" that should be supplied to the
292:             * factory that creates the <code>TreeNode</code> for the given tree node
293:             * model object.</p> <p>
294:             *
295:             * Some useful options for the standard <code>TreeNode</code> component
296:             * include:<p>
297:             *
298:             *
299:             * <ul>
300:             *   <li> text</li>
301:             *   <li> url</li>
302:             *   <li> imageURL</li>
303:             *   <li> target</li>
304:             *   <li> action
305:             *   <li>
306:             *   <li> actionListener</li>
307:             *   <li> expanded</li>
308:             * </ul>
309:             * <p>
310:             *
311:             * See Tree / TreeNode component documentation for more details.</p>
312:             *
313:             * @param nodeObject  Description of Parameter
314:             * @return            The FactoryOptions value
315:             */
316:            public Map<String, Object> getFactoryOptions(Object nodeObject) {
317:                Map<String, Object> result = null;
318:
319:                if (null != nodeObject) {
320:                    LayoutComponent desc = getLayoutComponent();
321:                    result = new HashMap<String, Object>();
322:
323:                    sLog.fine("JBITreeAdaptorImpl getFactoryOptions ("
324:                            + nodeObject + "), nodeObject.getClass()="
325:                            + nodeObject.getClass() + ", desc=" + desc
326:                            + ", this=" + this );
327:
328:                    if (nodeObject instanceof  String) {
329:                        // This case deals with the top node.
330:
331:                        // NOTE: All supported options must be handled here,
332:                        //      otherwise they'll be ignored.
333:                        // NOTE: Options will be evaluated later, do not eval here.
334:                        setProperty(result, "text", desc.getOption("text"));
335:                        setProperty(result, "url", desc.getOption("url"));
336:                        setProperty(result, "imageURL", desc
337:                                .getOption("imageURL"));
338:                        setProperty(result, "target", desc.getOption("target"));
339:                        setProperty(result, "action", desc.getOption("action"));
340:
341:                        // NOTE: Although actionListener is supported, LH currently
342:                        //       implements this to be the ActionListener of the "turner"
343:                        //       which is inconsistent with "action".  We should make use
344:                        //       of the "Handler" feature which provides a "toggle"
345:                        //       CommandEvent.
346:                        setProperty(result, "actionListener", desc
347:                                .getOption("actionListener"));
348:                        setProperty(result, "expanded", desc
349:                                .getOption("expanded"));
350:                        sLog
351:                                .fine("JBITreeAdaptorImpl getFactoryOptions (parent), text="
352:                                        + desc.getOption("text")
353:                                        + ", (partial)result=" + result);
354:
355:                    } else {
356:                        // This case deals with the children
357:
358:                        // NOTE: All supported options must be handled here,
359:                        // otherwise they'll be ignored
360:
361:                        // Finish setting the child properties
362:                        String childName = null;
363:                        String imageUrlSuffix = null;
364:                        String type = null;
365:                        String compType = null;
366:                        String urlSuffix = "type=";
367:                        String urlBase = (String) desc
368:                                .getOption("childURLbase");
369:
370:                        if (nodeObject instanceof  JBIComponentInfo) {
371:                            JBIComponentInfo compInfo = (JBIComponentInfo) nodeObject;
372:                            childName = compInfo.getName();
373:                            type = compInfo.getType();
374:                            sLog.fine("JBITreeAdaptorImpl getFactoryOptions)"
375:                                    + ", childName=" + childName + ", type="
376:                                    + type + ", (partial)result=" + result
377:                                    + ", this=" + this );
378:                            BeanUtilities.setStringPropertyUsingExpression(
379:                                    childName,
380:                                    "#{sessionScope.serviceAssemblyName}");
381:                        }
382:
383:                        else if (nodeObject instanceof  ServiceAssemblyInfo) {
384:                            ServiceAssemblyInfo saInfo = (ServiceAssemblyInfo) nodeObject;
385:                            childName = saInfo.getName();
386:                            type = "service-assembly";
387:                        }
388:
389:                        else if (nodeObject instanceof  ServiceUnitInfoWrapper) {
390:                            ServiceUnitInfo suInfo = ((ServiceUnitInfoWrapper) nodeObject)
391:                                    .getServiceUnitInfo();
392:                            childName = suInfo.getName();
393:                            type = "service-unit";
394:
395:                            String saName = ((ServiceUnitInfoWrapper) nodeObject)
396:                                    .getServiceAssemblyName();
397:                            String compName = ((ServiceUnitInfoWrapper) nodeObject)
398:                                    .getComponentName();
399:                            String qs = ((ServiceUnitInfoWrapper) nodeObject)
400:                                    .getQueryString();
401:
402:                            compType = ((ServiceUnitInfoWrapper) nodeObject)
403:                                    .getComponentType();
404:
405:                            String grandChildURLBase = "/jbi/cluster/showServiceUnit.jsf?";
406:                            if (urlBase.indexOf("cluster") == -1) {
407:                                grandChildURLBase = "/jbi/pe/showServiceUnit.jsf?";
408:                            }
409:                            urlBase = (String) grandChildURLBase + "saname="
410:                                    + saName + "&" + "qs=" + qs + "&"
411:                                    + "compName=" + compName + "&"
412:                                    + "compType=" + compType + "&";
413:                        }
414:
415:                        if (null != childName) {
416:                            setProperty(result, "text", childName);
417:                            urlSuffix += type + "&name=" + childName;
418:                            if ("service-assembly".equals(type)) {
419:                                imageUrlSuffix = "JBIServiceAssembly.gif";
420:                            } else if ("binding-component".equals(type)) {
421:                                imageUrlSuffix = "JBIBindingComponent.gif";
422:                            } else if ("service-engine".equals(type)) {
423:                                imageUrlSuffix = "JBIServiceEngine.gif";
424:                            } else if ("shared-library".equals(type)) {
425:                                imageUrlSuffix = "JBISharedLibrary.gif";
426:                            } else if ("service-unit".equals(type)) {
427:                                imageUrlSuffix = "JBISU.gif";
428:                                // Generic Service Unit
429:                                // *** TBD remove comment bars after images have been created.
430:                                if (compType
431:                                        .equals(JBIConstants.JBI_BINDING_COMPONENT_TYPE)) {
432:                                    //imageUrlSuffix = "JBIBCSU.gif"; // Binding Component Service Unit
433:                                } else if (compType
434:                                        .equals(JBIConstants.JBI_SERVICE_ENGINE_TYPE)) {
435:                                    //imageUrlSuffix = "JBISESU.gif"; // Service Engine Service Unit
436:                                }
437:                            }
438:                        }
439:                        String url = urlBase + urlSuffix;
440:                        sLog.fine("JBITreeAdaptorImpl.getFactoryOptions()"
441:                                + ", url=" + url + ", imageUrlSuffix="
442:                                + imageUrlSuffix + ", this=" + this );
443:                        setProperty(result, "url", url);
444:                        setProperty(result, "imageURL", desc
445:                                .getOption("childImageURLbase")
446:                                + imageUrlSuffix);
447:                        setProperty(result, "target", desc
448:                                .getOption("childTarget"));
449:                        setProperty(result, "action", desc
450:                                .getOption("childAction"));
451:                        setProperty(result, "expanded", desc
452:                                .getOption("childExpanded"));
453:                        sLog
454:                                .fine("JBITreeAdaptorImpl getFactoryOptions (child), type="
455:                                        + type + ", url=" + url);
456:                    }
457:                }
458:
459:                sLog.fine("JBITreeAdaptorImpl getFactoryOptions, result="
460:                        + result + ", this=" + this );
461:                return result;
462:            }
463:
464:            /**
465:             * <p>
466:             *
467:             * This method returns the <code>id</code> for the given tree node model
468:             * object.</p>
469:             *
470:             * @param nodeObject  Description of Parameter
471:             * @return            The Id value
472:             */
473:            public String getId(Object nodeObject) {
474:                String result = "nullNodeObject";
475:
476:                if (null != nodeObject) {
477:                    if (nodeObject instanceof  ServiceAssemblyInfo) {
478:                        result = ((ServiceAssemblyInfo) nodeObject).getName();
479:                    } else if (nodeObject instanceof  JBIComponentInfo) {
480:                        result = ((JBIComponentInfo) nodeObject).getName();
481:                    } else if (nodeObject instanceof  ServiceUnitInfoWrapper) {
482:                        result = ((ServiceUnitInfoWrapper) nodeObject)
483:                                .getName();
484:                    } else {
485:                        result = genId(nodeObject.toString());
486:                    }
487:                }
488:                result = sanitize(result);
489:                return result;
490:            }
491:
492:            /**
493:             * <p>
494:             *
495:             * This method returns any facets that should be applied to the <code>TreeNode (comp)</code>
496:             * . Useful facets for the sun <code>TreeNode</code> component are:
497:             * "content" and "image".</p> <p>
498:             *
499:             * Facets that already exist on <code>comp</code>, or facets that are
500:             * directly added to <code>comp</code> do not need to be returned from
501:             * this method.</p> <p>
502:             *
503:             * This implementation directly adds a "content" facet and returns <code>null</code>
504:             * from this method.</p>
505:             *
506:             * @param comp        The tree node <code>UIComponent</code>.
507:             * @param nodeObject  The (model) object representing the tree node.
508:             * @return            The Facets value
509:             */
510:            public Map<String, UIComponent> getFacets(UIComponent comp,
511:                    Object nodeObject) {
512:                return null;
513:            }
514:
515:            /**
516:             * <p>
517:             *
518:             * Advanced framework feature which provides better handling for things
519:             * such as expanding TreeNodes, beforeEncode, and other events.</p> <p>
520:             *
521:             * This method should return a <code>Map</code> of <code>List</code> of
522:             * <code>Handler</code> objects. Each <code>List</code> in the <code>Map</code>
523:             * should be registered under a key that cooresponds to to the "event" in
524:             * which the <code>Handler</code>s should be invoked.</p>
525:             *
526:             * @param comp        Description of Parameter
527:             * @param nodeObject  Description of Parameter
528:             * @return            The HandlersByType value
529:             */
530:            public Map getHandlersByType(UIComponent comp, Object nodeObject) {
531:                return null;
532:            }
533:
534:            /**
535:             * <p>
536:             *
537:             * This method is called shortly after {@link #getInstance(FacesContext,
538:             * LayoutComponent, UIComponent)}. It provides a place for post-creation
539:             * initialization to take occur.</p>
540:             */
541:            public void init() {
542:                //initialise the logger
543:                sLog.fine("JBITreeAdaptorImpl.init(), this=" + this );
544:
545:                // Get the FacesContext
546:                FacesContext ctx = FacesContext.getCurrentInstance();
547:
548:                // This is the descriptor for this dynamic TreeNode, it contains all
549:                // information (options) necessary for this Adaptor
550:                LayoutComponent desc = getLayoutComponent();
551:
552:                // The parent UIComponent
553:                UIComponent parent = getParentUIComponent();
554:
555:                // add extension subtree, if any
556:                addExtensionSubtree(parent);
557:
558:                // Get the Method Name
559:                Object val = desc.getEvaluatedOption(ctx,
560:                        "treeAdaptorListType", parent);
561:                if (val == null) {
562:                    throw new IllegalArgumentException(
563:                            "'treeAdaptorListType' must be specified!");
564:                }
565:                mAdaptorListType = (String) val;
566:
567:                setTreeNodeObject(mAdaptorListType);
568:
569:                sLog.fine("JBITreeAdaptorImpl.init(), desc=" + desc
570:                        + ", parent=" + parent + ", mAdaptorListType="
571:                        + mAdaptorListType + ", this=" + this );
572:            }
573:
574:            /**
575:             * <p>
576:             *
577:             * Helper method for setting Properties while avoiding NPE's.</p>
578:             *
579:             * @param props  The new Property value
580:             * @param key    The new Property value
581:             * @param value  The new Property value
582:             */
583:            void setProperty(Map props, String key, Object value) {
584:                if (value != null) {
585:                    props.put(key, value);
586:                }
587:            }
588:
589:            private Object[] mChildren;
590:
591:            private static Logger sLog = JBILogger.getInstance();
592:
593:            /**
594:             * Gets the DynamicTreeNode attribute of the JBITreeAdaptorImpl object
595:             *
596:             * @return   The DynamicTreeNode value
597:             */
598:            private UIComponent getDynamicTreeNode() {
599:                UIComponent result = null;
600:
601:                FacesContext facesContext = FacesContext.getCurrentInstance();
602:
603:                LayoutComponent currentLayout = getLayoutComponent();
604:                LayoutElement parentLayout = currentLayout.getParent();
605:                List layouts = parentLayout.getChildLayoutElements();
606:                LayoutElement parent = null;
607:                // TBD
608:                String id = "JBITreeExtension";
609:                ComponentType type = new ComponentType("dynamicTreeNode",
610:                        "com.sun.jbi.jsf.util.JBITreeExtensionAdaptorImpl");
611:                LayoutComponent dynamicTreeNodeLayout = new LayoutComponent(
612:                        parent, id, type);
613:                dynamicTreeNodeLayout.addOption("treeAdaptorClass",
614:                        "com.sun.jbi.jsf.util.JBITreeExtensionAdaptorImpl");
615:
616:                UIComponent parentComponent = getParentUIComponent();
617:
618:                DynamicTreeNodeFactory dynamicTreeNodeFactory = new DynamicTreeNodeFactory();
619:
620:                UIComponent extensionRoot = dynamicTreeNodeFactory.create(
621:                        facesContext, dynamicTreeNodeLayout, parentComponent);
622:                sLog.fine("JBITreeAdaptorImpl.getDynamicTreeNode(), result="
623:                        + result);
624:
625:                return result;
626:            }
627:
628:            /**
629:             * Description of the Method
630:             *
631:             * @param anIdCandidate  Description of Parameter
632:             * @return               Description of the Returned Value
633:             */
634:            private String sanitize(String anIdCandidate) {
635:                String result = null;
636:
637:                if (null != anIdCandidate) {
638:                    result = START_WITH_ALPHA + anIdCandidate;
639:                    // ensure first chararcter is alpha
640:
641:                    if (0 <= result.indexOf(BLANK)) {
642:                        result = result.replaceAll(BLANK, DASH);
643:                        result += "B";
644:                        // indicate that blanks were substituted
645:                    } else {
646:                        result += "b";
647:                        // indicate that blanks were not substituted
648:                    }
649:                    if (0 <= result.indexOf(PERIOD)) {
650:                        result = result.replaceAll(ESCAPED_PERIOD, DASH);
651:                        // NOT I18n
652:                        result += "P";
653:                        // indicate that periods were substituted
654:                    } else {
655:                        result += "p";
656:                        // indicate that periods were not substituted
657:                    }
658:
659:                }
660:
661:                sLog.fine("JBITreeAdaptorImpl.sanitize(" + anIdCandidate
662:                        + "), result=" + result);
663:
664:                return result;
665:            }
666:
667:            /**
668:             * <p>
669:             *
670:             * This method generates an ID that is safe for JSF for the given String.
671:             * It does not guarantee that the id is unique, it is the responsibility
672:             * of the caller to pass in a String that will result in a UID. All
673:             * non-ascii characters will be stripped.</p>
674:             *
675:             * @param uid  A non-null String.
676:             * @return     Description of the Returned Value
677:             */
678:            private String genId(String uid) {
679:                char[] chArr = uid.toCharArray();
680:                int len = chArr.length;
681:                int newIdx = 0;
682:                for (int idx = 0; idx < len; idx++) {
683:                    char test = chArr[idx];
684:                    if (Character.isLetterOrDigit(test) || test == '_'
685:                            || test == '-') {
686:                        chArr[newIdx++] = test;
687:                    }
688:                }
689:                return new String(chArr, 0, newIdx);
690:            }
691:
692:            /**
693:             * @param aParentRef  The feature to be added to the ExtensionSubtree
694:             *      attribute
695:             */
696:            private void addExtensionSubtree(UIComponent aParentRef) {
697:                JBIConfigBean jbiConfigBean = BeanUtilities.getJBIConfigBean();
698:
699:                JBITreeExtension jbiTreeExtension = null;
700:
701:                if (null != jbiConfigBean) {
702:                    jbiTreeExtension = jbiConfigBean.getJBITreeExtension();
703:                }
704:
705:                if (null != jbiTreeExtension) {
706:                    TreeNode selfTreeNode = null;
707:                    TreeNode newTreeNode = null;
708:
709:                    List siblings = aParentRef.getParent().getChildren();
710:                    Iterator siblingsIt = siblings.iterator();
711:                    while (siblingsIt.hasNext()) {
712:                        Object next = siblingsIt.next();
713:                        sLog
714:                                .fine("JBITreeAdaptorImpl.addExtensionSubtree(), next="
715:                                        + next);
716:                        TreeNode sibling = null;
717:                        if (next instanceof  TreeNode) {
718:                            sibling = (TreeNode) next;
719:                            String siblingId = sibling.getId();
720:                            if ("JBIRoot".equals(siblingId)) {
721:                                sLog
722:                                        .fine("JBITreeAdaptorImpl.addExtensionSubtree()"
723:                                                + ", found self treeNode="
724:                                                + sibling.getText());
725:                                selfTreeNode = sibling;
726:                            } else if ("JBIExtRootTreeNode".equals(siblingId)) {
727:                                sLog
728:                                        .fine("JBITreeAdaptorImpl.addExtensionSubtree()"
729:                                                + ", found new treeNode="
730:                                                + sibling.getText());
731:                                newTreeNode = sibling;
732:                            } else {
733:                                sLog
734:                                        .fine("JBITreeAdaptorImpl.addExtensionSubtree()"
735:                                                + ", sibling="
736:                                                + sibling.getText()
737:                                                + ", id="
738:                                                + sibling.getId());
739:                            }
740:                        }
741:
742:                    }
743:
744:                    if (null != selfTreeNode) {
745:                        if (null != newTreeNode) {
746:                            sLog
747:                                    .fine("JBITreeAdaptorImpl.addExtensionSubtree(), updating treeNode"
748:                                            + ", newTreeNode=" + newTreeNode);
749:                            jbiTreeExtension.update(newTreeNode);
750:                            sLog
751:                                    .fine("JBITreeAdaptorImpl.addExtensionSubtree(), treeNode updated"
752:                                            + ", newTreeNode.getText()="
753:                                            + newTreeNode.getText());
754:                        } else {
755:                            sLog
756:                                    .fine("JBITreeAdaptorImpl.addExtensionSubtree(), creating new treeNode"
757:                                            + ", jbiTreeExtension="
758:                                            + jbiTreeExtension);
759:                            if (false) {
760:                                newTreeNode = (TreeNode) getDynamicTreeNode();
761:                            }
762:                            newTreeNode = new com.sun.webui.jsf.component.TreeNode();
763:                            newTreeNode.setId("JBIExtRootTreeNode");
764:                            newTreeNode.setText("JBI Extension");
765:                            // TBD I18n
766:                            newTreeNode.setTarget(selfTreeNode.getTarget());
767:
768:                            jbiTreeExtension.init(newTreeNode);
769:                            sLog
770:                                    .fine("JBITreeAdaptorImpl.addExtensionSubtree(), new treeNode initialized"
771:                                            + ", newTreeNode.getText()="
772:                                            + newTreeNode.getText());
773:                            siblings.add(newTreeNode);
774:                        }
775:
776:                    }
777:                }
778:            }
779:
780:            private static final String BLANK = " "; // NOT I18n
781:            private static final String DASH = "-"; // NOT I18n
782:            private static final String ESCAPED_PERIOD = "\\."; // NOT I18n
783:            private static final String PERIOD = "."; // NOT I18n
784:            private static final String START_WITH_ALPHA = "A"; // NOT I18n
785:
786:            private JBIAdminCommands mJac = BeanUtilities.getClient();
787:
788:            private String mAdaptorListType;
789:            private String mNameAtt;
790:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.