Source Code Cross Referenced for ChannelDefinitionTagHandler.java in  » Portal » uPortal_rel-2-6-1-GA » org » jasig » portal » car » 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 » uPortal_rel 2 6 1 GA » org.jasig.portal.car 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Copyright 2002 The JA-SIG Collaborative.  All rights reserved.
002:         *  See license distributed with this file and
003:         *  available online at http://www.uportal.org/license.html
004:         */
005:
006:        package org.jasig.portal.car;
007:
008:        import java.lang.reflect.Constructor;
009:        import org.jasig.portal.properties.PropertiesManager;
010:        import org.apache.commons.logging.Log;
011:        import org.apache.commons.logging.LogFactory;
012:        import org.xml.sax.Attributes;
013:        import org.xml.sax.ContentHandler;
014:        import org.xml.sax.SAXException;
015:        import org.xml.sax.helpers.DefaultHandler;
016:
017:        /**
018:         * Processes all channel definitions located in a CAR and instantiates and 
019:         * delegates to an inner content handler for each block to do the real work
020:         * of publishing.
021:         * 
022:         * @author Mark Boyd  {@link <a href="mailto:mark.boyd@engineer.com">mark.boyd@engineer.com</a>}
023:         * @version $Revision: 36690 $
024:         */
025:        public class ChannelDefinitionTagHandler extends DefaultHandler {
026:            private static final Log log = LogFactory
027:                    .getLog(ChannelDefinitionTagHandler.class);
028:            private static Class cHandlerClass = null;
029:            private static Constructor cDefaultConstructor = null;
030:            private static Constructor cExtendedConstructor = null;
031:
032:            private ContentHandler handlerInstance = null;
033:            private ParsingContext ctx = null;
034:
035:            private static final String HANDLER_PROPERTY = "org.jasig.portal.car.ChannelDefinition.contentHandler";
036:
037:            /**
038:             * Construct a ChannelDefinitionHandler that receives events from parsing
039:             * a channel archive deployment descriptor but only for any contained 
040:             * channel-definition elements and their children.
041:             * 
042:             * @param ctx
043:             */
044:            ChannelDefinitionTagHandler(ParsingContext ctx) {
045:                this .ctx = ctx;
046:
047:                if (cHandlerClass == null) {
048:                    initialize();
049:                }
050:            }
051:
052:            /**
053:             * Load an appropriate class for handling the channel definition content
054:             * and publishing the channel specified therein.
055:             */
056:            private void initialize() {
057:                String declaredClass = null;
058:
059:                try {
060:                    declaredClass = PropertiesManager
061:                            .getProperty(HANDLER_PROPERTY);
062:                } catch (Exception e) {
063:                    // no handler specified so use default.
064:                }
065:                if (declaredClass != null)
066:                    loadTheClass(declaredClass);
067:                else
068:                    cHandlerClass = DefaultChanPubInnerHandler.class;
069:
070:                if (cHandlerClass != null)
071:                    getTheConstructor();
072:            }
073:
074:            /**
075:             * Attempt to load the class specified.
076:             * @param handlerClass
077:             */
078:            private void loadTheClass(String handlerClass) {
079:                try {
080:                    CarResources cRes = CarResources.getInstance();
081:                    ClassLoader cl = cRes.getClassLoader();
082:                    cHandlerClass = cl.loadClass(handlerClass);
083:                } catch (ClassNotFoundException clfe) {
084:                    log.error("Specified contentHandler class " + handlerClass
085:                            + " specified in portal.properties not found. "
086:                            + "Ignoring channel-definition block "
087:                            + "in deployment descriptor of "
088:                            + ctx.getJarFile().getName() + ".");
089:                }
090:            }
091:
092:            private void getTheConstructor() {
093:                try {
094:                    cExtendedConstructor = cHandlerClass
095:                            .getConstructor(new Class[] { ParsingContext.class });
096:                    return;
097:                } catch (NoSuchMethodException nsme) {
098:                    // since this constructor is optional ignore exception
099:                    // and try default construction.
100:                }
101:                try {
102:                    cDefaultConstructor = cHandlerClass
103:                            .getConstructor((Class[]) null);
104:                } catch (NoSuchMethodException nsme) {
105:                    log.error("Niether Extended constructor nor default, zero "
106:                            + "parameter constructor were found "
107:                            + "for specified contentHandler class "
108:                            + cHandlerClass.getName()
109:                            + " specified in portal.properties. Ignoring "
110:                            + "channel-definition block "
111:                            + "in deployment descriptor of "
112:                            + ctx.getJarFile().getName() + ".", nsme);
113:                }
114:            }
115:
116:            /**
117:             * Attempt to load an instance of the class. The classes must support a
118:             * default constructor but can optionally provide a constructor with a 
119:             * single argument of type DescriptorHandler. If found that constructor
120:             * will be used. If not found then the default constructor wil be used.
121:             * 
122:             * @return
123:             */
124:            private Object instantiateTheClass() {
125:                Object obj = null;
126:
127:                try {
128:                    if (cExtendedConstructor != null)
129:                        obj = cExtendedConstructor
130:                                .newInstance(new Object[] { ctx });
131:                    else if (cDefaultConstructor != null)
132:                        obj = cDefaultConstructor.newInstance(new Object[] {});
133:                } catch (Exception e) {
134:                    log
135:                            .error(
136:                                    "Unable to create specified contentHandler class "
137:                                            + cHandlerClass.getName()
138:                                            + " specified in portal.properties. Ignoring "
139:                                            + "channel-definition block "
140:                                            + "in deployment descriptor of "
141:                                            + ctx.getJarFile().getName() + ".",
142:                                    e);
143:                }
144:                return obj;
145:            }
146:
147:            /**
148:             * Casts the object to a ContentHandler and logs any error that occurs.
149:             * 
150:             * @param obj
151:             * @return
152:             */
153:            private ContentHandler castToContentHandler(Object obj) {
154:                ContentHandler handler = null;
155:
156:                try {
157:                    handler = (ContentHandler) obj;
158:                } catch (ClassCastException cce) {
159:                    log.error("ContentHandler class "
160:                            + obj.getClass().getName()
161:                            + " specified in portal.properties"
162:                            + " does not implement ContentHandler."
163:                            + " Ignoring channel-definition block in"
164:                            + " deployment descriptor of "
165:                            + ctx.getJarFile().getName() + ".");
166:                }
167:                return handler;
168:            }
169:
170:            ///////////////////// Content Handler Implementations //////////////////    
171:
172:            /**
173:             * Handle start element events.
174:             */
175:            public void startElement(String namespaceURI, String localName,
176:                    String qName, Attributes atts) throws SAXException {
177:                // if starting a new channel definition then instantiate a new
178:                // inner handler to which to pass events
179:                if (qName.equals(DescriptorHandler.CHANDEF_TAG_NAME)
180:                        && ctx.getPath().equals(DescriptorHandler.CHANDEFS)) {
181:                    if (cHandlerClass != null) {
182:                        Object obj = instantiateTheClass();
183:                        handlerInstance = castToContentHandler(obj);
184:                    }
185:                }
186:
187:                if (handlerInstance != null)
188:                    handlerInstance.startElement(namespaceURI, localName,
189:                            qName, atts);
190:            }
191:
192:            /**
193:             * Handle the characters event to capture textual content for elements.
194:             */
195:            public void characters(char[] ch, int start, int length)
196:                    throws SAXException {
197:                if (handlerInstance != null)
198:                    handlerInstance.characters(ch, start, length);
199:            }
200:
201:            /**
202:             * Handle the closing element event.
203:             */
204:            public void endElement(String namespaceURI, String localName,
205:                    String qName) throws SAXException {
206:                // while within channel-definition block handler will be non-null and 
207:                // should receive all events.
208:                if (handlerInstance != null)
209:                    handlerInstance.endElement(namespaceURI, localName, qName);
210:
211:                if (qName.equals(DescriptorHandler.CHANDEF_TAG_NAME)
212:                        && ctx.getPath().equals(DescriptorHandler.CHANDEFS)) {
213:                    // leaving block so remove the handler in prep for a new
214:                    // block
215:                    handlerInstance = null;
216:                }
217:            }
218:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.