[gatein-commits] gatein SVN: r3394 - in components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer: portlet/info and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Sun Jun 20 08:18:14 EDT 2010


Author: chris.laprun at jboss.com
Date: 2010-06-20 08:18:14 -0400 (Sun, 20 Jun 2010)
New Revision: 3394

Added:
   components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/portlet/info/WSRPEventInfo.java
   components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/portlet/info/WSRPNavigationInfo.java
   components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/portlet/info/WSRPParameterInfo.java
Modified:
   components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/ProducerInfo.java
   components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/portlet/info/WSRPPortletInfo.java
Log:
- Started adding events and PRP metadata on the consumer side.

Modified: components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/ProducerInfo.java
===================================================================
--- components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/ProducerInfo.java	2010-06-20 12:15:10 UTC (rev 3393)
+++ components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/ProducerInfo.java	2010-06-20 12:18:14 UTC (rev 3394)
@@ -23,16 +23,20 @@
 
 package org.gatein.wsrp.consumer;
 
+import org.gatein.common.NotYetImplemented;
 import org.gatein.common.util.ParameterValidation;
 import org.gatein.pc.api.InvokerUnavailableException;
 import org.gatein.pc.api.NoSuchPortletException;
 import org.gatein.pc.api.Portlet;
 import org.gatein.pc.api.PortletContext;
 import org.gatein.pc.api.PortletInvokerException;
+import org.gatein.pc.api.info.EventInfo;
+import org.gatein.pc.api.info.TypeInfo;
 import org.gatein.wsrp.WSRPConstants;
 import org.gatein.wsrp.WSRPTypeFactory;
 import org.gatein.wsrp.WSRPUtils;
 import org.gatein.wsrp.consumer.portlet.WSRPPortlet;
+import org.gatein.wsrp.consumer.portlet.info.WSRPEventInfo;
 import org.gatein.wsrp.consumer.portlet.info.WSRPPortletInfo;
 import org.gatein.wsrp.consumer.registry.ConsumerRegistry;
 import org.gatein.wsrp.servlet.UserAccess;
@@ -58,6 +62,8 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.namespace.QName;
 import javax.xml.ws.Holder;
 import java.util.Collections;
 import java.util.HashMap;
@@ -123,6 +129,9 @@
    private Map<String, ItemDescription> customModes;
    private Map<String, ItemDescription> customWindowStates;
 
