1 /*
2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3  *
4  * Copyright 2000, 2010 Oracle and/or its affiliates.
5  *
6  * OpenOffice.org - a multi-platform office productivity suite
7  *
8  * This file is part of OpenOffice.org.
9  *
10  * OpenOffice.org is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Lesser General Public License version 3
12  * only, as published by the Free Software Foundation.
13  *
14  * OpenOffice.org is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Lesser General Public License version 3 for more details
18  * (a copy is included in the LICENSE file that accompanied this code).
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * version 3 along with OpenOffice.org.  If not, see
22  * <http://www.openoffice.org/license.html>
23  * for a copy of the LGPLv3 License.
24  *
25  */
26 
27 package util.db;
28 
29 import com.sun.star.beans.PropertyValue;
30 import com.sun.star.frame.XModel;
31 import com.sun.star.frame.XStorable;
32 import com.sun.star.io.IOException;
33 import com.sun.star.lang.XMultiServiceFactory;
34 import com.sun.star.sdb.XDocumentDataSource;
35 import com.sun.star.sdb.XOfficeDatabaseDocument;
36 import com.sun.star.uno.UnoRuntime;
37 
38 /**
39  *  encapsulates a css.sdb.DatabaseDocument
40  */
41 public class DatabaseDocument
42 {
43     protected DatabaseDocument( final XMultiServiceFactory _orb, final DataSource _dataSource )
44     {
45         m_orb = _orb;
46         m_dataSource = _dataSource;
47 
48         XDocumentDataSource docDataSource = (XDocumentDataSource)UnoRuntime.queryInterface(
49             XDocumentDataSource.class, m_dataSource.getDataSource() );
50         m_databaseDocument = (XOfficeDatabaseDocument)UnoRuntime.queryInterface(XOfficeDatabaseDocument.class,
51             docDataSource.getDatabaseDocument() );
52 
53         m_model = (XModel)UnoRuntime.queryInterface( XModel.class, m_databaseDocument );
54         m_storeDoc = (XStorable)UnoRuntime.queryInterface( XStorable.class, m_databaseDocument );
55     }
56 
57     public DataSource getDataSource()
58     {
59         return m_dataSource;
60     }
61 
62     public XOfficeDatabaseDocument getDatabaseDocument()
63     {
64         return m_databaseDocument;
65     }
66 
67     /**
68      * passes through to XModel.getURL.
69      */
70     public String getURL()
71     {
72         return m_model.getURL();
73     }
74 
75     /**
76      * simplified version (taking no arguments except the target URL) of XStorage.storeAsURL
77      * @param _url
78      *      specifies the location to where to store the document
79      */
80     public void storeAsURL( final String _url ) throws IOException
81     {
82         m_storeDoc.storeAsURL( _url, new PropertyValue[] { } );
83     }
84 
85     private XMultiServiceFactory    m_orb;
86     private DataSource              m_dataSource;
87     private XOfficeDatabaseDocument m_databaseDocument;
88     private XModel                  m_model;
89     private XStorable               m_storeDoc;
90 }
91