1 9 package org.jboss.portal.server.invocation.portal; 10 11 import java.io.PrintWriter ; 12 import java.util.Collection ; 13 import java.util.Iterator ; 14 15 import org.jboss.portal.server.Component; 16 import org.jboss.portal.server.Instance; 17 import org.jboss.portal.server.PortalRequest; 18 import org.jboss.portal.server.PortalServer; 19 import org.jboss.portal.server.ServerObjectID; 20 import org.jboss.portal.server.Window; 21 import org.jboss.portal.server.WindowContext; 22 import org.jboss.portal.server.PortalResponse; 23 import org.jboss.portal.server.invocation.AttachmentKey; 24 import org.jboss.portal.server.invocation.Interceptor; 25 import org.jboss.portal.server.invocation.Invocation; 26 import org.jboss.portal.server.invocation.InvocationType; 27 import org.jboss.portal.server.output.ErrorResult; 28 import org.jboss.portal.server.output.FragmentResult; 29 import org.jboss.portal.server.output.Result; 30 import org.jboss.portal.server.output.UnavailableResult; 31 import org.jboss.portal.server.user.UserContext; 32 import org.jboss.portal.server.util.Properties; 33 34 38 public class MainDispatcherInterceptor implements Interceptor 39 { 40 41 public Object invoke(Invocation invocation) 42 { 43 PortalRequest req = (PortalRequest)invocation.getAttachment(AttachmentKey.PORTAL_REQUEST); 44 PortalResponse resp = (PortalResponse)invocation.getAttachment(AttachmentKey.PORTAL_RESPONSE); 45 UserContext userContext = (UserContext)invocation.getAttachment(AttachmentKey.USER_CONTEXT); 46 47 Collection windows = (Collection )invocation.getAttachment(AttachmentKey.VIEW); 49 50 Result targetResult = resp.getTargetResult(); 52 53 if (targetResult instanceof ErrorResult) 55 { 56 ErrorResult errorResult = (ErrorResult)targetResult; 58 59 WindowContext producer = errorResult.getProducer(); 61 ServerObjectID id = producer.getID(); 62 for (Iterator i = windows.iterator();i.hasNext();) 63 { 64 Window window = (Window)i.next(); 65 if (window.getID().equals(id)) 66 { 67 i.remove(); 68 } 69 } 70 71 FragmentResult fragment = new FragmentResult(errorResult.getProducer()); 72 fragment.setContentType("text/html"); 73 PrintWriter writer = fragment.getWriter(); 74 writer.write("Error"); 75 resp.addRenderResult(fragment); 76 } 77 78 for (Iterator i = windows.iterator();i.hasNext();) 80 { 81 Window window = (Window)i.next(); 82 Instance instance = window.getInstance(); 83 Component component = instance.getComponent(); 84 WindowContext windowContext = (WindowContext)userContext.getContext(window); 85 86 Result renderResult = null; 87 try 88 { 89 invocation.setAttachment(AttachmentKey.WINDOW, window); 90 invocation.setAttachment(AttachmentKey.WINDOW_CONTEXT, windowContext); 91 invocation.setAttachment(AttachmentKey.RESPONSE_PROPERTIES, new Properties()); 92 invocation.setAttachment(AttachmentKey.INVOCATION_TYPE, InvocationType.PROCESS_RENDER); 93 renderResult = (Result)component.invoke(invocation); 94 } 95 finally 96 { 97 invocation.removeAttachment(AttachmentKey.WINDOW); 98 invocation.removeAttachment(AttachmentKey.WINDOW_CONTEXT); 99 invocation.removeAttachment(AttachmentKey.RESPONSE_PROPERTIES); 100 } 101 102 if (renderResult instanceof UnavailableResult) 104 { 105 PortalServer container = component.getServer(); 106 container.stop(component.getID()); 107 } 108 else 109 { 110 resp.addRenderResult(renderResult); 111 } 112 } 113 114 return null; 115 } 116 } 117 | Popular Tags |