oracle.ide.model
Class NodeFactory

The type of Node that gets created depends on the URL that is passed into the findOrCreate(URL). The NodeFactory makes use of registered Recognizer instances to determine what Node class corresponds to a particular URL. Many nodes are simply recognized by the file extension while others are recognized only after a Recognizer reads the contents of the file/resource pointed by the URL. Because some Recognizers count on the physical file/resource to do their job, the findOrCreate(URL) method must only be called when the file/resource pointed by the URL physically exists on a file system/repository.

When the file/resource does not physically exists on the file system/repository, the findOrCreate(Class, URL) method must be called. The specified Class indicates what node type to create.

Every Node instance created by the NodeFactory is cached. An instance of an already created Node can be retrieved from the cache by calling the find(URL) method.

Returns the Node associated with the URL. If the Node does not exist, a new Node is created.

Unlike findOrCreate(URL), this method handles exceptional cases using a RuntimeException, on the basis that most callers will be unable to do anything to recover from such a case. If you want to handle failed creation, using findOrCreate(URL)} is recommended.

Parameters:

url - unique URL identifying the node.

Returns:

an existing node or a newly created one. This method will not return null.

Throws:

java.lang.RuntimeException - if the node could not be created.

java.lang.NullPointerException - if url is null.

Since:

11.1.1

findOrCreate

Use this method when creating a Node for a resource that physically exists at the location pointed to by the URL. When the URL points to a resource that does not exist, you must always use the findOrCreate(Class, URL) method. Returns the Node associated with the URL. If the Node does not exist, a new Node is created.

Parameters:

url - unique URL identifying the node.

Returns:

an existing node or a newly created one.

Throws:

java.lang.IllegalAccessException - if the Node class or its initializer is not accessible.

java.lang.InstantiationException - if the Node class is an abstract class, an interface, an array class, a primitive type, or void; or if the instantiation fails for some other reason.

findOrCreate

Use this method when creating a Node for a resource that does not yet exist at the location pointed to by the URL. When the URL points to a resource that physically exists, you must always use the findOrCreate(URL) method. Returns the Node associated with the URL. If the Node does not exist, a new Node is created.

findOrCreateUsingDefault

Avoid using this method. This method will be made private soon. URLs must be recognized by Recognizers. The IDE will use findOrCreate(URL) method to create Nodes for the URLs contained in a project's content. If Recognizers are not able to recognize your Node types, then the wrong node will be created. Only use methods findOrCreate(URL) and/or findOrCreate(Class, URL). Returns the Node associated with the URL. If the Node does not exist, a new Node is created.

Parameters:

url - unique URL identifying the node.

defaultNodeType - the default Node type to use if none of the recognizers can recognize the URL. Pass null to indicate that there is no default type, and that null should be returned if no recognizer can recognize the URL.

Returns:

an existing node or a newly created one.

Throws:

java.lang.IllegalAccessException - if the Node class or its initializer is not accessible.

java.lang.InstantiationException - if the Node class is an abstract class, an interface, an array class, a primitive type, or void; or if the instantiation fails for some other reason.

clone

Returns a new Node instance whose contents are identical to (and copied from) the specified Node. The original Node is not modified. The copying is done based on the last saved state of the srcNode. The returned Node is cached and assigned the URL specified by dstNodeURL.

getOpenNodeCount

attach

Associates the specified observer with the given type. Every time an instance of type is cached in the node factory, a NODE_CACHED notification is broadcast to the observer. The type should be the class of node and not of the data. The reason for this is that calling Node.getData() may break lazy loading for some nodes.

attach

Associates the specified observer with the given type. Every time an instance of type is cached in the node factory, a NODE_CACHED notification is broadcast to the observer. The type should be the class of node and not of the data. The reason for this is that calling Node.getData() may break lazy loading for some nodes.

detach

recognizeUrl

public static java.lang.Class recognizeUrl(java.net.URL url)

Find the specified url in the cache or recognize it and return the Class instance of the Node that can be, or has been, created for this url. As a side-effect, this method will initialize the extension that defines the relevant Node type, if it hasn't been initialized yet.