+   /** Events */
+   private Map<QName, EventInfo> eventDescriptions;
+
    /*protected org.oasis.wsrp.v1.ItemDescription[] userCategoryDescriptions;
    protected org.oasis.wsrp.v1.ItemDescription[] customUserProfileItemDescriptions;   
 
@@ -479,6 +488,37 @@
       // custom window state descriptions
       customWindowStates = toMap(serviceDescription.getCustomWindowStateDescriptions());
 
+      // event descriptions
+      List<EventDescription> eventDescriptions = serviceDescription.getEventDescriptions();
+      if (!eventDescriptions.isEmpty())
+      {
+         this.eventDescriptions = new HashMap<QName, EventInfo>(eventDescriptions.size());
+
+         for (final EventDescription event : eventDescriptions)
+         {
+            QName name = event.getName();
+            EventInfo eventInfo = new WSRPEventInfo(
+               name,
+               WSRPUtils.convertToCommonLocalizedStringOrNull(event.getLabel()),
+               WSRPUtils.convertToCommonLocalizedStringOrNull(event.getDescription()),
+               new TypeInfo()
+               {
+                  public String getName()
+                  {
+                     return event.getType().toString();
+                  }
+
+                  public XmlRootElement getXMLBinding()
+                  {
+                     throw new NotYetImplemented(); // todo
+                  }
+               },
+               event.getAliases());
+
+            this.eventDescriptions.put(name, eventInfo);
+         }
+      }
+
       // do we need to register?
       if (serviceDescription.isRequiresRegistration())
       {
@@ -1168,4 +1208,9 @@
 
       log.warn(ERASED_LOCAL_REGISTRATION_INFORMATION);
    }
+
+   public EventInfo getInfoForEvent(QName name)
+   {
+      return eventDescriptions.get(name);
+   }
 }

Added: components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/portlet/info/WSRPEventInfo.java
===================================================================
--- components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/portlet/info/WSRPEventInfo.java	                        (rev 0)
+++ components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/portlet/info/WSRPEventInfo.java	2010-06-20 12:18:14 UTC (rev 3394)
@@ -0,0 +1,79 @@
+/*
+ * 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.wsrp.consumer.portlet.info;
+
+import org.gatein.common.i18n.LocalizedString;
+import org.gatein.pc.api.info.EventInfo;
+import org.gatein.pc.api.info.TypeInfo;
+
+import javax.xml.namespace.QName;
+import java.util.Collection;
+import java.util.Collections;
+
+/**
+ * @author <a href="mailto:chris.laprun at jboss.com">Chris Laprun</a>
+ * @version $Revision$
+ */
+public class WSRPEventInfo implements EventInfo
+{
+   private final QName name;
+   private final LocalizedString displayName;
+   private final LocalizedString description;
+   private final TypeInfo type;
+   private final Collection<QName> aliases;
+
+   public WSRPEventInfo(QName name, LocalizedString displayName, LocalizedString description, TypeInfo type, Collection<QName> aliases)
+   {
+      this.name = name;
+      this.displayName = displayName;
+      this.description = description;
+      this.type = type;
+      this.aliases = Collections.unmodifiableCollection(aliases);
+   }
+
+   public QName getName()
+   {
+      return name;
+   }
+
+   public LocalizedString getDisplayName()
+   {
+      return displayName;
+   }
+
+   public LocalizedString getDescription()
+   {
+      return description;
+   }
+
+   public TypeInfo getType()
+   {
+      return type;
+   }
+
+   public Collection<QName> getAliases()
+   {
+      return aliases;
+   }
+}

Added: components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/portlet/info/WSRPNavigationInfo.java
===================================================================
--- components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/portlet/info/WSRPNavigationInfo.java	                        (rev 0)
+++ components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/portlet/info/WSRPNavigationInfo.java	2010-06-20 12:18:14 UTC (rev 3394)
@@ -0,0 +1,79 @@
+/*
+ * 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.wsrp.consumer.portlet.info;
+
+import org.gatein.common.util.ParameterValidation;
+import org.gatein.pc.api.info.NavigationInfo;
+import org.gatein.pc.api.info.ParameterInfo;
+
+import javax.xml.namespace.QName;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:chris.laprun at jboss.com">Chris Laprun</a>
+ * @version $Revision$
+ */
+public class WSRPNavigationInfo implements NavigationInfo
+{
+   private final Map<String, ParameterInfo> byId;
+   private final Map<QName, ParameterInfo> byName;
+
+   public WSRPNavigationInfo(Collection<ParameterInfo> params)
+   {
+      if (ParameterValidation.existsAndIsNotEmpty(params))
+      {
+         byId = new HashMap<String, ParameterInfo>(params.size());
+         byName = new HashMap<QName, ParameterInfo>(params.size());
+
+         for (ParameterInfo param : params)
+         {
+            byId.put(param.getId(), param);
+            byName.put(param.getName(), param);
+         }
+      }
+      else
+      {
+         byId = Collections.emptyMap();
+         byName = Collections.emptyMap();
+      }
+   }
+
+   public ParameterInfo getPublicParameter(String id)
+   {
+      return byId.get(id);
+   }
+
+   public ParameterInfo getPublicParameter(QName name)
+   {
+      return byName.get(name);
+   }
+
+   public Collection<? extends ParameterInfo> getPublicParameters()
+   {
+      return Collections.unmodifiableCollection(byId.values());
+   }
+}

