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.xmpp;
018:
019: import java.net.URI;
020: import java.net.URISyntaxException;
021: import java.util.List;
022: import java.util.Map;
023:
024: import javax.jbi.servicedesc.ServiceEndpoint;
025:
026: import org.apache.servicemix.common.DefaultComponent;
027: import org.apache.servicemix.common.Endpoint;
028: import org.apache.servicemix.jbi.util.IntrospectionSupport;
029: import org.apache.servicemix.jbi.util.URISupport;
030: import org.springframework.beans.BeansException;
031: import org.springframework.beans.factory.BeanFactory;
032: import org.springframework.beans.factory.BeanFactoryAware;
033:
034: /**
035: * A JBI component for binding POJOs to the JBI bus which work directly off of the JBI messages
036: * without requiring any SOAP Processing. If you require support for SOAP, JAX-WS, JSR-181 then you
037: * should use the servicemix-jsr181 module instead.
038: *
039: * @version $Revision: $
040: * @org.apache.xbean.XBean element="component" description="POJO Component"
041: */
042: public class XMPPComponent extends DefaultComponent implements
043: BeanFactoryAware {
044:
045: private XMPPEndpoint[] endpoints;
046: private BeanFactory beanFactory;
047: private String user;
048: private String password;
049:
050: public XMPPEndpoint[] getEndpoints() {
051: return endpoints;
052: }
053:
054: public void setEndpoints(XMPPEndpoint[] endpoints) {
055: this .endpoints = endpoints;
056: }
057:
058: public String getUser() {
059: return user;
060: }
061:
062: public void setUser(String user) {
063: this .user = user;
064: }
065:
066: public String getPassword() {
067: return password;
068: }
069:
070: public void setPassword(String password) {
071: this .password = password;
072: }
073:
074: /**
075: * @org.apache.xbean.Property hidden="true"
076: */
077: public BeanFactory getBeanFactory() {
078: return beanFactory;
079: }
080:
081: public void setBeanFactory(BeanFactory beanFactory)
082: throws BeansException {
083: this .beanFactory = beanFactory;
084: }
085:
086: protected List getConfiguredEndpoints() {
087: return asList(getEndpoints());
088: }
089:
090: protected Class[] getEndpointClasses() {
091: return new Class[] { XMPPEndpoint.class };
092: }
093:
094: protected Endpoint getResolvedEPR(ServiceEndpoint ep)
095: throws Exception {
096: XMPPEndpoint endpoint = createEndpoint(ep);
097: endpoint.activate();
098: return endpoint;
099: }
100:
101: /**
102: * A factory method for creating endpoints from a service endpoint
103: * which is public so that it can be easily unit tested
104: */
105: public XMPPEndpoint createEndpoint(ServiceEndpoint ep)
106: throws URISyntaxException {
107: URI uri = new URI(ep.getEndpointName());
108: Map map = URISupport.parseQuery(uri.getQuery());
109:
110: XMPPEndpoint endpoint = null;
111:
112: // TODO how do we decide whether to use group or private chat from the URI in a nicer way?
113: String room = (String) map.get("room");
114: if (room != null) {
115: endpoint = new GroupChatEndpoint(this , ep, room);
116: } else {
117: endpoint = new PrivateChatEndpoint(this , ep);
118: }
119:
120: IntrospectionSupport.setProperties(endpoint, map);
121: IntrospectionSupport.setProperties(endpoint.getMarshaler(),
122: map, "marshal.");
123:
124: // TODO
125: //endpoint.setRole(MessageExchange.Role.PROVIDER);
126:
127: endpoint.setUri(uri);
128:
129: return endpoint;
130: }
131:
132: }
|