Author: julien(a)jboss.com
Date: 2008-04-18 08:02:38 -0400 (Fri, 18 Apr 2008)
New Revision: 10643
Added:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/server/PresentationServerImpl.java
Log:
move presentation server impl to presentation package so it can be reused by ajax client
Added:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/server/PresentationServerImpl.java
===================================================================
---
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/server/PresentationServerImpl.java
(rev 0)
+++
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/server/PresentationServerImpl.java 2008-04-18
12:02:38 UTC (rev 10643)
@@ -0,0 +1,119 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.presentation.impl.server;
+
+import org.jboss.portal.presentation.client.PresentationClient;
+import org.jboss.portal.presentation.impl.state.structural.StructuralNode;
+import org.jboss.portal.presentation.impl.state.structural.StructuralStateContextImpl;
+import org.jboss.portal.presentation.impl.state.structural.WindowNode;
+import org.jboss.portal.presentation.model.content.WindowContent;
+import org.jboss.portal.presentation.protocol.ErrorResponse;
+import org.jboss.portal.presentation.protocol.ProtocolAction;
+import org.jboss.portal.presentation.protocol.ShowUIObjectResponse;
+import org.jboss.portal.presentation.protocol.UIObjectAction;
+import org.jboss.portal.presentation.protocol.ViewUIObjectAction;
+import org.jboss.portal.presentation.server.PresentationRequest;
+import org.jboss.portal.presentation.server.PresentationResponse;
+import org.jboss.portal.presentation.server.PresentationServer;
+import org.jboss.portal.presentation.server.PresentationServerException;
+import org.jboss.portal.presentation.state.structural.StructuralStateContext;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public class PresentationServerImpl implements PresentationServer
+{
+
+ /** . */
+ private StructuralStateContextImpl structuralStateContext;
+
+ public PresentationServerImpl(StructuralStateContextImpl structuralStateContext)
+ {
+ this.structuralStateContext = structuralStateContext;
+ }
+
+ public StructuralStateContext getStructuralStateContext()
+ {
+ return structuralStateContext;
+ }
+
+ public String render(ProtocolAction action) throws IllegalArgumentException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public WindowContent renderWindow(PresentationClient client, String windowId) throws
PresentationServerException
+ {
+ StructuralNode node = structuralStateContext.getNode(windowId);
+
+ //
+ if (node instanceof WindowNode)
+ {
+ WindowNode window = (WindowNode)node;
+
+
+
+
+
+
+
+ return new WindowContent(0, "Window " + window.getName(),
window.getContent());
+ }
+ else
+ {
+ throw new PresentationServerException("No such window " + windowId);
+ }
+ }
+
+ public PresentationResponse process(PresentationClient client, PresentationRequest
request) throws PresentationServerException
+ {
+ ProtocolAction action = request.getProtocolAction();
+
+ if (action instanceof UIObjectAction)
+ {
+ UIObjectAction objectAction = (UIObjectAction)action;
+
+ //
+ String targetId = objectAction.getTargetId();
+
+ //
+ StructuralNode targetNode = structuralStateContext.getNode(targetId);
+
+ //
+ if (targetNode == null)
+ {
+ return new PresentationResponse(new ErrorResponse(404));
+ }
+
+ //
+ if (objectAction instanceof ViewUIObjectAction)
+ {
+ return new PresentationResponse(new ShowUIObjectResponse(targetId));
+ }
+ }
+
+ //
+ throw new UnsupportedOperationException();
+ }
+}