Added: components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/portlet/info/WSRPParameterInfo.java
===================================================================
--- components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/portlet/info/WSRPParameterInfo.java	                        (rev 0)
+++ components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/portlet/info/WSRPParameterInfo.java	2010-06-20 12:18:14 UTC (rev 3394)
@@ -0,0 +1,70 @@
+/*
+ * 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.wsrp.consumer.portlet.info;
+
+import org.gatein.common.i18n.LocalizedString;
+import org.gatein.pc.api.info.ParameterInfo;
+
+import javax.xml.namespace.QName;
+import java.util.Collection;
+
+/**
+ * @author <a href="mailto:chris.laprun at jboss.com">Chris Laprun</a>
+ * @version $Revision$
+ */
+public class WSRPParameterInfo implements ParameterInfo
+{
+   private final String id;
+   private final QName name;
+   private final Collection<QName> aliases;
+   private final LocalizedString description;
+
+   public WSRPParameterInfo(String id, QName name, Collection<QName> aliases, LocalizedString description)
+   {
+      this.id = id;
+      this.name = name;
+      this.aliases = aliases;
+      this.description = description;
+   }
+
+   public String getId()
+   {
+      return id;
+   }
+
+   public QName getName()
+   {
+      return name;
+   }
+
+   public Collection<QName> getAliases()
+   {
+      return aliases;
+   }
+
+   public LocalizedString getDescription()
+   {
+      return description;
+   }
+}

Modified: components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/portlet/info/WSRPPortletInfo.java
===================================================================
--- components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/portlet/info/WSRPPortletInfo.java	2010-06-20 12:15:10 UTC (rev 3393)
+++ components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/portlet/info/WSRPPortletInfo.java	2010-06-20 12:18:14 UTC (rev 3394)
@@ -46,11 +46,13 @@
 import org.oasis.wsrp.v2.LocalizedString;
 import org.oasis.wsrp.v2.MarkupType;
 import org.oasis.wsrp.v2.ModelDescription;
+import org.oasis.wsrp.v2.ParameterDescription;
 import org.oasis.wsrp.v2.PortletDescription;
 import org.oasis.wsrp.v2.PortletPropertyDescriptionResponse;
 import org.oasis.wsrp.v2.PropertyDescription;
 
 import javax.xml.namespace.QName;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
@@ -84,25 +86,104 @@
    private PreferencesInfo prefInfo;
    private ProducerInfo originatingProducer;
    private String portletHandle;
+   private final EventingInfo eventingInfo;
+   private final NavigationInfo navigationInfo;
 
    public WSRPPortletInfo(final PortletDescription portletDescription, ProducerInfo originatingProducerInfo)
    {
       ParameterValidation.throwIllegalArgExceptionIfNull(portletDescription, "PortletDescription");
       ParameterValidation.throwIllegalArgExceptionIfNull(originatingProducerInfo, "ProducerInfo");
 
+      this.originatingProducer = originatingProducerInfo;
+      this.portletHandle = portletDescription.getPortletHandle();
+
       createCapabilitiesInfo(portletDescription);
 
       createMetaInfo(portletDescription, originatingProducerInfo.getId());
 
       createWSRPInfo(portletDescription, originatingProducerInfo.getId());
 
-      this.originatingProducer = originatingProducerInfo;
-      this.portletHandle = portletDescription.getPortletHandle();
+      this.eventingInfo = createEventingInfo(portletDescription);
+      this.navigationInfo = createNavigationInfo(portletDescription);
    }
 
+   private NavigationInfo createNavigationInfo(PortletDescription portletDescription)
+   {
+      List<ParameterDescription> parameterDescriptions = portletDescription.getNavigationalPublicValueDescriptions();
+      if (!parameterDescriptions.isEmpty())
+      {
+         Collection<ParameterInfo> params = new ArrayList<ParameterInfo>(parameterDescriptions.size());
+         for (ParameterDescription parameterDescription : parameterDescriptions)
+         {
+            // WSRP doesn't distinguish between name and aliases as JSR-286 does so assume that first name is the name,
+            // rest are considered aliases...
+            List<QName> names = parameterDescription.getNames();
+            int nameNb = names.size();
+            QName name;
+            Collection<QName> aliases;
+            switch (nameNb)
+            {
+               case 0:
+                  throw new IllegalArgumentException("Parameter must at least have one name");
+               case 1:
+                  name = names.get(0);
+                  aliases = Collections.emptyList();
+                  break;
+               default:
+                  name = names.get(0);
+                  aliases = names.subList(1, nameNb);
+            }
 
-   public WSRPPortletInfo(WSRPPortletInfo other, String newHandle)
+            // create new ParameterInfo and add it
+            params.add(
+               new WSRPParameterInfo(
+                  parameterDescription.getIdentifier(),
+                  name,
+                  aliases,
+                  WSRPUtils.convertToCommonLocalizedStringOrNull(parameterDescription.getDescription())));
+         }
+
+         return new WSRPNavigationInfo(params);
+      }
+      else
+      {
+         return new WSRPNavigationInfo(Collections.<ParameterInfo>emptyList());
+      }
+   }
+
+   private EventingInfo createEventingInfo(PortletDescription portletDescription)
    {
+      Map<QName, EventInfo> produced = null;
+      Map<QName, EventInfo> consumed = null;
+
+      List<QName> events = portletDescription.getPublishedEvents();
+      if (!events.isEmpty())
+      {
+         produced = new HashMap<QName, EventInfo>(events.size());
+         for (QName event : events)
+         {
+            EventInfo desc = originatingProducer.getInfoForEvent(event);
+            produced.put(event, desc);
+         }
+      }
+
+      events = portletDescription.getHandledEvents();
+      if (!events.isEmpty())
+      {
+         consumed = new HashMap<QName, EventInfo>(events.size());
+         for (QName event : events)
+         {
+            EventInfo desc = originatingProducer.getInfoForEvent(event);
+            consumed.put(event, desc);
+         }
+      }
+
+      return new WSRPEventingInfo(produced, consumed);
+   }
+
+
+   public WSRPPortletInfo(final WSRPPortletInfo other, String newHandle)
+   {
       ParameterValidation.throwIllegalArgExceptionIfNull(other, "WSRPPortletInfo");
       ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(newHandle, "new portlet handle", "WSRPPortletInfo");
 
@@ -126,6 +207,9 @@
       WSRPPreferencesInfo otherPref = (WSRPPreferencesInfo)other.getPreferences();
       prefInfo = new WSRPPreferencesInfo(new HashMap<String, PreferenceInfo>(otherPref.preferences));
 
+      eventingInfo = other.eventingInfo;
+      navigationInfo = other.navigationInfo;
+
       originatingProducer = other.originatingProducer;
       portletHandle = newHandle;
    }
@@ -166,8 +250,8 @@
                   for (PropertyDescription desc : descs)
                   {
                      String keyAsString = desc.getName().toString();
-                     prefInfos.put(keyAsString, new WSRPPreferenceInfo(keyAsString, getPortalLocalizedStringOrNullFrom(desc.getLabel()),
-                        getPortalLocalizedStringOrNullFrom(desc.getHint())));
+                     prefInfos.put(keyAsString, new WSRPPreferenceInfo(keyAsString, WSRPUtils.convertToCommonLocalizedStringOrNull(desc.getLabel()),
+                        WSRPUtils.convertToCommonLocalizedStringOrNull(desc.getHint())));
                   }
                }
                else
