001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.wsrp;
022:
023: import com.liferay.portal.service.PortletLocalServiceUtil;
024: import com.liferay.portal.wsrp.util.WSRPUtil;
025: import com.liferay.util.CollectionFactory;
026:
027: import java.util.ArrayList;
028: import java.util.Iterator;
029: import java.util.List;
030: import java.util.Map;
031:
032: import org.apache.wsrp4j.exception.WSRPException;
033: import org.apache.wsrp4j.producer.provider.ConsumerConfiguredPortlet;
034: import org.apache.wsrp4j.producer.provider.Portlet;
035: import org.apache.wsrp4j.producer.provider.PortletPool;
036: import org.apache.wsrp4j.producer.provider.ProducerOfferedPortlet;
037: import org.apache.wsrp4j.producer.provider.driver.ConsumerConfiguredPortletImpl;
038: import org.apache.wsrp4j.producer.provider.driver.ProducerOfferedPortletImpl;
039:
040: /**
041: * <a href="PortletPoolImpl.java.html"><b><i>View Source</i></b></a>
042: *
043: * @author Michael Young
044: *
045: */
046: public class PortletPoolImpl implements PortletPool {
047:
048: public Iterator getAllConsumerConfiguredPortlets() {
049: return _consumerConfiguredPortlets.values().iterator();
050: }
051:
052: public Iterator getAllProducerOfferedPortlets() {
053: long companyId = WSRPUtil.getCompanyId();
054: Iterator wsrpPortletsIt = null;
055: List wsrpPortlets = new ArrayList();
056:
057: try {
058: List liferayPortlets = PortletLocalServiceUtil
059: .getPortlets(companyId);
060:
061: for (int i = 0; i < liferayPortlets.size(); i++) {
062: com.liferay.portal.model.Portlet liferayPortlet = (com.liferay.portal.model.Portlet) liferayPortlets
063: .get(i);
064:
065: Portlet producerPortlet = _createProducerPortlet(liferayPortlet);
066:
067: wsrpPortlets.add(producerPortlet);
068: }
069: } catch (Exception e) {
070: e.printStackTrace();
071: }
072:
073: return wsrpPortlets.iterator();
074: }
075:
076: public Portlet clone(String portletHandle) throws WSRPException {
077: Portlet portlet = (Portlet) _consumerConfiguredPortlets
078: .get(portletHandle);
079:
080: // we don't really support cloning right now
081: // this is done be compliant with the wsrp4j implementation
082: if (portlet != null) {
083: return null;
084: } else {
085: portlet = _createConsumerPortlet(portletHandle);
086: _consumerConfiguredPortlets.put(portletHandle, portlet);
087: }
088:
089: return portlet;
090: }
091:
092: public boolean destroy(String portletHandle) throws WSRPException {
093: // we do not support cloning yet
094: return false;
095: }
096:
097: public Iterator destroySeveral(Iterator portletHandles) {
098: // we do not support cloning yet
099: 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: } catch (Exception e) {
120: }
121:
122: return wsrpPortlet;
123: }
124:
125: private Portlet _createProducerPortlet(String portletHandle) {
126: ProducerOfferedPortlet producerPortlet = new ProducerOfferedPortletImpl();
127:
128: producerPortlet.setPortletHandle(portletHandle);
129: producerPortlet.setRegistrationRequired(false);
130:
131: return producerPortlet;
132: }
133:
134: private Portlet _createConsumerPortlet(String portletHandle) {
135: ConsumerConfiguredPortlet consumerPortlet = new ConsumerConfiguredPortletImpl();
136:
137: consumerPortlet.setPortletHandle(portletHandle);
138: consumerPortlet.setParentHandle(portletHandle);
139:
140: return consumerPortlet;
141: }
142:
143: private Portlet _createProducerPortlet(
144: com.liferay.portal.model.Portlet liferayPortlet) {
145: return _createProducerPortlet(liferayPortlet.getPortletId());
146: }
147:
148: private Map _consumerConfiguredPortlets = CollectionFactory
149: .getHashMap();
150:
151: }
|