Package org.mitre.sim.analysis.instrument

Examples of org.mitre.sim.analysis.instrument.AnalysisException


      String qualifiedName = getQualifiedName(className);
      String aspectName = nameForCombining + "_instrument";
      File aspectFile = new File(directoryPath, aspectName + ".aj");
      if (aspectFile.exists()) aspectFile.delete();
      if (!aspectFile.createNewFile())
        throw new AnalysisException("aspect file " + aspectFile
            + " already exists");
      ps = new PrintStream(new FileOutputStream(aspectFile));
      ps.println("package " + aspectPathInfo.getPackageName() + ";");
      ps.println("import java.util.List;");
      ps.println("import java.util.HashSet;");
      ps.println("import java.util.ArrayList;");
      ps.println("import java.lang.reflect.Field;");
      ps.println("import java.lang.reflect.Method;");
      ps.println("import org.mitre.sim.analysis.instrument.InstrumentedTrigger;");
      //aspect is privileged to allow it access to Triggers' private fields
      ps.println("\nprivileged aspect " + aspectName + " {");
     
      ps.println("\n  declare parents : " + unqualifiedName
          + " implements InstrumentedTrigger;");
      ps.println("  private ArrayList " + unqualifiedName + ".earlyBoundNotifiers"
          + " = new ArrayList();");
     
      AspectData.TriggerRecord tr = (AspectData.TriggerRecord)aspectData
        .getTriggerRecord(className);
      String enclosingClassName = null, unqualifiedEnclosingClassName = null;
      String enclosingNameForCombining = null;
      if (tr.enclosingClassName != null) {
        enclosingClassName = getQualifiedName(tr.enclosingClassName);
        unqualifiedEnclosingClassName = getUnqualifiedName(tr.enclosingClassName);
        enclosingNameForCombining = unqualifiedEnclosingClassName.replace('.', '_');
      }
      if (tr.enclosingClassName != null && tr.enclosingCollections.size() > 0)
        addTheAddNotifierMethod(ps, unqualifiedName);
     
      ps.println("\n  public List " + unqualifiedName
          + ".getNotifiers(InstrumentedTrigger it) {");
      ps.println("    ArrayList allNotifiers = new ArrayList();");
      //for each Collection class field in Trigger
      for (Iterator cc = tr.collectionFields.keySet().iterator(); cc.hasNext(); ) {
        String fieldName = (String)cc.next();
        ps.println("    allNotifiers.add(((" + unqualifiedName + ")it)."
            + fieldName + ");" );
      }
      //for each Collection class field in enclosing class
      if (enclosingClassName != null) {
        for (Iterator ecc = tr.enclosingCollections.keySet().iterator();
          ecc.hasNext(); ) {
          String fieldName = (String)ecc.next();
          AspectData.EnclosingClassCollectionRecord eccr = (AspectData.EnclosingClassCollectionRecord)
            tr.enclosingCollections.get(fieldName);
          ps.println("    addTortugaNotifier(it,");
          ps.println("      allNotifiers,");
          ps.println("      " + unqualifiedName + ".class,");
          ps.println("      " + unqualifiedEnclosingClassName + ".class,");
          ps.println("      \"" + eccr.accessMethodName + "\",");
          ps.println("      \"" + tr.referenceToEnclosingName + "\");");
        }
      }
      ps.println("    allNotifiers.addAll(earlyBoundNotifiers);" );
      ps.println("    return allNotifiers;" );
      ps.println("  } //getNotifiers");
     
      ps.println("\n  public void " + unqualifiedName + ".addNotifier(Object n)" );
      ps.println("    { earlyBoundNotifiers.add(n); }" );

      //add enclosing class as notifier, if it has primitive fields
      if (enclosingClassName != null && !tr.enclosingPrimitives.isEmpty()) {
        String pointcutName = nameForCombining + "_add_" + enclosingNameForCombining;
        ps.println("\n  pointcut " + pointcutName + "(InstrumentedTrigger trigger)");
        ps.println("    : initialization(public " + unqualifiedName
            + ".new(..)) && target(trigger);" );
        ps.println("\n  after (InstrumentedTrigger trigger) : "
            + pointcutName + "(trigger) {");
        ps.println("    try {");
        ps.println("      Field enclosingThisField = trigger.getClass().getDeclaredField(\""
            + tr.referenceToEnclosingName + "\");");
        ps.println("      enclosingThisField.setAccessible(true);");
        ps.println("      trigger.addNotifier(enclosingThisField.get(trigger));");
        ps.println("    }");
        ps.println("    catch (Exception e) {");
        ps.println("      throw new IllegalStateException(\"See Tortuga Support. "
            + "(\" + e + \" in trigger instrument aspect for field "
            + tr.referenceToEnclosingName + " trigger " + qualifiedName
            + ")\");");
        ps.println("    } //catch");
        ps.println("  } //after" );
      }
      //add trigger class itself as notifier, if it has primitive fields
      if (!tr.primitiveFields.isEmpty()) {
        String pointcutName = nameForCombining + "_add_" + nameForCombining;
        ps.println("\n  pointcut " + pointcutName + "(InstrumentedTrigger trigger)");
        ps.println("    : initialization(public " + unqualifiedName
            + ".new(..)) && target(trigger);" );
        ps.println("\n  after (InstrumentedTrigger trigger) : "
            + pointcutName + "(trigger) {");
        ps.println("    trigger.addNotifier(trigger);" );
        ps.println("  } //after" );
      }
      ps.println("} //aspect");
    }    
    catch (IOException ex) {
      throw new AnalysisException(ex);
    }
    finally {
      if (ps != null) ps.close();
    }
  }
