1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package util.db;
25 
26 import com.sun.star.beans.PropertyValue;
27 import com.sun.star.frame.XModel;
28 import com.sun.star.frame.XStorable;
29 import com.sun.star.io.IOException;
30 import com.sun.star.lang.XMultiServiceFactory;
31 import com.sun.star.sdb.XDocumentDataSource;
32 import com.sun.star.sdb.XOfficeDatabaseDocument;
33 import com.sun.star.uno.UnoRuntime;
34 
35 /**
36  *  encapsulates a css.sdb.DatabaseDocument
37  */
38 public class DatabaseDocument
39 {
DatabaseDocument( final XMultiServiceFactory _orb, final DataSource _dataSource )40     protected DatabaseDocument( final XMultiServiceFactory _orb, final DataSource _dataSource )
41     {
42         m_orb = _orb;
43         m_dataSource = _dataSource;
44 
45         XDocumentDataSource docDataSource = (XDocumentDataSource)UnoRuntime.queryInterface(
46             XDocumentDataSource.class, m_dataSource.getDataSource() );
47         m_databaseDocument = (XOfficeDatabaseDocument)UnoRuntime.queryInterface(XOfficeDatabaseDocument.class,
48             docDataSource.getDatabaseDocument() );
49 
50         m_model = (XModel)UnoRuntime.queryInterface( XModel.class, m_databaseDocument );
51         m_storeDoc = (XStorable)UnoRuntime.queryInterface( XStorable.class, m_databaseDocument );
52     }
53 
getDataSource()54     public DataSource getDataSource()
55     {
56         return m_dataSource;
57     }
58 
getDatabaseDocument()59     public XOfficeDatabaseDocument getDatabaseDocument()
60     {
61         return m_databaseDocument;
62     }
63 
64     /**
65      * passes through to XModel.getURL.
66      */
getURL()67     public String getURL()
68     {
69         return m_model.getURL();
70     }
71 
72     /**
73      * simplified version (taking no arguments except the target URL) of XStorage.storeAsURL
74      * @param _url
75      *      specifies the location to where to store the document
76      */
storeAsURL( final String _url )77     public void storeAsURL( final String _url ) throws IOException
78     {
79         m_storeDoc.storeAsURL( _url, new PropertyValue[] { } );
80     }
81 
82     private XMultiServiceFactory    m_orb;
83     private DataSource              m_dataSource;
84     private XOfficeDatabaseDocument m_databaseDocument;
85     private XModel                  m_model;
86     private XStorable               m_storeDoc;
87 }
88