[gatein-commits] gatein SVN: r3761 - in components/wsrp/trunk/producer/src/main/java/org/gatein/exports: impl and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Aug 5 11:05:31 EDT 2010


Author: mwringe
Date: 2010-08-05 11:05:31 -0400 (Thu, 05 Aug 2010)
New Revision: 3761

Added:
   components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/ExportContext.java
   components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/ExportData.java
   components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/ExportPortletData.java
   components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/PersistedExportData.java
   components/wsrp/trunk/producer/src/main/java/org/gatein/exports/impl/ExportManagerImpl.java
Log:
GTNWSRP-55: committing files which somehow didn't get added in the last commit.

Added: components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/ExportContext.java
===================================================================
--- components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/ExportContext.java	                        (rev 0)
+++ components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/ExportContext.java	2010-08-05 15:05:31 UTC (rev 3761)
@@ -0,0 +1,116 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat                                               *
+ * Copyright 2010, 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.gatein.exports.data;
+
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.oasis.wsrp.v2.Lifetime;
+
+/**
+ * @author <a href="mailto:mwringe at redhat.com">Matt Wringe</a>
+ * @version $Revision$
+ */
+public class ExportContext extends ExportData
+{
+
+   protected static final String ENCODING = "UTF-8";
+   public static final String TYPE = "WSRP_EC";
+   public static final double VERSION = 1.0;
+   
+   
+   protected Lifetime lifeTime;
+   protected final boolean exportByValue;
+   
+   protected List<String> portlets;
+   
+   //for now, we don't store anything in the exported by value ExportContext
+   public ExportContext()
+   {
+      this.lifeTime = null;
+      this.exportByValue = true;
+   }
+   
+   public ExportContext(boolean exportByValue, Lifetime lifetime)
+   {
+      //ignore the lifetime if we are exporting by value 
+      if (exportByValue)
+      {
+         this.lifeTime = null;
+      }
+      else
+      {
+         this.lifeTime = lifetime;
+      }
+      this.exportByValue = exportByValue;
+   }
+   
+   public boolean isExportByValue()
+   {
+      return this.exportByValue;
+   }
+   
+   public Lifetime getLifeTime()
+   {
+      return lifeTime;
+   }
+   
+   public void setLifeTime(Lifetime lifetime)
+   {
+      this.lifeTime = lifetime;
+   }
+   
+   public void addPortlet(String portletName)
+   {
+      if (portlets == null)
+      {
+         this.portlets = new ArrayList<String>();
+      }
+      this.portlets.add(portletName);
+   }
+   
+   public static ExportContext create(byte[] bytes)
+   {
+      //for now, we don't store anything in the stored by value ExportContext
+      ExportContext exportContext = new ExportContext();
+      return exportContext;
+   }
+
+   public String getType()
+   {
+      return TYPE;
+   }
+   
+   public double getVersion()
+   {
+      return VERSION;
+   }
+
+   protected byte[] internalEncodeAsBytes() throws UnsupportedEncodingException
+   {
+      return "EMPTY".getBytes(ENCODING);
+   }
+
+}
+

