KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > wsrp > consumer > impl > ProducerImpl


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

5
6 package org.exoplatform.services.wsrp.consumer.impl;
7
8 import org.apache.commons.logging.Log;
9 import org.exoplatform.container.PortalContainer;
10 import org.exoplatform.services.log.LogService;
11 import org.exoplatform.services.wsrp.consumer.Producer;
12 import org.exoplatform.services.wsrp.exceptions.Faults;
13 import org.exoplatform.services.wsrp.exceptions.WSRPException;
14 import org.exoplatform.services.wsrp.intf.WSRP_v1_Markup_PortType;
15 import org.exoplatform.services.wsrp.intf.WSRP_v1_PortletManagement_PortType;
16 import org.exoplatform.services.wsrp.intf.WSRP_v1_Registration_PortType;
17 import org.exoplatform.services.wsrp.intf.WSRP_v1_ServiceDescription_PortType;
18 import org.exoplatform.services.wsrp.type.*;
19 import org.exoplatform.services.wsrp.wsdl.WSRPService;
20 import org.exoplatform.services.wsrp.wsdl.WSRPServiceLocator;
21
22 import javax.xml.rpc.ServiceException JavaDoc;
23 import java.net.MalformedURLException JavaDoc;
24 import java.net.URL JavaDoc;
25 import java.rmi.RemoteException JavaDoc;
26
27 /*
28  * @author Mestrallet Benjamin
29  * benjmestrallet@users.sourceforge.net
30  * Date: 2 févr. 2004
31  * Time: 23:10:08
32  */

33
34 public class ProducerImpl implements Producer , java.io.Serializable JavaDoc {
35
36   private String JavaDoc name;
37   private String JavaDoc ID;
38   private String JavaDoc description;
39   private String JavaDoc serviceDescriptionInterfaceEndpoint;
40   private transient WSRP_v1_ServiceDescription_PortType serviceDescriptionInterface;
41   private String JavaDoc markupInterfaceEndpoint;
42   private transient WSRP_v1_Markup_PortType markupInterface;
43   private String JavaDoc portletManagementInterfaceEndpoint;
44   private transient WSRP_v1_PortletManagement_PortType portletManagementInterface;
45   private String JavaDoc registrationInterfaceEndpoint;
46   private ServiceDescription serviceDescription;
47   private transient WSRP_v1_Registration_PortType registrationInterface;
48   private boolean registrationRequired;
49   private RegistrationData registrationData;
50   private RegistrationContext registrationContext;
51   private transient WSRPService service;
52   private String JavaDoc[] desiredLocales;
53   private transient Log log;
54
55   public ProducerImpl() {
56     init();
57   }
58
59   public void init() {
60     service = (WSRPService) PortalContainer.getInstance().
61         getComponentInstanceOfType(WSRPService.class);
62     ((WSRPServiceLocator)service).setMaintainSession(true);
63     this.log = ((LogService) PortalContainer.getInstance().
64         getComponentInstanceOfType(LogService.class)).getLog("org.exoplatform.services.wsrp");
65   }
66
67   public String JavaDoc[] getDesiredLocales() {
68     return desiredLocales;
69   }
70
71   public void setDesiredLocales(String JavaDoc[] desiredLocales) {
72     this.desiredLocales = desiredLocales;
73   }
74
75   public String JavaDoc getName() {
76     return name;
77   }
78
79   public void setName(String JavaDoc name) {
80     this.name = name;
81   }
82
83   public String JavaDoc getID() {
84     return ID;
85   }
86
87   public void setID(String JavaDoc ID) {
88     this.ID = ID;
89   }
90
91   public String JavaDoc getDescription() {
92     return description;
93   }
94
95   public void setDescription(String JavaDoc description) {
96     this.description = description;
97   }
98
99   //service description
100
public String JavaDoc getServiceDescriptionInterfaceEndpoint() {
101     return serviceDescriptionInterfaceEndpoint;
102   }
103
104   public void setServiceDescriptionInterfaceEndpoint(String JavaDoc serviceDescriptionInterfaceEndpoint) {
105     this.serviceDescriptionInterfaceEndpoint = serviceDescriptionInterfaceEndpoint;
106     serviceDescriptionInterface = null;
107   }
108
109   public WSRP_v1_ServiceDescription_PortType getServiceDescriptionInterface() {
110     if (serviceDescriptionInterface == null) {
111       try {
112         try {
113           serviceDescriptionInterface = service.
114               getWSRPServiceDescriptionService(new URL JavaDoc(serviceDescriptionInterfaceEndpoint));
115
116         } catch (MalformedURLException JavaDoc e) {
117           log.debug("Malformed URL : " + serviceDescriptionInterfaceEndpoint);
118           serviceDescriptionInterface = service.getWSRPServiceDescriptionService();
119         }
120       } catch (ServiceException JavaDoc e) {
121         e.printStackTrace();
122       }
123     }
124     return serviceDescriptionInterface;
125   }
126
127   public ServiceDescription getServiceDescription(boolean newRequest) throws WSRPException {
128     if (newRequest) {
129       return getServiceDescription();
130     } else {
131       return serviceDescription;
132     }
133   }
134
135   public ServiceDescription getServiceDescription() throws WSRPException {
136     if (desiredLocales == null) {
137       throw new IllegalStateException JavaDoc("Desired locales field must be set");
138     }
139     if (serviceDescription == null) {
140       updateServiceDescription();
141     }
142     return serviceDescription;
143   }
144
145   public PortletDescription getPortletDescription(String JavaDoc portletHandle) throws WSRPException {
146     if (serviceDescription == null) {
147       updateServiceDescription();
148     }
149     PortletDescription[] array = serviceDescription.getOfferedPortlets();
150     for (int i = 0; i < array.length; i++) {
151       PortletDescription portletDescription = array[i];
152       if (portletDescription.getPortletHandle().equals(portletHandle)) {
153         return portletDescription;
154       }
155     }
156     return null;
157   }
158
159   private void updateServiceDescription() {
160     try {
161       getServiceDescriptionInterface();
162       ServiceDescriptionRequest getServiceDescription = getServiceDescription(desiredLocales);
163       serviceDescription = serviceDescriptionInterface.getServiceDescription(getServiceDescription);
164     } catch (RemoteException JavaDoc e) {
165       e.printStackTrace();
166     }
167   }
168
169   private ServiceDescriptionRequest getServiceDescription(String JavaDoc[] desiredLocales) {
170     ServiceDescriptionRequest getServiceDescription = new ServiceDescriptionRequest();
171     getServiceDescription.setRegistrationContext(registrationContext);
172     getServiceDescription.setDesiredLocales(desiredLocales);
173     return getServiceDescription;
174   }
175
176   //markup
177
public String JavaDoc getMarkupInterfaceEndpoint() {
178     return markupInterfaceEndpoint;
179   }
180
181   public void setMarkupInterfaceEndpoint(String JavaDoc markupInterfaceEndpoint) {
182     this.markupInterfaceEndpoint = markupInterfaceEndpoint;
183   }
184
185   //portlet management
186
public String JavaDoc getPortletManagementInterfaceEndpoint() {
187     return portletManagementInterfaceEndpoint;
188   }
189
190   public void setPortletManagementInterfaceEndpoint(String JavaDoc portletManagementInterfaceEndpoint) {
191     this.portletManagementInterfaceEndpoint = portletManagementInterfaceEndpoint;
192     portletManagementInterface = null;
193   }
194
195   public WSRP_v1_PortletManagement_PortType getPortletManagementInterface() {
196     if (portletManagementInterface == null) {
197       try {
198         try {
199           portletManagementInterface = service.
200               getWSRPPortletManagementService(new URL JavaDoc(portletManagementInterfaceEndpoint));
201         } catch (MalformedURLException JavaDoc e) {
202           portletManagementInterface = service.getWSRPPortletManagementService();
203         }
204       } catch (ServiceException JavaDoc e) {
205         e.printStackTrace();
206       }
207     }
208     return portletManagementInterface;
209   }
210
211   public boolean isPortletManagementInferfaceSupported() {
212     if (portletManagementInterface == null) {
213       getPortletManagementInterface();
214     }
215     if (portletManagementInterface == null) {
216       return false;
217     } else {
218       return true;
219     }
220   }
221
222   //registration
223
public String JavaDoc getRegistrationInterfaceEndpoint() {
224     return registrationInterfaceEndpoint;
225   }
226
227   public void setRegistrationInterfaceEndpoint(String JavaDoc registrationInterfaceEndpoint) {
228     this.registrationInterfaceEndpoint = registrationInterfaceEndpoint;
229     registrationInterface = null;
230   }
231
232   public WSRP_v1_Registration_PortType getRegistrationInterface() {
233     if (registrationInterface == null) {
234       try {
235         try {
236           registrationInterface = service.
237               getWSRPRegistrationService(new URL JavaDoc(registrationInterfaceEndpoint));
238         } catch (MalformedURLException JavaDoc e) {
239           registrationInterface = service.getWSRPRegistrationService();
240         }
241       } catch (ServiceException JavaDoc e) {
242         e.printStackTrace();
243       }
244     }
245     return registrationInterface;
246   }
247
248   public boolean isRegistrationRequired() {
249     if (serviceDescription == null) {
250       updateServiceDescription();
251     }
252     return serviceDescription.isRequiresRegistration();
253   }
254
255   public RegistrationData getRegistrationData() {
256     return registrationData;
257   }
258
259   public void setRegistrationData(RegistrationData registrationData) {
260     this.registrationData = registrationData;
261   }
262
263   public RegistrationContext getRegistrationContext() throws WSRPException {
264     return registrationContext;
265   }
266
267   public RegistrationContext register(RegistrationData registrationData) throws WSRPException {
268     if (registrationInterface == null) {
269       getRegistrationInterface();
270     }
271     try {
272       this.registrationContext = registrationInterface.register(registrationData);
273       this.registrationData = registrationData;
274     } catch (RemoteException JavaDoc e) {
275       e.printStackTrace();
276     }
277     return registrationContext;
278   }
279
280   public RegistrationState modifyRegistration(RegistrationData registrationData) throws WSRPException {
281     ModifyRegistrationRequest modifyRegistration = new ModifyRegistrationRequest();
282     modifyRegistration.setRegistrationData(registrationData);
283     modifyRegistration.setRegistrationContext(registrationContext);
284     try {
285       return registrationInterface.modifyRegistration(modifyRegistration);
286     } catch (RemoteException JavaDoc e) {
287       throw new WSRPException(Faults.INVALID_REGISTRATION_FAULT, e);
288     }
289   }
290
291   public ReturnAny deregister() throws WSRPException {
292     if (registrationInterface == null) {
293       getRegistrationInterface();
294     }
295     try {
296       return registrationInterface.deregister(registrationContext);
297     } catch (RemoteException JavaDoc e) {
298       throw new WSRPException(Faults.INVALID_REGISTRATION_FAULT, e);
299     } finally {
300       registrationContext = null;
301       registrationData = null;
302     }
303   }
304
305   public boolean isRegistrationInterfaceSupported() {
306     if (serviceDescriptionInterface == null) {
307       getServiceDescriptionInterface();
308     }
309     if (serviceDescriptionInterface == null) {
310       return false;
311     } else {
312       return true;
313     }
314   }
315
316
317 }
318
Popular Tags