001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.transport.local;
019:
020: import java.io.IOException;
021: import java.util.ArrayList;
022: import java.util.HashMap;
023: import java.util.HashSet;
024: import java.util.List;
025: import java.util.Map;
026: import java.util.Set;
027: import java.util.logging.Logger;
028:
029: import javax.annotation.Resource;
030:
031: import org.apache.cxf.Bus;
032: import org.apache.cxf.message.Message;
033: import org.apache.cxf.service.model.EndpointInfo;
034: import org.apache.cxf.transport.AbstractTransportFactory;
035: import org.apache.cxf.transport.Conduit;
036: import org.apache.cxf.transport.ConduitInitiator;
037: import org.apache.cxf.transport.Destination;
038: import org.apache.cxf.transport.DestinationFactory;
039: import org.apache.cxf.ws.addressing.AttributedURIType;
040: import org.apache.cxf.ws.addressing.EndpointReferenceType;
041:
042: public class LocalTransportFactory extends AbstractTransportFactory
043: implements DestinationFactory, ConduitInitiator {
044:
045: public static final String TRANSPORT_ID = "http://cxf.apache.org/transports/local";
046:
047: private static final Logger LOG = Logger
048: .getLogger(LocalTransportFactory.class.getName());
049: private static final Set<String> URI_PREFIXES = new HashSet<String>();
050:
051: static {
052: URI_PREFIXES.add("local://");
053: }
054:
055: private Map<String, Destination> destinations = new HashMap<String, Destination>();
056: private Bus bus;
057:
058: private Set<String> messageFilterProperties;
059:
060: public LocalTransportFactory() {
061: super ();
062: List<String> ids = new ArrayList<String>();
063: ids.add(TRANSPORT_ID);
064: setTransportIds(ids);
065:
066: messageFilterProperties = new HashSet<String>();
067: messageFilterProperties.add(Message.REQUESTOR_ROLE);
068: }
069:
070: @Resource(name="bus")
071: public void setBus(Bus b) {
072: bus = b;
073: }
074:
075: public Bus getBus() {
076: return bus;
077: }
078:
079: public Destination getDestination(EndpointInfo ei)
080: throws IOException {
081: return getDestination(ei, createReference(ei));
082: }
083:
084: protected Destination getDestination(EndpointInfo ei,
085: EndpointReferenceType reference) throws IOException {
086: Destination d = destinations.get(reference.getAddress()
087: .getValue());
088: if (d == null) {
089: d = createDestination(ei, reference);
090: destinations.put(reference.getAddress().getValue(), d);
091: }
092: return d;
093: }
094:
095: private Destination createDestination(EndpointInfo ei,
096: EndpointReferenceType reference) {
097: LOG.info("Creating destination for address "
098: + reference.getAddress().getValue());
099: return new LocalDestination(this , reference, ei);
100: }
101:
102: void remove(LocalDestination destination) {
103: destinations.remove(destination);
104: }
105:
106: public Conduit getConduit(EndpointInfo ei) throws IOException {
107: return new LocalConduit(this ,
108: (LocalDestination) getDestination(ei));
109: }
110:
111: public Conduit getConduit(EndpointInfo ei,
112: EndpointReferenceType target) throws IOException {
113: return new LocalConduit(this ,
114: (LocalDestination) getDestination(ei, target));
115: }
116:
117: EndpointReferenceType createReference(EndpointInfo ei) {
118: EndpointReferenceType epr = new EndpointReferenceType();
119: AttributedURIType address = new AttributedURIType();
120: address.setValue(ei.getAddress());
121: epr.setAddress(address);
122: return epr;
123: }
124:
125: public Set<String> getUriPrefixes() {
126: return URI_PREFIXES;
127: }
128:
129: public Set<String> getMessageFilterProperties() {
130: return messageFilterProperties;
131: }
132:
133: public void setMessageFilterProperties(
134: Set<String> messageFilterProperties) {
135: this.messageFilterProperties = messageFilterProperties;
136: }
137:
138: }
|