001: /******************************************************************************
002: * JBoss, a division of Red Hat *
003: * Copyright 2006, Red Hat Middleware, LLC, and individual *
004: * contributors as indicated by the @authors tag. See the *
005: * copyright.txt in the distribution for a full listing of *
006: * individual contributors. *
007: * *
008: * This is free software; you can redistribute it and/or modify it *
009: * under the terms of the GNU Lesser General Public License as *
010: * published by the Free Software Foundation; either version 2.1 of *
011: * the License, or (at your option) any later version. *
012: * *
013: * This software is distributed in the hope that it will be useful, *
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
016: * Lesser General Public License for more details. *
017: * *
018: * You should have received a copy of the GNU Lesser General Public *
019: * License along with this software; if not, write to the Free *
020: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
021: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
022: ******************************************************************************/package org.jboss.portal.test.wsrp.framework;
023:
024: import org.jboss.portal.common.util.Tools;
025: import org.jboss.portal.wsrp.WSRPConstants;
026: import org.jboss.portal.wsrp.WSRPTypeFactory;
027: import org.jboss.portal.wsrp.core.CookieProtocol;
028: import org.jboss.portal.wsrp.core.GetServiceDescription;
029: import org.jboss.portal.wsrp.core.InvalidRegistrationFault;
030: import org.jboss.portal.wsrp.core.OperationFailedFault;
031: import org.jboss.portal.wsrp.core.PortletDescription;
032: import org.jboss.portal.wsrp.core.PropertyDescription;
033: import org.jboss.portal.wsrp.core.ServiceDescription;
034: import org.jboss.portal.wsrp.core.WSRP_v1_ServiceDescription_PortType;
035:
036: import java.rmi.RemoteException;
037: import java.util.List;
038:
039: /**
040: * @author <a href="mailto:chris.laprun@jboss.com?subject=org.jboss.portal.test.wsrp.framework.ServiceDescriptionBehavior">Chris
041: * Laprun</a>
042: * @version $Revision: 8784 $
043: * @since 2.6
044: */
045: public class ServiceDescriptionBehavior extends TestProducerBehavior
046: implements WSRP_v1_ServiceDescription_PortType {
047: protected ServiceDescription serviceDescription;
048: private static final ServiceDescription DEFAULT_SERVICE_DESCRIPTION = WSRPTypeFactory
049: .createServiceDescription(false);
050: public static final ServiceDescriptionBehavior DEFAULT = new ServiceDescriptionBehavior();
051:
052: public ServiceDescriptionBehavior() {
053: //Prepare sample ServiceDescription
054: serviceDescription = WSRPTypeFactory
055: .createServiceDescription(false);
056: }
057:
058: public ServiceDescription getServiceDescription(
059: GetServiceDescription getServiceDescription)
060: throws OperationFailedFault, InvalidRegistrationFault,
061: RemoteException {
062: incrementCallCount();
063: return serviceDescription;
064: }
065:
066: public void setRequiresRegistration(boolean requiresRegistration) {
067: serviceDescription
068: .setRequiresRegistration(requiresRegistration);
069: }
070:
071: public void setRequiresInitCookie(CookieProtocol requiresInitCookie) {
072: serviceDescription.setRequiresInitCookie(requiresInitCookie);
073: }
074:
075: public void setServiceDescription(boolean requiresRegistration,
076: int numberOfProps) {
077: serviceDescription = createServiceDescription(
078: requiresRegistration, numberOfProps);
079: }
080:
081: public static ServiceDescription getDefaultServiceDescription() {
082: return DEFAULT_SERVICE_DESCRIPTION;
083: }
084:
085: public void addPortletDescription(
086: PortletDescription portletDescription) {
087: PortletDescription[] initial = serviceDescription
088: .getOfferedPortlets();
089: if (initial == null || initial.length == 0) {
090: serviceDescription
091: .setOfferedPortlets(new PortletDescription[] { portletDescription });
092: } else {
093: List portlets = Tools.toList(initial);
094: portlets.add(portletDescription);
095: serviceDescription
096: .setOfferedPortlets((PortletDescription[]) portlets
097: .toArray(new PortletDescription[0]));
098: }
099: }
100:
101: public static ServiceDescription createServiceDescription(
102: boolean requiresRegistration, int numberOfProperties) {
103: ServiceDescription sd = WSRPTypeFactory
104: .createServiceDescription(requiresRegistration);
105:
106: if (requiresRegistration) {
107: PropertyDescription[] descriptions = new PropertyDescription[numberOfProperties];
108: for (int i = 0; i < numberOfProperties; i++) {
109: descriptions[i] = WSRPTypeFactory
110: .createPropertyDescription("prop" + i,
111: WSRPConstants.XSD_STRING);
112: }
113: sd.setRegistrationPropertyDescription(WSRPTypeFactory
114: .createModelDescription(descriptions));
115: }
116:
117: return sd;
118: }
119: }
|