Working with the MdFactory Interface

Overview of Tasks That Can Be Performed with the MdFactory Interface

The MdFactory interface provides methods for creating and deleting SAS Metadata Model metadata objects and for invoking the SAS Java Metadata Interface event-handling interface and messaging mechanisms.

Instantiating the Object Factory

The object factory should be instantiated before any other tasks are performed.
MdFactory factory = new MdFactoryImpl();
If the object factory does not need to be used in a remote environment—that is, it does not need to be available to remote Java Virtual Machines (JVMs)—you can pass in a false value to the constructor. As a result, the factory behaves as if it is running in a local, single JVM environment.
The object factory is instantiated once for each user. If the application is intended to support multiple users, such as a Web application, a separate object factory needs to be created for each user.

Creating Metadata Objects

After you have instantiated the object factory and connected to the SAS Metadata Server (using the makeOMRConnection method of the MdOMRConnection interface), you can then use the methods in the MdFactory interface to create SAS Metadata Model object instances on the client. MdFactory provides the createComplexMetadataObject method for creating objects. The createComplexMetadataObject method creates an object that stores information about a metadata object's attributes and its potential associations. You can use this method to create an object that represents a new or existing object.
The following are examples of the createComplexMetadataObject method. To create an object that represents a new metadata object, specify:
MdFactory.createComplexMetadataObject(myNewObjectName, 
                                        metadata_type, 
                                        8char_target_repository_identifier)
To create an object that represents an existing metadata object on the SAS Metadata Server, specify:
MdFactory.createComplexMetadataObject(ObjectName,
                                       metadata_type,
                                       identifier_of_existing_metadata_object)
An alternate — and preferred — approach for creating objects for an existing metadata object is to issue a getMetadata or getMetadataObjects request. The getMetadata and getMetadataObject methods are available within the MdOMIUtil interface. The createComplexMetadataObject method creates an empty metadata object; it has no attributes or associations set. Use of one of the GetMetadata methods will then be needed to fully populate the object.
You can get the identifiers of all registered repositories on the SAS Metadata Server by using the getRepositories method of the MdOMIUtil interface. You can get the identifier of an existing object instance by using one of the getMetadataObjects methods of the MdOMIUtil interface. For more information about repository and object instance identifiers, see Identifying Metadata.

Invoking the Event Handling Interface

The MdFactoryListener interface notifies other users of the factory every time a metadata object is created, updated, or deleted on the SAS Metadata Server. Notifications are sent when the changes are persisted to the SAS Metadata Server. Users of the factory can use the information to make other changes (for example, to refresh their displays to include the new, modified, or deleted objects).
The MdFactoryListener interface includes the MdFactoryEvent class and the addMdFactoryListener method. You can have multiple listeners in a factory. The addMdFactoryListener method can be instantiated either directly before or after the server connection is made.
A listener should be removed when it is no longer needed. All listeners are automatically removed at the end of the factory’s session.

Deleting Objects

To delete an existing metadata object from the SAS Metadata Server, you must create an object that represents it in the SAS Java Metadata Interface client. Then, you delete both the server and client metadata objects by calling the deleteMetadataObjects method of the MdFactory interface. Calling this method removes the metadata object from both the server and client.
An alternate way to delete existing metadata objects is to use the delete method that is available with each object. Using this method simply marks the object as deleted. The updateMetadataAll method needs to be called to persist this change to the SAS Metadata Server.

Disposing of the Object Factory

To remove the object factory from memory, use the MdFactory dispose method before closing the client application. The dispose method removes the object factory and any remaining object stores. The dispose method should be used whenever the factory is no longer needed.