Пример #1
0
 public T find(String moduleId, String symbolId) throws IllegalArgumentException {
   if (moduleId != null) {
     SmiModule module = moduleMap.get(moduleId);
     if (module == null) {
       throw new IllegalArgumentException("Module " + moduleId + " could not be found.");
     }
     SmiSymbol symbol = module.findSymbol(symbolId);
     if (symbol == null) {
       return null;
     }
     if (symbolClass.isAssignableFrom(symbol.getClass())) {
       return symbolClass.cast(symbol);
     } else {
       // throw new
       // IllegalArgumentException(symbol.getClass().getSimpleName() +
       // " with id " + symbolId + " is not an instance of " +
       // m_symbolClass);
       return null; // when the lookup is through the global map, we
       // also return null for an object that is of the
       // wrong type.
     }
   } else {
     return getOne(symbolId);
   }
 }
Пример #2
0
 public <T extends SmiSymbol> T resolveReference(
     IdToken idToken, Class<T> expectedClass, XRefProblemReporter reporter) {
   SmiSymbol result = resolveReference(idToken, reporter);
   if (result != null) {
     if (expectedClass.isInstance(result)) {
       return expectedClass.cast(result);
     } else {
       reporter.reportFoundSymbolButWrongType(idToken, expectedClass, result.getClass());
     }
   }
   return null;
 }
Пример #3
0
 private SmiSymbol determineBestMatchBasedOnSnmpVersion(List<SmiSymbol> symbols) {
   if (symbols.size() == 2) {
     SmiSymbol s0 = symbols.get(0);
     SmiSymbol s1 = symbols.get(1);
     SmiVersion version0 = s0.getModule().getVersion();
     SmiVersion version1 = s1.getModule().getVersion();
     if (version0 != null && version1 != null && version0 != version1) {
       if (getVersion() == version0) {
         return s0;
       } else if (getVersion() == version1) {
         return s1;
       }
     }
   }
   return null;
 }
Пример #4
0
 private SmiSymbol determineBestMatchBasedOnOtherImports(
     IdToken idToken, List<SmiSymbol> symbols) {
   for (SmiSymbol symbol : symbols) {
     for (SmiImports imports : m_imports) {
       if (imports.getModule() == symbol.getModule()) {
         m_log.debug(
             "Determined best match for "
                 + idToken
                 + " based on other imports from "
                 + symbol.getModule().getId());
         return symbol;
       }
     }
   }
   return null;
 }
Пример #5
0
 private SmiSymbol determineBestMatch(IdToken idToken, List<SmiSymbol> symbols) {
   SmiSymbol result = determineBestMatchBasedOnSnmpVersion(symbols);
   if (result != null) {
     return result;
   }
   result = determineBestMatchBasedOnOtherImports(idToken, symbols);
   if (result != null) {
     return result;
   }
   if (m_log.isDebugEnabled()) {
     m_log.debug(
         "Couldn't choose between " + symbols.size() + " choices for resolving: " + idToken + ":");
     for (SmiSymbol symbol : symbols) {
       m_log.debug(symbol.toString());
     }
   }
   return null;
 }
Пример #6
0
 public void addSymbol(SmiSymbol symbol) {
   m_symbols.add(symbol);
   m_symbolMap.put(symbol.getId(), symbol);
 }
Пример #7
0
 private <T extends SmiSymbol> void put(Map<String, T> map, Class<T> clazz, SmiSymbol symbol) {
   if (clazz.isInstance(symbol)) {
     map.put(symbol.getId(), clazz.cast(symbol));
   }
 }