package com.sun.slp;
import java.util.*;
import java.net.*;
import java.io.*;
import java.security.*;
class SLPServerHeaderV2 extends SLPHeaderV2 implements Cloneable {
int replyFunctionCode = SrvLocHeader.SrvAck;
SLPServerHeaderV2() {
super();
}
SLPServerHeaderV2(int functionCode, boolean fresh, Locale locale)
throws ServiceLocationException {
super(functionCode, fresh, locale);
}
void parseHeader(int functionCode, DataInputStream dis)
throws ServiceLocationException, IOException {
switch (functionCode) {
case SrvLocHeader.SrvReq:
replyFunctionCode = SrvLocHeader.SrvRply;
break;
case SrvLocHeader.AttrRqst:
replyFunctionCode = SrvLocHeader.AttrRply;
break;
case SrvLocHeader.SrvTypeRqst:
replyFunctionCode = SrvLocHeader.SrvTypeRply;
break;
case SrvLocHeader.SrvReg: case SrvLocHeader.SrvDereg:
replyFunctionCode = SrvLocHeader.SrvAck;
break;
case SrvLocHeader.DAAdvert:
replyFunctionCode = SrvLocHeader.DAAdvert;
break;
}
super.parseHeader(functionCode, dis);
}
SrvLocMsg parseMsg(DataInputStream dis)
throws ServiceLocationException,
IOException,
IllegalArgumentException {
SrvLocMsg msg = null;
if (functionCode == SrvLocHeader.DAAdvert) {
errCode = (short)getInt(dis);
}
switch (functionCode) {
case SrvLocHeader.SrvReg:
msg = new SSrvReg(this, dis);
break;
case SrvLocHeader.SrvDereg:
msg = new SSrvDereg(this, dis);
break;
case SrvLocHeader.SrvReq:
msg = new SSrvMsg(this, dis);
break;
case SrvLocHeader.AttrRqst:
msg = new SAttrMsg(this, dis);
break;
case SrvLocHeader.SrvAck:
msg = this;
iNumReplies = 1;
break;
case SrvLocHeader.SrvTypeRqst:
msg = new SSrvTypeMsg(this, dis);
break;
case SrvLocHeader.DAAdvert:
msg = new CDAAdvert(this, dis);
break;
case SrvLocHeader.SAAdvert:
msg = new CSAAdvert(this, dis);
break;
default:
throw
new ServiceLocationException(
ServiceLocationException.PARSE_ERROR,
"function_code_error",
new Object[] {
Integer.valueOf(functionCode)});
}
if (nbytes > length) {
throw
new ServiceLocationException(
ServiceLocationException.PARSE_ERROR,
"length_overflow",
new Object[] {
Integer.valueOf(nbytes), Integer.valueOf(length)});
}
return msg;
}
SrvLocMsg makeErrorReply(Exception ex) {
SrvLocHeader hdr = null;
try {
hdr = (SrvLocHeader)this.clone();
} catch (CloneNotSupportedException exx) {
}
hdr.fresh = false;
hdr.overflow = false;
hdr.functionCode = replyFunctionCode;
Assert.slpassert(ex != null,
"null_parameter",
new Object[] {ex});
if (ex instanceof ServiceLocationException) {
hdr.errCode = ((ServiceLocationException)ex).getErrorCode();
if (!ServiceLocationException.validWireErrorCode(hdr.errCode)) {
hdr.errCode = ServiceLocationException.INTERNAL_ERROR;
}
} else if (ex instanceof IllegalArgumentException ||
ex instanceof IOException) {
hdr.errCode = ServiceLocationException.PARSE_ERROR;
} else {
hdr.errCode = ServiceLocationException.INTERNAL_ERROR;
}
constructDescription("SrvLocMsg", "");
return hdr;
}
SLPServerHeaderV2 makeReplyHeader() {
SLPServerHeaderV2 hdr = null;
try {
hdr = (SLPServerHeaderV2)this.clone();
} catch (CloneNotSupportedException ex) {
}
hdr.functionCode = replyFunctionCode;
hdr.length = 0;
hdr.previousResponders = null;
hdr.scopes = null;
hdr.overflow = false;
hdr.fresh = false;
hdr.mcast = false;
hdr.nbytes = 0;
return hdr;
}
public String toString() {
return
getMsgType() + ":version=``" + version + "''\n" +
" functionCode=``" + functionCode + "''\n" +
" length=``" + length + "''" + "''\n" +
" overflow=``" + overflow + "''\n" +
" mcast = ``" + mcast + "''\n" +
" fresh=``" + fresh + "''\n" +
" locale = ``" + locale + "''\n" +
" xid=``0x" + Integer.toHexString(xid) + "''\n" +
" errCode=``" + errCode + "''\n" +
" previousResponders=``" + previousResponders + "''\n" +
" scopes=``" + scopes + "''\n" +
getMsgDescription();
}
void parseScopesIn(DataInputStream dis)
throws ServiceLocationException, IOException {
StringBuffer buf = new StringBuffer();
getString(buf, dis);
scopes = parseCommaSeparatedListIn(buf.toString(), true);
unescapeScopeStrings(scopes);
DATable.validateScopes(scopes, locale);
}
void parsePreviousRespondersIn(DataInputStream dis)
throws ServiceLocationException, IOException {
StringBuffer buf = new StringBuffer();
getString(buf, dis);
previousResponders =
parseCommaSeparatedListIn(buf.toString(), true);
}
SDAAdvert
getDAAdvert(short xid,
long timestamp,
ServiceURL url,
Vector scopes,
Vector attrs)
throws ServiceLocationException {
if (scopes.size() <= 0) {
scopes = SLPConfig.getSLPConfig().getSAConfiguredScopes();
}
return new SDAAdvert(this, xid, timestamp, url, scopes, attrs);
}
}