Create Instance with Arguments

From Apache OpenOffice Wiki
Jump to: navigation, search

A factory can create an instance of components and pass additional arguments. To do that, a client calls the createInstanceWithArguments() function of the interface or the createInstanceWithArgumentsAndContext() of the interface.

  //javamaker generated interface
  //XSingleServiceFactory interface 
  public java.lang.Object createInstanceWithArguments(java.lang.Object[] aArguments) 
  public java.lang.Object createInstanceWithArgumentsAndContext(java.lang.Object[] Arguments,

Both functions take an array of values as an argument. A component implements the interface to receive the values. A factory passes the array on to the single method initialize() supported by XInitialization.

  public void initialize(java.lang.Object[] aArguments) throws;

Alternatively, a component may also receive these arguments in its constructor. If a factory is written, determine exactly which arguments are provided by the factory when it instantiates the component. When using the FactoryHelper, implement the constructors with the following arguments:

First Argument Second Argument Third Argument java.lang.Object[] java.lang.Object[]

The FactoryHelper automatically passes the array of arguments it received from the createInstanceWithArguments[AndContext]() call to the appropriate constructor. Therefore, it is not always necessary to implement XInitialization to use arguments.

Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages