KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > wsrp > producer > impl > ServiceDescriptionInterfaceImpl


1 /**
2  * Copyright 2001-2003 The eXo platform SARL All rights reserved.
3  * Please look at license.txt in info directory for more license detail.
4  ***/

5 package org.exoplatform.services.wsrp.producer.impl;
6
7 import org.apache.commons.logging.Log;
8 import org.exoplatform.services.log.LogService;
9 import org.exoplatform.services.portletcontainer.pci.*;
10 import org.exoplatform.services.wsrp.producer.PortletContainerProxy;
11 import org.exoplatform.services.wsrp.producer.ServiceDescriptionInterface;
12 import org.exoplatform.services.wsrp.type.*;
13 import org.exoplatform.services.wsrp.utils.Utils;
14
15 import java.rmi.RemoteException JavaDoc;
16 import java.util.*;
17
18 /**
19  * Created by the Exo Development team.
20  * Author : Tuan Nguyen
21  * tuan08@users.sourceforge.net
22  * Author : Mestrallet Benjamin
23  * benjmestrallet@users.sourceforge.net
24  * Date: 10 Dec. 2003
25  * Time: 09:40:23
26  * */

27 public class ServiceDescriptionInterfaceImpl implements ServiceDescriptionInterface {
28   private PortletContainerProxy container;
29   public static String JavaDoc[] localesArray = {"en", "fr"};
30   private WSRPConfiguration conf;
31   private Log log;
32
33   public ServiceDescriptionInterfaceImpl(PortletContainerProxy container,
34                                          WSRPConfiguration conf,
35                                          LogService logService) {
36     this.container = container;
37     this.conf = conf;
38     this.log = logService.getLog("org.exoplatform.services.wsrp");
39   }
40
41   public ServiceDescription getServiceDescription(RegistrationContext registrationContext,
42                                                   String JavaDoc[] desiredLocales) throws RemoteException JavaDoc {
43     log.debug("getServiceDescription entered with registrationContext : " + registrationContext);
44     Map portletMetaDatas = container.getAllPortletMetaData();
45     PortletDescription[] pdescription = new PortletDescription[portletMetaDatas.size()];
46     Set keys = portletMetaDatas.keySet();
47     int i = 0;
48     for (Iterator iter = keys.iterator(); iter.hasNext(); i++) {
49       String JavaDoc producerOfferedPortletHandle = (String JavaDoc) iter.next();
50       log.debug("fill service description with portlet description ");
51       pdescription[i] = container.getPortletDesciption(producerOfferedPortletHandle,
52                                                        desiredLocales);
53     }
54     ServiceDescription sD = new ServiceDescription() ;
55     sD.setRequiresRegistration(conf.isRegistrationRequired());
56     sD.setRegistrationPropertyDescription(new ModelDescription());//extension of the WSRP specs
57
sD.setRequiresInitCookie(CookieProtocol.none);
58     sD.setCustomModeDescriptions(getCustomModeDescriptions(container.getSupportedPortletModesWithDescriptions()));
59     sD.setCustomUserProfileItemDescriptions(new ItemDescription[0]);
60     sD.setCustomWindowStateDescriptions(getCustomWindowStateDescriptions(container.getSupportedWindowStatesWithDescriptions()));
61     sD.setLocales(localesArray);
62     sD.setOfferedPortlets(pdescription);
63     sD.setResourceList(new ResourceList());
64     return sD ;
65   }
66
67   private ItemDescription[] getCustomWindowStateDescriptions(Collection collection) {
68     Collection c = new ArrayList();
69     for (Iterator iter = collection.iterator(); iter.hasNext();) {
70       CustomWindowStateWithDescription element = (CustomWindowStateWithDescription) iter.next();
71       List l = element.getDescriptions();
72       ItemDescription iD = null;
73       for (Iterator iterator = l.iterator(); iterator.hasNext();) {
74         LocalisedDescription d = (LocalisedDescription) iterator.next();
75         iD = new ItemDescription();
76         iD.setItemName(element.getWindowState().toString());
77         iD.setDescription(Utils.getLocalizedString(d.getDescription(),
78                                                    d.getLocale().getLanguage()));
79         c.add(iD);
80       }
81     }
82     ItemDescription[] iDTab = new ItemDescription[c.size()];
83     int i = 0;
84     for (Iterator iter = c.iterator(); iter.hasNext(); i++) {
85       iDTab[i] = (ItemDescription) iter.next();
86     }
87     return iDTab;
88   }
89
90   private ItemDescription[] getCustomModeDescriptions(Collection collection) {
91     Collection c = new ArrayList();
92     for (Iterator iter = collection.iterator(); iter.hasNext();) {
93       CustomModeWithDescription element = (CustomModeWithDescription) iter.next();
94       List l = element.getDescriptions();
95       ItemDescription iD = null;
96       for (Iterator iterator = l.iterator(); iterator.hasNext();) {
97         LocalisedDescription d = (LocalisedDescription) iterator.next();
98         iD = new ItemDescription();
99         iD.setItemName(element.getPortletMode().toString());
100         iD.setDescription(Utils.getLocalizedString(d.getDescription(),
101                                                    d.getLocale().getLanguage()));
102         c.add(iD);
103       }
104     }
105     ItemDescription[] iDTab = new ItemDescription[c.size()];
106     int i = 0;
107     for (Iterator iter = c.iterator(); iter.hasNext(); i++) {
108       iDTab[i] = (ItemDescription) iter.next();
109     }
110     return iDTab;
111   }
112
113 }
Popular Tags