Added: components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/ExportData.java
===================================================================
--- components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/ExportData.java	                        (rev 0)
+++ components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/ExportData.java	2010-08-05 15:05:31 UTC (rev 3761)
@@ -0,0 +1,104 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat                                               *
+ * Copyright 2010, 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.gatein.exports.data;
+
+import java.io.UnsupportedEncodingException;
+
+import org.gatein.common.NotYetImplemented;
+
+/**
+ * @author <a href="mailto:mwringe at redhat.com">Matt Wringe</a>
+ * @version $Revision$
+ */
+public abstract class ExportData
+{
+
+   public abstract double getVersion();
+   public abstract String getType();
+   
+   protected abstract byte[] internalEncodeAsBytes() throws UnsupportedEncodingException;
+   
+   
+   //The encoding used to create the byte array
+   protected static final String ENCODING = "UTF-8";
+   
+   protected static final String SEPARATOR = "_ at _";
+   
+   public byte[] encodeAsBytes() throws UnsupportedEncodingException 
+   {
+      byte[] internalBytes = internalEncodeAsBytes();
+      
+      String token =  this.getType() + SEPARATOR + this.getVersion() + SEPARATOR;
+      String dataString = new String(internalBytes, ENCODING);
+      
+      return (token + dataString).getBytes(ENCODING);
+   }
+   
+   public static double getVersion(byte[] bytes) throws UnsupportedEncodingException
+   {
+      String dataString = new String(bytes, ENCODING);
+      String[] split = dataString.split(SEPARATOR, 3);
+      
+      if (split.length >= 2)
+      {
+         double version = Double.parseDouble(split[1]);
+         return version;
+      }
+   
+      //if a version could not be found, return -1
+      return -1;
+   }
+   
+   public static String getType(byte[] bytes) throws UnsupportedEncodingException
+   {
+      String dataString = new String(bytes, ENCODING);
+      String[] split = dataString.split(SEPARATOR, 2);
+      
+      if (split.length >= 2)
+      {
+         return split[0];
+      }
+      
+      //if we could not find a type, then return null
+      return null;
+   }
+
+   public static byte[] getInternalBytes(byte[] bytes) throws UnsupportedEncodingException
+   {
+      String dataString = new String(bytes, ENCODING);
+      String[] split = dataString.split(SEPARATOR, 3);
+      
+      if (split.length >= 3)
+      {
+         String internalString = split[2];
+         return internalString.getBytes(ENCODING);
+      }
+      else
+      {
+         //if we could not find the internal bytes, return null
+         return null;
+      }
+   }
+   
+}
+

Added: components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/ExportPortletData.java
===================================================================
--- components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/ExportPortletData.java	                        (rev 0)
+++ components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/ExportPortletData.java	2010-08-05 15:05:31 UTC (rev 3761)
@@ -0,0 +1,122 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat                                               *
+ * Copyright 2010, 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.gatein.exports.data;
+
+import java.io.UnsupportedEncodingException;
+import java.util.Map;
+
+import org.gatein.pc.api.ParametersStateString;
+import org.gatein.pc.api.StateString;
+
+/**
+ * @author <a href="mailto:mwringe at redhat.com">Matt Wringe</a>
+ * @version $Revision$
+ */
+public class ExportPortletData extends ExportData
+{
+
+   protected static final String ENCODING = "UTF-8";
+   public static final String TYPE = "WSRP_EC";
+   public static final double VERSION = 1.0;
+   
+   protected static final String PORTLETHANDLEKEY = "pID";
+   protected static final String PORTLETSTATEKEY = "pState";
+   
+   protected String portletHandle;
+   protected byte[] portletState;
+   
+   public ExportPortletData(String portletHandle, byte[] portletState)
+   {
+      this.portletHandle = portletHandle;
+      this.portletState = portletState;
+   }
+   
+   public String getPortletHandle()
+   {
+      return this.portletHandle;
+   }
+   
+   public byte[] getPortletState()
+   {
+      return this.portletState;
+   }
+   
+   public String getType()
+   {
+      return TYPE;
+   }
+
+   public double getVersion()
+   {
+      return VERSION;
+   }
+
+   public static ExportPortletData create(byte[] bytes) throws UnsupportedEncodingException
+   {      
+      //why isn't there a way for a ParameterStateString to directly create itself from the string?
+      Map<String, String[]> map = StateString.decodeOpaqueValue(new String(bytes, ENCODING));
+
+      String portletHandle;
+      byte[] portletState;
+
+      String[] portletHandles = map.get(PORTLETHANDLEKEY);
+      if (portletHandles != null && portletHandles.length > 0)
+      {
+         portletHandle = portletHandles[0];
+      }
+      else
+      {
+         return null; //TODO: should probably throw an error here about not getting a proper value
+      }
+
+      String[] portletStates = map.get(PORTLETSTATEKEY);
+      if (portletStates != null && portletStates.length > 0)
+      {
+         portletState = portletStates[0].getBytes(ENCODING);
+      }
+      else
+      {
+         portletState = null;
+      }
+
+      return new ExportPortletData(portletHandle, portletState);
+   }
+   
+   protected byte[] internalEncodeAsBytes() throws UnsupportedEncodingException
+   {
+      ParametersStateString parameterStateString = ParametersStateString.create();
+      if (portletState != null)
+      {
+         //TODO: if might be better to use something other than a statestring that can handle byte[] directly
+         String state = new String(portletState, ENCODING);
+         parameterStateString.setValue(PORTLETSTATEKEY, state);
+      }
+
+      parameterStateString.setValue(PORTLETHANDLEKEY, portletHandle);
+      
+      String stateString = parameterStateString.getStringValue();
+      return stateString.getBytes(ENCODING);
+   }
+
+}
+

Added: components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/PersistedExportData.java
===================================================================
--- components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/PersistedExportData.java	                        (rev 0)
+++ components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/PersistedExportData.java	2010-08-05 15:05:31 UTC (rev 3761)
@@ -0,0 +1,93 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat                                               *
+ * Copyright 2010, 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.gatein.exports.data;
+
+import java.io.UnsupportedEncodingException;
+import java.util.Map;
+
+import org.gatein.pc.api.ParametersStateString;
+import org.gatein.pc.api.StateString;
+
+/**
+ * @author <a href="mailto:mwringe at redhat.com">Matt Wringe</a>
+ * @version $Revision$
+ */
+public class PersistedExportData extends ExportData
+{
+   protected final String type;
+   protected final String refID;
+   protected static final double VERSION = 1.0;
+   
+   protected static final String REFIDKEY = "rID";
+   protected static final String TYPEKEY = "type";
+   
+   public PersistedExportData(String type, String refID)
+   {
+     this.type = type;
+     this.refID = refID;
+   }
+   
+   public String getType()
+   {
+      return type;
+   }
+
+   public double getVersion()
+   {
+      return VERSION;
+   }
+
+   protected byte[] internalEncodeAsBytes() throws UnsupportedEncodingException
+   {
+      ParametersStateString parameterStateString = ParametersStateString.create();
+
+      parameterStateString.setValue(REFIDKEY, REFIDKEY);
+      parameterStateString.setValue(TYPEKEY, type);
+      
+      String stateString = parameterStateString.getStringValue();
+      return stateString.getBytes(ENCODING);
+   }
+   
+   public static PersistedExportData create(byte[] bytes) throws UnsupportedEncodingException
+   {
+      Map<String, String[]> map = StateString.decodeOpaqueValue(new String(bytes, ENCODING));
+      
+      String refId = null;
+      String type = null;
+      
+      if (map.containsKey(REFIDKEY) && map.get(REFIDKEY).length > 0)
+      {
+         refId = map.get(REFIDKEY)[0];
+      }
+      
+      if (map.containsKey(TYPEKEY) && map.get(TYPEKEY).length > 0 )
+      {
+         type = map.get(TYPEKEY)[0];
+      }
+      
+      return new PersistedExportData(type, refId);
+   }
+   
+
+}
+

