1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef DBA_COREDATAACESS_COMPONENTDEFINITION_HXX
29 #define DBA_COREDATAACESS_COMPONENTDEFINITION_HXX
30 
31 #ifndef _DBA_CORE_COMMANDBASE_HXX_
32 #include "commandbase.hxx"
33 #endif
34 #ifndef _COMPHELPER_PROPERTYCONTAINER_HXX_
35 #include <comphelper/propertycontainer.hxx>
36 #endif
37 #ifndef _COM_SUN_STAR_SDBCX_XRENAME_HPP_
38 #include <com/sun/star/sdbcx/XRename.hpp>
39 #endif
40 #ifndef _CPPUHELPER_IMPLBASE1_HXX_
41 #include <cppuhelper/implbase1.hxx>
42 #endif
43 #ifndef _COMPHELPER_PROPERTY_ARRAY_HELPER_HXX_
44 #include <comphelper/proparrhlp.hxx>
45 #endif
46 #ifndef _DBA_CORE_DATASETTINGS_HXX_
47 #include "datasettings.hxx"
48 #endif
49 #ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
50 #include <com/sun/star/container/XNameAccess.hpp>
51 #endif
52 #ifndef _COM_SUN_STAR_SDBCX_XCOLUMNSSUPPLIER_HPP_
53 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
54 #endif
55 #ifndef _COM_SUN_STAR_BEANS_XPROPERTYCHANGELISTENER_HPP_
56 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
57 #endif
58 #ifndef _COM_SUN_STAR_UNO_XCOMPONENTCONTEXT_HPP_
59 #include <com/sun/star/uno/XComponentContext.hpp>
60 #endif
61 #ifndef DBA_CONTENTHELPER_HXX
62 #include "ContentHelper.hxx"
63 #endif
64 #ifndef _DBASHARED_APITOOLS_HXX_
65 #include "apitools.hxx"
66 #endif
67 #ifndef _DBA_COREAPI_COLUMN_HXX_
68 #include <column.hxx>
69 #endif
70 #include <comphelper/implementationreference.hxx>
71 
72 #include <memory>
73 //........................................................................
74 namespace dbaccess
75 {
76 //........................................................................
77 
78 	typedef ::cppu::ImplHelper1< ::com::sun::star::sdbcx::XColumnsSupplier > OComponentDefinition_BASE;
79 
80 	class OComponentDefinition_Impl : public OContentHelper_Impl
81 									 ,public ODataSettings_Base
82 	{
83 	public:
84         typedef ::std::map  <   ::rtl::OUString
85                             ,   ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
86                             >   Columns;
87     typedef Columns::iterator           iterator;
88     typedef Columns::const_iterator     const_iterator;
89 
90     private:
91 		Columns             m_aColumns;
92 
93     public:
94 		::rtl::OUString		m_sSchemaName;
95 		::rtl::OUString		m_sCatalogName;
96 
97     public:
98         OComponentDefinition_Impl();
99         virtual ~OComponentDefinition_Impl();
100 
101         inline size_t size() const { return m_aColumns.size(); }
102 
103         inline const_iterator begin() const   { return m_aColumns.begin(); }
104         inline const_iterator end() const     { return m_aColumns.end(); }
105 
106         inline const_iterator find( const ::rtl::OUString& _rName ) const { return m_aColumns.find( _rName ); }
107 
108         inline void erase( const ::rtl::OUString& _rName ) { m_aColumns.erase( _rName ); }
109 
110         inline void insert( const ::rtl::OUString& _rName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxColumn )
111         {
112             OSL_PRECOND( m_aColumns.find( _rName ) == m_aColumns.end(), "OComponentDefinition_Impl::insert: there's already an element with this name!" );
113             m_aColumns.insert( Columns::value_type( _rName, _rxColumn ) );
114         }
115 	};
116 
117 class OColumnPropertyListener;
118 //=========================================================================
119 //= OComponentDefinition - a database "document" which describes a query
120 //=========================================================================
121 class OComponentDefinition	:public OContentHelper
122 							,public ODataSettings
123 							,public IColumnFactory
124 							,public OComponentDefinition_BASE
125 							,public ::comphelper::OPropertyArrayUsageHelper< OComponentDefinition >
126 {
127 	OComponentDefinition();
128 
129 protected:
130     ::std::auto_ptr< OColumns >     m_pColumns;
131     ::comphelper::ImplementationReference< OColumnPropertyListener,::com::sun::star::beans::XPropertyChangeListener>
132                                     m_xColumnPropertyListener;
133 	sal_Bool	                    m_bTable;
134 
135 	virtual ~OComponentDefinition();
136 	virtual void SAL_CALL disposing();
137 
138 
139 protected:
140 	OComponentDefinition(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&
141 		,const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >&	_xParentContainer
142 		,const TContentPtr& _pImpl
143 		,sal_Bool _bTable = sal_True);
144 
145     const   OComponentDefinition_Impl& getDefinition() const { return dynamic_cast< const OComponentDefinition_Impl& >( *m_pImpl.get() ); }
146             OComponentDefinition_Impl& getDefinition()       { return dynamic_cast<       OComponentDefinition_Impl& >( *m_pImpl.get() ); }
147 public:
148 
149 	OComponentDefinition(
150 			 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxContainer
151 			,const ::rtl::OUString& _rElementName
152 			,const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&
153 			,const TContentPtr& _pImpl
154 			,sal_Bool _bTable = sal_True
155 		);
156 
157 // com::sun::star::lang::XTypeProvider
158 	DECLARE_TYPEPROVIDER( );
159 
160 // ::com::sun::star::uno::XInterface
161 	DECLARE_XINTERFACE( )
162 
163 // ::com::sun::star::lang::XServiceInfo
164 	virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw(::com::sun::star::uno::RuntimeException);
165 	virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw(::com::sun::star::uno::RuntimeException);
166 
167 	static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_static(void) throw( ::com::sun::star::uno::RuntimeException );
168 	static ::rtl::OUString getImplementationName_static(void) throw( ::com::sun::star::uno::RuntimeException );
169 	static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL
170 		Create(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >&);
171 
172 // ::com::sun::star::beans::XPropertySet
173 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo(  ) throw(::com::sun::star::uno::RuntimeException);
174 
175 	// XColumnsSupplier
176 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getColumns(  ) throw (::com::sun::star::uno::RuntimeException);
177 
178 	// OPropertySetHelper
179 	virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper();
180 
181 	// IColumnFactory
182 	virtual OColumn*	createColumn(const ::rtl::OUString& _rName) const;
183 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > createColumnDescriptor();
184     virtual void columnAppended( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxSourceDescriptor );
185 	virtual void columnDropped(const ::rtl::OUString& _sName);
186     virtual void notifyDataSourceModified() { OContentHelper::notifyDataSourceModified(); }
187 
188 protected:
189 // OPropertyArrayUsageHelper
190 	virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const;
191 
192 	virtual void SAL_CALL setFastPropertyValue_NoBroadcast(
193 									sal_Int32 nHandle,
194 									const ::com::sun::star::uno::Any& rValue) throw (::com::sun::star::uno::Exception);
195 
196     // OContentHelper overridables
197     virtual ::rtl::OUString determineContentType() const;
198 
199 private:
200 	void registerProperties();
201 };
202 
203 //........................................................................
204 }	// namespace dbaccess
205 //........................................................................
206 
207 #endif // DBA_COREDATAACESS_COMPONENTDEFINITION_HXX
208