001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.servicemix.jbi.container;
018    
019    import java.io.Serializable;
020    
021    import javax.xml.namespace.QName;
022    
023    import org.apache.servicemix.jbi.api.EndpointResolver;
024    import org.apache.servicemix.jbi.messaging.PojoMarshaler;
025    import org.apache.servicemix.jbi.resolver.EndpointChooser;
026    import org.apache.servicemix.jbi.resolver.InterfaceNameEndpointResolver;
027    import org.apache.servicemix.jbi.resolver.ServiceAndEndpointNameResolver;
028    import org.apache.servicemix.jbi.resolver.ServiceNameEndpointResolver;
029    import org.apache.servicemix.jbi.resolver.URIResolver;
030    
031    /**
032     * Represents the registration of a component with the {@link JBIContainer}
033     * 
034     * @org.apache.xbean.XBean element="activationSpec" description="The Component
035     *                         configuration consisting of its container related
036     *                         properties such as its routing information"
037     * 
038     * @version $Revision: 690190 $
039     */
040    public class ActivationSpec implements Serializable {
041    
042        static final long serialVersionUID = 8458586342841647313L;
043    
044        private String id;
045        private String componentName;
046        private Object component;
047        private QName service;
048        private QName interfaceName;
049        private QName operation;
050        private String endpoint;
051        private transient EndpointResolver destinationResolver;
052        private transient EndpointChooser interfaceChooser;
053        private transient EndpointChooser serviceChooser;
054        private QName destinationService;
055        private QName destinationInterface;
056        private QName destinationOperation;
057        private String destinationEndpoint;
058        private transient PojoMarshaler marshaler;
059        private SubscriptionSpec[] subscriptions = {};
060        private boolean failIfNoDestinationEndpoint = true;
061        private Boolean persistent;
062        private String destinationUri;
063    
064        public ActivationSpec() {
065        }
066    
067        public ActivationSpec(Object component) {
068            this.component = component;
069        }
070    
071        public ActivationSpec(String id, Object component) {
072            this.id = id;
073            this.component = component;
074        }
075    
076        /**
077         * The unique component ID
078         * 
079         * @return the unique ID
080         */
081        public String getId() {
082            return id;
083        }
084    
085        /**
086         * Sets the unique component ID
087         * 
088         * @param id
089         */
090        public void setId(String id) {
091            this.id = id;
092        }
093    
094        public String getComponentName() {
095            return componentName;
096        }
097    
098        public void setComponentName(String componentName) {
099            this.componentName = componentName;
100        }
101    
102        /**
103         * @org.apache.xbean.Property
104         * @return
105         */
106        public Object getComponent() {
107            return component;
108        }
109    
110        public void setComponent(Object component) {
111            this.component = component;
112        }
113    
114        /**
115         * Returns the service of the component to register
116         */
117        public QName getService() {
118            return service;
119        }
120    
121        public void setService(QName service) {
122            this.service = service;
123        }
124    
125        /**
126         * Returns the endpoint name of this component
127         */
128        public String getEndpoint() {
129            return endpoint;
130        }
131    
132        public void setEndpoint(String endpoint) {
133            this.endpoint = endpoint;
134        }
135    
136        public QName getInterfaceName() {
137            return interfaceName;
138        }
139    
140        public void setInterfaceName(QName interfaceName) {
141            this.interfaceName = interfaceName;
142        }
143    
144        public QName getOperation() {
145            return operation;
146        }
147    
148        public void setOperation(QName operation) {
149            this.operation = operation;
150        }
151    
152        /**
153         * Returns the destination resolver used to decide which destination the
154         * container should route this component to.
155         * 
156         * @return the destination resolver, lazily creating one if possible
157         */
158        public EndpointResolver getDestinationResolver() {
159            if (destinationResolver == null) {
160                destinationResolver = createEndpointResolver();
161            }
162            return destinationResolver;
163        }
164    
165        /**
166         * Sets the destination resolver used by the container to route requests
167         * send on the default endpoint.
168         * 
169         * @param destinationResolver
170         */
171        public void setDestinationResolver(EndpointResolver destinationResolver) {
172            this.destinationResolver = destinationResolver;
173        }
174    
175        public EndpointChooser getInterfaceChooser() {
176            return interfaceChooser;
177        }
178    
179        public void setInterfaceChooser(EndpointChooser interfaceChooser) {
180            this.interfaceChooser = interfaceChooser;
181        }
182    
183        public EndpointChooser getServiceChooser() {
184            return serviceChooser;
185        }
186    
187        public void setServiceChooser(EndpointChooser serviceChooser) {
188            this.serviceChooser = serviceChooser;
189        }
190    
191        /**
192         * The destination service name
193         */
194        public QName getDestinationService() {
195            return destinationService;
196        }
197    
198        public void setDestinationService(QName destinationService) {
199            this.destinationService = destinationService;
200        }
201    
202        /**
203         * The destination interface
204         */
205        public QName getDestinationInterface() {
206            return destinationInterface;
207        }
208    
209        public void setDestinationInterface(QName destinationInterface) {
210            this.destinationInterface = destinationInterface;
211        }
212    
213        /**
214         * The destination operation name
215         */
216        public QName getDestinationOperation() {
217            return destinationOperation;
218        }
219    
220        public void setDestinationOperation(QName destinationOperation) {
221            this.destinationOperation = destinationOperation;
222        }
223    
224        /**
225         * The destination endpoint
226         */
227        public String getDestinationEndpoint() {
228            return destinationEndpoint;
229        }
230    
231        public void setDestinationEndpoint(String destinationEndpoint) {
232            this.destinationEndpoint = destinationEndpoint;
233        }
234    
235        public PojoMarshaler getMarshaler() {
236            return marshaler;
237        }
238    
239        public void setMarshaler(PojoMarshaler marshaler) {
240            this.marshaler = marshaler;
241        }
242    
243        public SubscriptionSpec[] getSubscriptions() {
244            return subscriptions;
245        }
246    
247        public void setSubscriptions(SubscriptionSpec[] subscriptions) {
248            this.subscriptions = subscriptions;
249        }
250    
251        public boolean isFailIfNoDestinationEndpoint() {
252            return failIfNoDestinationEndpoint;
253        }
254    
255        /**
256         * Sets whether or not there should be a failure if there is no matching
257         * endpoint for the service dispatch. It may be in a pure publish/subscribe
258         * model you want all available subscribes to receive the message but do not
259         * mind if there is not a single destination endpoint that can be found.
260         * 
261         * @param failIfNoDestinationEndpoint
262         */
263        public void setFailIfNoDestinationEndpoint(boolean failIfNoDestinationEndpoint) {
264            this.failIfNoDestinationEndpoint = failIfNoDestinationEndpoint;
265        }
266    
267        /**
268         * Lazily create a resolver from the available information
269         */
270        protected EndpointResolver createEndpointResolver() {
271            // lets construct a resolver if any of the output
272            if (destinationService != null) {
273                if (destinationEndpoint != null) {
274                    return new ServiceAndEndpointNameResolver(destinationService, destinationEndpoint);
275                } else {
276                    return new ServiceNameEndpointResolver(destinationService);
277                }
278            } else if (destinationInterface != null) {
279                return new InterfaceNameEndpointResolver(destinationInterface);
280            } else if (destinationUri != null) {
281                return new URIResolver(destinationUri);
282            }
283            return null;
284        }
285    
286        public Boolean getPersistent() {
287            return persistent;
288        }
289    
290        /**
291         * Set if message exchanges issued by the component should be persistent or
292         * not. This value will override the default one given on the
293         * {@link org.apache.servicemix.jbi.container.JBIContainer#persistent}
294         * attribute.
295         * 
296         * @param persistent
297         *            the new value to set
298         */
299        public void setPersistent(Boolean persistent) {
300            this.persistent = persistent;
301        }
302    
303        /**
304         * @return the destinationUri
305         */
306        public String getDestinationUri() {
307            return destinationUri;
308        }
309    
310        /**
311         * @param destinationUri
312         *            the destinationUri to set
313         */
314        public void setDestinationUri(String destinationUri) {
315            this.destinationUri = destinationUri;
316        }
317    
318    }