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