[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[cme-dev] Visiting Concerns
|
Hi all.
Forgive me if this is obvious (and it probably is!) but I'm puzzling over how to
best traverse the structure of Concerns. What I'm driving at is a way to take a
Concern and build my own abstract representation. I was expecting some kind
of visitor scheme but haven't found anything...
As a simple example, suppose I wanted to collect all the AdviceArtifacts in a
Concern. I'd like to avoid code that looks like this:
/* final */ Collection adviceCollector = new ArrayList();
ConcernModelElement cme =
/* ProxyConcernModelElement */ pcme.getConcernModelElement();
if (cme instanceof ConcernImpl) {
ConcernImpl concern = (ConcernImpl)cme;
QueryableRead elems = concern.getElements();
for (Iterator iter = elems.iterator(); iter.hasNext();) {
Object o = iter.next();
if (o instanceof AdviceUnit) {
adviceCollector.add(((AdviceArtifact)o).
getAdviceArtifacts());
}
...
}
...
}
preferring something more like this:
cme.accept(new ConcernVisitor() {
void visit(AdviceUnit advice) {
adviceCollector.add(advice.getAdviceArtifact());
};
);
(Admittedly this is an overly simple example, but you get the idea.)
What's the best way to programmatically explore the structure of Concerns?
Any help would be greatly appreciated. Thanks!
-phil