01: /* Copyright 2004 The JA-SIG Collaborative. All rights reserved.
02: * See license distributed with this file and
03: * available online at http://www.uportal.org/license.html
04: */
05:
06: package org.jasig.portal.wsrp.consumer.portlet;
07:
08: import java.util.Map;
09:
10: import oasis.names.tc.wsrp.v1.types.RegistrationData;
11:
12: import org.apache.wsrp4j.consumer.PortletKey;
13: import org.apache.wsrp4j.consumer.Producer;
14: import org.apache.wsrp4j.consumer.ProducerRegistry;
15: import org.apache.wsrp4j.consumer.driver.PortletKeyImpl;
16: import org.apache.wsrp4j.consumer.driver.ProducerImpl;
17: import org.apache.wsrp4j.consumer.util.ConsumerConstants;
18: import org.apache.wsrp4j.exception.WSRPException;
19:
20: /**
21: * Custom version of WSRP4J Consumer Proxy Portlet that
22: * reads Portlet preferences in order to determine the
23: * producer configuration. The ID of a Producer will be
24: * derived from the Portlet preferences themselves.
25: * This is different from the WSRP4J ProxyPortlet which
26: * relies on a pre-configured Producer registry.
27: * @author Ken Weiner, kweiner@unicon.net
28: * @version $Revision: 34799 $
29: */
30: public class ProxyPortlet extends
31: org.apache.wsrp4j.consumer.portlet.impl.ProxyPortlet {
32:
33: private String markupUrl;
34: private String serviceDescUrl;
35: private String regUrl;
36: private String mgmtUrl;
37:
38: /**
39: * Construct producer ID by concatinating the 4 producer URLs
40: * and Consumer registration data.
41: */
42: protected PortletKey getPortletKey(Map preferences) {
43: PortletKey portletKey = null;
44: String portletHandle = (String) preferences
45: .get(ConsumerConstants.WSRP_PORTLET_HANDLE);
46: markupUrl = (String) preferences
47: .get(ConsumerConstants.WSRP_MARKUP_URL);
48: serviceDescUrl = (String) preferences
49: .get(ConsumerConstants.WSRP_SERVICE_DESC_URL);
50: regUrl = (String) preferences
51: .get(ConsumerConstants.WSRP_REGISTRATION_URL);
52: mgmtUrl = (String) preferences
53: .get(ConsumerConstants.WSRP_PORTLET_MGMT_URL);
54: String producerId = markupUrl + serviceDescUrl + regUrl
55: + mgmtUrl;
56: portletKey = new PortletKeyImpl(portletHandle, producerId);
57: //System.out.println("portletKey=" + portletKey);
58: return portletKey;
59: }
60:
61: protected Producer getProducer(String producerID)
62: throws WSRPException {
63: ProducerRegistry producerRegistry = getConsumerEnvironment()
64: .getProducerRegistry();
65: Producer producer = producerRegistry.getProducer(producerID);
66: if (producer == null) {
67: // Create producer and register it
68: RegistrationData regData = new RegistrationData();
69: regData.setConsumerName("uPortal WSRP Consumer");
70: regData.setConsumerAgent("uPortal WSRP Consumer");
71: producer = new ProducerImpl(producerID, markupUrl,
72: serviceDescUrl, regUrl, mgmtUrl, regData);
73: producerRegistry.addProducer(producer);
74: }
75: //System.out.println("returning producer=" + producer.toString());
76: return producer;
77:
78: }
79:
80: }
|