private static String[] getTagList(String context,String tagtype,String subsys,int timeout)
{
int cc,n,i;
TDataType dout;
TDataType din;
TLink tl;
StringBuffer host = new StringBuffer(32);
StringBuffer query = new StringBuffer(32);
short[] numout = new short[1];
TDataType numoutData = new TDataType(numout);
NAME16[] taglist16;
NAME32[] taglist32;
String[] strlist;
if (subsys == null || subsys.compareTo("ALL") == 0)
{
din = new TDataType();
}
else
{
din = new TDataType(subsys);
}
host.delete(0,31); query.delete(0,31);
if (context != null && context.length() != 0)
{
host.insert(0,"ENS/" + context);
}
else
{
host.insert(0,"ENS");
}
query.insert(0,"N" + tagtype);
try
{
tl = new TLink(host.toString(),query.toString(),numoutData,din,TAccess.CA_READ);
cc = tl.execute(timeout,true);
srvAddr = tl.srvAddr;
tl.close();
}
catch (Exception e)
{ // if the host name cannot be resolved -> runtime exception
MsgLog.log("getTagList", e.getMessage(),TErrorList.non_existent_elem,e,0);
cc = TErrorList.non_existent_elem;
}
if (cc != 0) return null;
if (numout[0] == 0 && subsys != null && subsys.length() > 0) numout[0] = 100;
query.delete(0,31);
query.insert(0,tagtype);
n = numout[0];
taglist32 = new NAME32[n];
for (i=0; i<n; i++) taglist32[i] = new NAME32();
if (taglist32.length == 0) return null;
if (numout[0] > taglist32.length) numout[0] = (short)taglist32.length;
dout = new TDataType(taglist32);
tl = new TLink(host.toString(),query.toString(),dout,din,TAccess.CA_READ);
cc = tl.execute(TLink.defaultTimeout,true);
if (dout.getCompletionLength() < n) n = dout.getCompletionLength();
tl.close();
if (cc == 0)
{ // this worked, so we're finished
strlist = new String[n];
for (i=0; i<n; i++) strlist[i] = taglist32[i].name;
return strlist;
}
if (cc == TErrorList.illegal_format)
{ // old ENS ? -> try with reduced lengths ...
taglist16 = new NAME16[n];
for (i=0; i<n; i++) taglist16[i] = new NAME16();
if (taglist16.length == 0) return null;
if (numout[0] > taglist16.length) numout[0] = (short)taglist16.length;
dout = new TDataType(taglist16);
tl = new TLink(host.toString(),query.toString(),dout,din,TAccess.CA_READ);
cc = tl.execute(TLink.defaultTimeout,true);
tl.close();
if (cc != 0) return null;
strlist = new String[n];
for (i=0; i<n; i++) strlist[i] = taglist16[i].name;
return strlist;
}