Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*************************************************************************
3 : *
4 : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : *
6 : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : *
8 : * OpenOffice.org - a multi-platform office productivity suite
9 : *
10 : * This file is part of OpenOffice.org.
11 : *
12 : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : * it under the terms of the GNU Lesser General Public License version 3
14 : * only, as published by the Free Software Foundation.
15 : *
16 : * OpenOffice.org is distributed in the hope that it will be useful,
17 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : * GNU Lesser General Public License version 3 for more details
20 : * (a copy is included in the LICENSE file that accompanied this code).
21 : *
22 : * You should have received a copy of the GNU Lesser General Public License
23 : * version 3 along with OpenOffice.org. If not, see
24 : * <http://www.openoffice.org/license.html>
25 : * for a copy of the LGPLv3 License.
26 : *
27 : ************************************************************************/
28 :
29 : #include <plugin/model.hxx>
30 : #include <com/sun/star/beans/PropertyAttribute.hpp>
31 :
32 : using namespace com::sun::star::uno;
33 :
34 :
35 0 : Reference< XInterface > SAL_CALL PluginModel_CreateInstance( const Reference< ::com::sun::star::lang::XMultiServiceFactory > & ) throw( Exception )
36 : {
37 0 : Reference< XInterface > xService = *new PluginModel();
38 0 : return xService;
39 : }
40 :
41 0 : Any PluginModel::queryAggregation( const Type& type ) throw( RuntimeException, std::exception )
42 : {
43 : Any aRet( ::cppu::queryInterface( type,
44 : static_cast< ::com::sun::star::lang::XComponent* >(this),
45 : static_cast< ::com::sun::star::io::XPersistObject* >(this ),
46 : static_cast< ::com::sun::star::awt::XControlModel* >(this),
47 : static_cast< ::com::sun::star::beans::XPropertySet* >(this),
48 : static_cast< ::com::sun::star::beans::XMultiPropertySet* >(this),
49 : static_cast< ::com::sun::star::beans::XFastPropertySet* >(this)
50 0 : ) );
51 0 : return aRet.hasValue() ? aRet : OWeakAggObject::queryAggregation( type );
52 : }
53 :
54 :
55 : // XPluginManager_Impl
56 0 : Sequence< OUString > PluginModel::getSupportedServiceNames_Static(void) throw()
57 : {
58 0 : Sequence< OUString > aSNS( 1 );
59 0 : aSNS[0] = "com.sun.star.plugin.PluginModel";
60 0 : return aSNS;
61 : }
62 :
63 :
64 : static const char* aCreationURL = "URL";
65 : static const char* aMime = "TYPE";
66 :
67 2 : static ::osl::Mutex aPropertyMutex;
68 :
69 4 : static ::com::sun::star::beans::Property aProps[] =
70 : {
71 : ::com::sun::star::beans::Property(
72 : OUString::createFromAscii( aMime ),
73 : 1,
74 2 : ::cppu::UnoType<OUString>::get(),
75 : ::com::sun::star::beans::PropertyAttribute::BOUND ),
76 : ::com::sun::star::beans::Property(
77 : OUString::createFromAscii( aCreationURL ),
78 : 2,
79 2 : ::cppu::UnoType<OUString>::get(),
80 : ::com::sun::star::beans::PropertyAttribute::BOUND )
81 6 : };
82 :
83 0 : PluginModel::PluginModel() :
84 : BroadcasterHelperHolder( aPropertyMutex ),
85 : OPropertySetHelper( m_aHelper ),
86 0 : OPropertyArrayHelper( aProps, 2 )
87 : {
88 0 : }
89 :
90 0 : PluginModel::PluginModel(const OUString& rURL, const OUString& rMimeType ) :
91 : BroadcasterHelperHolder( aPropertyMutex ),
92 : OPropertySetHelper( m_aHelper ),
93 : OPropertyArrayHelper( aProps, 2 ),
94 : m_aCreationURL( rURL ),
95 0 : m_aMimeType( rMimeType )
96 : {
97 0 : }
98 :
99 0 : PluginModel::~PluginModel()
100 : {
101 0 : }
102 :
103 0 : Reference< ::com::sun::star::beans::XPropertySetInfo > PluginModel::getPropertySetInfo() throw(std::exception)
104 : {
105 : static Reference< ::com::sun::star::beans::XPropertySetInfo > aInfo =
106 0 : createPropertySetInfo( *this );
107 0 : return aInfo;
108 : }
109 :
110 0 : ::cppu::IPropertyArrayHelper& PluginModel::getInfoHelper()
111 : {
112 0 : return *this;
113 : }
114 :
115 0 : sal_Bool PluginModel::convertFastPropertyValue( Any & rConvertedValue,
116 : Any & rOldValue,
117 : sal_Int32 nHandle,
118 : const Any& rValue ) throw()
119 : {
120 0 : if( nHandle == 1 || nHandle == 2 )
121 : {
122 0 : if( rValue.getValueTypeClass() == TypeClass_STRING )
123 : {
124 0 : rConvertedValue = rValue;
125 0 : if( nHandle == 2 )
126 0 : rOldValue <<= m_aCreationURL;
127 0 : else if( nHandle == 1 )
128 0 : rOldValue <<= m_aMimeType;
129 0 : return sal_True;
130 : }
131 : }
132 0 : return sal_False;
133 : }
134 :
135 0 : void PluginModel::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle,
136 : const Any& rValue )
137 : throw(::com::sun::star::uno::Exception, std::exception)
138 : {
139 0 : if( rValue.getValueTypeClass() == TypeClass_STRING ) // FIXME wrong type!
140 :
141 : {
142 0 : if( nHandle == 2 )
143 0 : rValue >>= m_aCreationURL;
144 0 : else if( nHandle == 1 )
145 0 : rValue >>= m_aMimeType;
146 : }
147 : else
148 0 : throw ::com::sun::star::lang::IllegalArgumentException();
149 0 : }
150 :
151 0 : void PluginModel::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const throw()
152 : {
153 0 : if( nHandle == 2 )
154 0 : rValue <<= m_aCreationURL;
155 0 : else if( nHandle == 1 )
156 0 : rValue <<= m_aMimeType;
157 0 : }
158 :
159 : //---- ::com::sun::star::lang::XComponent ----------------------------------------------------------------------------------
160 0 : void PluginModel::addEventListener( const Reference< ::com::sun::star::lang::XEventListener > & l ) throw(std::exception)
161 : {
162 0 : m_aDisposeListeners.push_back( l );
163 0 : }
164 :
165 : //---- ::com::sun::star::lang::XComponent ----------------------------------------------------------------------------------
166 0 : void PluginModel::removeEventListener( const Reference< ::com::sun::star::lang::XEventListener > & l ) throw(std::exception)
167 : {
168 0 : m_aDisposeListeners.remove( l );
169 0 : }
170 :
171 : //---- ::com::sun::star::lang::XComponent ----------------------------------------------------------------------------------
172 0 : void PluginModel::dispose(void) throw(std::exception)
173 : {
174 : // send disposing events
175 0 : ::com::sun::star::lang::EventObject aEvt;
176 0 : aEvt.Source = (::cppu::OWeakObject*)this;
177 0 : ::std::list< Reference< ::com::sun::star::lang::XEventListener > > aLocalListeners = m_aDisposeListeners;
178 0 : for( ::std::list< Reference< ::com::sun::star::lang::XEventListener > >::iterator it = aLocalListeners.begin();
179 0 : it != aLocalListeners.end(); ++it )
180 0 : (*it)->disposing( aEvt );
181 :
182 0 : m_aDisposeListeners.clear();
183 :
184 0 : disposing();
185 0 : }
186 :
187 :
188 : // ::com::sun::star::io::XPersistObject
189 0 : OUString PluginModel::getServiceName() throw(std::exception)
190 : {
191 0 : return OUString("com.sun.star.plugin.PluginModel");
192 : }
193 :
194 0 : void PluginModel::write(const Reference< ::com::sun::star::io::XObjectOutputStream > & OutStream) throw(std::exception)
195 : {
196 0 : OutStream->writeUTF( m_aCreationURL );
197 0 : }
198 :
199 0 : void PluginModel::read(const Reference< ::com::sun::star::io::XObjectInputStream > & InStream) throw(std::exception)
200 : {
201 0 : m_aCreationURL = InStream->readUTF();
202 6 : }
203 :
204 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|