/** * Creates a new Extended Resolver * * @param servers An array of server names for which SimpleResolver contexts should be * initialized. * @see SimpleResolver * @exception UnknownHostException Failure occured initializing SimpleResolvers */ public ExtendedResolver(String[] servers) throws UnknownHostException { init(); for (int i = 0; i < servers.length; i++) { Resolver r = new SimpleResolver(servers[i]); r.setTimeout(quantum); resolvers.add(r); } }
/** * Creates a new Extended Resolver. The default ResolverConfig is used to determine the servers * for which SimpleResolver contexts should be initialized. * * @see SimpleResolver * @see ResolverConfig * @exception UnknownHostException Failure occured initializing SimpleResolvers */ public ExtendedResolver() throws UnknownHostException { init(); String[] servers = ResolverConfig.getCurrentConfig().servers(); if (servers != null) { for (int i = 0; i < servers.length; i++) { Resolver r = new SimpleResolver(servers[i]); r.setTimeout(quantum); resolvers.add(r); } } else resolvers.add(new SimpleResolver()); }
public static void load( Resolver loader, String file, SimpleDirectedGraph<GraphClass, Inclusion> graph, Vector problems) { ISGCIReader gcr = new ISGCIReader(graph, problems); XMLParser xml = new XMLParser(loader.openInputSource(file), gcr, loader.getEntityResolver()); xml.parse(); date = gcr.getDate(); nodecount = gcr.getNodeCount(); edgecount = gcr.getEdgeCount(); relations = gcr.getRelations(); }
/** * Creates a Zone by performing a zone transfer to the specified host. All records that do not * belong in the Zone are added to the specified Cache. * * @see Cache * @see Master */ public Zone(Name zone, short dclass, String remote, Cache cache) throws IOException { super(false); origin = zone; this.dclass = dclass; type = SECONDARY; Resolver res = new SimpleResolver(remote); Record rec = Record.newRecord(zone, Type.AXFR, dclass); Message query = Message.newQuery(rec); Message response = res.send(query); Record[] recs = response.getSectionArray(Section.ANSWER); for (int i = 0; i < recs.length; i++) { if (!recs[i].getName().subdomain(origin)) { if (Options.check("verbose")) System.err.println(recs[i].getName() + "is not in zone " + origin); continue; } addRecord(recs[i]); } if (cache != null) { recs = response.getSectionArray(Section.ADDITIONAL); for (int i = 0; i < recs.length; i++) cache.addRecord(recs[i], Credibility.GLUE, recs); } validate(); }
/** * Find a type object in the context of the class. * * @param name The name to search for. */ public Named find(Matcher<Named> matcher, Context context) throws SemanticException { Name name = matcher.name(); if (Report.should_report(TOPICS, 2)) Report.report(2, "Looking for " + name + " in " + this); if (!(type instanceof ClassType)) { throw new NoClassException(name.toString(), type); } ClassType type = (ClassType) this.type; Named m = null; QName fullName = null; QName rawName = null; if (type.isGloballyAccessible()) { fullName = QName.make(type.fullName(), name); QName q = ts.getTransformedClassName(type.def()); rawName = QName.make(q.qualifier(), Name.make(q.name() + "$" + name)); } if (fullName != null) { // First check the system resolver. m = ts.systemResolver().check(fullName); // Try the raw class file name. if (m == null) { m = ts.systemResolver().check(rawName); } if (m == null) { // Go to disk, but only if there is no job for the type. // If there is a job, all members should be in the resolver // already. boolean useLoadedResolver = true; if (type instanceof ParsedTypeObject) { ParsedTypeObject pto = (ParsedTypeObject) type; if (pto.job() != null) { useLoadedResolver = false; } } if (useLoadedResolver) { try { m = ts.systemResolver().find(rawName); } catch (SemanticException e) { // Not found; will fall through to error handling code } } } // If we found something, verify that it matches. if (m != null) { try { m = matcher.instantiate(m); } catch (SemanticException e) { // Doesn't match; try again. m = null; } } } // Check if the member was explicitly declared. if (m == null) { m = type.memberTypeMatching(matcher); } // If we found something, make sure it's accessible. if (m instanceof ClassType) { ClassType mt = (ClassType) m; if (!mt.isMember()) { throw new SemanticException( "Class " + mt + " is not a member class, " + " but was found in " + type + "."); } if (!mt.outer().equals((Object) type)) { throw new SemanticException( "Class " + mt + " is not a member class " + " of " + type + "."); } return mt; } if (m instanceof MemberInstance) { MemberInstance<?> mi = (MemberInstance<?>) m; if (!mi.container().equals((Object) type)) { throw new SemanticException("Type " + mi + " is not a member " + " of " + type + "."); } } if (m != null) { if (!canAccess(m, context.currentClassDef(), context)) { throw new SemanticException("Cannot access member type \"" + m + "\"."); } return m; } // If we struck out, try the super types. // Collect all members of the super types. // Use a Set to eliminate duplicates. Set<Named> acceptable = new HashSet<Named>(); if (type.superClass() != null) { Type sup = type.superClass(); if (sup instanceof ClassType) { Resolver r = ts.classContextResolver((ClassType) sup, context); try { Named n = r.find(matcher); acceptable.add(n); } catch (SemanticException e) { } } } for (Iterator<Type> i = type.interfaces().iterator(); i.hasNext(); ) { Type sup = (Type) i.next(); if (sup instanceof ClassType) { Resolver r = ts.classContextResolver((ClassType) sup, context); try { Named n = r.find(matcher); acceptable.add(n); } catch (SemanticException e) { } } } if (acceptable.size() == 0) { throw new NoClassException(name.toString(), type); } else if (acceptable.size() > 1) { Set<Type> containers = new HashSet<Type>(acceptable.size()); for (Named n : acceptable) { if (n instanceof MemberInstance) { MemberInstance<?> mi = (MemberInstance<?>) n; containers.add(mi.container()); } } if (containers.size() == 2) { Iterator<Type> i = containers.iterator(); Type t1 = (Type) i.next(); Type t2 = (Type) i.next(); throw new SemanticException( "Member \"" + name + "\" of " + type + " is ambiguous; it is defined in both " + t1 + " and " + t2 + "."); } else if (containers.size() == 0) { throw new SemanticException("Member \"" + name + "\" of " + type + " is ambiguous."); } else { throw new SemanticException( "Member \"" + name + "\" of " + type + " is ambiguous; it is defined in " + CollectionUtil.listToString(new ArrayList<Type>(containers)) + "."); } } assert acceptable.size() == 1; Named t = acceptable.iterator().next(); if (Report.should_report(TOPICS, 2)) Report.report(2, "Found member type " + t); return t; }
public static Record[] getRecords(String namestr, short type, short dclass, byte cred) { Message query; Message response; Record question; Record[] answers; int answerCount = 0, i = 0; Enumeration e; Name name = new Name(namestr); /*System.out.println("lookup of " + name + " " + Type.string(type));*/ if (!Type.isRR(type) && type != Type.ANY) return null; if (res == null) { try { eres = new ExtendedResolver(); } catch (UnknownHostException uhe) { System.out.println("Failed to initialize resolver"); System.exit(-1); } } if (cache == null) cache = new Cache(); CacheResponse cached = cache.lookupRecords(name, type, dclass, cred); /*System.out.println(cached);*/ if (cached.isSuccessful()) { RRset rrset = cached.answer(); answerCount = rrset.size(); e = rrset.rrs(); } else if (cached.isNegative()) { answerCount = 0; e = null; } else { question = Record.newRecord(name, type, dclass); query = Message.newQuery(question); if (res != null) response = res.send(query); else response = eres.send(query); short rcode = response.getHeader().getRcode(); if (rcode == Rcode.NOERROR || rcode == Rcode.NXDOMAIN) cache.addMessage(response); if (rcode != Rcode.NOERROR) return null; e = response.getSection(Section.ANSWER); while (e.hasMoreElements()) { Record r = (Record) e.nextElement(); if (matchType(r.getType(), type)) answerCount++; } e = response.getSection(Section.ANSWER); } if (answerCount == 0) return null; answers = new Record[answerCount]; while (e.hasMoreElements()) { Record r = (Record) e.nextElement(); if (matchType(r.getType(), type)) answers[i++] = r; } return answers; }