/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.servicemix.camel.nmr;
import org.apache.camel.ExchangePattern;
import org.apache.camel.CamelContext;
import org.apache.camel.impl.DefaultExchange;
import org.apache.servicemix.nmr.api.Message;
import org.apache.servicemix.nmr.api.Pattern;
import java.util.Map;
/**
* Created by IntelliJ IDEA.
* User: gnodet
* Date: Sep 19, 2007
* Time: 8:50:07 AM
* To change this template use File | Settings | File Templates.
*/
public class ServiceMixExchange extends DefaultExchange {
private org.apache.servicemix.nmr.api.Exchange exchange;
public ServiceMixExchange(org.apache.servicemix.nmr.api.Exchange exchange, CamelContext camelContext) {
super(camelContext);
this.exchange = exchange;
setIn(new ServiceMixMessage(exchange.getIn()));
if (exchange.getPattern() != Pattern.InOnly) {
setOut(new ServiceMixMessage(exchange.getOut()));
} else {
setOut(null);
}
if (exchange.getFault() != null) {
setFault(new ServiceMixMessage(exchange.getFault()));
}
}
public ServiceMixExchange(CamelContext context, ExchangePattern pattern, org.apache.servicemix.nmr.api.Exchange exchange) {
super(context, pattern);
this.exchange = exchange;
setIn(new ServiceMixMessage(exchange.getIn()));
if (exchange.getPattern() != Pattern.InOnly) {
setOut(new ServiceMixMessage(exchange.getOut()));
} else {
setOut(null);
}
if (exchange.getFault() != null) {
setFault(new ServiceMixMessage(exchange.getFault()));
}
}
public ServiceMixExchange(CamelContext context, ExchangePattern exchangePattern, org.apache.servicemix.nmr.api.Message inMessage,
org.apache.servicemix.nmr.api.Exchange exchange) {
super(context, exchangePattern);
setIn(new ServiceMixMessage(exchange.getIn()));
if (exchange.getPattern() != Pattern.InOnly) {
setOut(new ServiceMixMessage(exchange.getOut()));
} else {
setOut(null);
}
if (exchange.getFault() != null) {
setFault(new ServiceMixMessage(exchange.getFault()));
}
this.exchange = exchange;
}
public Object getProperty(String name) {
return exchange.getProperty(name);
}
public <T> T getProperty(String name, Class<T> type) {
return exchange.getProperty(name, type);
}
public void setProperty(String name, Object value) {
exchange.setProperty(name, value);
}
public Object removeProperty(String name) {
Object value = exchange.getProperty(name);
exchange.setProperty(name, null);
return value;
}
public Map<String, Object> getProperties() {
return exchange.getProperties();
}
public ServiceMixMessage getIn() {
return (ServiceMixMessage) super.getIn();
}
public ServiceMixMessage getOut() {
return (ServiceMixMessage) super.getOut();
}
public ServiceMixMessage getOut(boolean lazyCreate) {
return (ServiceMixMessage) super.getOut(lazyCreate);
}
public ServiceMixMessage getFault() {
return (ServiceMixMessage) super.getFault();
}
@Override
protected ServiceMixMessage createInMessage() {
Message msg = exchange.getIn(true);
return msg != null ? new ServiceMixMessage(msg) : null;
}
@Override
protected ServiceMixMessage createOutMessage() {
Message msg = exchange.getOut(true);
return msg != null ? new ServiceMixMessage(msg) : null;
}
@Override
protected org.apache.camel.Message createFaultMessage() {
Message msg = exchange.getFault(true);
return msg != null ? new ServiceMixMessage(msg) : null;
}
}