001: /******************************************************************************
002: * JBoss, a division of Red Hat *
003: * Copyright 2007, 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.wsrp.WSRPExceptionFactory;
025: import org.jboss.portal.wsrp.core.InvalidHandleFault;
026:
027: import java.util.HashMap;
028: import java.util.Map;
029:
030: /**
031: * @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
032: * @version $Revision: 9360 $
033: * @since 2.6
034: */
035: public class BehaviorRegistry {
036: private final Map<String, MarkupBehavior> behaviors = new HashMap<String, MarkupBehavior>();
037: private PortletManagementBehavior portletManagementBehavior;
038: private ServiceDescriptionBehavior serviceDescriptionBehavior;
039: private RegistrationBehavior registrationBehavior;
040:
041: public ServiceDescriptionBehavior getServiceDescriptionBehavior() {
042: // this is required since the consumer will try to access the producer as soon as it's started and the test
043: // producer will not be properly setup at that time since it's set up in the test's setUp method...
044: if (serviceDescriptionBehavior == null) {
045: return ServiceDescriptionBehavior.DEFAULT;
046: }
047:
048: return serviceDescriptionBehavior;
049: }
050:
051: public void clear() {
052: behaviors.clear();
053: }
054:
055: public MarkupBehavior getMarkupBehaviorFor(String handle)
056: throws InvalidHandleFault {
057: if (behaviors.containsKey(handle)) {
058: return behaviors.get(handle);
059: }
060: throw WSRPExceptionFactory.throwSOAPFaultException(
061: WSRPExceptionFactory.INVALID_HANDLE,
062: "There is no registered MarkupBehavior for handle '"
063: + handle + "'", null);
064: }
065:
066: public void registerMarkupBehavior(MarkupBehavior behavior) {
067: for (String handle : behavior.getSupportedHandles()) {
068: MarkupBehavior existing = behaviors.get(handle);
069: if (existing != null) {
070: throw new IllegalArgumentException(
071: "Cannot register behavior "
072: + behavior.getClass().getName()
073: + " because it uses a handle '"
074: + handle
075: + "' that's already associated with behavior "
076: + existing.getClass().getName());
077: }
078: behaviors.put(handle, behavior);
079: }
080: }
081:
082: public PortletManagementBehavior getPortletManagementBehavior() {
083: return portletManagementBehavior;
084: }
085:
086: public void setPortletManagementBehavior(
087: PortletManagementBehavior portletManagementBehavior) {
088: this .portletManagementBehavior = portletManagementBehavior;
089: }
090:
091: public void setServiceDescriptionBehavior(
092: ServiceDescriptionBehavior serviceDescriptionBehavior) {
093: this .serviceDescriptionBehavior = serviceDescriptionBehavior;
094: }
095:
096: public RegistrationBehavior getRegistrationBehavior() {
097: return registrationBehavior;
098: }
099:
100: public void setRegistrationBehavior(
101: RegistrationBehavior registrationBehavior) {
102: this.registrationBehavior = registrationBehavior;
103: }
104: }
|