Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 package javax.jmdns.impl.tasks.resolver;
00006 
00007 import java.io.IOException;
00008 
00009 import javax.jmdns.ServiceInfo;
00010 import javax.jmdns.impl.DNSOutgoing;
00011 import javax.jmdns.impl.DNSQuestion;
00012 import javax.jmdns.impl.DNSRecord;
00013 import javax.jmdns.impl.JmDNSImpl;
00014 import javax.jmdns.impl.constants.DNSConstants;
00015 import javax.jmdns.impl.constants.DNSRecordClass;
00016 import javax.jmdns.impl.constants.DNSRecordType;
00017 
00023 public class ServiceResolver extends DNSResolverTask {
00024 
00025     private final String _type;
00026 
00027     public ServiceResolver(JmDNSImpl jmDNSImpl, String type) {
00028         super(jmDNSImpl);
00029         this._type = type;
00030     }
00031 
00032     
00033 
00034 
00035 
00036     @Override
00037     public String getName() {
00038         return "ServiceResolver(" + (this.getDns() != null ? this.getDns().getName() : "") + ")";
00039     }
00040 
00041     
00042 
00043 
00044 
00045     @Override
00046     protected DNSOutgoing addAnswers(DNSOutgoing out) throws IOException {
00047         DNSOutgoing newOut = out;
00048         long now = System.currentTimeMillis();
00049         for (ServiceInfo info : this.getDns().getServices().values()) {
00050             newOut = this.addAnswer(newOut, new DNSRecord.Pointer(info.getType(), DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE, DNSConstants.DNS_TTL, info.getQualifiedName()), now);
00051             
00052             
00053         }
00054         return newOut;
00055     }
00056 
00057     
00058 
00059 
00060 
00061     @Override
00062     protected DNSOutgoing addQuestions(DNSOutgoing out) throws IOException {
00063         DNSOutgoing newOut = out;
00064         newOut = this.addQuestion(newOut, DNSQuestion.newQuestion(_type, DNSRecordType.TYPE_PTR, DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE));
00065         
00066         return newOut;
00067     }
00068 
00069     
00070 
00071 
00072 
00073     @Override
00074     protected String description() {
00075         return "querying service";
00076     }
00077 }