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 __FRAMEWORK_UIFACTORY_UIELEMENTFACTORYMANAGER_HXX_
25 #define __FRAMEWORK_UIFACTORY_UIELEMENTFACTORYMANAGER_HXX_
26 
27 /** Attention: stl headers must(!) be included at first. Otherwise it can make trouble
28                with solaris headers ...
29 */
30 #include <vector>
31 #include <list>
32 
33 //_________________________________________________________________________________________________________________
34 //	my own includes
35 //_________________________________________________________________________________________________________________
36 #include <threadhelp/threadhelpbase.hxx>
37 #include <macros/generic.hxx>
38 #include <macros/xinterface.hxx>
39 #include <macros/xtypeprovider.hxx>
40 #include <macros/xserviceinfo.hxx>
41 #include <stdtypes.h>
42 
43 //_________________________________________________________________________________________________________________
44 //	interface includes
45 //_________________________________________________________________________________________________________________
46 #include <com/sun/star/lang/XServiceInfo.hpp>
47 #include <com/sun/star/ui/XUIElementFactory.hpp>
48 #include <com/sun/star/ui/XUIElementFactoryRegistration.hpp>
49 #include <com/sun/star/container/XContainerListener.hpp>
50 #include <com/sun/star/container/XNameAccess.hpp>
51 #include "com/sun/star/frame/XModuleManager.hpp"
52 
53 //_________________________________________________________________________________________________________________
54 //	other includes
55 //_________________________________________________________________________________________________________________
56 #include <cppuhelper/implbase1.hxx>
57 #include <cppuhelper/implbase3.hxx>
58 #include <rtl/ustring.hxx>
59 
60 namespace framework
61 {
62 
63     class ConfigurationAccess_FactoryManager : // interfaces
64                                                     // baseclasses
65 							                        // Order is necessary for right initialization!
66                                                     private ThreadHelpBase                           ,
67                                                     public  ::cppu::WeakImplHelper1< ::com::sun::star::container::XContainerListener>
68 {
69     public:
70                       ConfigurationAccess_FactoryManager( ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rServiceManager,const ::rtl::OUString& _sRoot );
71         virtual       ~ConfigurationAccess_FactoryManager();
72 
73         void          readConfigurationData();
74 
75         rtl::OUString                           getFactorySpecifierFromTypeNameModule( const rtl::OUString& rType, const rtl::OUString& rName, const rtl::OUString& rModule ) const;
76         void                                    addFactorySpecifierToTypeNameModule( const rtl::OUString& rType, const rtl::OUString& rName, const rtl::OUString& rModule, const rtl::OUString& aServiceSpecifier );
77         void                                    removeFactorySpecifierFromTypeNameModule( const rtl::OUString& rType, const rtl::OUString& rName, const rtl::OUString& rModule );
78         ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > >   getFactoriesDescription() const;
79 
80         // container.XContainerListener
81     virtual void SAL_CALL elementInserted( const ::com::sun::star::container::ContainerEvent& Event ) throw (::com::sun::star::uno::RuntimeException);
82     virtual void SAL_CALL elementRemoved( const ::com::sun::star::container::ContainerEvent& Event ) throw (::com::sun::star::uno::RuntimeException);
83     virtual void SAL_CALL elementReplaced( const ::com::sun::star::container::ContainerEvent& Event ) throw (::com::sun::star::uno::RuntimeException);
84 
85     // lang.XEventListener
86     virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
87 
88     private:
89         class FactoryManagerMap : public std::hash_map< rtl::OUString,
90                                                      rtl::OUString,
91                                                      rtl::OUStringHash,
92                                                      ::std::equal_to< ::rtl::OUString > >
93         {
free()94             inline void free()
95             {
96                 FactoryManagerMap().swap( *this );
97             }
98         };
99 
100         sal_Bool impl_getElementProps( const ::com::sun::star::uno::Any& rElement, rtl::OUString& rType, rtl::OUString& rName, rtl::OUString& rModule, rtl::OUString& rServiceSpecifier ) const;
101 
102         rtl::OUString                     m_aPropType;
103         rtl::OUString                     m_aPropName;
104         rtl::OUString                     m_aPropModule;
105         rtl::OUString                     m_aPropFactory;
106         ::rtl::OUString                   m_sRoot;
107         FactoryManagerMap                 m_aFactoryManagerMap;
108         ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xServiceManager;
109         ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xConfigProvider;
110         ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >     m_xConfigAccess;
111         sal_Bool                          m_bConfigAccessInitialized;
112         bool							  m_bConfigDirty;
113 };
114 
115 
116 class UIElementFactoryManager :  private ThreadHelpBase							                    ,	// Struct for right initialization of mutex member! Must be first of baseclasses.
117                                  public ::cppu::WeakImplHelper3< ::com::sun::star::lang::XServiceInfo,
118                                                                  ::com::sun::star::ui::XUIElementFactory,
119                                                                  ::com::sun::star::ui::XUIElementFactoryRegistration>
120 {
121 	public:
122 		UIElementFactoryManager( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager );
123 		virtual ~UIElementFactoryManager();
124 
125         //  XInterface, XTypeProvider, XServiceInfo
126 		DECLARE_XSERVICEINFO
127 
128         // XUIElementFactory
129         virtual ::com::sun::star::uno::Reference< ::com::sun::star::ui::XUIElement > SAL_CALL createUIElement( const ::rtl::OUString& ResourceURL, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& Args ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
130 
131         // XUIElementFactoryRegistration
132         virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > > SAL_CALL getRegisteredFactories(  ) throw (::com::sun::star::uno::RuntimeException);
133         virtual ::com::sun::star::uno::Reference< ::com::sun::star::ui::XUIElementFactory > SAL_CALL getFactory( const ::rtl::OUString& ResourceURL, const ::rtl::OUString& ModuleIdentifier ) throw (::com::sun::star::uno::RuntimeException);
134         virtual void SAL_CALL registerFactory( const ::rtl::OUString& aType, const ::rtl::OUString& aName, const ::rtl::OUString& aModuleIdentifier, const ::rtl::OUString& aFactoryImplementationName ) throw (::com::sun::star::container::ElementExistException, ::com::sun::star::uno::RuntimeException);
135         virtual void SAL_CALL deregisterFactory( const ::rtl::OUString& aType, const ::rtl::OUString& aName, const ::rtl::OUString& aModuleIdentifier ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException);
136 
137     private:
138 
139         sal_Bool                                                                            m_bConfigRead;
140         ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >    m_xServiceManager;
141         ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModuleManager > m_xModuleManager;
142         ConfigurationAccess_FactoryManager*                                        m_pConfigAccess;
143 };
144 
145 } // namespace framework
146 
147 #endif // __FRAMEWORK_UIFACTORY_UIELEMENTFACTORYMANAGER_HXX_
148