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 #ifndef DBA_COREDATAACESS_COMPONENTDEFINITION_HXX
25 #define DBA_COREDATAACESS_COMPONENTDEFINITION_HXX
26 
27 #ifndef _DBA_CORE_COMMANDBASE_HXX_
28 #include "commandbase.hxx"
29 #endif
30 #ifndef _COMPHELPER_PROPERTYCONTAINER_HXX_
31 #include <comphelper/propertycontainer.hxx>
32 #endif
33 #ifndef _COM_SUN_STAR_SDBCX_XRENAME_HPP_
34 #include <com/sun/star/sdbcx/XRename.hpp>
35 #endif
36 #ifndef _CPPUHELPER_IMPLBASE1_HXX_
37 #include <cppuhelper/implbase1.hxx>
38 #endif
39 #ifndef _COMPHELPER_PROPERTY_ARRAY_HELPER_HXX_
40 #include <comphelper/proparrhlp.hxx>
41 #endif
42 #ifndef _DBA_CORE_DATASETTINGS_HXX_
43 #include "datasettings.hxx"
44 #endif
45 #ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
46 #include <com/sun/star/container/XNameAccess.hpp>
47 #endif
48 #ifndef _COM_SUN_STAR_SDBCX_XCOLUMNSSUPPLIER_HPP_
49 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
50 #endif
51 #ifndef _COM_SUN_STAR_BEANS_XPROPERTYCHANGELISTENER_HPP_
52 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
53 #endif
54 #ifndef _COM_SUN_STAR_UNO_XCOMPONENTCONTEXT_HPP_
55 #include <com/sun/star/uno/XComponentContext.hpp>
56 #endif
57 #ifndef DBA_CONTENTHELPER_HXX
58 #include "ContentHelper.hxx"
59 #endif
60 #ifndef _DBASHARED_APITOOLS_HXX_
61 #include "apitools.hxx"
62 #endif
63 #ifndef _DBA_COREAPI_COLUMN_HXX_
64 #include <column.hxx>
65 #endif
66 #include <comphelper/implementationreference.hxx>
67 
68 #include <memory>
69 //........................................................................
70 namespace dbaccess
71 {
72 //........................................................................
73 
74 	typedef ::cppu::ImplHelper1< ::com::sun::star::sdbcx::XColumnsSupplier > OComponentDefinition_BASE;
75 
76 	class OComponentDefinition_Impl : public OContentHelper_Impl
77 									 ,public ODataSettings_Base
78 	{
79 	public:
80         typedef ::std::map  <   ::rtl::OUString
81                             ,   ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
82                             >   Columns;
83     typedef Columns::iterator           iterator;
84     typedef Columns::const_iterator     const_iterator;
85 
86     private:
87 		Columns             m_aColumns;
88 
89     public:
90 		::rtl::OUString		m_sSchemaName;
91 		::rtl::OUString		m_sCatalogName;
92 
93     public:
94         OComponentDefinition_Impl();
95         virtual ~OComponentDefinition_Impl();
96 
size() const97         inline size_t size() const { return m_aColumns.size(); }
98 
begin() const99         inline const_iterator begin() const   { return m_aColumns.begin(); }
end() const100         inline const_iterator end() const     { return m_aColumns.end(); }
101 
find(const::rtl::OUString & _rName) const102         inline const_iterator find( const ::rtl::OUString& _rName ) const { return m_aColumns.find( _rName ); }
103 
erase(const::rtl::OUString & _rName)104         inline void erase( const ::rtl::OUString& _rName ) { m_aColumns.erase( _rName ); }
105 
insert(const::rtl::OUString & _rName,const::com::sun::star::uno::Reference<::com::sun::star::beans::XPropertySet> & _rxColumn)106         inline void insert( const ::rtl::OUString& _rName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxColumn )
107         {
108             OSL_PRECOND( m_aColumns.find( _rName ) == m_aColumns.end(), "OComponentDefinition_Impl::insert: there's already an element with this name!" );
109             m_aColumns.insert( Columns::value_type( _rName, _rxColumn ) );
110         }
111 	};
112 
113 class OColumnPropertyListener;
114 //=========================================================================
115 //= OComponentDefinition - a database "document" which describes a query
116 //=========================================================================
117 class OComponentDefinition	:public OContentHelper
118 							,public ODataSettings
119 							,public IColumnFactory
120 							,public OComponentDefinition_BASE
121 							,public ::comphelper::OPropertyArrayUsageHelper< OComponentDefinition >
122 {
123 	OComponentDefinition();
124 
125 protected:
126     ::std::auto_ptr< OColumns >     m_pColumns;
127     ::comphelper::ImplementationReference< OColumnPropertyListener,::com::sun::star::beans::XPropertyChangeListener>
128                                     m_xColumnPropertyListener;
129 	sal_Bool	                    m_bTable;
130 
131 	virtual ~OComponentDefinition();
132 	virtual void SAL_CALL disposing();
133 
134 
135 protected:
136 	OComponentDefinition(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&
137 		,const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >&	_xParentContainer
138 		,const TContentPtr& _pImpl
139 		,sal_Bool _bTable = sal_True);
140 
getDefinition() const141     const   OComponentDefinition_Impl& getDefinition() const { return dynamic_cast< const OComponentDefinition_Impl& >( *m_pImpl.get() ); }
getDefinition()142             OComponentDefinition_Impl& getDefinition()       { return dynamic_cast<       OComponentDefinition_Impl& >( *m_pImpl.get() ); }
143 public:
144 
145 	OComponentDefinition(
146 			 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxContainer
147 			,const ::rtl::OUString& _rElementName
148 			,const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&
149 			,const TContentPtr& _pImpl
150 			,sal_Bool _bTable = sal_True
151 		);
152 
153 // com::sun::star::lang::XTypeProvider
154 	DECLARE_TYPEPROVIDER( );
155 
156 // ::com::sun::star::uno::XInterface
157 	DECLARE_XINTERFACE( )
158 
159 // ::com::sun::star::lang::XServiceInfo
160 	virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw(::com::sun::star::uno::RuntimeException);
161 	virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw(::com::sun::star::uno::RuntimeException);
162 
163 	static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_static(void) throw( ::com::sun::star::uno::RuntimeException );
164 	static ::rtl::OUString getImplementationName_static(void) throw( ::com::sun::star::uno::RuntimeException );
165 	static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL
166 		Create(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >&);
167 
168 // ::com::sun::star::beans::XPropertySet
169 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo(  ) throw(::com::sun::star::uno::RuntimeException);
170 
171 	// XColumnsSupplier
172 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getColumns(  ) throw (::com::sun::star::uno::RuntimeException);
173 
174 	// OPropertySetHelper
175 	virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper();
176 
177 	// IColumnFactory
178 	virtual OColumn*	createColumn(const ::rtl::OUString& _rName) const;
179 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > createColumnDescriptor();
180     virtual void columnAppended( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxSourceDescriptor );
181 	virtual void columnDropped(const ::rtl::OUString& _sName);
notifyDataSourceModified()182     virtual void notifyDataSourceModified() { OContentHelper::notifyDataSourceModified(); }
183 
184 protected:
185 // OPropertyArrayUsageHelper
186 	virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const;
187 
188 	virtual void SAL_CALL setFastPropertyValue_NoBroadcast(
189 									sal_Int32 nHandle,
190 									const ::com::sun::star::uno::Any& rValue) throw (::com::sun::star::uno::Exception);
191 
192     // OContentHelper overridables
193     virtual ::rtl::OUString determineContentType() const;
194 
195 private:
196 	void registerProperties();
197 };
198 
199 //........................................................................
200 }	// namespace dbaccess
201 //........................................................................
202 
203 #endif // DBA_COREDATAACESS_COMPONENTDEFINITION_HXX
204