001: /*
002: * Portions Copyright 2000-2007 Sun Microsystems, Inc. All Rights
003: * Reserved. Use is subject to license terms.
004: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License version
008: * 2 only, as published by the Free Software Foundation.
009: *
010: * This program is distributed in the hope that it will be useful, but
011: * WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * General Public License version 2 for more details (a copy is
014: * included at /legal/license.txt).
015: *
016: * You should have received a copy of the GNU General Public License
017: * version 2 along with this work; if not, write to the Free Software
018: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
019: * 02110-1301 USA
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
022: * Clara, CA 95054 or visit www.sun.com if you need additional
023: * information or have any questions.
024: */
025: /*
026: */
027:
028: package gov.nist.siplite;
029:
030: import gov.nist.siplite.stack.*;
031: import gov.nist.siplite.message.*;
032: import gov.nist.core.*;
033:
034: import com.sun.midp.log.Logging;
035: import com.sun.midp.log.LogChannels;
036:
037: /**
038: * Implements all the support classes that are necessary for the nist-sip
039: * stack on which the jain-sip stack has been based.
040: * This is a mapping class to map from the NIST-SIP abstractions to
041: * the JAIN abstractions. (i.e. It is the glue code that ties
042: * the NIST-SIP event model and the JAIN-SIP event model together.
043: * When a SIP Request or SIP Response is read from the corresponding
044: * messageChannel, the NIST-SIP stack calls the SIPStackMessageFactory
045: * implementation that has been registered with it to process the request.)
046: *
047: * @version JAIN-SIP-1.1
048: *
049: *
050: * <a href="{@docRoot}/uncopyright.html">This code is in the public domain.</a>
051: *
052: */
053: public class NistSipMessageFactoryImpl implements
054: SIPStackMessageFactory {
055: /** Current SIP stack context. */
056: private SipStack sipStackImpl;
057:
058: /**
059: * Constructs a new SIP Server Request.
060: * @param sipRequest is the Request from which the SIPServerRequest
061: * is to be constructed.
062: * @param messageChannel is the MessageChannel abstraction for this
063: * SIPServerRequest.
064: * @return a new SIP Server Request handle
065: */
066: public SIPServerRequestInterface newSIPServerRequest(
067: Request sipRequest, MessageChannel messageChannel)
068: throws IllegalArgumentException {
069:
070: if (messageChannel == null || sipRequest == null) {
071: throw new IllegalArgumentException("Null Arg!");
072: }
073:
074: NistSipMessageHandlerImpl retval = new NistSipMessageHandlerImpl();
075: if (messageChannel instanceof Transaction) {
076: // If the transaction has already been created
077: // then set the transaction channel.
078: retval.transactionChannel = (Transaction) messageChannel;
079: }
080: SIPTransactionStack theStack = (SIPTransactionStack) messageChannel
081: .getSIPStack();
082:
083: /*
084: * IMPL_NOTE :
085: * May not need to initialize listeningPoint like this. Please refer to
086: * processRequest() method in NistSipMessageHandlerImpl
087: */
088: retval.listeningPoint = messageChannel.getMessageProcessor()
089: .getListeningPoint();
090:
091: if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
092: Logging.report(Logging.INFORMATION, LogChannels.LC_JSR180,
093: "Returning request interface for "
094: + sipRequest.getFirstLine() + " " + retval
095: + " messageChannel = " + messageChannel);
096: }
097:
098: return retval;
099: }
100:
101: /**
102: * Generates a new server response for the stack.
103: * @param sipResponse is the Request from which the SIPServerRequest
104: * is to be constructed.
105: * @param messageChannel is the MessageChannel abstraction for this
106: * SIPServerResponse
107: * @return a new SIP Server Response handle
108: */
109: public SIPServerResponseInterface newSIPServerResponse(
110: Response sipResponse, MessageChannel messageChannel) {
111: try {
112: NistSipMessageHandlerImpl retval = new NistSipMessageHandlerImpl();
113: SIPTransactionStack theStack = (SIPTransactionStack) messageChannel
114: .getSIPStack();
115: SipStack sipStackImpl = (SipStack) theStack;
116: // Tr is null if a transaction is not mapped.
117: Transaction tr = (Transaction) ((SIPTransactionStack) theStack)
118: .findTransaction(sipResponse, false);
119:
120: retval.transactionChannel = tr;
121:
122: if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
123: Logging.report(Logging.INFORMATION,
124: LogChannels.LC_JSR180, "Found Transaction "
125: + tr + " for " + sipResponse);
126: Logging.report(Logging.INFORMATION,
127: LogChannels.LC_JSR180, "MessageProcessor = "
128: + messageChannel.getMessageProcessor()
129: + "/"
130: + messageChannel.getMessageProcessor()
131: .getListeningPoint());
132: }
133:
134: ListeningPoint lp = messageChannel.getMessageProcessor()
135: .getListeningPoint();
136:
137: retval.listeningPoint = lp;
138: return retval;
139:
140: } catch (RuntimeException ex) {
141: if (Logging.REPORT_LEVEL <= Logging.ERROR) {
142: Logging.report(Logging.ERROR, LogChannels.LC_JSR180,
143: "runtime exception caught!");
144: ex.printStackTrace();
145: }
146: return null;
147: }
148:
149: }
150:
151: /**
152: * Contrictor.
153: * @param sipStackImpl current SIP stack context
154: */
155: public NistSipMessageFactoryImpl(SipStack sipStackImpl) {
156: this.sipStackImpl = sipStackImpl;
157: }
158:
159: }
|