Source Code Cross Referenced for PortletWebApplicationImpl.java in  » Portal » gridsphere » org » gridsphere » portletcontainer » impl » 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 » gridsphere » org.gridsphere.portletcontainer.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * @author <a href="mailto:novotny@gridsphere.org">Jason Novotny</a>
003:         * @version $Id: PortletWebApplicationImpl.java 6407 2008-01-16 15:20:21Z wehrens $
004:         */package org.gridsphere.portletcontainer.impl;
005:
006:        import org.apache.commons.logging.Log;
007:        import org.apache.commons.logging.LogFactory;
008:        import org.gridsphere.portlet.service.PortletServiceException;
009:        import org.gridsphere.portlet.service.spi.PortletServiceFactory;
010:        import org.gridsphere.portlet.service.spi.impl.descriptor.PortletServiceCollection;
011:        import org.gridsphere.portletcontainer.ApplicationPortlet;
012:        import org.gridsphere.portletcontainer.PortletStatus;
013:        import org.gridsphere.portletcontainer.PortletWebApplication;
014:        import org.gridsphere.portletcontainer.impl.descriptor.*;
015:
016:        import javax.portlet.PortletException;
017:        import javax.servlet.RequestDispatcher;
018:        import javax.servlet.ServletContext;
019:        import java.io.File;
020:        import java.util.ArrayList;
021:        import java.util.Collection;
022:        import java.util.Hashtable;
023:        import java.util.Map;
024:
025:        /**
026:         * The <code>PortletWebApplicationImpl</code> is an implementation of a <code>PortletWebApplication</code> that
027:         * represents a collection of portlets contained in a packaged WAR file. Currently
028:         * under development is the notion of dynamically managing portlet web applications.
029:         */
030:        public class PortletWebApplicationImpl implements  PortletWebApplication {
031:
032:            private Log log = LogFactory
033:                    .getLog(PortletWebApplicationImpl.class);
034:            private PortletApp portletWebApp = null;
035:
036:            protected Map<String, PortletDefinition> portletDefinitions = new Hashtable<String, PortletDefinition>();
037:            protected Map<String, ApplicationPortlet> appPortlets = new Hashtable<String, ApplicationPortlet>();
038:
039:            protected String webApplicationName = "Unknown portlet web application";
040:            protected String webAppDescription = "Unknown portlet web application description";
041:
042:            protected PortletStatus status = PortletStatus.SUCCESS;
043:            protected String statusMessage = "Portlet web application loaded successfully";
044:
045:            protected RequestDispatcher rd = null;
046:
047:            public PortletWebApplicationImpl(ServletContext context,
048:                    ClassLoader loader) {
049:
050:                // Make all jsr portlets have only one concrete instance
051:                String realPath = context.getRealPath("");
052:                int l = realPath.lastIndexOf(File.separator);
053:                webApplicationName = realPath.substring(l + 1);
054:
055:                this .webAppDescription = context.getServletContextName();
056:                try {
057:                    // load portlet.xml
058:                    loadPortlets(context, loader);
059:
060:                    // load services.xml
061:                    loadServices(context, loader);
062:                } catch (PortletException e) {
063:                    status = PortletStatus.FAILURE;
064:                    statusMessage = e.getMessage();
065:                }
066:            }
067:
068:            /**
069:             * Loads collection of portlets from portlet descriptor file using the associated <code>ServletContext</code>
070:             *
071:             * @param ctx    the <code>ServletContext</code>
072:             * @param loader the classloader of the web application
073:             * @throws PortletException if an error occurs loading the portlets
074:             */
075:            protected void loadPortlets(ServletContext ctx, ClassLoader loader)
076:                    throws PortletException {
077:                // load in the portlet.xml file
078:                String portletXMLfile = ctx.getRealPath("/WEB-INF/portlet.xml");
079:
080:                PortletDeploymentDescriptor pdd = null;
081:                try {
082:                    pdd = new PortletDeploymentDescriptor(portletXMLfile);
083:                } catch (Exception e) {
084:                    status = PortletStatus.FAILURE;
085:                    statusMessage = "Unable to load portlets from: "
086:                            + webApplicationName + " due to mapping error";
087:                    throw new PortletException(statusMessage, e);
088:                }
089:
090:                this .portletWebApp = pdd.getPortletWebApplication();
091:                // Every SportletDefinition has a PortletApplication and possibly multiple ConcretePortletConfig's
092:                PortletDefinition[] portletDefs = pdd
093:                        .getPortletDefinitionList();
094:
095:                // Iterate thru portlet definitions for portlet applications
096:                for (int i = 0; i < portletDefs.length; i++) {
097:                    ApplicationPortlet portletApp = new ApplicationPortletImpl(
098:                            pdd, portletDefs[i], webApplicationName, ctx);
099:
100:                    String portletClass = portletApp.getApplicationPortletID();
101:                    String portletName = portletApp.getApplicationPortletName();
102:                    portletDefinitions.put(portletName, portletDefs[i]);
103:                    appPortlets.put(portletName, portletApp);
104:
105:                    log.debug("sticking " + portletName + " class: "
106:                            + portletClass + " in hash");
107:                }
108:
109:            }
110:
111:            public PortletDefinition getPortletDefinition(String portletName) {
112:                return portletDefinitions.get(portletName);
113:            }
114:
115:            public void init() {
116:            }
117:
118:            public void destroy() {
119:                portletWebApp = null;
120:                appPortlets = null;
121:                portletDefinitions = null;
122:                rd = null;
123:            }
124:
125:            public CustomPortletMode[] getCustomPortletModes() {
126:                return portletWebApp.getCustomPortletMode();
127:            }
128:
129:            public CustomWindowState[] getCustomWindowStates() {
130:                return portletWebApp.getCustomWindowState();
131:            }
132:
133:            public UserAttribute[] getUserAttributes() {
134:                return portletWebApp.getUserAttribute();
135:            }
136:
137:            public SecurityConstraint[] getSecurityConstraints() {
138:                return portletWebApp.getSecurityConstraint();
139:            }
140:
141:            /**
142:             * Loads in a service descriptor file from the associated servlet context
143:             *
144:             * @param ctx    the <code>ServletContext</code>
145:             * @param loader the classloader of the web application
146:             * @throws PortletException if an error occurs loading the portlets
147:             */
148:            protected void loadServices(ServletContext ctx, ClassLoader loader)
149:                    throws PortletException {
150:                // load in the portlet-services.xml file
151:                String descriptorPath = ctx
152:                        .getRealPath("/WEB-INF/PortletServices.xml");
153:                File f = new File(descriptorPath);
154:                if (f.exists()) {
155:                    PortletServiceDescriptor descriptor = null;
156:                    try {
157:                        System.err.println("loading from: " + descriptorPath);
158:                        descriptor = new PortletServiceDescriptor(
159:                                descriptorPath);
160:                    } catch (Exception e) {
161:                        //log.error("error unmarshalling " + servicesPath + " using " + servicesMappingPath + " : " + e.getMessage());
162:                        status = PortletStatus.FAILURE;
163:                        statusMessage = "Error unmarshalling " + descriptorPath;
164:                        throw new PortletServiceException(statusMessage, e);
165:                    }
166:                    PortletServiceCollection serviceCollection = descriptor
167:                            .getServiceCollection();
168:                    PortletServiceFactory.addServices(webApplicationName, ctx,
169:                            serviceCollection, loader);
170:                } else {
171:                    descriptorPath = ctx
172:                            .getRealPath("/WEB-INF/portlet-services");
173:                    f = new File(descriptorPath);
174:                    if (f.exists()) {
175:                        String[] servicePaths = f.list();
176:                        for (int i = 0; i < servicePaths.length; i++) {
177:                            servicePaths[i] = descriptorPath + File.separator
178:                                    + servicePaths[i];
179:                        }
180:                        for (int i = 0; i < servicePaths.length; i++) {
181:                            PortletServiceDescriptor descriptor = null;
182:                            try {
183:                                System.err.println("loading from: "
184:                                        + servicePaths[i]);
185:                                descriptor = new PortletServiceDescriptor(
186:                                        servicePaths[i]);
187:                            } catch (Exception e) {
188:                                status = PortletStatus.FAILURE;
189:                                statusMessage = "Error unmarshalling "
190:                                        + servicePaths[i];
191:                                throw new PortletServiceException(
192:                                        "error unmarshalling "
193:                                                + servicePaths[i], e);
194:                            }
195:                            PortletServiceCollection serviceCollection = descriptor
196:                                    .getServiceCollection();
197:                            PortletServiceFactory.addServices(
198:                                    webApplicationName, ctx, serviceCollection,
199:                                    loader);
200:                        }
201:                    } else {
202:                        log
203:                                .debug("Did not find PortletServices.xml or portlet-services directory for: "
204:                                        + ctx.getServletContextName());
205:                    }
206:                }
207:                String loadSpring = ctx.getInitParameter("spring4gridsphere");
208:                if (loadSpring != null && loadSpring.equalsIgnoreCase("true")) {
209:                    PortletServiceFactory.addSpringServices(ctx);
210:                }
211:            }
212:
213:            /**
214:             * Returns the portlet web application name
215:             *
216:             * @return the portlet web application name
217:             */
218:            public String getWebApplicationName() {
219:                return webApplicationName;
220:            }
221:
222:            /**
223:             * Returns the portlet web application description
224:             *
225:             * @return the portlet web application description
226:             */
227:            public String getWebApplicationDescription() {
228:                return webAppDescription;
229:            }
230:
231:            /**
232:             * Returns the collection of application portlets contained by this portlet web application
233:             *
234:             * @return the collection of application portlets
235:             */
236:            public Collection<ApplicationPortlet> getAllApplicationPortlets() {
237:                return (appPortlets != null ? appPortlets.values()
238:                        : new ArrayList<ApplicationPortlet>());
239:            }
240:
241:            public void setWebApplicationStatus(PortletStatus status) {
242:                this .status = status;
243:            }
244:
245:            public void setWebApplicationStatusMessage(String statusMessage) {
246:                this .statusMessage = statusMessage;
247:            }
248:
249:            public PortletStatus getWebApplicationStatus() {
250:                return status;
251:            }
252:
253:            public String getWebApplicationStatusMessage() {
254:                return statusMessage;
255:            }
256:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.