public final DataEntry resolveUcodeLocal(Ucode code, Ucode mask, QueryAttribute attribute, QueryMode mode) throws Exception {
// Check if database has properly initialized
if(database == null) throw new NullPointerException("Database of type UcodeRD must not be null.");
Iterator<DataFile> i = database.getDataFilesView().iterator();
DataFile file = null;
DataFile resolvedFile = null;
boolean isSpaceMatched = false;
// Search for matching criteria of a data file (Specification page 12)
// (queryucode & querymask & dbmask) equals (dbucode & querymask & dbmask)
while(i.hasNext()) {
file = i.next();
isSpaceMatched = code
.bitwiseAND(mask)
.bitwiseAND(file.getDbMask())
.equals(file.getDbUcode().bitwiseAND(mask)
.bitwiseAND(file.getDbMask()));
if(isSpaceMatched) {
// Remember space matched file
resolvedFile = file;
// Check Cascade query mode and supported file
if(mode == QueryMode.UIDC_RSMODE_CASCADE) {
if(file.getCascadeMode() == CascadeMode.UIDC_CSC) break;
else continue;
} else {
break;
}
}
}
// If no data file is matched, return null as the result
if(!isSpaceMatched) return null;
// Search for matching Data Entry within selected file (Specification page 12)
// (queryucode & querymask & ucodemask) equals (ucode & querymask & ucodemask)
// and (querymask & ucodemask) equals ucodemask
Iterator<DataEntry> j = resolvedFile.getDataEntriesView().iterator();
DataEntry entry = null;
DataEntry resolvedEntry = null;
isSpaceMatched = false;
// Default alternative server with which another search attempt may succeed
// OPT this should be defined as constant or file resource
DataEntry defaultEntry = new DataEntry( new Ucode(0x0efffec000000000L, 0x0000000000050200L),
new Ucode(0xffffffffffffffffL, 0xffffffffffffff00L),
DataAttribute.UIDC_ATTR_RS,
(short) 1,
3600,
DataType.UIDC_DATATYPE_UCODE_IPV4,
"192.168.10.1");
while (j.hasNext()) {
entry = j.next();
isSpaceMatched = (code.bitwiseAND(mask).bitwiseAND(
entry.getUcodeMask()).equals(entry.getUcode()
.bitwiseAND(mask).bitwiseAND(entry.getUcodeMask())))
&& (mask.bitwiseAND(entry.getUcodeMask()).equals(entry
.getUcodeMask()));
if (isSpaceMatched) {
// Choose any data entry if query attribute is UIDC_ATTR_ANONYMOUS
if (attribute.equals(QueryAttribute.UIDC_ATTR_ANONYMOUS)) {
return entry;
// Further check if the query attribute matches one in the entry
} else if (attribute.getCode() == entry.getDataAttribute().getCode()) {
return entry;
// Remember entry with UIDC_ATTR_RS for resolution redirect if requested attribute not found
} else if (entry.getDataAttribute().equals(DataAttribute.UIDC_ATTR_RS)) {
// Check if cascade search mode is requested and the file is supported, do query for the client
if( (mode == QueryMode.UIDC_RSMODE_CASCADE) && (resolvedFile.getCascadeMode() == CascadeMode.UIDC_CSC) ) {
resolveUcodeCascade(code, mask, attribute, mode, entry.getStringData());
resolvedEntry = null;
} else {
resolvedEntry = entry;
}