001/*
002 * Created on 19-Apr-2004
003 */
004package ca.uhn.hl7v2.protocol.impl;
005
006import java.util.ArrayList;
007import java.util.List;
008
009import ca.uhn.hl7v2.protocol.AcceptValidator;
010import ca.uhn.hl7v2.protocol.ApplicationRouter;
011import ca.uhn.hl7v2.protocol.ProcessorContext;
012import ca.uhn.hl7v2.protocol.SafeStorage;
013import ca.uhn.hl7v2.protocol.TransportLayer;
014
015/**
016 * Default implementation of <code>ProcessorContext</code>. 
017 * 
018 * @author <a href="mailto:bryan.tripp@uhn.on.ca">Bryan Tripp</a>
019 * @version $Revision: 1.1 $ updated on $Date: 2007-02-19 02:24:26 $ by $Author: jamesagnew $
020 */
021public class ProcessorContextImpl implements ProcessorContext {
022
023    private final ApplicationRouter myRouter;
024    private final TransportLayer myLocallyDrivenTransport;
025    private final TransportLayer myRemotelyDrivenTransport;
026    private final SafeStorage mySafeStorage;
027    private final List<AcceptValidator> myValidators;
028    private final List<String> myMetadataFields;
029
030    /**
031     * Creates a new instance that uses the given resources.  
032     * 
033     * @param theRouter 
034     * @param theTransport a <code>TransportLayer</code> used for both locally-initiated
035     *      and remotely-initiated message exchanges 
036     * @param theStorage
037     */    
038    public ProcessorContextImpl(
039            ApplicationRouter theRouter,
040            TransportLayer theTransport, 
041            SafeStorage theStorage) {
042                
043        myRouter = theRouter;
044        myRemotelyDrivenTransport = theTransport;
045        myLocallyDrivenTransport = theTransport;
046        mySafeStorage = theStorage;
047        
048        myValidators = new ArrayList<AcceptValidator>(8);
049        myMetadataFields = new ArrayList<String>(30);
050    }
051
052    /**
053     * Creates a new instance that uses the given resources.  
054     * 
055     * @param theRouter 
056     * @param theLocallyDrivenTransport a <code>TransportLayer</code> used for locally-initiated
057     *      and message exchanges 
058     * @param theRemotelyDrivenTransport a <code>TransportLayer</code> used for remotely-initiated
059     *      and message exchanges 
060     * @param theStorage
061     */    
062    public ProcessorContextImpl(
063            ApplicationRouter theRouter,
064            TransportLayer theLocallyDrivenTransport,
065            TransportLayer theRemotelyDrivenTransport,  
066            SafeStorage theStorage) {
067                
068        myRouter = theRouter;
069        myRemotelyDrivenTransport = theRemotelyDrivenTransport;
070        myLocallyDrivenTransport = theLocallyDrivenTransport;
071        mySafeStorage = theStorage;
072        
073        myValidators = new ArrayList<AcceptValidator>(8);
074        myMetadataFields = new ArrayList<String>(30);
075    }
076
077    /**
078     * @see ca.uhn.hl7v2.protocol.ProcessorContext#getRouter()
079     */
080    public ApplicationRouter getRouter() {
081        return myRouter;
082    }
083
084    /**
085     * @see ca.uhn.hl7v2.protocol.ProcessorContext#getRemotelyDrivenTransportLayer()
086     */
087    public TransportLayer getRemotelyDrivenTransportLayer() {
088        return myRemotelyDrivenTransport;
089    }
090
091    /**
092     * @see ca.uhn.hl7v2.protocol.ProcessorContext#getLocallyDrivenTransportLayer()
093     */
094    public TransportLayer getLocallyDrivenTransportLayer() {
095        return myLocallyDrivenTransport;
096    }
097
098    /**
099     * @see ca.uhn.hl7v2.protocol.ProcessorContext#getValidators()
100     */
101    public AcceptValidator[] getValidators() {
102        return myValidators.toArray(new AcceptValidator[0]);
103    }
104    
105    /**
106     * Adds a new validator to the list of those returned by 
107     * <code>getValidators()</code>.  
108     *  
109     * @param theValidator the validator to add 
110     */
111    public void addValidator(AcceptValidator theValidator) {
112        myValidators.add(theValidator);
113    }
114
115    /**
116     * @see ca.uhn.hl7v2.protocol.ProcessorContext#getSafeStorage()
117     */
118    public SafeStorage getSafeStorage() {
119        return mySafeStorage;
120    }
121
122    /** 
123     * @see ca.uhn.hl7v2.protocol.ProcessorContext#getMetadataFields()
124     */
125    public List<String> getMetadataFields() {
126        return myMetadataFields;
127    }
128
129}