From do-not-reply at jboss.org Thu Aug 5 11:05:32 2010 Content-Type: multipart/mixed; boundary="===============0184960829858164473==" MIME-Version: 1.0 From: do-not-reply at jboss.org To: gatein-commits at lists.jboss.org Subject: [gatein-commits] gatein SVN: r3761 - in components/wsrp/trunk/producer/src/main/java/org/gatein/exports: impl and 1 other directory. Date: Thu, 05 Aug 2010 11:05:31 -0400 Message-ID: <201008051505.o75F5V5r024243@svn01.web.mwc.hst.phx2.redhat.com> --===============0184960829858164473== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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/Exp= ortContext.java components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/Exp= ortData.java components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/Exp= ortPortletData.java components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/Per= sistedExportData.java components/wsrp/trunk/producer/src/main/java/org/gatein/exports/impl/Exp= ortManagerImpl.java Log: GTNWSRP-55: committing files which somehow didn't get added in the last com= mit. Added: components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data= /ExportContext.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/Ex= portContext.java (rev 0) +++ components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/Ex= portContext.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 Matt Wringe + * @version $Revision$ + */ +public class ExportContext extends ExportData +{ + + protected static final String ENCODING =3D "UTF-8"; + public static final String TYPE =3D "WSRP_EC"; + public static final double VERSION =3D 1.0; + = + = + protected Lifetime lifeTime; + protected final boolean exportByValue; + = + protected List portlets; + = + //for now, we don't store anything in the exported by value ExportConte= xt + public ExportContext() + { + this.lifeTime =3D null; + this.exportByValue =3D true; + } + = + public ExportContext(boolean exportByValue, Lifetime lifetime) + { + //ignore the lifetime if we are exporting by value = + if (exportByValue) + { + this.lifeTime =3D null; + } + else + { + this.lifeTime =3D lifetime; + } + this.exportByValue =3D exportByValue; + } + = + public boolean isExportByValue() + { + return this.exportByValue; + } + = + public Lifetime getLifeTime() + { + return lifeTime; + } + = + public void setLifeTime(Lifetime lifetime) + { + this.lifeTime =3D lifetime; + } + = + public void addPortlet(String portletName) + { + if (portlets =3D=3D null) + { + this.portlets =3D new ArrayList(); + } + this.portlets.add(portletName); + } + = + public static ExportContext create(byte[] bytes) + { + //for now, we don't store anything in the stored by value ExportCont= ext + ExportContext exportContext =3D new ExportContext(); + return exportContext; + } + + public String getType() + { + return TYPE; + } + = + public double getVersion() + { + return VERSION; + } + + protected byte[] internalEncodeAsBytes() throws UnsupportedEncodingExce= ption + { + return "EMPTY".getBytes(ENCODING); + } + +} + Added: components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data= /ExportData.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/Ex= portData.java (rev 0) +++ components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/Ex= portData.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 Matt Wringe + * @version $Revision$ + */ +public abstract class ExportData +{ + + public abstract double getVersion(); + public abstract String getType(); + = + protected abstract byte[] internalEncodeAsBytes() throws UnsupportedEnc= odingException; + = + = + //The encoding used to create the byte array + protected static final String ENCODING =3D "UTF-8"; + = + protected static final String SEPARATOR =3D "_(a)_"; + = + public byte[] encodeAsBytes() throws UnsupportedEncodingException = + { + byte[] internalBytes =3D internalEncodeAsBytes(); + = + String token =3D this.getType() + SEPARATOR + this.getVersion() + S= EPARATOR; + String dataString =3D new String(internalBytes, ENCODING); + = + return (token + dataString).getBytes(ENCODING); + } + = + public static double getVersion(byte[] bytes) throws UnsupportedEncodin= gException + { + String dataString =3D new String(bytes, ENCODING); + String[] split =3D dataString.split(SEPARATOR, 3); + = + if (split.length >=3D 2) + { + double version =3D Double.parseDouble(split[1]); + return version; + } + = + //if a version could not be found, return -1 + return -1; + } + = + public static String getType(byte[] bytes) throws UnsupportedEncodingEx= ception + { + String dataString =3D new String(bytes, ENCODING); + String[] split =3D dataString.split(SEPARATOR, 2); + = + if (split.length >=3D 2) + { + return split[0]; + } + = + //if we could not find a type, then return null + return null; + } + + public static byte[] getInternalBytes(byte[] bytes) throws UnsupportedE= ncodingException + { + String dataString =3D new String(bytes, ENCODING); + String[] split =3D dataString.split(SEPARATOR, 3); + = + if (split.length >=3D 3) + { + String internalString =3D 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 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/Ex= portPortletData.java (rev 0) +++ components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/Ex= portPortletData.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 Matt Wringe + * @version $Revision$ + */ +public class ExportPortletData extends ExportData +{ + + protected static final String ENCODING =3D "UTF-8"; + public static final String TYPE =3D "WSRP_EC"; + public static final double VERSION =3D 1.0; + = + protected static final String PORTLETHANDLEKEY =3D "pID"; + protected static final String PORTLETSTATEKEY =3D "pState"; + = + protected String portletHandle; + protected byte[] portletState; + = + public ExportPortletData(String portletHandle, byte[] portletState) + { + this.portletHandle =3D portletHandle; + this.portletState =3D 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 Unsupported= EncodingException + { = + //why isn't there a way for a ParameterStateString to directly creat= e itself from the string? + Map map =3D StateString.decodeOpaqueValue(new Stri= ng(bytes, ENCODING)); + + String portletHandle; + byte[] portletState; + + String[] portletHandles =3D map.get(PORTLETHANDLEKEY); + if (portletHandles !=3D null && portletHandles.length > 0) + { + portletHandle =3D portletHandles[0]; + } + else + { + return null; //TODO: should probably throw an error here about no= t getting a proper value + } + + String[] portletStates =3D map.get(PORTLETSTATEKEY); + if (portletStates !=3D null && portletStates.length > 0) + { + portletState =3D portletStates[0].getBytes(ENCODING); + } + else + { + portletState =3D null; + } + + return new ExportPortletData(portletHandle, portletState); + } + = + protected byte[] internalEncodeAsBytes() throws UnsupportedEncodingExce= ption + { + ParametersStateString parameterStateString =3D ParametersStateString= .create(); + if (portletState !=3D null) + { + //TODO: if might be better to use something other than a statestr= ing that can handle byte[] directly + String state =3D new String(portletState, ENCODING); + parameterStateString.setValue(PORTLETSTATEKEY, state); + } + + parameterStateString.setValue(PORTLETHANDLEKEY, portletHandle); + = + String stateString =3D parameterStateString.getStringValue(); + return stateString.getBytes(ENCODING); + } + +} + Added: components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data= /PersistedExportData.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/Pe= rsistedExportData.java (rev 0) +++ components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/Pe= rsistedExportData.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 Matt Wringe + * @version $Revision$ + */ +public class PersistedExportData extends ExportData +{ + protected final String type; + protected final String refID; + protected static final double VERSION =3D 1.0; + = + protected static final String REFIDKEY =3D "rID"; + protected static final String TYPEKEY =3D "type"; + = + public PersistedExportData(String type, String refID) + { + this.type =3D type; + this.refID =3D refID; + } + = + public String getType() + { + return type; + } + + public double getVersion() + { + return VERSION; + } + + protected byte[] internalEncodeAsBytes() throws UnsupportedEncodingExce= ption + { + ParametersStateString parameterStateString =3D ParametersStateString= .create(); + + parameterStateString.setValue(REFIDKEY, REFIDKEY); + parameterStateString.setValue(TYPEKEY, type); + = + String stateString =3D parameterStateString.getStringValue(); + return stateString.getBytes(ENCODING); + } + = + public static PersistedExportData create(byte[] bytes) throws Unsupport= edEncodingException + { + Map map =3D StateString.decodeOpaqueValue(new Stri= ng(bytes, ENCODING)); + = + String refId =3D null; + String type =3D null; + = + if (map.containsKey(REFIDKEY) && map.get(REFIDKEY).length > 0) + { + refId =3D map.get(REFIDKEY)[0]; + } + = + if (map.containsKey(TYPEKEY) && map.get(TYPEKEY).length > 0 ) + { + type =3D map.get(TYPEKEY)[0]; + } + = + return new PersistedExportData(type, refId); + } + = + +} + Added: components/wsrp/trunk/producer/src/main/java/org/gatein/exports/impl= /ExportManagerImpl.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- components/wsrp/trunk/producer/src/main/java/org/gatein/exports/impl/Ex= portManagerImpl.java (rev 0) +++ components/wsrp/trunk/producer/src/main/java/org/gatein/exports/impl/Ex= portManagerImpl.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 Matt Wringe + * @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 =3D false; + = + protected boolean supportExportByValue =3D true; + = + public ExportPersistenceManager getPersistenceManager() + { + return exportPersistenceManager; + } + + public void setPersistanceManager(ExportPersistenceManager exportPersis= tenceManager) + { + this.exportPersistenceManager =3D exportPersistenceManager; + } + = + public ExportContext createExportContext(boolean exportByValueRequired,= Lifetime lifetime) + throws UnsupportedEncodingException + { + boolean useExportByValue =3D false; + if (exportByValueRequired || (exportPersistenceManager =3D=3D null &= & preferExportByValue)) + { + useExportByValue =3D true; + } + = + return new ExportContext(useExportByValue, lifetime); + } + = + public boolean supportExportByValue() + { + return supportExportByValue; + } + = + public ExportContext createExportContext(byte[] bytes) + { + try + { + String type =3D ExportData.getType(bytes); + double version =3D ExportData.getVersion(bytes); + if (ExportContext.TYPE.equals(type) && ExportContext.VERSION=3D= =3Dversion) + { + byte[] internalBytes =3D 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 exportCo= ntextData, String portletHandle, + byte[] portletState) throws UnsupportedEncodingException + { + return new ExportPortletData(portletHandle, portletState); + } + + public ExportPortletData createExportPortletData(ExportContext exportCo= ntextData, Lifetime lifetime, byte[] bytes) + { + try + { + String type =3D ExportData.getType(bytes); + double version =3D ExportData.getVersion(bytes); + if (ExportPortletData.TYPE.equals(type) && ExportPortletData.VERS= ION=3D=3Dversion) + { + byte[] internalBytes =3D 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, "Can= not set the lifetime for an export that was exported by value.", null); + } + if (getPersistenceManager() =3D=3D null) + { + WSRPExceptionFactory.throwWSException(OperationNotSupported.class= , "The producer only supports export by value. Cannot call setExportLifetim= e on this producer", null); + } + = + return getPersistenceManager().updateExportLifetime(exportContext, l= ifetime); + } + + public void releaseExport(ExportContext exportContext) + { + //TODO: since we can't return any errors, we should at least log mes= sages if this method is called and it can't be completed for some reason. + if (exportContext !=3D null && !exportContext.isExportByValue() && e= xportPersistenceManager!=3D null) + { + exportPersistenceManager.releaseExport(exportContext); + } + } + = + = +} + --===============0184960829858164473==--