/** * Construct an event manager over multiple specifications. * * @param name The name of the event manager. * @param specs All the specifications that this manages events from. * @param combinedAspect The AspectJ output for this program. */ public EventManager( final String name, final List<JavaMOPSpec> specs, final CombinedAspect combinedAspect) throws MOPException { this.endProgramEvent = new EndProgram(name); for (JavaMOPSpec spec : specs) { if (spec.isEnforce()) { endThreadEvents.add(new ThreadStatusMonitor(spec, combinedAspect)); } for (EventDefinition event : spec.getEvents()) { // normal event if (!event.isEndObject() && !event.isEndProgram() && !event.isEndThread() && !event.isStartThread()) { boolean added = false; for (AdviceAndPointCut advice : advices) { if (advice.isAround != event.getPos().equals("around")) continue; if (advice.isAround) { if (!advice.retType.equals(event.getRetType().toString())) continue; } if (!advice.pos.equals(event.getPos())) continue; if (!advice.retVal.equals(event.getRetVal())) continue; if (!advice.throwVal.equals(event.getThrowVal())) continue; PointcutComparator comparator = new PointcutComparator(); PointCut p1 = event.getPointCut().accept(new ConvertPointcutToCNFVisitor(), null); PointCut p2 = advice.getPointCut().accept(new ConvertPointcutToCNFVisitor(), null); if (comparator.compare(p1, p2)) { added = advice.addEvent(spec, event, combinedAspect); if (added) break; } } if (!added) { advices.add(new AdviceAndPointCut(spec, event, combinedAspect)); } } // endObject if (event.isEndObject()) { endObjectEvents.add(new EndObject(spec, event, combinedAspect)); } // endThread if (event.isEndThread()) { endThreadEvents.add(new EndThread(spec, event, combinedAspect)); } // startThread if (event.isStartThread()) { startThreadEvents.add(new StartThread(spec, event, combinedAspect)); } // endProgram if (event.isEndProgram()) { endProgramEvent.addEndProgramEvent(spec, event, combinedAspect); } } // end of for event } // end of for spec endProgramEvent.registerEndThreadEvents(endThreadEvents); }
/** * Construct a method name for a particular event. * * @param enclosing The specification the event is a part of. * @param evt The event the method is being generated for. * @param aspectName The aspect the method will be a part of. */ public static String methodName(JavaMOPSpec enclosing, EventDefinition evt, String aspectName) { return methodName(enclosing.getName(), evt, aspectName); }