001: /* ----- BEGIN LICENSE BLOCK -----
002: * Version: MPL 1.1
003: *
004: * The contents of this file are subject to the Mozilla Public License Version
005: * 1.1 (the "License"); you may not use this file except in compliance with
006: * the License. You may obtain a copy of the License at
007: * http://www.mozilla.org/MPL/
008: *
009: * Software distributed under the License is distributed on an "AS IS" basis,
010: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
011: * for the specific language governing rights and limitations under the
012: * License.
013: *
014: * The Original Code is the DataShare server.
015: *
016: * The Initial Developer of the Original Code is
017: * Ball Aerospace & Technologies Corp, Fairborn, Ohio
018: * Portions created by the Initial Developer are Copyright (C) 2001
019: * the Initial Developer. All Rights Reserved.
020: *
021: * Contributor(s): Charles Wood <cwood@ball.com>
022: *
023: * ----- END LICENSE BLOCK ----- */
024: /* RCS $Id: SocketAdapter.java,v 1.3 2002/02/04 19:34:57 lizellaman Exp $
025: * $Log: SocketAdapter.java,v $
026: * Revision 1.3 2002/02/04 19:34:57 lizellaman
027: * correct spelling of privilege
028: *
029: * Revision 1.2 2002/01/29 20:50:17 lizellaman
030: * Added LoggingInterface, modified the PropertiesInterface implementation
031: *
032: * Revision 1.1.1.1 2001/10/23 13:37:18 lizellaman
033: * initial sourceforge release
034: *
035: */
036:
037: package org.datashare;
038:
039: import java.net.InetAddress;
040: import org.datashare.objects.DataShareObject;
041: import java.util.Date;
042: import java.util.GregorianCalendar;
043:
044: /**
045: * @date March 01, 2001
046: */
047: public abstract class SocketAdapter {
048: protected String clientKey = ""; // unique string for this sockets client
049: protected String clientClass = "";
050: protected boolean admin = false; // set to true if this client has admin privileges
051: private boolean active = false;
052: protected String keyValue = ""; // uniqe string for this socket
053: protected InetAddress remoteIP = null;
054: protected int remotePort;
055: protected InetAddress localIP = null;
056: protected int localPort;
057: protected DataReceiverInterface dri = null;
058: private Date creationDate = null;
059:
060: /**
061: * constructor for abstract class
062: */
063: SocketAdapter() {
064: creationDate = new GregorianCalendar().getTime();
065: }
066:
067: /**
068: * call this method when data is to be sent over this connection,
069: * this will buffer the data and schedule it for transmission
070: */
071: abstract void sendData(DataShareObject dsObject);
072:
073: /**
074: * this is the method that actually sends the data
075: */
076: abstract void xmitData(DataShareObject dsObject);
077:
078: /**
079: * returns the type for this instance, should come from the selections in ChannelDescription class
080: */
081: abstract int getType();
082:
083: /**
084: * close the socket, stop any threads, and inform the server
085: */
086: abstract void close();
087:
088: /**
089: * returns the data/time this socket was established
090: */
091: Date getCreationDate() {
092: return creationDate;
093: }
094:
095: /**
096: * retrieves this sockets client key
097: */
098: String getClientKey() {
099: return clientKey;
100: }
101:
102: /**
103: * sets the clientKey (if param is not blank)
104: */
105: void setClientKey(String clientKey) {
106: if (!clientKey.equals(""))
107: this .clientKey = clientKey;
108: }
109:
110: /**
111: * retrieves this sockets client class
112: */
113: String getClientClass() {
114: return clientClass;
115: }
116:
117: /**
118: * sets the clientClass (if param is not blank)
119: */
120: void setClientClass(String clientClass) {
121: if (!clientClass.equals(""))
122: this .clientClass = clientClass;
123: }
124:
125: /**
126: * returns true if client has provided its clientKey (so we know who this connection is for)
127: */
128: boolean getActive() {
129: return active;
130: }
131:
132: /**
133: * set to true if the client has sent its client key for this connection
134: */
135: void setActive(boolean active) {
136: SessionUtilities.getLoggingInterface().debugMsg(
137: SessionUtilities.getLoggingInterface().DEBUG,
138: SessionUtilities.getLoggingInterface().NETWORK,
139: "Setting SocketAdapter.active to "
140: + (active ? "true" : "false") + " for "
141: + this .getKeyValue());
142: this .active = active;
143: }
144:
145: /**
146: * set to true if the client has admin privileges
147: */
148: void setAdmin(boolean admin) {
149: this .admin = admin;
150: }
151:
152: /**
153: * returns true if client has admin privileges, default if false
154: */
155: boolean getAdmin() {
156: return admin;
157: }
158:
159: /**
160: * retrieves this sockets key
161: */
162: String getKeyValue() {
163: return keyValue;
164: }
165:
166: /**
167: * sets the keyValue (but only if the parameter is not blank)
168: */
169: void setKeyValue(String keyValue) {
170: if (!keyValue.equals(""))
171: this .keyValue = keyValue;
172: }
173:
174: /**
175: * retrieves the remote IP address for this connection
176: */
177: InetAddress getRemoteIP() {
178: return remoteIP;
179: }
180:
181: /**
182: * sets the remote IP for this connection
183: */
184: void setRemoteIP(InetAddress remoteIP) {
185: this .remoteIP = remoteIP;
186: }
187:
188: /**
189: * retrieves the local address for this connection
190: */
191: InetAddress getLocalIP() {
192: return localIP;
193: }
194:
195: /**
196: * sets the local IP for this connection
197: */
198: void setLocalIP(InetAddress localIP) {
199: this .localIP = localIP;
200: }
201:
202: /**
203: * retrieves the remote port for this connection
204: */
205: int getRemotePort() {
206: return remotePort;
207: }
208:
209: /**
210: * sets the remote port for this connection
211: */
212: void setRemotePort(int remotePort) {
213: this .remotePort = remotePort;
214: }
215:
216: /**
217: * retrieves the local port for this connection
218: */
219: int getLocalPort() {
220: return localPort;
221: }
222:
223: /**
224: * sets the local port for this connection
225: */
226: void setLocalPort(int localPort) {
227: this.localPort = localPort;
228: }
229: }
|