Index: arch-javamodel.xml =================================================================== RCS file: /cvs/java/javamodel/arch/arch-javamodel.xml,v retrieving revision 1.5 diff -r1.5 arch-javamodel.xml 115a116,148 > > > Some modules (e.g. Java module) may expose metadata elements via nodes - i.e. various nodes presenting a java file structure may offer > org.netbeans.jmi.javamodel.Element or its subclasses in their lookup. > In this case clients need to check validity of the provided > element inside of an MDR transaction before any of the element's method > is used, since node supplying the element cannot guarantee the element > stays valid. Here is an example code:
>
>     public void performAction(Node node) {
>         // try to get an implementation of Element from the lookup
>         Element el = (Element) node.getLookup().lookup(Element.class);
>         if (el == null) return;
>
>         try {
>             // start a transaction
>             JavaMetamodel.getDefaultRepository().beginTrans(false);
>             try {
>                 // it is important to check validity of the element first
>                 if (element.isValid()) {
>                     // do the work
>                     ...
>                 }
>             } finally {
>                 // stop the transaction
>                 JavaMetamodel.getDefaultRepository().endTrans();
>             }
>         } catch (JmiException e) {
>             ErrorManager.getDefault().notify(e);
>         }
>     }
> 
>