コード例 #1
0
 @Override
 public ModuleInfo getModuleForAccelerator(final Accelerator acc) {
   for (final ModuleInfo info : getModules()) {
     final MenuPath menuPath = info.getMenuPath();
     if (menuPath == null || menuPath.isEmpty()) continue;
     if (acc.equals(menuPath.getLeaf().getAccelerator())) return info;
   }
   return null;
 }
コード例 #2
0
ファイル: ModuleContext.java プロジェクト: Keruspe/Bianca
  /** Returns the module with the given name. */
  public BiancaModule findModule(String name) {
    ModuleInfo info = _moduleInfoMap.get(name);

    if (info != null) {
      return info.getModule();
    } else {
      return null;
    }
  }
コード例 #3
0
  @Override
  public Module createModule(final ModuleInfo info) {
    final Module existing = getRegisteredModuleInstance(info);
    if (existing != null) return existing;

    try {
      final Module module = info.createModule();
      getContext().inject(module);
      Priority.inject(module, info.getPriority());
      return module;
    } catch (final ModuleException exc) {
      log.error("Cannot create module: " + info.getDelegateClassName());
    }
    return null;
  }
  public List<ArtifactResult> dependencies() throws RepositoryException {
    List<ModuleInfo> infos = BytecodeUtils.readModuleInformation(name(), artifact());
    if (infos.isEmpty()) return Collections.emptyList();

    final List<ArtifactResult> results = new ArrayList<ArtifactResult>();
    for (ModuleInfo mi : infos) {
      results.add(
          new LazyArtifactResult(
              mi.getName(),
              mi.getVersion(),
              mi.isOptional()
                  ? ImportType.OPTIONAL
                  : (mi.isExport() ? ImportType.EXPORT : ImportType.UNDEFINED)));
    }
    return results;
  }
コード例 #5
0
  /**
   * Checks the {@link ObjectService} for a single registered {@link Module} instance of the given
   * {@link ModuleInfo}. In this way, if you want to repeatedly reuse the same module instance
   * instead of creating a new one with each execution, you can register it with the {@link
   * ObjectService} and it will be automatically returned by the {@link #createModule(ModuleInfo)}
   * method (and hence automatically used whenever a {@link #run} method with {@link ModuleInfo}
   * argument is called).
   */
  private Module getRegisteredModuleInstance(final ModuleInfo info) {
    final Class<?> type = ClassUtils.loadClass(info.getDelegateClassName());
    if (type == null || !Module.class.isAssignableFrom(type)) return null;

    // the module metadata's delegate class extends Module, so there is hope
    @SuppressWarnings("unchecked")
    final Class<? extends Module> moduleType = (Class<? extends Module>) type;

    // ask the object service for an instance of the delegate type
    final List<? extends Module> objects = objectService.getObjects(moduleType);
    if (objects == null || objects.isEmpty()) {
      // the object service has no such instances
      return null;
    }
    if (objects.size() > 1) {
      // there are multiple instances; it's not clear which one to use
      log.warn("Ignoring multiple candidate module instances for class: " + type.getName());
      return null;
    }
    // found exactly one instance; return it!
    return objects.get(0);
  }
コード例 #6
0
 @Override
 public ModuleInfo getModuleInfo() {
   ModuleInfo info = new ModuleInfo();
   info.getDependencies().addAll(dependencies);
   return info;
 }
コード例 #7
0
 public Collection<Artifact> getUsedModules(boolean usePic, Set<Artifact> usedHeaders) {
   return usePic
       ? picModuleInfo.getUsedModules(usedHeaders)
       : moduleInfo.getUsedModules(usedHeaders);
 }
コード例 #8
0
 public Set<Artifact> getTopLevelModules(boolean usePic) {
   return usePic ? picModuleInfo.getTopLevelModules() : moduleInfo.getTopLevelModules();
 }
コード例 #9
0
 /**
  * Verifies the equality of the two objects. Performs special handling of certain types.
  *
  * @param inExpected expected object.
  * @param inActual actual object.
  * @throws IOException if there were errors.
  */
 private static void verifyEquals(Object inExpected, Object inActual) throws IOException {
   if (inExpected == null) {
     assertNull(inActual);
   } else {
     assertNotNull("Expected:" + inExpected, inActual);
     // special handling for certain types
     if (inExpected instanceof ModuleInfo) {
       ModuleInfo e = (ModuleInfo) inExpected;
       ModuleInfo a = (ModuleInfo) inActual;
       ModuleTestBase.assertModuleInfo(
           a,
           e.getURN(),
           e.getState(),
           e.getInitiatedDataFlows(),
           e.getParticipatingDataFlows(),
           e.isAutocreated(),
           e.isAutostart(),
           e.isReceiver(),
           e.isEmitter(),
           e.isFlowRequester());
       assertEquals(e.getLastStartFailure(), a.getLastStartFailure());
       assertEquals(e.getLastStopFailure(), a.getLastStopFailure());
       assertEquals(e.getLockQueueLength(), a.getLockQueueLength());
       assertEquals(e.getReadLockCount(), a.getReadLockCount());
       assertEquals(e.isWriteLocked(), a.isWriteLocked());
     } else if (inExpected instanceof Map) {
       // Convert both maps to the same type
       Map e = new HashMap<Object, Object>((Map<?, ?>) inExpected);
       Map a = new HashMap<Object, Object>((Map<?, ?>) inActual);
       assertEquals(e, a);
     } else if (inExpected instanceof CreateStrategyParameters) {
       CreateStrategyParameters e = (CreateStrategyParameters) inExpected;
       CreateStrategyParameters a = (CreateStrategyParameters) inActual;
       assertEquals(e.getInstanceName(), a.getInstanceName());
       assertEquals(e.getStrategyName(), a.getStrategyName());
       assertEquals(e.getLanguage(), a.getLanguage());
       InputStream ein = e.getStrategySource();
       InputStream ain = a.getStrategySource();
       assertArrayEquals(IOUtils.toByteArray(ein), IOUtils.toByteArray(ain));
       ein.close();
       ain.close();
     } else {
       assertEquals(inExpected, inActual);
     }
   }
 }