Difference between revisions of "Documentation/DevGuide/WritingUNO/Create Instance with Arguments"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (1 revision(s))
(source tag+table from left =-> centered: better with large displays)
Line 7: Line 7:
 
{{DISPLAYTITLE:Create Instance with Arguments}}
 
{{DISPLAYTITLE:Create Instance with Arguments}}
 
A factory can create an instance of components and pass additional arguments. To do that, a client calls the <code>createInstanceWithArguments()</code> function of the <idl>com.sun.star.lang.XSingleServiceFactory</idl> interface or the <code>createInstanceWithArgumentsAndContext()</code> of the <idl>com.sun.star.lang.XSingleComponentFactory</idl> interface.
 
A factory can create an instance of components and pass additional arguments. To do that, a client calls the <code>createInstanceWithArguments()</code> function of the <idl>com.sun.star.lang.XSingleServiceFactory</idl> interface or the <code>createInstanceWithArgumentsAndContext()</code> of the <idl>com.sun.star.lang.XSingleComponentFactory</idl> interface.
 
+
<source lang="java">
 
   //javamaker generated interface
 
   //javamaker generated interface
 
   //XSingleServiceFactory interface  
 
   //XSingleServiceFactory interface  
Line 17: Line 17:
 
                               com.sun.star.uno.XComponentContext Context)
 
                               com.sun.star.uno.XComponentContext Context)
 
                           throws com.sun.star.uno.Exception;
 
                           throws com.sun.star.uno.Exception;
 
+
</source>
 
Both functions take an array of values as an argument. A component implements the <idl>com.sun.star.lang.XInitialization</idl> interface to receive the values. A factory passes the array on to the single method <code>initialize()</code> supported by <code>XInitialization</code>.
 
Both functions take an array of values as an argument. A component implements the <idl>com.sun.star.lang.XInitialization</idl> interface to receive the values. A factory passes the array on to the single method <code>initialize()</code> supported by <code>XInitialization</code>.
 
+
<source lang="java">
 
   public void initialize(java.lang.Object[] aArguments) throws com.sun.star.uno.Exception;
 
   public void initialize(java.lang.Object[] aArguments) throws com.sun.star.uno.Exception;
 
+
</source>
 
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:
 
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:
  
{|border="1" cellpadding=4 style="border-collapse:collapse;" align="left"
+
{|border="1" cellpadding=4 style="border-collapse:collapse;" align="center"
 
|-bgcolor=#EDEDED
 
|-bgcolor=#EDEDED
 
!First Argument  
 
!First Argument  

Revision as of 21:22, 21 March 2008



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

  //javamaker generated interface
  //XSingleServiceFactory interface 
  public java.lang.Object createInstanceWithArguments(java.lang.Object[] aArguments) 
                              throws com.sun.star.uno.Exception;
 
  //XSingleComponentFactory
  public java.lang.Object createInstanceWithArgumentsAndContext(java.lang.Object[] Arguments,
                              com.sun.star.uno.XComponentContext Context)
                          throws com.sun.star.uno.Exception;

Both functions take an array of values as an argument. A component implements the com.sun.star.lang.XInitialization 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 com.sun.star.uno.Exception;

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
com.sun.star.uno.XComponentContext com.sun.star.registry.XRegistryKey java.lang.Object[]
com.sun.star.uno.XComponentContext com.sun.star.registry.XRegistryKey
com.sun.star.uno.XComponentContext java.lang.Object[]
com.sun.star.uno.XComponentContext
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