Update ooo320-m1
[ooovba.git] / extensions / source / plugin / base / plmodel.cxx
blobef53e25593cfdbaf0cd065dcb96016bfe9f2164d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: plmodel.cxx,v $
10 * $Revision: 1.10 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_extensions.hxx"
33 #include <plugin/model.hxx>
34 #include <com/sun/star/beans/PropertyAttribute.hpp>
36 using namespace com::sun::star::uno;
38 //==================================================================================================
39 Reference< XInterface > SAL_CALL PluginModel_CreateInstance( const Reference< ::com::sun::star::lang::XMultiServiceFactory > & ) throw( Exception )
41 Reference< XInterface > xService = *new PluginModel();
42 return xService;
45 Any PluginModel::queryAggregation( const Type& type ) throw( RuntimeException )
47 Any aRet( ::cppu::queryInterface( type,
48 static_cast< ::com::sun::star::lang::XComponent* >(this),
49 static_cast< ::com::sun::star::io::XPersistObject* >(this ),
50 static_cast< ::com::sun::star::awt::XControlModel* >(this),
51 static_cast< ::com::sun::star::beans::XPropertySet* >(this),
52 static_cast< ::com::sun::star::beans::XMultiPropertySet* >(this),
53 static_cast< ::com::sun::star::beans::XFastPropertySet* >(this)
54 ) );
55 return aRet.hasValue() ? aRet : OWeakAggObject::queryAggregation( type );
59 // XPluginManager_Impl
60 Sequence< ::rtl::OUString > PluginModel::getSupportedServiceNames_Static(void) throw()
62 Sequence< ::rtl::OUString > aSNS( 1 );
63 aSNS.getArray()[0] = ::rtl::OUString::createFromAscii( "com.sun.star.plugin.PluginModel" );
64 return aSNS;
68 static const char* aCreationURL = "URL";
69 static const char* aMime = "TYPE";
71 static ::osl::Mutex aPropertyMutex;
73 static ::com::sun::star::beans::Property aProps[] =
75 ::com::sun::star::beans::Property(
76 ::rtl::OUString::createFromAscii( aMime ),
78 ::getCppuType((const ::rtl::OUString*)0),
79 ::com::sun::star::beans::PropertyAttribute::BOUND ),
80 ::com::sun::star::beans::Property(
81 ::rtl::OUString::createFromAscii( aCreationURL ),
83 ::getCppuType((const ::rtl::OUString*)0),
84 ::com::sun::star::beans::PropertyAttribute::BOUND )
87 PluginModel::PluginModel() :
88 BroadcasterHelperHolder( aPropertyMutex ),
89 OPropertySetHelper( m_aHelper ),
90 OPropertyArrayHelper( aProps, 2 )
94 PluginModel::PluginModel(const ::rtl::OUString& rURL, const rtl::OUString& rMimeType ) :
95 BroadcasterHelperHolder( aPropertyMutex ),
96 OPropertySetHelper( m_aHelper ),
97 OPropertyArrayHelper( aProps, 2 ),
98 m_aCreationURL( rURL ),
99 m_aMimeType( rMimeType )
103 PluginModel::~PluginModel()
107 Reference< ::com::sun::star::beans::XPropertySetInfo > PluginModel::getPropertySetInfo() throw()
109 static Reference< ::com::sun::star::beans::XPropertySetInfo > aInfo =
110 createPropertySetInfo( *this );
111 return aInfo;
114 ::cppu::IPropertyArrayHelper& PluginModel::getInfoHelper()
116 return *this;
119 sal_Bool PluginModel::convertFastPropertyValue( Any & rConvertedValue,
120 Any & rOldValue,
121 sal_Int32 nHandle,
122 const Any& rValue ) throw()
124 if( nHandle == 1 || nHandle == 2 )
126 if( rValue.getValueTypeClass() == TypeClass_STRING )
128 rConvertedValue = rValue;
129 if( nHandle == 2 )
130 rOldValue <<= m_aCreationURL;
131 else if( nHandle == 1 )
132 rOldValue <<= m_aMimeType;
133 return sal_True;
136 return sal_False;
139 void PluginModel::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle,
140 const Any& rValue )
141 throw(::com::sun::star::uno::Exception)
143 if( rValue.getValueTypeClass() == TypeClass_STRING ) // FIXME wrong type!
146 if( nHandle == 2 )
147 rValue >>= m_aCreationURL;
148 else if( nHandle == 1 )
149 rValue >>= m_aMimeType;
151 else
152 throw ::com::sun::star::lang::IllegalArgumentException();
155 void PluginModel::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const throw()
157 if( nHandle == 2 )
158 rValue <<= m_aCreationURL;
159 else if( nHandle == 1 )
160 rValue <<= m_aMimeType;
163 //---- ::com::sun::star::lang::XComponent ----------------------------------------------------------------------------------
164 void PluginModel::addEventListener( const Reference< ::com::sun::star::lang::XEventListener > & l ) throw()
166 m_aDisposeListeners.push_back( l );
169 //---- ::com::sun::star::lang::XComponent ----------------------------------------------------------------------------------
170 void PluginModel::removeEventListener( const Reference< ::com::sun::star::lang::XEventListener > & l ) throw()
172 m_aDisposeListeners.remove( l );
175 //---- ::com::sun::star::lang::XComponent ----------------------------------------------------------------------------------
176 void PluginModel::dispose(void) throw()
178 // send disposing events
179 ::com::sun::star::lang::EventObject aEvt;
180 aEvt.Source = (::cppu::OWeakObject*)this;
181 ::std::list< Reference< ::com::sun::star::lang::XEventListener > > aLocalListeners = m_aDisposeListeners;
182 for( ::std::list< Reference< ::com::sun::star::lang::XEventListener > >::iterator it = aLocalListeners.begin();
183 it != aLocalListeners.end(); ++it )
184 (*it)->disposing( aEvt );
186 m_aDisposeListeners.clear();
188 disposing();
192 // ::com::sun::star::io::XPersistObject
193 ::rtl::OUString PluginModel::getServiceName() throw()
195 return ::rtl::OUString::createFromAscii( "com.sun.star.plugin.PluginModel" );
198 void PluginModel::write(const Reference< ::com::sun::star::io::XObjectOutputStream > & OutStream) throw()
200 OutStream->writeUTF( m_aCreationURL );
203 void PluginModel::read(const Reference< ::com::sun::star::io::XObjectInputStream > & InStream) throw()
205 m_aCreationURL = InStream->readUTF();