[jboss-cvs] jboss-portal/portlet/src/main/org/jboss/portal/portlet/test/support/state ...

Julien Viet julien at jboss.com
Sun Jul 30 08:36:24 EDT 2006


  User: julien  
  Date: 06/07/30 08:36:24

  Added:       portlet/src/main/org/jboss/portal/portlet/test/support/state  
                        StateStoreSupport.java StateSupport.java
  Log:
  JBPORTAL-973 : Portlet instance container integration testing
  JBPORTAL-972 : Portlet stateful invoker testing
  
  Revision  Changes    Path
  1.1      date: 2006/07/30 12:36:24;  author: julien;  state: Exp;jboss-portal/portlet/src/main/org/jboss/portal/portlet/test/support/state/StateStoreSupport.java
  
  Index: StateStoreSupport.java
  ===================================================================
  /*
  * JBoss, Home of Professional Open Source
  * Copyright 2005, JBoss Inc., 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.portlet.test.support.state;
  
  import org.jboss.portal.common.system.AbstractJBossService;
  import org.jboss.portal.common.value.SimpleValueMap;
  import org.jboss.portal.common.value.ValueMap;
  import org.jboss.portal.portlet.state.producer.StateStore;
  import org.jboss.portal.portlet.state.producer.State;
  import org.jboss.portal.portlet.state.producer.NoSuchStateException;
  import org.jboss.portal.portlet.state.producer.InvalidStateIdException;
  
  import java.util.Map;
  import java.util.HashMap;
  
  /**
   * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
   * @version $Revision: 1.1 $
   */
  public class StateStoreSupport extends AbstractJBossService implements StateStore
  {
  
     /** . */
     private Map store = new HashMap();
  
     /** . */
     private int counter = 0;
  
     public synchronized State loadState(String stateId) throws NoSuchStateException, InvalidStateIdException
     {
        if (stateId == null)
        {
           throw new IllegalArgumentException("No null state id accepted");
        }
        try
        {
           Integer.parseInt(stateId);
        }
        catch (NumberFormatException e)
        {
           throw new InvalidStateIdException(e, stateId);
        }
        StateSupport state = (StateSupport)store.get(stateId);
        if (state == null)
        {
           throw new NoSuchStateException(stateId);
        }
        return state;
     }
  
     public synchronized String createState(String portletId, ValueMap valueMap)
     {
        if (portletId == null)
        {
           throw new IllegalArgumentException("No null portlet id accepted");
        }
        if (valueMap == null)
        {
           throw new IllegalArgumentException("No null value map accepted");
        }
        StateSupport state = new StateSupport(Integer.toString(counter++), portletId, new SimpleValueMap(valueMap));
        store.put(state.getId(), state);
        return state.getId();
     }
  
     public synchronized String cloneState(String stateId, ValueMap valueMap) throws NoSuchStateException, InvalidStateIdException
     {
        if (valueMap == null)
        {
           throw new IllegalArgumentException();
        }
        StateSupport state = (StateSupport)loadState(stateId);
        return createState(state.getPortletId(), valueMap);
     }
  
     public String cloneState(String stateId) throws IllegalArgumentException, NoSuchStateException, InvalidStateIdException
     {
        StateSupport state = (StateSupport)loadState(stateId);
        return createState(state.getPortletId(), new SimpleValueMap(state.getProperties()));
     }
  
     public synchronized void updateState(String stateId, ValueMap valueMap) throws NoSuchStateException, InvalidStateIdException
     {
        if (valueMap == null)
        {
           throw new IllegalArgumentException("No null value map");
        }
        StateSupport state = (StateSupport)loadState(stateId);
        state.setValue(new SimpleValueMap(valueMap));
     }
  
     public synchronized void destroyState(String stateId) throws InvalidStateIdException, NoSuchStateException
     {
        if (stateId == null)
        {
           throw new IllegalArgumentException();
        }
        try
        {
           Integer.parseInt(stateId);
        }
        catch (NumberFormatException e)
        {
           throw new InvalidStateIdException(e, stateId);
        }
        if (store.remove(stateId) == null)
        {
           throw new NoSuchStateException(stateId);
        }
     }
  }
  
  
  
  1.1      date: 2006/07/30 12:36:24;  author: julien;  state: Exp;jboss-portal/portlet/src/main/org/jboss/portal/portlet/test/support/state/StateSupport.java
  
  Index: StateSupport.java
  ===================================================================
  /*
  * JBoss, Home of Professional Open Source
  * Copyright 2005, JBoss Inc., 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.portlet.test.support.state;
  
  import org.jboss.portal.portlet.state.producer.State;
  import org.jboss.portal.common.value.ValueMap;
  import org.jboss.portal.common.value.SimpleValueMap;
  
  import java.util.Date;
  
  /**
   * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
   * @version $Revision: 1.1 $
   */
  public class StateSupport implements State
  {
  
     /** . */
     private String id;
  
     /** . */
     private String portletId;
  
     /** . */
     private ValueMap value;
  
     /** . */
     private Date terminationTime;
  
     public StateSupport(String id, String portletId, ValueMap value)
     {
        this.id = id;
        this.portletId = portletId;
        this.value = value;
        this.terminationTime = null;
     }
  
     public StateSupport(String id, StateSupport that)
     {
        this.id = id;
        this.portletId = that.portletId;
        this.value = new SimpleValueMap(that.value);
        this.terminationTime = null;
     }
  
     public String getId()
     {
        return id;
     }
  
     public String getPortletId()
     {
        return portletId;
     }
  
     public void setPortletId(String portletId)
     {
        this.portletId = portletId;
     }
  
     public ValueMap getProperties()
     {
        return value;
     }
  
     public void setValue(ValueMap value)
     {
        this.value = value;
     }
  
     public Date getTerminationTime()
     {
        return terminationTime;
     }
  
     public void setTerminationTime(Date terminationTime)
     {
        this.terminationTime = terminationTime;
     }
  }
  
  
  



More information about the jboss-cvs-commits mailing list