/** 
 * 
 * Copyright 2004 Protique Ltd
 * 
 * Licensed 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.activemq.ws.addressing;

import org.activemq.ws.xmlbeans.addressing.v2003_03.*;

import javax.xml.namespace.QName;
import java.util.Map;
import java.util.HashMap;

/**
 * Provides a thread local view of the current WS-Addressing context
 *
 * @version $Revision: 1.1 $
 */
public class AddressingContext {
    private static ThreadLocal threadLocal = new ThreadLocal();
    private AttributedURI messageID;
    private Relationship relationship;
    private AttributedURI to;
    private AttributedURI action;
    private EndpointReferenceType from;
    private EndpointReferenceType replyTo;
    private EndpointReferenceType faultTo;
    private EndpointReferenceType recipient;
    private Map properties = new HashMap();

    public static AddressingContext getCurrentContext() {
        AddressingContext context = (AddressingContext) threadLocal.get();
        if (context == null) {
            context = new AddressingContext();
            threadLocal.set(context);
        }
        return context;
    }

    public static void setCurrentContext(AddressingContext context) {
        threadLocal.set(context);
    }

    public AttributedURI getMessageID() {
        return messageID;
    }

    public void setMessageID(AttributedURI messageID) {
        this.messageID = messageID;
    }

    public Relationship getRelationship() {
        return relationship;
    }

    public void setRelationship(Relationship relationship) {
        this.relationship = relationship;
    }

    public AttributedURI getTo() {
        return to;
    }

    public void setTo(AttributedURI to) {
        this.to = to;
    }

    public AttributedURI getAction() {
        return action;
    }

    public void setAction(AttributedURI action) {
        this.action = action;
    }

    public EndpointReferenceType getFrom() {
        return from;
    }

    public void setFrom(EndpointReferenceType from) {
        this.from = from;
    }

    public EndpointReferenceType getReplyTo() {
        return replyTo;
    }

    public void setReplyTo(EndpointReferenceType replyTo) {
        this.replyTo = replyTo;
    }

    public EndpointReferenceType getFaultTo() {
        return faultTo;
    }

    public void setFaultTo(EndpointReferenceType faultTo) {
        this.faultTo = faultTo;
    }

    public EndpointReferenceType getRecipient() {
        return recipient;
    }

    public void setRecipient(EndpointReferenceType recipient) {
        this.recipient = recipient;
    }

    public void addProperty(QName name, Object value) {
        properties.put(name, value);
    }

    public Map getProperties() {
        return properties;
    }

    public void setProperties(Map properties) {
        this.properties = properties;
    }
}
