package com.sun.slp;
import java.util.*;
import java.io.*;
class SLPV1SAttrMsg extends SAttrMsg {
SLPV1SAttrMsg() {}
SLPV1SAttrMsg(SrvLocHeader hdr, DataInputStream dis)
throws ServiceLocationException, IOException {
super(hdr, dis);
}
static SrvLocMsg makeEmptyReply(SLPHeaderV1 hdr)
throws ServiceLocationException {
SLPV1SAttrMsg msg = new SLPV1SAttrMsg();
msg.hdr = hdr;
msg.makeReply(new Vector(), null);
return msg;
}
void initialize(DataInputStream dis)
throws ServiceLocationException, IOException {
SLPHeaderV1 hdr = (SLPHeaderV1)getHeader();
StringBuffer buf = new StringBuffer();
hdr.parsePreviousRespondersIn(dis);
hdr.getString(buf, dis);
String urlOrServiceType = buf.toString().trim();
try {
URL = new ServiceURLV1(urlOrServiceType,
ServiceURL.LIFETIME_DEFAULT);
serviceType = null;
} catch (IllegalArgumentException ex) {
serviceType =
hdr.checkServiceType(urlOrServiceType.toLowerCase());
URL = null;
}
hdr.getString(buf, dis);
String scope = buf.toString().toLowerCase().trim();
hdr.validateScope(scope);
if (scope.length() <= 0) {
scope = Defaults.DEFAULT_SCOPE;
}
hdr.scopes = new Vector();
hdr.scopes.addElement(scope);
hdr.getString(buf, dis);
tags =
hdr.parseCommaSeparatedListIn(buf.toString().trim(), true);
int i, n = tags.size();
for (i = 0; i < n; i++) {
String tag = (String)tags.elementAt(i);
boolean wildcardStart = false;
boolean wildcardEnd = false;
if (tag.startsWith("*")) {
wildcardStart = true;
tag = tag.substring(1, tag.length());
}
if (tag.endsWith("*")) {
wildcardEnd = true;
tag = tag.substring(0, tag.length()-1);
}
tag =
ServiceLocationAttributeV1.unescapeAttributeString(tag,
hdr.charCode);
if (wildcardStart) {
tag = "*" + tag;
}
if (wildcardEnd) {
tag = tag + "*";
}
tags.setElementAt(tag.trim(), i);
}
hdr.constructDescription("AttrRqst",
" " +
(URL != null ? ("URL=``" + URL):
("service type=``" + serviceType)) +
"''\n" +
" tags=``" + tags + "''");
}
SrvLocMsg makeReply(Vector attrs, Hashtable auth)
throws ServiceLocationException {
SLPHeaderV1 hdr = ((SLPHeaderV1)getHeader()).makeReplyHeader();
if (serviceType != null) {
ServiceType type = new ServiceType(serviceType);
ServiceStore store = ServiceTable.getServiceTable().store;
Vector types = store.findServiceTypes(type.getNamingAuthority(),
this.hdr.scopes);
int i, n = types.size();
for (i = 0; i < n; i++) {
String stype = (String)types.elementAt(i);
ServiceType ttype = new ServiceType(stype);
if (ttype.isAbstractType() &&
type.equals(ttype.getAbstractTypeName())) {
SLPConfig config = SLPConfig.getSLPConfig();
config.writeLog("v1_abstract_type_conflict",
new Object[] {serviceType,
ttype});
attrs.removeAllElements();
}
}
}
hdr.iNumReplies = attrs.size();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
hdr.parseAttributeVectorOut(attrs, baos);
hdr.payload = baos.toByteArray();
hdr.constructDescription("AttrRply",
" attributes=``" + attrs + "''\n");
return hdr;
}
}