You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wsrp4j-dev@portals.apache.org by dl...@apache.org on 2005/08/23 21:25:12 UTC

cvs commit: ws-wsrp4j/sandbox/wsrp4j/consumer/src/java/org/apache/wsrp4j/consumer/proxyportlet/impl GroupSessionImpl.java PortletRegistryImpl.java PortletSessionImpl.java ProducerRegistryImpl.java SessionHandlerImpl.java URLTemplateComposerImpl.java UserRegistryImpl.java UserSessionImpl.java

dlouzan     2005/08/23 12:25:12

  Added:       sandbox/wsrp4j/consumer/src/java/org/apache/wsrp4j/consumer/proxyportlet/impl
                        GroupSessionImpl.java PortletRegistryImpl.java
                        PortletSessionImpl.java ProducerRegistryImpl.java
                        SessionHandlerImpl.java
                        URLTemplateComposerImpl.java UserRegistryImpl.java
                        UserSessionImpl.java
  Log:
  Initial version.
  
  Revision  Changes    Path
  1.1                  ws-wsrp4j/sandbox/wsrp4j/consumer/src/java/org/apache/wsrp4j/consumer/proxyportlet/impl/GroupSessionImpl.java
  
  Index: GroupSessionImpl.java
  ===================================================================
  /*
   * Copyright 2003-2005 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.wsrp4j.consumer.proxyportlet.impl;
  
  import org.apache.wsrp4j.commons.consumer.interfaces.session.PortletSession;
  import org.apache.wsrp4j.commons.consumer.driver.GenericGroupSessionImpl;
  import org.apache.wsrp4j.commons.exception.WSRPException;
  
  
  /**
   * @version $Id: GroupSessionImpl.java,v 1.1 2005/08/23 19:25:12 dlouzan Exp $
   */
  public class GroupSessionImpl extends GenericGroupSessionImpl
  {
  
      public GroupSessionImpl(String groupID, String portletServicesURL) 
      throws WSRPException
      {
          super(groupID, portletServicesURL);
      }
  
      public PortletSession getPortletSession(String portletHandle)
      {
          if (portletHandle == null)
              return null;
  
          PortletSession portletSession = 
                  (PortletSession)this.portletSessions.get(portletHandle);
          if (portletSession == null)
          {
              portletSession = new PortletSessionImpl(portletHandle);
              addPortletSession(portletSession);
          }
  
          return portletSession;
      }
  }
  
  
  
  1.1                  ws-wsrp4j/sandbox/wsrp4j/consumer/src/java/org/apache/wsrp4j/consumer/proxyportlet/impl/PortletRegistryImpl.java
  
  Index: PortletRegistryImpl.java
  ===================================================================
  /*
   * Copyright 2003-2005 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.wsrp4j.consumer.proxyportlet.impl;
  
  import org.apache.wsrp4j.commons.consumer.interfaces.portlet.PortletRegistry;
  import org.apache.wsrp4j.commons.consumer.driver.GenericPortletRegistryImpl;
  
  /**
   * @version $Id: PortletRegistryImpl.java,v 1.1 2005/08/23 19:25:12 dlouzan Exp $
   */
  public class PortletRegistryImpl extends GenericPortletRegistryImpl
  {
  
      private static PortletRegistry instance;
  
      private PortletRegistryImpl()
      {
          super();
      }
  
      public static PortletRegistry getInstance()
      {
          if (instance == null)
          {
              instance = new PortletRegistryImpl();
          }
  
          return instance;
      }
  }
  
  
  
  1.1                  ws-wsrp4j/sandbox/wsrp4j/consumer/src/java/org/apache/wsrp4j/consumer/proxyportlet/impl/PortletSessionImpl.java
  
  Index: PortletSessionImpl.java
  ===================================================================
  /*
   * Copyright 2003-2005 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.wsrp4j.consumer.proxyportlet.impl;
  
  import org.apache.wsrp4j.commons.consumer.interfaces.session.PortletWindowSession;
  import org.apache.wsrp4j.commons.consumer.driver.GenericPortletSessionImpl;
  import org.apache.wsrp4j.commons.consumer.driver.GenericPortletWindowSessionImpl;
  
  import org.apache.wsrp4j.commons.log.LogManager;
  import org.apache.wsrp4j.commons.log.Logger;
  
  /**
   * @version $Id: PortletSessionImpl.java,v 1.1 2005/08/23 19:25:12 dlouzan Exp $
   */
  public class PortletSessionImpl extends GenericPortletSessionImpl
  {
  	
  	// logger
  	private static final Logger logger = 
              LogManager.getLogManager().getLogger(PortletSessionImpl.class);
  
      public PortletSessionImpl(String handle)
      {
      	super(handle);
      }
  
      /**
       * Get the <code>PortletWindowSession</code> of the portlet window with 
       * the given ID.
       * 
       * @param windowID The ID of the portlet window
       * @return The <code>PorletWindowSession</code> with the given ID.    
       **/
      public PortletWindowSession getPortletWindowSession(String windowID)
      {
      	final String MN ="getPortletWindowSession";
      	
  		if (logger.isLogging(Logger.TRACE_HIGH))
  		{
  			logger.entry(Logger.TRACE_HIGH, MN);
  		}
  
          PortletWindowSession session = 
                  (PortletWindowSession)this.windowSessions.get(windowID);
          if (session == null)
          {
              session = new GenericPortletWindowSessionImpl(windowID, this);
              this.windowSessions.put(windowID, session);
              
              if (logger.isLogging(Logger.TRACE_HIGH))
              {
              	logger.text(Logger.TRACE_HIGH, MN,
                          "created windowSession with ID: " + windowID);
              }
          }
  
  		if (logger.isLogging(Logger.TRACE_HIGH))
  		{
  			logger.exit(Logger.TRACE_HIGH, MN);
  		}
  
          return session;
      }
  }
  
  
  
  1.1                  ws-wsrp4j/sandbox/wsrp4j/consumer/src/java/org/apache/wsrp4j/consumer/proxyportlet/impl/ProducerRegistryImpl.java
  
  Index: ProducerRegistryImpl.java
  ===================================================================
  /*
   * Copyright 2003-2005 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.wsrp4j.consumer.proxyportlet.impl;
  
  import org.apache.wsrp4j.commons.consumer.interfaces.producer.ProducerRegistry;
  import org.apache.wsrp4j.commons.consumer.driver.GenericPersistentProducerRegistryImpl;
  import org.apache.wsrp4j.commons.exception.WSRPException;
  import org.apache.wsrp4j.commons.persistence.ServerPersistentFactory;
  import org.apache.wsrp4j.commons.persistence.xml.driver.ServerPersistentFactoryImpl;
  import org.apache.wsrp4j.commons.persistence.driver.PersistentAccess;
  
  
  /**
   * @version $Id: ProducerRegistryImpl.java,v 1.1 2005/08/23 19:25:12 dlouzan Exp $
   */
  public class ProducerRegistryImpl extends GenericPersistentProducerRegistryImpl
  {
  
      private static ProducerRegistry instance;
  
      private ProducerRegistryImpl(String path)
      {
  
          super();
  
          // restore producers from persistent file store
          try
          {
  
              ServerPersistentFactory persistentFactory = 
                      PersistentAccess.getServerPersistentFactory();
              ((ServerPersistentFactoryImpl)persistentFactory).setPath(path);
              persistentHandler = persistentFactory.getPersistentHandler();
              persistentDataObject = persistentFactory.getProducerList();
  
              restore();
  
          } catch (Throwable t)
          {
  
              t.printStackTrace();
  
              if (t instanceof WSRPException)
              {
  
                  //TODO: throw exception
              } else
              {
  
                  //TODO: throw exception
              }
          }
      }
  
      /**
       * Get an instance of the singleton producer registry object
       **/
      public static ProducerRegistry getInstance(String path)
      {
          if (instance == null)
          {
              instance = new ProducerRegistryImpl(path);
          }
  
          return instance;
      }
  }
  
  
  
  1.1                  ws-wsrp4j/sandbox/wsrp4j/consumer/src/java/org/apache/wsrp4j/consumer/proxyportlet/impl/SessionHandlerImpl.java
  
  Index: SessionHandlerImpl.java
  ===================================================================
  /*
   * Copyright 2003-2005 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.wsrp4j.consumer.proxyportlet.impl;
  
  import javax.portlet.PortletSession;
  
  import org.apache.wsrp4j.commons.consumer.interfaces.consumer.ConsumerEnvironment;
  import org.apache.wsrp4j.commons.consumer.interfaces.producer.Producer;
  import org.apache.wsrp4j.commons.consumer.interfaces.session.UserSessionMgr;
  import org.apache.wsrp4j.consumer.proxyportlet.SessionHandler;
  import org.apache.wsrp4j.commons.exception.WSRPException;
  
  /**
   * @version $Id: SessionHandlerImpl.java,v 1.1 2005/08/23 19:25:12 dlouzan Exp $
   */
  public class SessionHandlerImpl implements SessionHandler
  {
  
      private PortletSession portletSession;
      private ConsumerEnvironment consumerEnv;
  
      private static SessionHandler instance;
  
      private SessionHandlerImpl(ConsumerEnvironment consumerEnv)
      {
          this.consumerEnv = consumerEnv;
      }
  
      public static SessionHandler getInstance(ConsumerEnvironment consumerEnv)
      {
          if (instance == null)
          {
              instance = new SessionHandlerImpl(consumerEnv);
          }
  
          return instance;
      }
  
      public void setPortletSession(PortletSession portletSession)
      {
          this.portletSession = portletSession;
      }
  
      public UserSessionMgr getUserSession(String producerID, String userID) 
      throws WSRPException
      {
          if (portletSession == null)
          {
              try
              {
                  throw new Exception("PortletSession is null. " +
                          "Call setPortletSession() first.");
              } catch (Exception e)
              {
                  e.printStackTrace();
              }
          } else
          {
  
              Producer producer = consumerEnv.getProducerRegistry().
                      getProducer(producerID);
  
              if (producer != null)
              {
  
                  String markupURL = producer.getMarkupInterfaceEndpoint();
  
                  return new UserSessionImpl(producerID, userID, markupURL, 
                          portletSession);
              }
          }
  
          return null;
      }
  }
  
  
  
  1.1                  ws-wsrp4j/sandbox/wsrp4j/consumer/src/java/org/apache/wsrp4j/consumer/proxyportlet/impl/URLTemplateComposerImpl.java
  
  Index: URLTemplateComposerImpl.java
  ===================================================================
  /*
   * Copyright 2003-2005 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.wsrp4j.consumer.proxyportlet.impl;
  
  import org.apache.wsrp4j.commons.consumer.interfaces.urlgenerator.URLGenerator;
  import org.apache.wsrp4j.commons.consumer.interfaces.urlgenerator.URLTemplateComposer;
  
  
  /**
   * <p>This class implements the URLTemplateComposer interface providing methods 
   * to generate URL templates.</p>
   * <p>The generated templates will be transmitted to Producers (or respectively 
   * portlets) that are willing to properly write URLs for a Consumer.
   * (With templates the Consumer indicates how it needs URLs formatted in order 
   * to process them properly.)</p> 
   * @version $Id: URLTemplateComposerImpl.java,v 1.1 2005/08/23 19:25:12 dlouzan Exp $
   */
  public class URLTemplateComposerImpl implements URLTemplateComposer
  {
  
      private static URLTemplateComposer instance;
      private URLGenerator urlGenerator;
  
      public static URLTemplateComposer getInstance()
      {
          if (instance == null)
          {
              instance = new URLTemplateComposerImpl();
          }
  
          return instance;
      }
  
      private URLTemplateComposerImpl()
      {
      }
  
      /**
       * Sets the url generator to be used.
       */
      public void setURLGenerator(URLGenerator urlGenerator)
      {
          this.urlGenerator = urlGenerator;
      }
  
      public String createBlockingActionTemplate(
          boolean includePortletHandle,
          boolean includeUserContextKey,
          boolean includePortletInstanceKey,
          boolean includeSessionID)
      {
  
          String template = null;
          
          //TODO: Template processing Pluto case
  
          return template;
      }
  
      public String createSecureBlockingActionTemplate(
          boolean includePortletHandle,
          boolean includeUserContextKey,
          boolean includePortletInstanceKey,
          boolean includeSessionID)
      {
  
          String template = null;
          
          //TODO: Template processing Pluto case
  /*
  
          if (this.urlGenerator != null)
          {
              template =
                  createTemplate(
                      urlGenerator.getBlockingActionURL(null),
                      false,
                      true,
                      true,
                      true,
                      true,
                      true,
                      false,
                      false,
                      includePortletHandle,
                      includeUserContextKey,
                      includePortletInstanceKey,
                      includeSessionID);
          }
  */
          return template;
      }
  
      public String createRenderTemplate(
          boolean includePortletHandle,
          boolean includeUserContextKey,
          boolean includePortletInstanceKey,
          boolean includeSessionID)
      {
  
          String template = null;
  
          //TODO: Template processing Pluto case
  
          return template;
      }
  
      public String createSecureRenderTemplate(
          boolean includePortletHandle,
          boolean includeUserContextKey,
          boolean includePortletInstanceKey,
          boolean includeSessionID)
      {
  
          String template = null;
  
          //TODO: Template processing Pluto case
  
          return template;
      }
  
      public String createResourceTemplate(
          boolean includePortletHandle,
          boolean includeUserContextKey,
          boolean includePortletInstanceKey,
          boolean includeSessionID)
      {
  
          String template = null;
          
          //TODO: Template processing Pluto case
  
          return template;
      }
  
      public String createSecureResourceTemplate(
          boolean includePortletHandle,
          boolean includeUserContextKey,
          boolean includePortletInstanceKey,
          boolean includeSessionID)
      {
  
          String template = null;
          
          //TODO: Template processing Pluto case
          
          return template;
      }
  
      public String createDefaultTemplate(
          boolean includePortletHandle,
          boolean includeUserContextKey,
          boolean includePortletInstanceKey,
          boolean includeSessionID)
      {
  
          String template = null;
  
          //TODO: Template processing Pluto case
          
          return template;
      }
  
      public String createSecureDefaultTemplate(
          boolean includePortletHandle,
          boolean includeUserContextKey,
          boolean includePortletInstanceKey,
          boolean includeSessionID)
      {
  
          String template = null;
  
          //TODO: Template processing Pluto case
          
          return template;
      }
  
      public String getNamespacePrefix()
      {
          return urlGenerator.getNamespacedToken("");
      }
  
  }
  
  
  
  1.1                  ws-wsrp4j/sandbox/wsrp4j/consumer/src/java/org/apache/wsrp4j/consumer/proxyportlet/impl/UserRegistryImpl.java
  
  Index: UserRegistryImpl.java
  ===================================================================
  /*
   * Copyright 2003-2005 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.wsrp4j.consumer.proxyportlet.impl;
  
  import org.apache.wsrp4j.commons.consumer.interfaces.user.UserRegistry;
  import org.apache.wsrp4j.commons.consumer.driver.GenericUserRegistryImpl;
  
  
  /**
   * @version $Id: UserRegistryImpl.java,v 1.1 2005/08/23 19:25:12 dlouzan Exp $
   */
  public class UserRegistryImpl extends GenericUserRegistryImpl
  {
  
      private static UserRegistry instance;
  
      private UserRegistryImpl()
      {
          super();
      }
  
      public static UserRegistry getInstance()
      {
          if (instance == null)
          {
              instance = new UserRegistryImpl();
          }
  
          return instance;
      }
  }
  
  
  
  1.1                  ws-wsrp4j/sandbox/wsrp4j/consumer/src/java/org/apache/wsrp4j/consumer/proxyportlet/impl/UserSessionImpl.java
  
  Index: UserSessionImpl.java
  ===================================================================
  /*
   * Copyright 2003-2005 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.wsrp4j.consumer.proxyportlet.impl;
  
  import java.util.Hashtable;
  import java.util.Map;
  
  import javax.portlet.PortletSession;
  
  import oasis.names.tc.wsrp.v1.intf.WSRP_v1_Markup_PortType;
  import org.apache.wsrp4j.commons.consumer.interfaces.session.GroupSessionMgr;
  import org.apache.wsrp4j.commons.consumer.driver.GenericUserSessionImpl;
  import org.apache.wsrp4j.consumer.util.ConsumerConstants;
  import org.apache.wsrp4j.commons.exception.WSRPException;
  
  /**
   * @version $Id: UserSessionImpl.java,v 1.1 2005/08/23 19:25:12 dlouzan Exp $
   */
  public class UserSessionImpl extends GenericUserSessionImpl
  {
  
      private PortletSession portletSession;
      private Map userSession;
  
      public UserSessionImpl(String producerID, String userID, 
              String portletServicesURL, PortletSession portletSession) 
      throws WSRPException
      {
  
          super(producerID, userID, portletServicesURL);
  
          this.portletSession = portletSession;
          userSession = getUserSessionMap();
          setGroupSessionTable(getGroupSessionTable());
      }
  
      private Hashtable getGroupSessionTable()
      {
  
          if ((groupSessions = (Hashtable)userSession.get(
                  ConsumerConstants.WSRP_GROUPSESSIONS)) == null)
          {
              groupSessions = new Hashtable();
              userSession.put(ConsumerConstants.WSRP_GROUPSESSIONS, 
                      groupSessions);
          }
  
          return groupSessions;
      }
  
      /**
       * Get the group session for this group ID
       *
       * @param groupID ID of the portlet application
       * @return The group session for the provided group ID
       **/
      public GroupSessionMgr getGroupSession(String groupID) throws WSRPException
      {
          if (groupID != null)
          {
              GroupSessionMgr groupSession = 
                      (GroupSessionMgr) this.groupSessions.get(groupID);
              if (groupSession == null)
              {
  
                  groupSession = new GroupSessionImpl(groupID, 
                          this.getMarkupInterfaceURL());
                  addGroupSession(groupSession);
              }
  
              return groupSession;
          }
          return null;
      }
  
      public WSRP_v1_Markup_PortType getWSRPBaseService()
      {
          WSRP_v1_Markup_PortType markupPort = null;
          if ((markupPort = (WSRP_v1_Markup_PortType)userSession.get(
                  ConsumerConstants.WSRP_MARKUP_PORT)) == null)
          {
              markupPort = super.getWSRPBaseService();
              userSession.put(ConsumerConstants.WSRP_MARKUP_PORT, markupPort);
          }
  
          this.setWSRPBaseService(markupPort);
          return markupPort;
      }
  
      public boolean isInitCookieRequired()
      {
          Boolean initCookieReq = null;
          if ((initCookieReq = (Boolean)userSession.get(
                  ConsumerConstants.WSRP_INIT_COOKIE_REQ)) == null)
          {
              initCookieReq = new Boolean(super.isInitCookieRequired());
              setInitCookieRequired(initCookieReq.booleanValue());
          }
  
          return initCookieReq.booleanValue();
      }
  
      public void setInitCookieRequired(boolean initCookieRequired)
      {
          userSession.put(ConsumerConstants.WSRP_INIT_COOKIE_REQ, 
                  new Boolean(initCookieRequired));
          super.setInitCookieRequired(initCookieRequired);
      }
  
      public boolean isInitCookieDone()
      {
          Boolean initCookieDone = null;
          if ((initCookieDone = (Boolean)userSession.get(
                  ConsumerConstants.WSRP_INIT_COOKIE_DONE)) == null)
          {
              initCookieDone = new Boolean(super.isInitCookieDone());
              setInitCookieDone(initCookieDone.booleanValue());
          }
  
          return initCookieDone.booleanValue();
      }
  
      public void setInitCookieDone(boolean initCookieDone)
      {
          userSession.put(ConsumerConstants.WSRP_INIT_COOKIE_DONE, 
                  new Boolean(initCookieDone));
          super.setInitCookieRequired(initCookieDone);
      }
  
      private Map getUserSessionMap()
      {
          String key = createKey();
          Map myMap = (Map)this.portletSession.getAttribute(key, 
                  PortletSession.APPLICATION_SCOPE);
  
          if (myMap == null)
          {
              myMap = new Hashtable();
              this.portletSession.setAttribute(key, myMap, 
                      PortletSession.APPLICATION_SCOPE);
          }
  
          return myMap;
      }
  
      private String createKey()
      {
          return "user :" + this.getUserID() + " producer:" + 
                  this.getProducerID();
      }
  }