All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.ow2.petals.binding.rest.utils.CachedExchangeImpl Maven / Gradle / Ivy

There is a newer version: 2.4.0
Show newest version
/**
 * 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();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy