001: /**
002: * $Id: ProducerImpl.java,v 1.8 2006/06/16 10:59:45 kk155903 Exp $
003: * Copyright 2003 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.wsrp.producer.impl;
014:
015: import java.util.Set;
016:
017: import javax.servlet.http.HttpServletRequest;
018: import javax.servlet.ServletContext;
019: import com.iplanet.am.sdk.AMOrganizationalUnit;
020: import com.iplanet.sso.SSOToken;
021:
022: import com.sun.portal.desktop.dp.DPRoot;
023:
024: import com.sun.portal.wsrp.producer.Producer;
025: import com.sun.portal.wsrp.producer.ISConnection;
026: import com.sun.portal.wsrp.producer.ISConstants;
027: import com.sun.portal.wsrp.producer.ProducerException;
028: import com.sun.portal.wsrp.producer.DPConnection;
029: import com.sun.portal.wsrp.producer.ProducerRegistryManager;
030: import com.sun.portal.wsrp.producer.ProducerDN;
031:
032: import com.sun.portal.wsrp.producer.markup.MarkupManager;
033: import com.sun.portal.wsrp.producer.markup.impl.MarkupManagerImpl;
034:
035: import com.sun.portal.wsrp.producer.registration.RegistrationManager;
036: import com.sun.portal.wsrp.producer.registration.impl.RegistrationManagerImpl;
037:
038: import com.sun.portal.wsrp.producer.servicedescription.ServiceDescriptionManager;
039: import com.sun.portal.wsrp.producer.servicedescription.impl.ServiceDescriptionManagerImpl;
040:
041: import com.sun.portal.wsrp.producer.portletmanagement.PortletManagementManager;
042: import com.sun.portal.wsrp.producer.portletmanagement.impl.PortletManagementManagerImpl;
043:
044: public class ProducerImpl implements Producer, ISConstants {
045: private ServiceDescriptionManager serviceDescriptionManager = null;
046: private MarkupManager markupManager = null;
047: private RegistrationManager registrationManager = null;
048: private PortletManagementManager portletManagementManager = null;
049:
050: private ISConnection isConnection = null;
051:
052: private String producerKey = null;
053: private String organization = null;
054: private String instanceName = null;
055: private String producerDN = null;
056:
057: private AMOrganizationalUnit producer = null;
058:
059: private HttpServletRequest req = null;
060: private ServletContext ctx = null;
061: private SSOToken token = null;
062: private String portalId = null;
063:
064: private void init(HttpServletRequest req, ServletContext ctx,
065: SSOToken token, String producerKey, String organization,
066: String instanceName) throws ProducerException {
067: this .req = req;
068: this .ctx = ctx;
069: this .token = token;
070: this .producerKey = producerKey;
071: this .organization = organization;
072: this .instanceName = instanceName;
073: this .isConnection = new ISConnection(token);
074: this .producerDN = ProducerDN.getProducerDN(organization,
075: instanceName, portalId);
076: }
077:
078: private void init(SSOToken token, String producerKey,
079: String organization, String instanceName)
080: throws ProducerException {
081: this .token = token;
082: this .producerKey = producerKey;
083: this .organization = organization;
084: this .instanceName = instanceName;
085: this .isConnection = new ISConnection(token, portalId);
086: this .producerDN = ProducerDN.getProducerDN(organization,
087: instanceName, portalId);
088: }
089:
090: public ProducerImpl(HttpServletRequest req, ServletContext ctx,
091: SSOToken token, String key) throws ProducerException {
092: ProducerRegistryManager prm = ProducerRegistryManager
093: .getRegistryManager();
094: String org = prm.getOrganization(key);
095: String name = prm.getInstance(key);
096:
097: init(req, ctx, token, key, org, name);
098: }
099:
100: public ProducerImpl(SSOToken token, String key, String portalId)
101: throws ProducerException {
102: this .portalId = portalId;
103: ProducerRegistryManager prm = ProducerRegistryManager
104: .getRegistryManager(portalId);
105: String org = prm.getOrganization(key);
106: String name = prm.getInstance(key);
107:
108: init(token, key, org, name);
109: }
110:
111: public ProducerImpl(HttpServletRequest req, ServletContext ctx,
112: SSOToken token, String organization, String instance)
113: throws ProducerException {
114: ProducerRegistryManager prm = ProducerRegistryManager
115: .getRegistryManager();
116: String pk = prm.getKey(organization, instance);
117:
118: init(req, ctx, token, pk, organization, instance);
119: }
120:
121: public boolean requiresRegistration() throws ProducerException {
122: String requiresRegistration = isConnection.getStringAttribute(
123: producerDN, ATTR_REQUIRES_REGISTRATION);
124:
125: if (requiresRegistration == null) {
126: return true;
127: }
128:
129: if (requiresRegistration.equalsIgnoreCase("true")) {
130: return true;
131: }
132:
133: return false;
134: }
135:
136: public void setRequiresRegistration(boolean requires)
137: throws ProducerException {
138: Boolean newValue = requires ? Boolean.TRUE : Boolean.FALSE;
139: isConnection.setStringAttribute(producerDN,
140: ATTR_REQUIRES_REGISTRATION, newValue.toString());
141: }
142:
143: public boolean inbandRegistrationSupported()
144: throws ProducerException {
145: String isInbandRegistrationSupported = isConnection
146: .getStringAttribute(producerDN,
147: ATTR_SUPPORTS_IN_BAND_REGISTRATION);
148:
149: if (isInbandRegistrationSupported == null) {
150: return false;
151: }
152:
153: if (isInbandRegistrationSupported.equalsIgnoreCase("true")) {
154: return true;
155: }
156:
157: return false;
158: }
159:
160: public void setInbandRegistrationSupported(boolean supported)
161: throws ProducerException {
162: Boolean newValue = supported ? Boolean.TRUE : Boolean.FALSE;
163: isConnection
164: .setStringAttribute(producerDN,
165: ATTR_SUPPORTS_IN_BAND_REGISTRATION, newValue
166: .toString());
167: }
168:
169: public Set getPortletChannelNames() throws ProducerException {
170: DPFilter filter = null;
171: if (req != null) {
172: filter = new DPFilter(req, organization);
173: } else {
174: filter = new DPFilter(portalId, organization);
175: }
176: return filter.getExistingChannels();
177: }
178:
179: public String getProducerKey() {
180: return producerKey;
181: }
182:
183: public String getOrganization() {
184: return organization;
185: }
186:
187: public String getInstanceName() {
188: return instanceName;
189: }
190:
191: public boolean isEnabled() throws ProducerException {
192: String dn = ProducerDN.getProducerDN(organization,
193: instanceName, portalId);
194: String enabled = isConnection.getStringAttribute(dn,
195: ATTR_STATUS);
196: return Boolean.valueOf(enabled).booleanValue();
197: }
198:
199: public void setIsEnabled(boolean enabled) throws ProducerException {
200: String dn = ProducerDN.getProducerDN(organization,
201: instanceName, portalId);
202: Boolean newValue = enabled ? Boolean.TRUE : Boolean.FALSE;
203: isConnection.setStringAttribute(dn, ATTR_STATUS, newValue
204: .toString());
205: }
206:
207: public ServiceDescriptionManager getServiceDescriptionManager()
208: throws ProducerException {
209: if (serviceDescriptionManager == null) {
210: //
211: // get the org-level dp root
212: //
213: DPConnection dpc = null;
214: DPRoot dpr = null;
215:
216: if (req != null) {
217: dpc = new DPConnection(req);
218: dpr = dpc.getDPRoot(organization);
219: serviceDescriptionManager = new ServiceDescriptionManagerImpl(
220: ctx, req, token, getProducerKey(), dpr);
221: } else {
222: dpc = new DPConnection(portalId);
223: dpr = dpc.getDPRoot(organization);
224: serviceDescriptionManager = new ServiceDescriptionManagerImpl(
225: token, getProducerKey(), dpr, portalId);
226: }
227: }
228:
229: return serviceDescriptionManager;
230: }
231:
232: public MarkupManager getMarkupManager() throws ProducerException {
233: if (markupManager == null) {
234: markupManager = new MarkupManagerImpl(req, ctx, token,
235: getProducerKey());
236: }
237:
238: return markupManager;
239: }
240:
241: public RegistrationManager getRegistrationManager()
242: throws ProducerException {
243: if (registrationManager == null) {
244: registrationManager = new RegistrationManagerImpl(token,
245: getProducerKey(), portalId);
246: }
247:
248: return registrationManager;
249: }
250:
251: public PortletManagementManager getPortletManagementManager()
252: throws ProducerException {
253: if (portletManagementManager == null) {
254: portletManagementManager = new PortletManagementManagerImpl(
255: req, ctx, token, getProducerKey());
256: }
257:
258: return portletManagementManager;
259: }
260: }
|