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.wsrp.services;
023:
024: import org.jboss.portal.common.util.ParameterValidation;
025: import org.jboss.portal.wsrp.consumer.EndpointConfigurationInfo;
026: import org.jboss.portal.wsrp.core.WSRP_v1_Markup_PortType;
027: import org.jboss.portal.wsrp.core.WSRP_v1_PortletManagement_PortType;
028: import org.jboss.portal.wsrp.core.WSRP_v1_Registration_PortType;
029: import org.jboss.portal.wsrp.core.WSRP_v1_ServiceDescription_PortType;
030:
031: import javax.xml.rpc.Service;
032: import javax.xml.rpc.Stub;
033:
034: /**
035: * @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
036: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
037: * @version $Revision: 8784 $
038: * @since 2.4
039: */
040: public class PerEndpointSOAPInvokerServiceFactory extends
041: AbstractSOAPServiceFactory {
042:
043: /** . */
044: protected String serviceDescriptionURL = EndpointConfigurationInfo.UNSET;
045:
046: /** . */
047: protected String markupURL = EndpointConfigurationInfo.UNSET;
048:
049: /** . */
050: protected String registrationURL;
051:
052: /** . */
053: protected String portletManagementURL;
054:
055: public String getServiceDescriptionURL() {
056: return serviceDescriptionURL;
057: }
058:
059: public void setServiceDescriptionURL(String serviceDescriptionURL) {
060: ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(
061: serviceDescriptionURL,
062: "Mandatory Service Description interface", null);
063: this .serviceDescriptionURL = serviceDescriptionURL;
064: }
065:
066: public String getMarkupURL() {
067: return markupURL;
068: }
069:
070: public void setMarkupURL(String markupURL) {
071: ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(
072: markupURL, "Mandatory Markup interface", null);
073: this .markupURL = markupURL;
074: }
075:
076: public String getRegistrationURL() {
077: return registrationURL;
078: }
079:
080: public void setRegistrationURL(String registrationURL) {
081: this .registrationURL = registrationURL;
082: }
083:
084: public String getPortletManagementURL() {
085: return portletManagementURL;
086: }
087:
088: public void setPortletManagementURL(String portletManagementURL) {
089: this .portletManagementURL = portletManagementURL;
090: }
091:
092: /** If retrieve object is of javax.xml.rpc.Service class, we're using the WS stack and we need to get the port. */
093: protected Object getStubFromService(Class serviceClass,
094: Service service) throws Exception {
095: log.debug("Unwrapping service " + service + " for class "
096: + serviceClass);
097: Object stub = service.getPort(serviceClass);
098:
099: //
100: String portAddress = null;
101: boolean isMandatoryInterface = false;
102: if (WSRP_v1_ServiceDescription_PortType.class
103: .equals(serviceClass)) {
104: portAddress = serviceDescriptionURL;
105: isMandatoryInterface = true;
106: } else if (WSRP_v1_Markup_PortType.class.equals(serviceClass)) {
107: portAddress = markupURL;
108: isMandatoryInterface = true;
109: } else if (WSRP_v1_Registration_PortType.class
110: .equals(serviceClass)) {
111: portAddress = registrationURL;
112: } else if (WSRP_v1_PortletManagement_PortType.class
113: .equals(serviceClass)) {
114: portAddress = portletManagementURL;
115: }
116:
117: //
118: if (portAddress != null) {
119: log.debug("Setting the end point to: " + portAddress);
120: ((Stub) stub)._setProperty(Stub.ENDPOINT_ADDRESS_PROPERTY,
121: portAddress);
122: } else {
123: if (isMandatoryInterface) {
124: throw new IllegalStateException(
125: "Mandatory interface URLs were not properly initialized: no proper service URL for "
126: + serviceClass.getName());
127: } else {
128: throw new IllegalStateException(
129: "No URL was provided for optional interface "
130: + serviceClass.getName());
131: }
132: }
133:
134: //
135: return stub;
136: }
137:
138: public boolean isAvailable() {
139: return !failed
140: && !EndpointConfigurationInfo.UNSET
141: .equals(serviceDescriptionURL)
142: && !EndpointConfigurationInfo.UNSET.equals(markupURL);
143: }
144: }
|