Hi,

you should ask this kind of question at [email protected] or
[email protected]

Tom

Stefan Schmid schrieb:
> Hello! 
> 
>  
> 
> I'm working on this problem for a long time now, but I can't get a solution.
> Maybe someone can help me. 
> 
>  
> 
> I want to add a new QueryDefinition to the DefenitionContainer. It's an
> example from the OOo Developer Guide (12.2.2 DataSources - Adding and
> Editing Predefined Queries) 
> 
> The Method createQuerydefinition() which I'm using is one-to-one from the
> CodeSamples.java (see code below)
> 
>  
> 
> The Problem is that the last-but-one command returns null (=> the xStore
> variable is null).
> 
>  
> 
> When I look at the XQueryDefinitionsSupplier interface at api.openoffice.org
> there is nothing about a support of XStorable. But there should be one as
> the example of the DevelopersGuide and CodeSamples.java explains. 
> 
> So how else can I retrieve the XStorable interface and then store the query
> definition?
> 
>  
> 
>  
> 
> Besides:
> 
>  
> 
> I have read in the api reference that XSingleServiceFactory is deprecated
> and it is recommended to use the XSingleComponentFactory instead. 
> 
> So I alter the method (see code below) with this code:
> 
>  
> 
> XInterface nQuery =null; 
> 
>          try { 
> 
>          nQuery = (XInterface)
> xSingleFac.createInstanceWithContext(xContext); 
> 
>          } catch (Exception e) {System.out.println(e);} 
> 
>          XPropertySet xProp = (XPropertySet)
> UnoRuntime.queryInterface(XPropertySet.class,nQuery);
> 
>  
> 
> Here the NullPointerException is already thrown at the [nQuery= ..........]
> line. 
> 
>  
> 
>  
> 
>  
> 
>  
> 
> I'm at my wits' end. I have read through the API 100 times but can't find a
> solution.
> 
>  
> 
> Greets Stefan
> 
>  
> 
>  
> 
>  
> 
> Code:   
> 
>  
> 
> public static void main(String[] args) { 
> 
>        
> 
>       /********* create service factory ******************************/ 
> 
>       //get the remote office component context 
> 
>       com.sun.star.uno.XComponentContext xContext = null; 
> 
>       com.sun.star.lang.XMultiComponentFactory xMCF = null; 
> 
>       try { 
> 
>          xContext = com.sun.star.comp.helper.Bootstrap.bootstrap(); 
> 
>          System.out.println("Connected to a running office ..."); 
> 
>          //get the Service Factory 
> 
>          xMCF =   xContext.getServiceManager(); 
> 
>       } catch (BootstrapException e) { e.printStackTrace(); } 
> 
>       /***************************************************************/ 
> 
>        
> 
>       try { 
> 
>          createQuerydefinition(xContext, xMCF); 
> 
>       } catch (Exception e) { 
> 
>          e.printStackTrace(); 
> 
>       } 
> 
>        
> 
>    } 
> 
>       public static void
> createQuerydefinition(com.sun.star.uno.XComponentContext xContext,
> com.sun.star.lang.XMultiComponentFactory xMCF) throws
> com.sun.star.uno.Exception 
> 
>       { 
> 
>          XNameAccess xNameAccess = (XNameAccess)UnoRuntime.queryInterface( 
> 
>                XNameAccess.class, 
> 
>  
> xMCF.createInstanceWithContext("com.sun.star.sdb.DatabaseContext", 
> 
>                                               xContext)); 
> 
>          // we use the first datasource 
> 
>          XQueryDefinitionsSupplier xQuerySup = (XQueryDefinitionsSupplier) 
> 
>  
> UnoRuntime.queryInterface(XQueryDefinitionsSupplier.class, 
> 
>                                     xNameAccess.getByName( "Bibliography"
> )); 
> 
>          XNameAccess xQDefs = xQuerySup.getQueryDefinitions(); 
> 
>          // create new query definition 
> 
>          XSingleServiceFactory xSingleFac =   (XSingleServiceFactory)
> UnoRuntime.queryInterface(XSingleServiceFactory.class, xQDefs); 
> 
>           
> 
>          XPropertySet xProp = (XPropertySet) UnoRuntime.queryInterface( 
> 
>                   XPropertySet.class,xSingleFac.createInstance()); 
> 
>           
> 
>          xProp.setPropertyValue("Command","SELECT * FROM biblio"); 
> 
>          xProp.setPropertyValue("EscapeProcessing",new Boolean(true)); 
> 
>  
> 
>          XNameContainer xCont = (XNameContainer)
> UnoRuntime.queryInterface(XNameContainer.class, xQDefs); 
> 
>                    try 
> 
>                    { 
> 
>                        if ( xCont.hasByName("Query1") ) 
> 
>                            xCont.removeByName("Query1"); 
> 
>                    } 
> 
>                    catch(com.sun.star.uno.Exception e) 
> 
>                    {} 
> 
>          xCont.insertByName("Query1",xProp); 
> 
>                    XStorable xStore =
> (XStorable)UnoRuntime.queryInterface(XStorable.class,xQuerySup); 
> 
>                    System.out.println(xStore); 
> 
>                    xStore.store();            
> 
>       }
> 
>  
> 
>  
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to