Esempio n. 1
0
  protected Definition loadBinaryADL(
      final String name, final URL location, final Map<Object, Object> context)
      throws ADLException, IOException {
    try {
      final InputStream is = location.openStream();
      final NodeInputStream nis = new NodeInputStream(is, nodeFactoryItf.getClassLoader());
      if (logger.isLoggable(Level.FINE))
        logger.log(Level.FINE, "Load ADL \"" + name + "\". Read ADL from " + location);

      long t = 0;
      if (logger.isLoggable(Level.FINER)) t = currentTimeMillis();

      final Definition d = NodeUtil.castNodeError(nis.readObject(), Definition.class);

      if (logger.isLoggable(Level.FINER)) {
        t = currentTimeMillis() - t;
        logger.log(
            Level.FINER, "Load ADL \"" + name + "\".  read from binary file in " + t + "ms.");
      }

      nis.close();

      return d;
    } catch (final ClassNotFoundException e) {
      errorManagerItf.logFatal(
          GenericErrors.INTERNAL_ERROR, e, "Can't read binary ADL " + location);
      return null;
    }
  }
  protected void checkUnboundInterfaces(
      final ComponentContainer container, final Map<Object, Object> context) throws ADLException {
    final Binding[] bindings =
        (container instanceof BindingContainer)
            ? ((BindingContainer) container).getBindings()
            : new Binding[0];

    // first check internal client interfaces
    if (container instanceof InternalInterfaceContainer) {
      for (final Interface itf : ((InternalInterfaceContainer) container).getInternalInterfaces()) {
        if (isClient(itf) && isMandatory(itf)) {
          if (findBinding(bindings, THIS_COMPONENT, itf) == null)
            errorManagerItf.logError(
                BindingErrors.UNBOUND_COMPOSITE_SERVER_INTERFACE,
                container,
                itf.getName(),
                ((Definition) container).getName());
        }
      }
    }

    // then check client interfaces of sub components
    for (final Component subComponent : container.getComponents()) {
      final Definition subCompDef =
          getResolvedComponentDefinition(subComponent, recursiveLoaderItf, context);
      assert subCompDef != null;
      if (ASTHelper.isUnresolvedDefinitionNode(subCompDef)) continue;

      if (subCompDef instanceof InterfaceContainer) {
        for (final Interface itf : ((InterfaceContainer) subCompDef).getInterfaces()) {
          if (isClient(itf) && isMandatory(itf)) {
            if (findBinding(bindings, subComponent.getName(), itf) == null)
              errorManagerItf.logError(
                  BindingErrors.UNBOUND_CLIENT_INTERFACE,
                  subComponent,
                  itf.getName(),
                  subComponent.getName());
          }
        }
      }
    }
  }
 protected void checkDualMeths(final IDL idl, final Map<Object, Object> context)
     throws ADLException {
   if (idl instanceof InterfaceDefinition) {
     for (final Method method : ((InterfaceDefinition) idl).getMethods()) {
       if (method.getVaArgs() != null) {
         if (method.getVaArgs().getDualMethodName() == null) {
           errorManagerItf.logWarning(IDLErrors.UNDEFINED_DUALMETH, method, method.getName());
         }
       }
     }
   }
 }
Esempio n. 4
0
  public Definition load(final String name, final Map<Object, Object> context) throws ADLException {
    final Map<String, Definition> cache = getCache(context);
    Definition d = cache.get(name);

    if (d == null) {
      Set<String> loadingDefinitions = this.loadingDefinitions.get();
      if (loadingDefinitions == null) {
        loadingDefinitions = new LinkedHashSet<String>();
        this.loadingDefinitions.set(loadingDefinitions);
      }

      if (!loadingDefinitions.add(name)) {
        errorManagerItf.logFatal(ComponentErrors.DEFINITION_CYCLE, loadingDefinitions.toString());
      }
      try {
        d = clientLoader.load(name, context);
      } finally {
        loadingDefinitions.remove(name);
      }
      cache.put(name, d);
    }

    return d;
  }
Esempio n. 5
0
  public Definition load(final String name, final Map<Object, Object> context) throws ADLException {

    if (ForceRegenContextHelper.getForceRegen(context)) {
      if (logger.isLoggable(Level.FINE))
        logger.log(Level.FINE, "Load ADL \"" + name + "\". Forced mode, load source");
      return loadSourceADL(name, context);
    }

    final URL binADL = adlLocatorItf.findBinaryADL(name, context);
    if (binADL == null) {
      if (logger.isLoggable(Level.FINE))
        logger.log(Level.FINE, "Load ADL \"" + name + "\". binary ADL not found, load source");
      return loadSourceADL(name, context);
    }

    final URL srcADL = adlLocatorItf.findSourceADL(name, context);
    if (srcADL == null) {
      // only binary file is available, load from binary file.
      if (logger.isLoggable(Level.FINE))
        logger.log(Level.FINE, "Load ADL \"" + name + "\". source unavailable, load binary");
      try {
        return loadBinaryADL(name, binADL, context);
      } catch (final IOException e) {
        errorManagerItf.logFatal(
            GenericErrors.INTERNAL_ERROR, e, "Can't read binary ADL " + binADL + ".");
        return null;
      }
    }

    // both binary and source file are available, check timestamps:
    boolean outOfDate;
    long binTimestamp = 0;
    try {
      binTimestamp = getTimestamp(binADL);
      outOfDate = getTimestamp(srcADL) >= binTimestamp;
    } catch (final MalformedURLException e) {
      if (logger.isLoggable(Level.WARNING))
        logger.log(Level.WARNING, "Load ADL \"" + name + "\". can't determine file timestamps");
      outOfDate = true;
    }
    if (outOfDate) {
      logger.log(
          Level.FINE, "Load ADL \"" + name + "\". Binary ADL older from source, load source");

    } else {
      // if binary file is more recent than source file, check dependencies.

      // load binary ADL to retrieve list of input resources.
      Definition binDef;
      try {
        binDef = loadBinaryADL(name, binADL, context);
      } catch (final IOException e) {
        errorManagerItf.logWarning(
            GenericErrors.INTERNAL_ERROR,
            e,
            "Can't read binary ADL " + binADL + ". Use source ADL.");
        return null;
      }

      if (binDef != null) {
        final Set<InputResource> dependencies = InputResourcesHelper.getInputResources(binDef);
        if (logger.isLoggable(Level.FINEST))
          logger.log(Level.FINEST, "Load ADL \"" + name + "\". check dependencies=" + dependencies);
        if (dependencies != null
            && inputResourceLocatorItf.isUpToDate(binTimestamp, dependencies, context)) {
          if (logger.isLoggable(Level.FINEST))
            logger.log(Level.FINEST, "Load ADL \"" + name + "\". Binary version is up-to-date");

          // binary version is up to date, return it
          return binDef;
        }
      }
    }

    if (logger.isLoggable(Level.FINE))
      logger.log(Level.FINE, "Load ADL \"" + name + "\". Binary ADL out of date, load source");
    // binary version is older than source file, load from source
    return loadSourceADL(name, context);
  }