1 9 package org.jboss.portal.server; 10 11 import org.jboss.portal.common.concurrent.Valve; 12 import org.jboss.portal.server.invocation.AttachmentKey; 13 import org.jboss.portal.server.invocation.Interceptor; 14 import org.jboss.portal.server.invocation.Invocation; 15 import org.jboss.portal.server.invocation.InvocationType; 16 import org.jboss.portal.server.kernel.Service; 17 import org.jboss.portal.server.kernel.ServiceImplementation; 18 import org.jboss.portal.server.output.UnavailableResult; 19 import org.jboss.portal.server.plugins.invocation.InvocationPlugin; 20 import org.jboss.portal.server.plugins.mode.ContentTypes; 21 import org.jboss.portal.server.plugins.mode.Mode; 22 import org.jboss.portal.server.plugins.windowstate.WindowState; 23 import org.jboss.portal.server.util.Parameters; 24 import org.jboss.portal.server.user.UserContext; 25 26 30 public abstract class Component 31 extends ServerObject 32 { 33 34 35 protected Application application; 36 37 38 protected Integer expirationCache; 39 40 41 protected final Valve valve; 42 43 protected Component(String name) 44 { 45 super(name); 46 this.valve = new Valve(); 47 } 48 49 public PortalServer getServer() 50 { 51 return application.getServer(); 52 } 53 54 57 public Integer getExpirationCache() 58 { 59 return expirationCache; 60 } 61 62 public ContentTypes getContentTypes() 63 { 64 return (ContentTypes)getPlugin(PortalConstants.PLUGIN_CONTENT_TYPES); 65 } 66 67 70 public Object invoke(Invocation invocation) 71 { 72 try 73 { 74 if (valve.beforeInvocation()) 75 { 76 InvocationType itype = (InvocationType)invocation.getAttachment(AttachmentKey.INVOCATION_TYPE); 77 PortalRequest preq = (PortalRequest)invocation.getAttachment(AttachmentKey.PORTAL_REQUEST); 78 WindowContext wctx = (WindowContext)invocation.getAttachment(AttachmentKey.WINDOW_CONTEXT); 79 80 InvocationType pitype = null; 82 if (itype == InvocationType.PROCESS_TARGET) 83 { 84 String windowStateAsString = preq.getControlParameters().getParameter("windowstate"); 86 WindowState windowState = windowStateAsString != null ? WindowState.create(windowStateAsString) : null; 87 88 if (windowState != null) 90 { 91 wctx.setWindowState(windowState); 93 } 94 95 String portletModeAsString = preq.getControlParameters().getParameter("mode"); 97 Mode mode = portletModeAsString != null ? Mode.create(portletModeAsString) : null; 98 99 if (mode != null) 101 { 102 PortalResponse resp = (PortalResponse)invocation.getAttachment(AttachmentKey.PORTAL_RESPONSE); 104 Window window = (Window)invocation.getAttachment(AttachmentKey.WINDOW); 105 Instance instance = window.getInstance(); 106 Component component = instance.getComponent(); 107 ContentTypes ct = component.getContentTypes(); 108 if (ct.isSupported(mode, resp.getContentType())) 109 { 110 wctx.setMode(mode); 111 } 112 else 113 { 114 wctx.setMode(Mode.VIEW); 115 } 116 } 117 118 String pitypeAsString = preq.getControlParameters().getParameter("type"); 119 if ("action".equals(pitypeAsString)) 120 { 121 pitype = InvocationType.ACTION; 122 try 123 { 124 InvocationPlugin ip = (InvocationPlugin)getPlugin(PortalConstants.PLUGIN_INVOCATION); 126 Interceptor[] stack = ip.getStack(); 127 128 invocation.setAttachment(AttachmentKey.INVOCATION_TYPE, pitype); 130 return invocation.invokeNext(stack); 131 } 132 finally 133 { 134 invocation.setAttachment(AttachmentKey.INVOCATION_TYPE, itype); 135 } 136 } 137 else if ("render".equals(pitypeAsString)) 138 { 139 UserContext userCtx = (UserContext)invocation.getAttachment(AttachmentKey.USER_CONTEXT); 141 Window window = (Window)invocation.getAttachment(AttachmentKey.WINDOW); 142 InstanceContext ictx = (InstanceContext)userCtx.getContext(window.getInstance()); 143 144 Parameters newParameters = preq.getTargetParameters(); 146 Parameters oldParameters = ictx.getParameters(); 147 oldParameters.setParameters(newParameters); 148 149 return null; 151 } 152 else if ("nav".equals(pitypeAsString)) 153 { 154 return null; 156 } 157 else 158 { 159 throw new IllegalArgumentException (); 160 } 161 } 162 else if (itype == InvocationType.PROCESS_RENDER) 163 { 164 pitype = InvocationType.RENDER; 165 try 166 { 167 InvocationPlugin ip = (InvocationPlugin)getPlugin(PortalConstants.PLUGIN_INVOCATION); 169 Interceptor[] stack = ip.getStack(); 170 171 invocation.setAttachment(AttachmentKey.INVOCATION_TYPE, pitype); 173 return invocation.invokeNext(stack); 174 } 175 finally 176 { 177 invocation.setAttachment(AttachmentKey.INVOCATION_TYPE, itype); 178 } 179 } 180 else 181 { 182 throw new IllegalArgumentException (); 183 } 184 } 185 else 186 { 187 return new UnavailableResult((WindowContext)invocation.getAttachment(AttachmentKey.WINDOW_CONTEXT)); 188 } 189 } 190 finally 191 { 192 valve.afterInvocation(); 193 } 194 } 195 196 199 public Valve getValve() 200 { 201 return valve; 202 } 203 204 207 public Application getApplication() 208 { 209 return application; 210 } 211 212 public void addIDependOn(ServiceImplementation implementation) 213 { 214 Service service = implementation.getService(); 215 if (service instanceof Application) 216 { 217 application = (Application)service; 218 } 219 else 220 { 221 super.addIDependOn(implementation); 222 } 223 } 224 225 public void removeIDependOn(ServiceImplementation implementation) 226 { 227 Service service = implementation.getService(); 228 if (service instanceof Application) 229 { 230 application = null; 231 } 232 else 233 { 234 super.removeIDependOn(implementation); 235 } 236 } 237 } 238 | Popular Tags |