Added: components/wsrp/trunk/producer/src/main/java/org/gatein/exports/impl/ExportManagerImpl.java
===================================================================
--- components/wsrp/trunk/producer/src/main/java/org/gatein/exports/impl/ExportManagerImpl.java	                        (rev 0)
+++ components/wsrp/trunk/producer/src/main/java/org/gatein/exports/impl/ExportManagerImpl.java	2010-08-05 15:05:31 UTC (rev 3761)
@@ -0,0 +1,183 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat                                               *
+ * Copyright 2010, 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.gatein.exports.impl;
+
+import java.io.UnsupportedEncodingException;
+
+import org.gatein.common.NotYetImplemented;
+import org.gatein.exports.ExportManager;
+import org.gatein.exports.ExportPersistenceManager;
+import org.gatein.exports.data.ExportContext;
+import org.gatein.exports.data.ExportData;
+import org.gatein.exports.data.ExportPortletData;
+import org.gatein.wsrp.WSRPExceptionFactory;
+import org.oasis.wsrp.v2.Lifetime;
+import org.oasis.wsrp.v2.OperationFailed;
+import org.oasis.wsrp.v2.OperationNotSupported;
+
+
+/**
+ * @author <a href="mailto:mwringe at redhat.com">Matt Wringe</a>
+ * @version $Revision$
+ */
+public class ExportManagerImpl implements ExportManager
+{
+
+   protected ExportPersistenceManager exportPersistenceManager;
+   
+   //set to true if we prefer to export by value instead of by reference
+   protected boolean preferExportByValue = false;
+   
+   protected boolean supportExportByValue = true;
+   
+   public ExportPersistenceManager getPersistenceManager()
+   {
+      return exportPersistenceManager;
+   }
+
+   public void setPersistanceManager(ExportPersistenceManager exportPersistenceManager)
+   {
+      this.exportPersistenceManager = exportPersistenceManager;
+   }
+   
+   public ExportContext createExportContext(boolean exportByValueRequired, Lifetime lifetime)
+         throws UnsupportedEncodingException
+   {
+      boolean useExportByValue = false;
+      if (exportByValueRequired || (exportPersistenceManager == null &&  preferExportByValue))
+      {
+         useExportByValue = true;
+      }
+            
+      return new ExportContext(useExportByValue, lifetime);
+   }
+   
+   public boolean supportExportByValue()
+   {
+      return supportExportByValue;
+   }
+   
+   public ExportContext createExportContext(byte[] bytes)
+   {
+      try
+      {
+         String type = ExportData.getType(bytes);
+         double version = ExportData.getVersion(bytes);
+         if (ExportContext.TYPE.equals(type) && ExportContext.VERSION==version)
+         {
+            byte[] internalBytes = ExportData.getInternalBytes(bytes);
+            return ExportContext.create(internalBytes);
+         }
+         else
+         {
+            //TODO: throw an error here about not being a recognized type
+            throw new IllegalArgumentException("byte[] format unreconized.");
+         }
+      }
+      catch (Exception e)
+      {
+         e.printStackTrace();
+         throw new NotYetImplemented();
+      }
+   }
+
+   public ExportPortletData createExportPortletData(ExportContext exportContextData, String portletHandle,
+         byte[] portletState) throws UnsupportedEncodingException
+   {
+      return new ExportPortletData(portletHandle, portletState);
+   }
+
+   public ExportPortletData createExportPortletData(ExportContext exportContextData, Lifetime lifetime, byte[] bytes)
+   {
+      try
+      {
+         String type = ExportData.getType(bytes);
+         double version = ExportData.getVersion(bytes);
+         if (ExportPortletData.TYPE.equals(type) && ExportPortletData.VERSION==version)
+         {
+            byte[] internalBytes = ExportData.getInternalBytes(bytes);
+            return ExportPortletData.create(internalBytes);
+         }
+         else
+         {
+            //TODO: throw an error here about not being a recognized type
+            throw new IllegalArgumentException("byte[] format unreconized.");
+         }
+      }
+      catch (Exception e)
+      {
+         e.printStackTrace();
+         throw new NotYetImplemented();
+      }
+   }
+
+   public byte[] encodeExportPortletData(ExportContext exportContextData, ExportPortletData exportPortletData) throws UnsupportedEncodingException
+   {
+      if (exportContextData.isExportByValue())
+      {
+         return exportPortletData.encodeAsBytes();
+      }
+      else
+      {
+         throw new NotYetImplemented();
+      }
+   }
+
+   public byte[] encodeExportContextData(ExportContext exportContextData) throws UnsupportedEncodingException
+   {
+      if (exportContextData.isExportByValue())
+      {
+         return exportContextData.encodeAsBytes();
+      }
+      else
+      {
+         throw new NotYetImplemented();
+      }
+   }
+
+   public Lifetime setExportLifetime(ExportContext exportContext, Lifetime lifetime) throws OperationFailed, OperationNotSupported
+   {
+      if (exportContext.isExportByValue())
+      {
+         WSRPExceptionFactory.throwWSException(OperationFailed.class, "Cannot set the lifetime for an export that was exported by value.", null);
+      }
+      if (getPersistenceManager() == null)
+      {
+         WSRPExceptionFactory.throwWSException(OperationNotSupported.class, "The producer only supports export by value. Cannot call setExportLifetime on this producer", null);
+      }
+      
+      return getPersistenceManager().updateExportLifetime(exportContext, lifetime);
+   }
+
+   public void releaseExport(ExportContext exportContext)
+   {
+      //TODO: since we can't return any errors, we should at least log messages if this method is called and it can't be completed for some reason.
+      if (exportContext != null && !exportContext.isExportByValue() && exportPersistenceManager!= null)
+      {
+         exportPersistenceManager.releaseExport(exportContext);
+      }
+   }
+   
+   
+}
+



More information about the gatein-commits mailing list