// Answer a query for services of a given type
// find matching services
for (Iterator serviceIterator = this.jmDNSImpl.getServices().values().iterator(); serviceIterator.hasNext();)
{
ServiceInfoImpl info = (ServiceInfoImpl) serviceIterator.next();
if (info.getState() == DNSState.ANNOUNCED)
{
if (q.getName().equalsIgnoreCase(info.getType()))
{
DNSRecord answer = this.jmDNSImpl.getLocalHost().getDNS4AddressRecord();
if (answer != null)
{
answers.add(answer);
}
answer = this.jmDNSImpl.getLocalHost().getDNS6AddressRecord();
if (answer != null)
{
answers.add(answer);
}
answers.add(new DNSRecord.Pointer(info.getType(), DNSConstants.TYPE_PTR, DNSConstants.CLASS_IN, DNSConstants.DNS_TTL, info.getQualifiedName()));
answers.add(new DNSRecord.Service(info.getQualifiedName(), DNSConstants.TYPE_SRV, DNSConstants.CLASS_IN | DNSConstants.CLASS_UNIQUE, DNSConstants.DNS_TTL,
info.getPriority(), info.getWeight(), info.getPort(), this.jmDNSImpl.getLocalHost().getName()));
answers.add(new DNSRecord.Text(info.getQualifiedName(), DNSConstants.TYPE_TXT, DNSConstants.CLASS_IN | DNSConstants.CLASS_UNIQUE, DNSConstants.DNS_TTL,
info.getText()));
}
}
}
if (q.getName().equalsIgnoreCase("_services._mdns._udp.local."))
{
for (Iterator serviceTypeIterator = this.jmDNSImpl.getServiceTypes().values().iterator(); serviceTypeIterator.hasNext();)
{
answers.add(new DNSRecord.Pointer("_services._mdns._udp.local.", DNSConstants.TYPE_PTR, DNSConstants.CLASS_IN, DNSConstants.DNS_TTL, (String) serviceTypeIterator.next()));
}
}
break;
}
case DNSConstants.TYPE_SRV:
case DNSConstants.TYPE_ANY:
case DNSConstants.TYPE_TXT:
{
ServiceInfoImpl info = (ServiceInfoImpl) this.jmDNSImpl.getServices().get(q.getName().toLowerCase());
if (info != null && info.getState() == DNSState.ANNOUNCED)
{
DNSRecord answer = this.jmDNSImpl.getLocalHost().getDNS4AddressRecord();
if (answer != null)
{
answers.add(answer);
}
answer = this.jmDNSImpl.getLocalHost().getDNS6AddressRecord();
if (answer != null)
{
answers.add(answer);
}
answers.add(new DNSRecord.Pointer(info.getType(), DNSConstants.TYPE_PTR, DNSConstants.CLASS_IN, DNSConstants.DNS_TTL, info.getQualifiedName()));
answers.add(new DNSRecord.Service(info.getQualifiedName(), DNSConstants.TYPE_SRV, DNSConstants.CLASS_IN | DNSConstants.CLASS_UNIQUE, DNSConstants.DNS_TTL,
info.getPriority(), info.getWeight(), info.getPort(), this.jmDNSImpl.getLocalHost().getName()));
answers.add(new DNSRecord.Text(info.getQualifiedName(), DNSConstants.TYPE_TXT, DNSConstants.CLASS_IN | DNSConstants.CLASS_UNIQUE, DNSConstants.DNS_TTL, info.getText()));
}
break;
}
default :
{