Package org.gatein.pc.api

Examples of org.gatein.pc.api.PortletContext


      }
   }

   public PortletContext createClone(PortletStateType stateType, PortletContext compoundPortletContext) throws PortletInvokerException
   {
      PortletContext portletContext = dereference(compoundPortletContext);
      PortletContext cloneContext = portletInvoker.createClone(stateType, portletContext);
      return reference(cloneContext);
   }
View Full Code Here


      //
      List<PortletContext> dereferencedList = new ArrayList<PortletContext>(portletContexts);
      for (int i = 0; i < dereferencedList.size(); i++)
      {
         PortletContext compoundPortletContext = dereferencedList.get(i);
         PortletContext portletContext = dereference(compoundPortletContext);
         dereferencedList.set(i, portletContext);
      }

      //
      List<DestroyCloneFailure> failures = portletInvoker.destroyClones(dereferencedList);
View Full Code Here

      return failures;
   }

   public PropertyMap getProperties(PortletContext compoundPortletContext) throws PortletInvokerException
   {
      PortletContext portletId = dereference(compoundPortletContext);
      return portletInvoker.getProperties(portletId);
   }
View Full Code Here

      return portletInvoker.getProperties(portletId);
   }

   public PropertyMap getProperties(PortletContext compoundPortletContext, Set<String> keys) throws IllegalArgumentException, PortletInvokerException, UnsupportedOperationException
   {
      PortletContext portletId = dereference(compoundPortletContext);
      return portletInvoker.getProperties(portletId, keys);
   }
View Full Code Here

      return portletInvoker.getProperties(portletId, keys);
   }

   public PortletContext setProperties(PortletContext compoundPortletContext, PropertyChange[] changes) throws IllegalArgumentException, PortletInvokerException, UnsupportedOperationException
   {
      PortletContext portletContext = dereference(compoundPortletContext);
      portletContext = portletInvoker.setProperties(portletContext, changes);
      return reference(portletContext);
   }
View Full Code Here

      }

      List<String> handles = new ArrayList<String>(numberOfClones);
      for (Object portletContext : portletContexts)
      {
         PortletContext context = (PortletContext)portletContext;
         String id = context.getId();
         handles.add(id);
      }
      if (log.isDebugEnabled())
      {
         log.debug("Attempting to destroy clones: " + handles);
View Full Code Here

            handle,
            portletState,
            new Holder<Lifetime>(),
            new Holder<List<Extension>>()
         );
         PortletContext newPortletContext = PortletContext.createPortletContext(handle.value, portletState.value);
         portlet.setPortletContext(newPortletContext);
         return newPortletContext;
      }
      catch (Exception e)
      {
View Full Code Here

            if (ParameterValidation.existsAndIsNotEmpty(importedPortlets))
            {
               for (ImportedPortlet importedPortlet : importedPortlets)
               {
                  org.oasis.wsrp.v2.PortletContext portletContext = importedPortlet.getNewPortletContext();
                  PortletContext apiPC = PortletContext.createPortletContext(portletContext.getPortletHandle(), portletContext.getPortletState());
                  // we need to reference the resulting PortletContext so that it can then be used properly
                  importIdToPortletContext.put(importedPortlet.getImportID(), FederatingPortletInvokerService.reference(apiPC, getProducerId()));
               }
            }
View Full Code Here

   }

   public PortletInvocationResponse invoke(PortletInvocation invocation) throws PortletInvokerException, InvocationException
   {
      // Get portlet container
      PortletContext ctx = invocation.getTarget();
      PortletImpl portlet = (PortletImpl)getPortlet(ctx);
      PortletContainer container = portlet.container;

      //
      try
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 = PortletContext.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 = PortletContext.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

TOP

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

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.