コード例 #1
0
 /**
  * Adds the mixin field to the target class.
  *
  * @param fieldInfo
  * @param deploymentModel
  * @param mixinDef
  */
 private void addMixinField(
     final MixinFieldInfo fieldInfo,
     final DeploymentModel deploymentModel,
     final MixinDefinition mixinDef) {
   final String signature = fieldInfo.mixinClassInfo.getSignature();
   int modifiers = 0;
   if (deploymentModel.equals(DeploymentModel.PER_CLASS)
       || deploymentModel.equals(DeploymentModel.PER_JVM)) {
     fieldInfo.isStatic = true;
     fieldInfo.isPerJVM = deploymentModel.equals(DeploymentModel.PER_JVM);
     modifiers = ACC_PRIVATE + ACC_FINAL + ACC_STATIC + ACC_SYNTHETIC;
   } else if (deploymentModel.equals(DeploymentModel.PER_INSTANCE)) {
     fieldInfo.isStatic = false;
     modifiers = ACC_PRIVATE + ACC_FINAL + ACC_SYNTHETIC;
   } else {
     throw new DefinitionException(
         "deployment model ["
             + mixinDef.getDeploymentModel()
             + "] for mixin ["
             + mixinDef.getMixinImpl().getName()
             + "] is not supported");
   }
   if (mixinDef.isTransient()) {
     modifiers += ACC_TRANSIENT;
   }
   cv.visitField(modifiers, fieldInfo.fieldName, signature, null, null);
   m_mixinFields.put(mixinDef.getMixinImpl(), fieldInfo);
 }
コード例 #2
0
  /**
   * Create a new introduction
   *
   * @param name of this introduction - by convention the AspectClassFQN $ InnerClass
   * @param implClass
   * @param aspectContext which defines this mixin
   * @param definition
   */
  public Introduction(
      final String name,
      final Class implClass,
      final AspectContext aspectContext,
      final IntroductionDefinition definition) {
    m_name = name;
    m_aspectContext = aspectContext;
    m_definition = definition;
    m_mixinImplClass = implClass;
    m_mixinConstructor = findConstructor();
    ARRAY_WITH_CROSS_CUTTING_INFO[0] = m_aspectContext;

    // handle deploymentModel dependancies
    // defaults to Aspect deploymentModel
    // else supported models are:
    // Mixin Aspect
    // perJVM perJVM
    // perClass perJVM,perClass
    // perInstance perJVM,perClass,perInstance
    // perThread perThread
    // todo all those checks should be done earlier
    // (AspectC thought doclet inheritance might cause problem when inheritating compiled
    // aspects without source
    // code)
    if (definition.getDeploymentModel() == null) {
      m_deploymentModel = m_aspectContext.getDeploymentModel();
    } else {
      int model = DeploymentModel.getDeploymentModelAsInt(definition.getDeploymentModel());
      if (DeploymentModel.isMixinDeploymentModelCompatible(
          model, m_aspectContext.getDeploymentModel())) {
        m_deploymentModel = model;
      } else {
        throw new RuntimeException(
            "could no create mixin from aspect: incompatible deployment models : mixin "
                + DeploymentModel.getDeploymentModelAsString(model)
                + " with aspect "
                + DeploymentModel.getDeploymentModelAsString(m_aspectContext.getDeploymentModel()));
      }
    }
  }
コード例 #3
0
  /**
   * Creates a new aspect container.
   *
   * @param aspectClass the aspect class
   */
  private static AspectContainer createAspectContainer(final Class aspectClass) {
    AspectDefinition aspectDefinition = null;

    Set definitions =
        SystemDefinitionContainer.getRegularAndVirtualDefinitionsFor(aspectClass.getClassLoader());
    for (Iterator iterator = definitions.iterator();
        iterator.hasNext() && aspectDefinition == null; ) {
      SystemDefinition systemDefinition = (SystemDefinition) iterator.next();
      for (Iterator iterator1 = systemDefinition.getAspectDefinitions().iterator();
          iterator1.hasNext(); ) {
        AspectDefinition aspectDef = (AspectDefinition) iterator1.next();
        if (aspectClass.getName().replace('/', '.').equals(aspectDef.getClassName())) {
          aspectDefinition = aspectDef;
          break;
        }
      }
    }
    if (aspectDefinition == null) {
      throw new Error("Could not find AspectDefinition for " + aspectClass.getName());
    }

    String containerClassName = aspectDefinition.getContainerClassName();
    try {
      Class containerClass;
      if (containerClassName == null
          || aspectClass.getName().equals(CFlowSystemAspect.CLASS_NAME)) {
        containerClass =
            ContextClassLoader.loadClass(aspectClass.getClassLoader(), DEFAULT_ASPECT_CONTAINER);
      } else {
        containerClass =
            ContextClassLoader.loadClass(aspectClass.getClassLoader(), containerClassName);
      }
      Constructor constructor = containerClass.getConstructor(new Class[] {AspectContext.class});
      final AspectContext aspectContext =
          new AspectContext(
              aspectDefinition.getSystemDefinition().getUuid(),
              aspectClass,
              aspectDefinition.getName(),
              DeploymentModel.getDeploymentModelAsInt(aspectDefinition.getDeploymentModel()),
              aspectDefinition,
              aspectDefinition.getParameters());
      final AspectContainer container =
          (AspectContainer) constructor.newInstance(new Object[] {aspectContext});
      aspectContext.setContainer(container);
      return container;
    } catch (InvocationTargetException e) {
      throw new DefinitionException(e.getTargetException().toString());
    } catch (NoSuchMethodException e) {
      throw new DefinitionException(
          "aspect container does not have a valid constructor ["
              + containerClassName
              + "] need to take an AspectContext instance as its only parameter: "
              + e.toString());
    } catch (Throwable e) {
      StringBuffer cause = new StringBuffer();
      cause.append("could not create aspect container using the implementation specified [");
      cause.append(containerClassName);
      cause.append("] due to: ");
      cause.append(e.toString());
      e.printStackTrace();
      throw new DefinitionException(cause.toString());
    }
  }