View Full Code Here


      String qualifiedName = getQualifiedName(className);
      String aspectName = nameForCombining + "_notifier";
      File aspectFile = new File(directoryPath, aspectName + ".aj");
      if (aspectFile.exists()) aspectFile.delete();
      if (!aspectFile.createNewFile())
        throw new AnalysisException("aspect file " + aspectFile
            + " already exists");
      ps = new PrintStream(new FileOutputStream(aspectFile));
      ps.println("package " + aspectPathInfo.getPackageName() + ";");
      ps.println("import org.mitre.sim.exec.Executive;");
      ps.println("import org.mitre.sim.analysis.instrument.Notifier;");
//      ps.println("\npublic aspect " + aspectName + " {");
      ps.println("\nprivileged aspect " + aspectName + " {");
      ps.println("\n  declare parents : " + unqualifiedName
          + " implements Notifier;");
      ps.println("  private Executive " + unqualifiedName + ".exec = null;" );
      ps.println("\n  public void " + unqualifiedName
          + ".setTortugaNotifierExecutive(Executive exec)");
      ps.println("    { this.exec = exec; }" );
      ps.println("  public Executive " + unqualifiedName + ".getTortugaNotifierExecutive()"
          + "\n    { return this.exec; }" );
      //for each primitive field in the Trigger
      for (Iterator pf = primitiveFields.keySet().iterator();
        pf.hasNext(); ) {
        String fieldName = (String)pf.next();
        String signature = (String)primitiveFields.get(fieldName);
        String pointcutName = nameForCombining + "_" + fieldName + "_cut";
        ps.println("\n  pointcut " + pointcutName + "(Notifier notifier)");
        ps.println("    : set(" + signature + " " + unqualifiedName
            + "." + fieldName + ") && target(notifier);" );
        ps.println("\n  after(Notifier notifier) : " + pointcutName
            + "(notifier) {");
        ps.println("    Executive exec = notifier.getTortugaNotifierExecutive();" );
        ps.println("    if (exec != null) exec.conditionMayHaveChanged(notifier);" );
        ps.println("  } //after");
      }
      ps.println("} //aspect");
    }    
    catch (IOException ex) {
      throw new AnalysisException(ex);
    }
    finally {
      if (ps != null) ps.close();
    }
  }
View Full Code Here

   */
  private static boolean isAnonymous(String className)
  throws AnalysisException
  {
    String[] pathElements = className.split("\\.");
    if (pathElements.length < 1) throw new AnalysisException(
        "Class name " + className + " is invalid");
    String lastElement = pathElements[pathElements.length - 1];
    String[] nameElements = lastElement.split("\\$");
    //anon class name has form <identifier>$<int> or <iden1>$<int>$<iden2>
    boolean isAnonymous = false;
View Full Code Here

   */
  private static String getUnqualifiedName(String className)
  throws AnalysisException
  {
    String[] pathElements = className.split("\\.");
    if (pathElements.length < 1) throw new AnalysisException(
        "Class name " + className + " is invalid");
    String lastElement = pathElements[pathElements.length - 1];
    String[] nameElements = lastElement.split("\\$");
    //anon class name has form <identifier>$<int> or <iden1>$<int>$<iden2>
    boolean isAnonymous = false;
View Full Code Here

  throws AnalysisException
  {
    this.className = className;
    this.aspectsRoot = aspectsRoot;
    String[] pathElements = className.split("\\.");
    if (pathElements.length < 1) throw new AnalysisException(
        "Class name " + className + " is invalid");
    unqualifiedClassName = pathElements[pathElements.length - 1];
    StringBuffer path = new StringBuffer();
    for (int i = 0; i < pathElements.length - 1; ++i ) {
      path.append(pathElements[i]);
View Full Code Here

TOP

Related Classes of org.mitre.sim.analysis.instrument.AnalysisException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.