org.ow2.petals.binding.rest.utils.CachedExchangeImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of petals-bc-rest Show documentation
Show all versions of petals-bc-rest Show documentation
petals-bc-rest Binding Component description
/**
* Copyright (c) 2017-2018 Linagora
*
* This program/library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or (at your
* option) any later version.
*
* This program/library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program/library; If not, see http://www.gnu.org/licenses/
* for the GNU Lesser General Public License version 2.1.
*/
package org.ow2.petals.binding.rest.utils;
import java.util.Collections;
import java.util.Map;
import javax.jbi.messaging.MessagingException;
import javax.xml.transform.Source;
import javax.xml.transform.dom.DOMSource;
import org.ow2.petals.component.framework.api.message.Exchange;
import org.w3c.dom.Document;
public class CachedExchangeImpl implements CachedExchange {
private final Exchange exchange;
private final Map uriParameters;
private Document inContent = null;
/**
*
* @param exchange
* can't be null
* @param uriParameters
* can't be null
* @param inContent
* can be null
*/
public CachedExchangeImpl(final Exchange exchange, final Map uriParameters,
final Document inContent) {
assert exchange != null;
assert uriParameters != null;
this.exchange = exchange;
this.uriParameters = uriParameters;
this.inContent = inContent;
}
@Override
public Exchange getExchange() {
return this.exchange;
}
@Override
public Map getUriParameters() {
return Collections.unmodifiableMap(uriParameters);
}
@Override
public Document getInMessageContentAsDocument() throws MessagingException {
if (this.inContent == null) {
this.inContent = this.exchange.getInMessageContentAsDocument(false);
}
return inContent;
}
@Override
public Source getInMessageContentAsSource() throws MessagingException {
if (this.inContent != null) {
return new DOMSource(this.inContent);
} else {
return this.exchange.getInMessageContentAsSource();
}
}
}