Difference between revisions of "Documentation/DevGuide/WritingUNO/Create Instance with Arguments"
(Initial author Sun Microsystems, Inc.) |
|||
| (8 intermediate revisions by 4 users not shown) | |||
| Line 5: | Line 5: | ||
|NextPage=Documentation/DevGuide/WritingUNO/Possible Structures for Java Components | |NextPage=Documentation/DevGuide/WritingUNO/Possible Structures for Java Components | ||
}} | }} | ||
| + | {{Documentation/DevGuideLanguages|Documentation/DevGuide/WritingUNO/{{SUBPAGENAME}}}} | ||
{{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. | ||
| − | + | <syntaxhighlight lang="java"> | |
//javamaker generated interface | //javamaker generated interface | ||
//XSingleServiceFactory interface | //XSingleServiceFactory interface | ||
| Line 17: | Line 18: | ||
com.sun.star.uno.XComponentContext Context) | com.sun.star.uno.XComponentContext Context) | ||
throws com.sun.star.uno.Exception; | throws com.sun.star.uno.Exception; | ||
| − | + | </syntaxhighlight> | |
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>. | ||
| − | + | <syntaxhighlight 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; | ||
| − | + | </syntaxhighlight> | |
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=" | + | {|border="1" cellpadding=4 style="border-collapse:collapse;" align="center" |
|-bgcolor=#EDEDED | |-bgcolor=#EDEDED | ||
!First Argument | !First Argument | ||
| Line 54: | Line 55: | ||
{{PDL1}} | {{PDL1}} | ||
| − | [[Category: Writing UNO Components]] | + | |
| + | [[Category:Documentation/Developer's Guide/Writing UNO Components]] | ||
Latest revision as of 13:42, 24 December 2020
- Class Definition with Helper Class
- Implementing Your Own Interfaces
- Providing a Single Factory Using a Helper Method
- Write Registration Info Using a Helper Method
- Implementing without Helpers
- Storing the Service Manager for Further Use
- Create Instance with Arguments
- Possible Structures for Java Components
- Running and Debugging Java Components
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). |