1
22
23 package com.liferay.portal.wsrp;
24
25 import com.liferay.portal.service.PortletLocalServiceUtil;
26 import com.liferay.portal.wsrp.util.WSRPUtil;
27
28 import java.util.ArrayList;
29 import java.util.HashMap;
30 import java.util.Iterator;
31 import java.util.List;
32 import java.util.Map;
33
34 import org.apache.wsrp4j.exception.WSRPException;
35 import org.apache.wsrp4j.producer.provider.ConsumerConfiguredPortlet;
36 import org.apache.wsrp4j.producer.provider.Portlet;
37 import org.apache.wsrp4j.producer.provider.PortletPool;
38 import org.apache.wsrp4j.producer.provider.ProducerOfferedPortlet;
39 import org.apache.wsrp4j.producer.provider.driver.ConsumerConfiguredPortletImpl;
40 import org.apache.wsrp4j.producer.provider.driver.ProducerOfferedPortletImpl;
41
42
48 public class PortletPoolImpl implements PortletPool {
49
50 public Iterator getAllConsumerConfiguredPortlets() {
51 return _consumerConfiguredPortlets.values().iterator();
52 }
53
54 public Iterator getAllProducerOfferedPortlets() {
55 long companyId = WSRPUtil.getCompanyId();
56 Iterator wsrpPortletsIt = null;
57 List wsrpPortlets = new ArrayList();
58
59 try {
60 List liferayPortlets = PortletLocalServiceUtil.getPortlets(companyId);
61
62 for (int i = 0; i < liferayPortlets.size(); i++) {
63 com.liferay.portal.model.Portlet liferayPortlet = (com.liferay.portal.model.Portlet) liferayPortlets
64 .get(i);
65
66 Portlet producerPortlet = _createProducerPortlet(liferayPortlet);
67
68 wsrpPortlets.add(producerPortlet);
69 }
70 }
71 catch (Exception e) {
72 e.printStackTrace();
73 }
74
75 return wsrpPortlets.iterator();
76 }
77
78 public Portlet clone(String portletHandle) throws WSRPException {
79 Portlet portlet = (Portlet) _consumerConfiguredPortlets
80 .get(portletHandle);
81
82 if (portlet != null) {
85 return null;
86 }
87 else {
88 portlet = _createConsumerPortlet(portletHandle);
89 _consumerConfiguredPortlets.put(portletHandle, portlet);
90 }
91
92 return portlet;
93 }
94
95 public boolean destroy(String portletHandle) throws WSRPException {
96 return false;
98 }
99
100 public Iterator destroySeveral(Iterator portletHandles) {
101 return null;
103 }
104
105 public Portlet get(String portletHandle) throws WSRPException {
106 Portlet wsrpPortlet = null;
107
108 try {
109 wsrpPortlet = (Portlet) _consumerConfiguredPortlets
110 .get(portletHandle);
111
112 if (wsrpPortlet == null) {
113 long companyId = WSRPUtil.getCompanyId();
114
115 com.liferay.portal.model.Portlet liferayPortlet = PortletLocalServiceUtil
116 .getPortletById(companyId, portletHandle);
117
118 if (liferayPortlet != null) {
119 wsrpPortlet = _createProducerPortlet(liferayPortlet);
120 }
121 }
122 }
123 catch (Exception e) {
124 }
125
126 return wsrpPortlet;
127 }
128
129 private Portlet _createProducerPortlet(String portletHandle) {
130 ProducerOfferedPortlet producerPortlet = new ProducerOfferedPortletImpl();
131
132 producerPortlet.setPortletHandle(portletHandle);
133 producerPortlet.setRegistrationRequired(false);
134
135 return producerPortlet;
136 }
137
138 private Portlet _createConsumerPortlet(String portletHandle) {
139 ConsumerConfiguredPortlet consumerPortlet = new ConsumerConfiguredPortletImpl();
140
141 consumerPortlet.setPortletHandle(portletHandle);
142 consumerPortlet.setParentHandle(portletHandle);
143
144 return consumerPortlet;
145 }
146
147 private Portlet _createProducerPortlet(
148 com.liferay.portal.model.Portlet liferayPortlet) {
149 return _createProducerPortlet(liferayPortlet.getPortletId());
150 }
151
152 private Map _consumerConfiguredPortlets = new HashMap();
153
154 }