java left logo
java middle logo
java right logo
 

Home arrow Other API Tips
 
 
Main Menu
Home
Java Tutorials
Book Reviews
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Java Network
Java Forums
Java Blog




Most Visited Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews
Top Rated Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews


Statistics
Registered Users: 4097
Java SE Tips: 614
Java ME Tips: 202
Java EE Tips: 183
Other API Tips: 779
Java Applications: 298
Java Libraries: 209
Java Games: 16
Book Reviews:
 
 
 
JavaModel...MDR...Metamodel...RefObjects...MultipartIds...what is all this stuff? E-mail
User Rating: / 1
PoorBest 

The current infrastructure for handling Java files programmatically in NetBeans is built on a bunch of standards relating to modelling and model-driven architecture (model-driven-architecture discussions tend toward being acronym salad; we get a bit of salad leakage into NetBeans APIs as a result).

Underlying it all is a generic infrastructure for handling things like refactoring in any language. So the API for Java is actually machine generated from a "metamodel" describing the Java language (i.e. specifying that there are things called packages, that they contain classes, which contain methods and fields, and so forth).

The result is that the API for interacting with Java sources usually has you dealing with objects which implement a heap of interfaces, each of which represents some characteristic of some element of a Java source. The basics of what you see look somewhat like:

Resource - a .java file containing 0 or more Java classes
  JavaClass - A java class
    Features - things such as methods, fields, etc
      Statements, StatementBlocks, VariableAccesses, MethodInvocations, etc.

Usually you get some object, and it returns a List of its child objects. Sometimes specialized getters are available for specific types of object, for example, Resource.getImports(). Be careful with these lists - they are live - if you remove an object, it disappears from the source code.

One thing to be aware of is that doing almost anything (even asking for the names of method objects) needs to be done inside the repository's transaction lock. The metadata repository (MDR) is the thing that holds a database of relationships between classes, etc. that is used for code completion and refactoring - so if you are going to modify something, you need to do this under a write lock. The typical pattern is:

boolean writeOperation = true;
JavaModel.getJavaRepository().beginTrans(writeOperation);
// rollback is applicable only for write transactions
boolean rollback = writeOperation;
try {
  //do something
  // ....
  // everything succeeded -> set rollback to false
  rollback = false;
finally {
  JavaModel.getJavaRepository().endTrans(rollback);
}

Acquiring the transaction lock is somewhat expensive - it is best to do as much work as possible inside a single transaction.

See also JavaModel basics.

Source: NetBeans FAQ


 Related Tips

 
< Prev   Next >

Page 1 of 0 ( 0 comments )

You can share your information about this topic using the form below!

Please do not post your questions with this form! Thanks.


Name (required)


E-Mail (required)

Your email will not be displayed on the site - only to our administrator
Homepage(optional)



Comment Enable HTML code : Yes No



 
       
         
     
 
 
 
   
 
 
java bottom left
java bottom middle
java bottom right
RSS 0.91 FeedRSS 1.0 FeedRSS 2.0 FeedATOM FeedOPML Feed

Home - About Us - Privacy Policy
Copyright 2005 - 2008 www.java-tips.org
Java is a trademark of Sun Microsystems, Inc.