I have already read about the new-style UNO services constructors, but I had never used them. Last week I discovered the power hidden in this tiny UNO improvement. Let's consider the following service specification:
module org { module openoffice { module test {
service Customer : XCustomer {
Customer( [in] string customerId );
};
}; }; };
To implement such a service we will need to add the
com::sun::star::lang::XInitialization
interface to the service
inherited interfaces. The service interface could look like this:
module org { module openoffice { module test {
interface XCustomer : com::sun::star::lang::XInitialization {
[attribute, readonly] string Id;
};
}; }; };
Then the UNO constructor of the service will be implemented in the
initialize()
method specified by the XInitialization
interface. Then
the implementation could be like the following in Java:
public void initialize(Object[] pArgs) throws com.sun.star.uno.Exception {
String id = args[0];
// Do the initialization from the Customer's database (for example)
}
Then to use the service constructor, it's easy in Java:
Customer johnDoe = Customer.Customer("johndoe");
To use the constructor in Basic it's slightly more complicated because you will need to create the service with arguments. It should look like this:
oServiceManager = getProcessServiceManager()
oCustomer = oServiceManager.createInstanceWithArguments("org.openoffice.test.Customer", "johndoe")
This could seem trivial for any common object-oriented language programmer like Java, C++, but for UNO it's a big step. I hope this could help someone to better know UNO.