@@ -229,41 +313,12 @@
 
    public EventingInfo getEventing()
    {
-      //todo: revisit when implementing WSRP 2
-      return new EventingInfo()
-      {
-         public Map<QName, ? extends EventInfo> getProducedEvents()
-         {
-            return Collections.emptyMap();
-         }
-
-         public Map<QName, ? extends EventInfo> getConsumedEvents()
-         {
-            return Collections.emptyMap();
-         }
-      };
+      return eventingInfo;
    }
 
    public NavigationInfo getNavigation()
    {
-      //todo: revisit when implementing WSRP 2
-      return new NavigationInfo()
-      {
-         public ParameterInfo getPublicParameter(String s)
-         {
-            return null;
-         }
-
-         public ParameterInfo getPublicParameter(QName qName)
-         {
-            return null;
-         }
-
-         public Collection<? extends ParameterInfo> getPublicParameters()
-         {
-            return Collections.emptyList();
-         }
-      };
+      return navigationInfo;
    }
 
    public <T> T getAttachment(Class<T> tClass) throws IllegalArgumentException
@@ -366,10 +421,10 @@
    private void createMetaInfo(PortletDescription portletDescription, String producerId)
    {
       final Map<String, org.gatein.common.i18n.LocalizedString> metaInfos = new HashMap<String, org.gatein.common.i18n.LocalizedString>();
-      metaInfos.put(MetaInfo.DESCRIPTION, getPortalLocalizedStringOrNullFrom(portletDescription.getDescription()));
-      metaInfos.put(MetaInfo.DISPLAY_NAME, getPortalLocalizedStringOrNullFrom(portletDescription.getDisplayName()));
-      metaInfos.put(MetaInfo.SHORT_TITLE, getPortalLocalizedStringOrNullFrom(portletDescription.getShortTitle()));
-      metaInfos.put(MetaInfo.TITLE, getPortalLocalizedStringOrNullFrom(portletDescription.getTitle()));
+      metaInfos.put(MetaInfo.DESCRIPTION, WSRPUtils.convertToCommonLocalizedStringOrNull(portletDescription.getDescription()));
+      metaInfos.put(MetaInfo.DISPLAY_NAME, WSRPUtils.convertToCommonLocalizedStringOrNull(portletDescription.getDisplayName()));
+      metaInfos.put(MetaInfo.SHORT_TITLE, WSRPUtils.convertToCommonLocalizedStringOrNull(portletDescription.getShortTitle()));
+      metaInfos.put(MetaInfo.TITLE, WSRPUtils.convertToCommonLocalizedStringOrNull(portletDescription.getTitle()));
 
       // keywords need to be concatenated
       List<LocalizedString> keywords = portletDescription.getKeywords();
@@ -403,17 +458,6 @@
       metaInfo = new WSRPMetaInfo(metaInfos);
    }
 
-   private org.gatein.common.i18n.LocalizedString getPortalLocalizedStringOrNullFrom(LocalizedString wsrpLocalizedString)
-   {
-      if (wsrpLocalizedString != null)
-      {
-         return new org.gatein.common.i18n.LocalizedString(wsrpLocalizedString.getValue(),
-            WSRPUtils.getLocale(wsrpLocalizedString.getLang()));
-      }
-
-      return null;
-   }
-
    class MediaTypeInfo
    {
       public MediaTypeInfo(MarkupType markupType)
@@ -725,4 +769,40 @@
          return null;
       }
    }
+
+   private static class WSRPEventingInfo implements EventingInfo
+   {
+      private final Map<QName, ? extends EventInfo> produced;
+      private final Map<QName, ? extends EventInfo> consumed;
+
+      public WSRPEventingInfo(Map<QName, ? extends EventInfo> produced, Map<QName, ? extends EventInfo> consumed)
+      {
+         if (produced != null)
+         {
+            this.produced = Collections.unmodifiableMap(produced);
+         }
+         else
+         {
+            this.produced = Collections.emptyMap();
+         }
+         if (consumed != null)
+         {
+            this.consumed = Collections.unmodifiableMap(consumed);
+         }
+         else
+         {
+            this.consumed = Collections.emptyMap();
+         }
+      }
+
+      public Map<QName, ? extends EventInfo> getProducedEvents()
+      {
+         return produced;
+      }
+
+      public Map<QName, ? extends EventInfo> getConsumedEvents()
+      {
+         return consumed;
+      }
+   }
 }



More information about the gatein-commits mailing list