Package org.gatein.pc.api

Examples of org.gatein.pc.api.PortletContext$InterpretedPortletContextComponents


   public PortletInvocationResponse invoke(PortletInvocation invocation) throws IllegalArgumentException, PortletInvokerException
   {
      InstanceContext oldContext = invocation.getInstanceContext();
      if ((invocation instanceof ActionInvocation || invocation instanceof EventInvocation) && oldContext.getAccessMode() == AccessMode.READ_ONLY)
      {
         PortletContext oldTarget = invocation.getTarget();
         try
         {
            UserContext userContext = invocation.getUserContext();
            PortletInstanceContext newContext = new PortletInstanceContext(userContext, oldTarget);
View Full Code Here


      public PortletInstanceContext(
         UserContext userContext,
         PortletContext portletContext)
      {
         String id = portletContext.getId();
         PortletContext target = portletContext;
         boolean useClone = false;
         PortletContext clone = (PortletContext)userContext.getAttribute("clone." + id);
         if (clone != null)
         {
            target = clone;
            useClone = true;
         }
View Full Code Here

      return getConsumerContext(portletContext).getPortlet();
   }

   public PortletInvocationResponse invoke(PortletInvocation invocation) throws IllegalArgumentException, PortletInvokerException
   {
      PortletContext portletContext = invocation.getTarget();
      if (portletContext == null)
      {
         throw new IllegalArgumentException();
      }

      //
      ConsumerContext consumerContext = getConsumerContext(portletContext);

      //
      InstanceContext cictx = invocation.getInstanceContext();
      StatefulInstanceContextImpl pictx = new StatefulInstanceContextImpl(cictx);

      try
      {
         invocation.setTarget(consumerContext.producerPortletContext);
         invocation.setInstanceContext(pictx);

         //
         PortletInvocationResponse response = super.invoke(invocation);

         //
         PortletContext clonedContext = pictx.clonedContext;
         if (clonedContext != null)
         {
            if (clonedContext instanceof StatefulPortletContext)
            {
               StatefulPortletContext statefulClonedContext = (StatefulPortletContext)clonedContext;
               Serializable state = statefulClonedContext.getState();
               PortletStateType stateType = statefulClonedContext.getType();

               // Save the clone state
               ConsumerState consumerState = new ConsumerState<Serializable>(clonedContext.getId(), stateType, state);
               String stateId = persistenceManager.createState(consumerState);
               String clonedId = CLONE_ID_PREFIX + stateId;
               StateEvent event = new StateEvent(PortletContext.createPortletContext(clonedId), StateEvent.Type.PORTLET_CLONED_EVENT);
               cictx.onStateEvent(event);
            }
            else
            {
               StateEvent event = new StateEvent(PortletContext.createPortletContext(clonedContext.getId()), StateEvent.Type.PORTLET_CLONED_EVENT);
               cictx.onStateEvent(event);
            }
         }
         else
         {
            PortletContext modifiedContext = pictx.modifiedContext;
            if (modifiedContext != null)
            {
               // update state if needed
               if (modifiedContext instanceof StatefulPortletContext)
               {
                  StatefulPortletContext statefulClonedContext = (StatefulPortletContext)modifiedContext;
                  Serializable state = statefulClonedContext.getState();
                  PortletStateType stateType = statefulClonedContext.getType();
                  try
                  {
                     ConsumerState consumerState = new ConsumerState<Serializable>(modifiedContext.getId(), stateType, state);
                     persistenceManager.updateState(consumerContext.stateId, consumerState);
                  }
                  catch (NoSuchStateException e)
                  {
                     e.printStackTrace();
View Full Code Here

   public PortletContext createClone(PortletStateType stateType, PortletContext portletContext) throws IllegalArgumentException, PortletInvokerException, UnsupportedOperationException
   {
      ConsumerContext consumerContext = getConsumerContext(portletContext);

      //
      PortletContext clonedContext = super.createClone(stateType, consumerContext.producerPortletContext);

      if (clonedContext instanceof StatefulPortletContext)
      {
         StatefulPortletContext statefulClonedContext = (StatefulPortletContext)clonedContext;
         ConsumerState consumerState = new ConsumerState<Serializable>(clonedContext.getId(), statefulClonedContext.getType(), statefulClonedContext.getState());
         String id = persistenceManager.createState(consumerState);
         return PortletContext.createPortletContext(CLONE_ID_PREFIX + id);
      }
      else
      {
View Full Code Here

   public PortletContext importPortlet(PortletStateType stateType,
                                       PortletContext portletContext) throws PortletInvokerException, IllegalArgumentException
   {
      ConsumerContext consumerContext = getConsumerContext(portletContext);

      PortletContext importContext = super.importPortlet(stateType, consumerContext.producerPortletContext);

      if (importContext instanceof StatefulPortletContext)
      {
         StatefulPortletContext statefulimportContext = (StatefulPortletContext)importContext;
         ConsumerState consumerState = new ConsumerState<Serializable>(importContext.getId(), statefulimportContext.getType(), statefulimportContext.getState());
         String id = persistenceManager.createState(consumerState);
         return PortletContext.createPortletContext(CLONE_ID_PREFIX + id);
      }
      else
      {
View Full Code Here

         throw new IllegalArgumentException();
      }
      portletContexts = new ArrayList<PortletContext>(portletContexts);
      for (int i = 0; i < portletContexts.size(); i++)
      {
         PortletContext portletContext = portletContexts.get(i);
         ConsumerContext consumerContext = getConsumerContext(portletContext);
         portletContexts.set(i, consumerContext.producerPortletContext);
         if (consumerContext.stateId != null)
         {
            try
View Full Code Here

   public PortletContext setProperties(PortletContext portletContext, PropertyChange[] changes) throws IllegalArgumentException, PortletInvokerException, UnsupportedOperationException
   {
      ConsumerContext consumerContext = getConsumerContext(portletContext);

      //
      PortletContext updatedPortletContext = super.setProperties(consumerContext.producerPortletContext, changes);

      if (updatedPortletContext instanceof StatefulPortletContext)
      {
         StatefulPortletContext statefulUpdatedPortletContext = (StatefulPortletContext)updatedPortletContext;
         Serializable state = statefulUpdatedPortletContext.getState();
         PortletStateType stateType = statefulUpdatedPortletContext.getType();

         //
         if (consumerContext.stateId == null)
         {
            throw new NotYetImplemented();
         }

         //
         ConsumerState consumerState = new ConsumerState<Serializable>(updatedPortletContext.getId(), stateType, state);
         try
         {
            persistenceManager.updateState(consumerContext.stateId, consumerState);
         }
         catch (NoSuchStateException e)
View Full Code Here

   }

   public PortletInvocationResponse invoke(PortletInvocation invocation) throws PortletInvokerException, InvocationException
   {
      // Get the context of the portlet that the client want to use
      final PortletContext portletContext = invocation.getTarget();
      if (portletContext == null)
      {
         throw new InvocationException("No portlet context provided");
      }

      // Get the access mode
      InstanceContext instanceCtx = invocation.getInstanceContext();
      AccessMode access = instanceCtx.getAccessMode();

      // Get a state contxt for the portlet context
      InternalContext context = getStateContext(portletContext);

      // If it is a producer offered portlet we consider read-write as read-only
      if (!context.isStateful() && access == AccessMode.READ_WRITE)
      {
         access = AccessMode.READ_ONLY;
      }

      // Get the portlet container and set it on invocation
      Portlet portlet = super.getPortlet(context.getPortletContext());
      if (portlet == null)
      {
         throw new NoSuchPortletException("Portlet " + context.getPortletContext() + " not found", context.getPortletId());
      }

      // Create prefs
      AbstractPropertyContext prefs = new AbstractPropertyContext(
         access,
         context.isStateful() ? ((StatefulContext)context).getProperties() : null,
         invocation instanceof RenderInvocation);

      //
      PortletInvocationResponse response;
      try
      {
         invocation.setTarget(context.getPortletContext());
         invocation.setAttribute(PropertyContext.PREFERENCES_ATTRIBUTE, prefs);

         // Invoke
         response = super.invoke(invocation);
      }
      finally
      {
         invocation.setTarget(portletContext);
         invocation.removeAttribute(PropertyContext.PREFERENCES_ATTRIBUTE);
      }

      //
      int status = prefs.getStatus();

      // Producer state management if the invocation was succesful
      if ((invocation instanceof ActionInvocation || invocation instanceof ResourceInvocation || invocation instanceof EventInvocation) && status == AbstractPropertyContext.UPDATE_SUCCESSFUL)
      {
         // Get the potentially updated prefs
         PropertyMap newPrefs = prefs.getPrefs();

         //
         PortletStateType stateType = instanceCtx.getStateType();
         boolean persistLocally;
         if (stateType == null)
         {
            persistLocally = true;
         }
         else
         {
            persistLocally = stateManagementPolicy.persistLocally();
         }

         //
         switch (access)
         {
            case CLONE_BEFORE_WRITE:
            {
               // Create the state
               if (context.isStateful())
               {
                  StatefulContext statefulContext = (StatefulContext)context;
                  if (persistLocally)
                  {
                     try
                     {
                        // The state id should be ok as it was used before to load the state
                        LocalContext localContext = (LocalContext)statefulContext;
                        String portletStateId = localContext.getStateId();
                        String cloneStateId = persistenceManager.cloneState(portletStateId, newPrefs);

                        // Return the clone context
                        String cloneId = PRODUCER_CLONE_ID_PREFIX + cloneStateId;
                        PortletContext clonedCtx = PortletContext.createPortletContext(cloneId);
                        StateEvent event = new StateEvent(clonedCtx, StateEvent.Type.PORTLET_CLONED_EVENT);
                        instanceCtx.onStateEvent(event);
                     }
                     catch (NoSuchStateException e)
                     {
                        throw new PortletInvokerException("Unexpected exception", e);
                     }
                     catch (InvalidStateIdException e)
                     {
                        throw new PortletInvokerException("Unexpected exception", e);
                     }
                  }
                  else
                  {
                     PortletContext clonedCtx = marshall(stateType, context.getPortletId(), newPrefs);
                     StateEvent event = new StateEvent(clonedCtx, StateEvent.Type.PORTLET_CLONED_EVENT);
                     instanceCtx.onStateEvent(event);
                  }
               }
               else
               {
                  // Add the missing mutable portlet state
                  getPropertiesFromMetaData(portlet.getContext(), newPrefs);

                  //
                  if (persistLocally)
                  {
                     // Create the new state
                     String cloneStateId = persistenceManager.createState(context.getPortletId(), newPrefs);

                     // Return the clone context
                     String cloneId = PRODUCER_CLONE_ID_PREFIX + cloneStateId;
                     PortletContext clonedCtx = PortletContext.createPortletContext(cloneId);
                     StateEvent event = new StateEvent(clonedCtx, StateEvent.Type.PORTLET_CLONED_EVENT);
                     instanceCtx.onStateEvent(event);
                  }
                  else
                  {
                     PortletContext clonedCtx = marshall(stateType, context.getPortletId(), newPrefs);
                     StateEvent event = new StateEvent(clonedCtx, StateEvent.Type.PORTLET_CLONED_EVENT);
                     instanceCtx.onStateEvent(event);
                  }
               }
               break;
            }
            case READ_WRITE:
            {
               StatefulContext statefulContext = (StatefulContext)context;
               if (statefulContext.isLocal())
               {
                  // Update the state
                  try
                  {
                     LocalContext localContext = (LocalContext)statefulContext;
                     String stateId = localContext.getStateId();
                     persistenceManager.updateState(stateId, newPrefs);
                  }
                  catch (NoSuchStateException e)
                  {
                     throw new PortletInvokerException("Unexpected exception", e);
                  }
                  catch (InvalidStateIdException e)
                  {
                     throw new PortletInvokerException("Unexpected exception", e);
                  }
               }
               else
               {
                  PortletContext modifiedCtx = marshall(stateType, context.getPortletId(), newPrefs);
                  StateEvent event = new StateEvent(modifiedCtx, StateEvent.Type.PORTLET_MODIFIED_EVENT);
                  instanceCtx.onStateEvent(event);
               }
               break;
            }
View Full Code Here

         // Get the content
         PropertyMap props = new SimplePropertyMap(statefulContext.getProperties());

         // Dereference the portlet
         PortletContext refPortletContext = context.getPortletContext();

         // Get the referenced portlet
         Portlet refPortlet = super.getPortlet(refPortletContext);

         // We need the referenced portlet
View Full Code Here

      initial.setPersistentKey(getPersistentKey());

      Collection<PortletContextMapping> pcms = getPortletContexts();
      for (PortletContextMapping pcm : pcms)
      {
         PortletContext pc = PortletContext.createPortletContext(pcm.getId(), IOTools.safeGetBytes(pcm.getState()));
         try
         {
            initial.addPortletContext(pc, false); // no need to save since we're loading from persistence :)
         }
         catch (RegistrationException e)
View Full Code Here

TOP

Related Classes of org.gatein.pc.api.PortletContext$InterpretedPortletContextComponents

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.