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: 4093
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:
 
 
 
What are .instance files? E-mail
User Rating: / 0
PoorBest 

.instance files are NetBeans parlance for a file which is actually standing in for an instance of an object. An instance file typically says what class it is an instance of via its class name - for example, com-foo-mymodule-MyObject.instance. A .instance file may represent any Java class with a default constructor, or which can be obtained by calling a static method on a class.

In NetBeans infrastructure, .instance files result in InstanceDataObject. InstanceDataObjects can supply InstanceCookies, which in turn instantiate the JavaBean?. So, code to actually get an instance of an object declared in the System Filesystem would look like:

public static Object getTheObject (String pathInSystemFilesystem) {

    InstanceCookie ck =  DataObject.find (Repository.getDefault().
       getDefaultFileSystem().getRoot().getFileObject(
       pathInSystemFilesystem)).getCookie(InstanceCookie.class);

    return ck.instanceCreate();
}

Alternately, FolderLookup offers a convenient way to get all instances of objects in a folder:

FileObject f = Repository.getDefault().getDefaultFileSystem().
  getRoot().getFileObject("MyFolder");

DataFolder fld = DataFolder.findFolder(f);
FolderLookup lkp = new FolderLookup (fld);

Lookup.Result res = lkp.lookup (
  new Lookup.Template(WhatISaidToPutHere.class));

res.allInstances();

Note that a default constructor is not required in an XML layer; you can also use a static method, using the following syntax:

<file name="ObjectTypes.instance">
  <attr name="instanceCreate" 
     methodvalue="org.netbeans.core.ui.UINodes.createObjectTypes" />

  <attr name="instanceClass" stringvalue="org.openide.nodes.Node" />
</file>

Part of the value of the second entry, instanceClass is that the system will not need to instantiate your object just to see if it matches the class Node.

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.