I am still having issues. I've typed (there may be typos) out most of the code. 
The following code will fail during runtime on the line bolded below. Can 
anyone identify why? Any help would be great!!!

Basically, I am just trying to populate an .ods file's worksheets with data.


       public class Load {
              String master_track_dir = System.getenv("PLN_MASTER_TRK");
              String restore_track = master_track_dir + 
"/RAYMOND/restore_track.xml";
              String master_track = master_track_dir + "/RAYMOND/track.xml";

       public Load() {

       }

       public static main(String[] args) {
              try {
                     Load block = new Load();
                     XComponentContext context = Bootstarp.bootstrap();
                     if(context == null) {
                           System.err.println("ERROR: Could not bootstrap 
default Office");
                           System.exit(1);
                     }

                     XMultiComponentFactory component_factory = 
context.getServiceManager();
                     try {
                           Object desktop = 
component_factory.createInstanceWithContext("com.sun.star.frame.Desktop", 
context);
                           XComponentLoader xComponentLoader = 
UnoRuntime.queryInterface(XComponentLoader.class, desktop);

                           PropertyValue loadProps= new PropertyValue[1];
                           loadProps[0] = new PropertyValue();
                           loadProps[0].Name = "Hidden";
                           loadProps[0].Value = Boolean.FALSE;

                           String odsFile = System.getenv("PLN_DAT_GCFILES") + 
"/Track.ods";
                           new File(odsFile).delete();
                           DocumentHandler otsHandler = new DocumentHandler();
                           String otsFile = "/tmp/Track.ots";
                           String otsUrl = 
otsHandler.convertFilePathToURL(otsFile);
                           String odsUrl = 
otsHandler.convertFilePathToURL(odsFile);

                           //Load .ots file, opens "Untitled 1.ods"
                           XComponent otsComponent = 
XComponentLoader.loadComponent.loadComponentFromURL(otsUrl, "_blank", 0, 
loadProps);
                           //export "Untitled 1" as /tmp/Track.ods file
                           block.exportDocumentAs(otsComponent, odsFile, 
DocumentHAndler.DocumentSaveFormat.SCALC, Boolean.TRUE, "1");
                           //close "Untitled 1.ods"
                           block.closeDocument(otsComponent);
                           //Open /tmp/Track.ods
                           XComponent odsComponent = 
XComponentLoader.loadComponentFromURL(odsUrl, "_blank", 0, loadProps);

                           String track = null;
                           if(new File(block.restore_track).exists()){
                                  track = block.restore_track;
                           } else {
                                  track = block.master_track;
                           }

                           XSpreadsheetDocument doc = 
UnoRuntime.queryInterface(XspreadsheetDocument.class, odsComponent);
                           XSpreadsheets sheets = doc.getSheets();

                           Object sheetObj = null;
                           XSpreadsheet sheet = null;
                           XCellRange cells = null;
                           XCellRange range = null;
                           XCellRangeData data = null;
                           Object[][] data_obj = null;

                           //Populate worksheet
                           sheetObj = sheets.getByName("Dest Data");
                           sheet = 
UnoRuntime.queryInterface(XSpreadsheet.class, sheetObj);
                           cells = UnoRuntime.queryInterface(XCellRange.class, 
sheet);
                           range = cells.getCellRangeByName("A2:E100");
                           data = 
UnoRuntime.queryInterface(XCellRangeData.class, range);
                           data_obj = data.getDataArray();
                           //Populate data_obj here..... This part omitted for 
clarity an need to manually type.
                           data.setDataArray(data_obj);

                           //Populate worksheet
                           sheetObj = sheets.getByName("Emer Data");
                           sheet = 
UnoRuntime.queryInterface(XSpreadsheet.class, sheetObj);
                           cells = UnoRuntime.queryInterface(XCellRange.class, 
sheet);
                           range = cells.getCellRangeByName("A2:F17");
                           data = 
UnoRuntime.queryInterface(XCellRangeData.class, range);
                           data_obj = data.getDataArray();
                           //Populate data_obj here..... This part omitted for 
clarity an need to manually type.
                           data.setDataArray(data_obj);

                           //Populate worksheet
                           sheetObj = sheets.getByName("Oper Data");
                           //**************** 
com.sun.star.lang.DisposedException occurs here.************************//
                     sheet = UnoRuntime.queryInterface(XSpreadsheet.class, 
sheetObj);
                           cells = UnoRuntime.queryInterface(XCellRange.class, 
sheet);
                           range = cells.getCellRangeByName("A2:E11");
                           data = 
UnoRuntime.queryInterface(XCellRangeData.class, range);
                           data_obj = data.getDataArray();
                           //Populate data_obj here..... This part omitted for 
clarity an need to manually type.
                           data.setDataArray(data_obj);

//Populate worksheet
                           sheetObj = sheets.getByName("Param Data");
                           sheet = 
UnoRuntime.queryInterface(XSpreadsheet.class, sheetObj);
                           cells = UnoRuntime.queryInterface(XCellRange.class, 
sheet);
                           range = cells.getCellRangeByName("A2:AW2");
                           data = 
UnoRuntime.queryInterface(XCellRangeData.class, range);
                           data_obj = data.getDataArray();
                           //Populate data_obj here..... This part omitted for 
clarity an need to manually type.
                           data.setDataArray(data_obj);

//Populate worksheet
                           sheetObj = sheets.getByName("Point Data");
                           sheet = 
UnoRuntime.queryInterface(XSpreadsheet.class, sheetObj);
                           cells = UnoRuntime.queryInterface(XCellRange.class, 
sheet);
                           range = cells.getCellRangeByName("A2:AJ151");
                           data = 
UnoRuntime.queryInterface(XCellRangeData.class, range);
                           data_obj = data.getDataArray();
                           //Populate data_obj here..... This part omitted for 
clarity an need to manually type.
                           data.setDataArray(data_obj);

                     } catch(com.sun.star.uno.Exception ex) {
                           System.err.println(ex.getMessage());
                     } finally {
                           System.exit(1);
                     }


              }
       }

       public void closeDocument(XComponent document) {
              XModel model = UnoRuntime.queryInterface(XModel.class, document);
              if(model != null) {
                     XCloseable closeable = 
UnoRuntime.queryInterface(XCloseable.class, model);
                     if(closeable != null) {
                           try {
                                  closeable.close(false);
                           } catch (CloseVetoException ex) {
                                  System.out.println(ex.getMessage());
                           }
                     }
              } else {
                     XComponent disposeable = 
UnoRuntime.queryInterface(XCompnent.class, model);
                     disposeable.dispose();
              }
       }

       public void ExportDocumentAs(XComponent doc, String save_file, 
DocumentHandler.DocumentSaveFormat format, boolean overwrite, String 
page_range) {
              if((save_file == null) || (save_file.trim().length()) == 0) {
                     return;
              }

              if(!overwrite) {
                     File sfile = new File(save_file);
                     if(sfile.exists()) {
                           throw new Exception("File exists");
                     }
              }

              DocumentHandler = new DocumentHandler();

              String file_url = handler.convertFIlePAthToUrl(save_file);
              XStoreable store = UnoRuntime.queryInterface(XStoreable.class, 
doc);

              PropertyValue filter_data= new PropertyValue[1];
              loadProps[0] = new PropertyValue();
              loadProps[0].Name = "PageRange";
              loadProps[0].Value = page_range;

              PropertyValue loadProps= new PropertyValue[2];
              loadProps[0] = new PropertyValue();
              loadProps[0].Name = "FilterName";
              loadProps[0].Value = format.getFormatCode;
              loadProps[1] = new PropertyValue();
              loadProps[1].Name = "FilterData";
              loadProps[1].Value = filter_data;

              store.storeToUrl(file_url, loadProps);


       }
}

From: Andre Fischer [mailto:awf....@gmail.com]
Sent: Wednesday, February 26, 2014 3:15 AM
To: Steele, Raymond; Andre Fischer; api@openoffice.apache.org
Subject: Re: EXTERNAL: Re: DisposedException

On 26.02.2014 00:25, Steele, Raymond wrote:

Thanks,



I am not explicitly calling the dispose method .

I would expect that dispose is called by a closing frame or something like that.



Here is an overview of what I am doing.



1.       opening a XSpreadsheetDocument (called temp_doc)  by calling after 
creating an object using  XMultiComponentFactory::createInstanceWithContext.

a.       The document is a .ots file which opens as "Untitled 1".

2.       XComponent  temp_comp = UnoRuntime.queryInterface(XComponent.class, 
temp_doc);

3.       XStoreable store = UnoRuntime.queryInterface(XStoreable.class, 
temp_comp);

a.        exporting "Unititled 1",  to an "ODF Spreadsheet", "StarOffice XML 
(Calc)" format by setting the PropertyValue FilterName property.  Once the 
properties are set, I use XStoreable::stopToURL to save "Untitled 1" to 
"RawData.ods"

4.       Then I close the document:

a.       XModel model = UnoRuntime.queryInterface(XModel.class, document);

b.      If model not null then, XCloseable closeable = 
UnoRuntime.queryInterface(XCloseable.class, model);

                                                               i.      
closeable.close(); (This is always the case that happens)

c.       If model null then,  XComponent disposable = 
UnoRuntime.queryInterface(Xcomponent.class,  model);

                                                               i.      
disposable.dispose(); (My code never gets into this condition)

5.       I then immediately open the file I exported in step three above by 
creating a new XSpreadsheetDocument (called doc), using the same methods 
defined in step one above,  but when I do a

a.       document = UnoRuntime.queryInterface(XpreadsheetDocument.class, 
xCalcComponent);

I receive: com.sun.star.lang.DisposedExcpetion

                at 
com.sun.star.lib.uno.environments.remote.JobQueue.removeJob(JobQueue.java: 210)





Is it possible that xCalcComponent still belongs to temp_doc?  That would 
explain why it is disposed.
Otherwise, xCalcComponent should not be disposed directly after loading.  Even 
if the loading failed, it should not be created in the first place and be NULL 
(well, an empty Reference, that contains NULL).  I would ask for any exceptions 
during the second loading, but unfortunately OpenOffice throws a lot of 
exceptions that don't notify any errors but are used for normal communication 
(don't ask)

-Andre



Hopefully, this provides some context. Basically, I am opening an .ots file, 
saving(exporting) it as an .ods file and closing it. Then  I open the .ods file 
so that I can populate the cells with data, but right after 
loadComponentFromURL, I try to query the XComponent returned from 
loadComponentFromURL to get the XSpreadsheetDocument.  That is when I get the 
DisposedException.





-----Original Message-----
From: Andre Fischer [mailto:awf....@gmail.com]
Sent: Tuesday, February 25, 2014 1:26 AM
To: Steele, Raymond; api@openoffice.apache.org<mailto:api@openoffice.apache.org>
Cc: awf....@gmail.com<mailto:awf....@gmail.com>
Subject: Re: EXTERNAL: Re: DisposedException



On 24.02.2014 20:56, Steele, Raymond wrote:

> Thanks for responding. How can I determine what called dispose()?



If you want to know who calls dispose() then you have to place a breakpoint in 
the dispose() method of xCalcComponent.



If you want to know when dispose() is called then register a 
com::sun::star::lang::XEventListener at the xCalcComponent object. When it is 
disposed, it will call disposing(...) at the listener.

I am just not sure if it calls disposing() when the object is already disposed 
when the listener is registered.  Probably not.



>   This is working in version AOO 3.3. Has something changed?



Without knowing the context this can easily be a timing problem in a 
multi-threaded environment: in AOO 3.3 some operation took longer resulting in 
the dispose() call made a few milliseconds later (or anything to this effect.)



-Andre



>

> -----Original Message-----

> From: Andre Fischer [mailto:awf....@gmail.com]

> Sent: Monday, February 24, 2014 3:54 AM

> To: api@openoffice.apache.org<mailto:api@openoffice.apache.org>

> Subject: EXTERNAL: Re: DisposedException

>

> On 21.02.2014 19:20, Steele, Raymond wrote:

>> While running my application using AOO 4.0.1 on Solaris 11,  a 
>> star.lang.DisposedException is thrown  inconsistently (sometimes it works) 
>> when I use UnoRuntime.queryInterface.

>>

>> The line of code causing the issue:

>>

>> XSpreadsheetDocument  document =

>> UnoRuntime.queryInterface(XSpreadsheetDocument.class,

>> xCalcCompinent);

> The DisposedException means that the throwing object has been marked by its 
> owner for destruction in the near future.  Any access after that results in 
> the DisposedException being thrown.

>

> That means, that the line above is executed after xCalcCompinent has received 
> a dispose() call.

>

> -Andre

>

>> This works perfectly when I use AOO 3.3, but not since upgrading to 4.0.1.

>>

>> Any help would be appreciated.

>>

>> Thanks,

>> Raymond

>>

>>

>

> ---------------------------------------------------------------------

> To unsubscribe, e-mail: 
> api-unsubscr...@openoffice.apache.org<mailto:api-unsubscr...@openoffice.apache.org>

> For additional commands, e-mail: 
> api-h...@openoffice.apache.org<mailto:api-h...@openoffice.apache.org>

>



Reply via email to