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.deployment;
023:
024: import org.jboss.deployment.DeploymentException;
025: import org.jboss.deployment.DeploymentInfo;
026: import org.jboss.deployment.SubDeployerSupport;
027: import org.jboss.portal.common.xml.NullEntityResolver;
028: import org.jboss.portal.wsrp.WSRPConsumer;
029: import org.jboss.portal.wsrp.consumer.ConsumerException;
030: import org.jboss.portal.wsrp.consumer.ConsumerRegistry;
031: import org.jboss.xb.binding.ObjectModelFactory;
032: import org.jboss.xb.binding.Unmarshaller;
033: import org.jboss.xb.binding.UnmarshallerFactory;
034: import org.xml.sax.EntityResolver;
035:
036: import java.net.URL;
037:
038: /**
039: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
040: * @version $Revision: 9360 $
041: */
042: public class WSRPDeployer extends SubDeployerSupport implements
043: WSRPDeployerMBean {
044: /** . */
045: private static final String[] DEFAULT_ENHANCED_SUFFIXES = new String[] { "800:-wsrp.xml" };
046:
047: public WSRPDeployer() {
048: setEnhancedSuffixes(DEFAULT_ENHANCED_SUFFIXES);
049: }
050:
051: private ConsumerRegistry consumerRegistry;
052:
053: /** . */
054: private URL deployedDefaultWSRPURL;
055:
056: /** . */
057: private String defaultWSRPLocation;
058:
059: private EntityResolver entityResolver;
060:
061: public EntityResolver getEntityResolver() {
062: return entityResolver;
063: }
064:
065: public void setEntityResolver(EntityResolver entityResolver) {
066: this .entityResolver = entityResolver;
067: }
068:
069: public ConsumerRegistry getConsumerRegistry() {
070: return consumerRegistry;
071: }
072:
073: public void setConsumerRegistry(ConsumerRegistry consumerRegistry) {
074: this .consumerRegistry = consumerRegistry;
075: }
076:
077: public String getDefaultWSRPLocation() {
078: return defaultWSRPLocation;
079: }
080:
081: public void setDefaultWSRPLocation(String defaultWSRPLocation) {
082: this .defaultWSRPLocation = defaultWSRPLocation;
083: }
084:
085: public void init(DeploymentInfo di) throws DeploymentException {
086: super .init(di);
087:
088: try {
089: Unmarshaller unmarshaller = UnmarshallerFactory
090: .newInstance().newUnmarshaller();
091: ObjectModelFactory factory = new WSRPDeploymentFactory(
092: consumerRegistry);
093: if (entityResolver == null) {
094: log
095: .debug("Could not obtain entity resolver for WSRPDeployer");
096: entityResolver = new NullEntityResolver();
097: }
098: unmarshaller.setEntityResolver(entityResolver);
099: di.metaData = unmarshaller.unmarshal(di.localUrl
100: .openStream(), factory, null);
101: } catch (Exception e) {
102: throw new DeploymentException(e);
103: }
104: }
105:
106: public void start(DeploymentInfo di) throws DeploymentException {
107: super .start(di);
108: WSRPDeployment deployment = (WSRPDeployment) di.metaData;
109: for (Object o : deployment.getConsumers()) {
110: WSRPConsumer consumer = (WSRPConsumer) o;
111: try {
112: consumerRegistry.activateConsumerWith(consumer
113: .getProducerId());
114: } catch (ConsumerException e) {
115: // ignore and continue
116: }
117: }
118: }
119:
120: public void stop(DeploymentInfo di) throws DeploymentException {
121: WSRPDeployment deployment = (WSRPDeployment) di.metaData;
122: for (Object o : deployment.getConsumers()) {
123: try {
124: WSRPConsumer consumer = (WSRPConsumer) o;
125: consumer.stop();
126: } catch (Exception e) {
127: e.printStackTrace();
128: }
129: }
130: super .stop(di);
131: }
132:
133: protected void startService() throws Exception {
134: super .startService();
135:
136: if (defaultWSRPLocation != null) {
137: URL defaultWSRPURL = Thread.currentThread()
138: .getContextClassLoader().getResource(
139: defaultWSRPLocation);
140: if (defaultWSRPURL != null) {
141: try {
142: deployedDefaultWSRPURL = defaultWSRPURL;
143:
144: mainDeployer.deploy(defaultWSRPURL);
145: } catch (DeploymentException e) {
146: e.printStackTrace();
147: }
148: }
149: }
150: }
151:
152: protected void stopService() throws Exception {
153: if (deployedDefaultWSRPURL != null) {
154: try {
155: mainDeployer.undeploy(deployedDefaultWSRPURL);
156: } catch (DeploymentException e) {
157: e.printStackTrace();
158: }
159: }
160: super .stopService();
161: }
162:
163: /*
164:
165: <!--
166:
167: to reuse if we take the wsrp consumer service and create mbeans out of it, for now
168: we only do pojos
169:
170: <mbean
171: code="org.jboss.portal.wsrp.services.SOAPInvokerServiceFactory"
172: name="portal.wsrp:service=ServiceFactory,id=self"
173: xmbean-dd=""
174: xmbean-code="org.jboss.portal.common.system.JBossServiceModelMBean">
175: <xmbean/>
176: <attribute name="EndpointURL">http://${jboss.bind.address}:8080/portal-wsrp/</attribute>
177: <attribute name="PortJNDIMapping">
178: org.jboss.portal.wsrp.core.WSRP_v1_ServiceDescription_PortType=wsrp-client/service/ServiceDescriptionService
179: org.jboss.portal.wsrp.core.WSRP_v1_Markup_PortType=wsrp-client/service/MarkupService
180: org.jboss.portal.wsrp.core.WSRP_v1_Markup_PortType=wsrp-client/service/RegistrationService
181: org.jboss.portal.wsrp.core.WSRP_v1_Markup_PortType=wsrp-client/service/RegistrationService
182: </attribute>
183: </mbean>
184: <mbean
185: code="org.jboss.portal.wsrp.consumer.WSRPConsumerImpl"
186: name="portal.wsrp:service=WSRPConsumer,id=self"
187: xmbean-dd=""
188: xmbean-code="org.jboss.portal.common.system.JBossServiceModelMBean">
189: <xmbean/>
190: <depends optional-attribute-name="ServiceFactory" proxy-type="attribute">portal.wsrp:service=ServiceFactory,id=self</depends>
191: </mbean>
192: <mbean
193: code="org.jboss.portal.federation.impl.PortletInvokerRegistrationService"
194: name="portal:service=PortletInvokerRegistration,id=self"
195: xmbean-dd=""
196: xmbean-code="org.jboss.portal.common.system.JBossServiceModelMBean">
197: <xmbean/>
198: <attribute name="Id">self</attribute>
199: <depends optional-attribute-name="PortletInvoker" proxy-type="attribute">portal.wsrp:service=WSRPConsumer,id=self</depends>
200: <depends optional-attribute-name="FederatingPortletInvoker" proxy-type="attribute">portal:service=PortletInvoker,type=Federating</depends>
201: </mbean>
202: -->
203:
204: */
205:
206: }
|