update dev300-m58
[ooovba.git] / forms / source / xforms / unohelper.cxx
blob3fe953496fe20a5b95d3b2a1c7d7a759361e8e5d
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: unohelper.cxx,v $
10 * $Revision: 1.6 $
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_forms.hxx"
34 #include "unohelper.hxx"
36 #include <osl/diagnose.h>
38 #include <com/sun/star/uno/Reference.hxx>
39 #include <com/sun/star/uno/Sequence.hxx>
40 #include <com/sun/star/uno/XInterface.hpp>
41 #include <com/sun/star/uno/Exception.hpp>
42 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
43 #include <com/sun/star/beans/Property.hpp>
44 #include <com/sun/star/beans/XPropertySet.hpp>
45 #include <com/sun/star/beans/XPropertySetInfo.hpp>
46 #include <com/sun/star/beans/PropertyAttribute.hpp>
47 #include <unotools/processfactory.hxx>
50 using com::sun::star::uno::Reference;
51 using com::sun::star::uno::Sequence;
52 using com::sun::star::uno::Exception;
53 using com::sun::star::uno::XInterface;
54 using com::sun::star::lang::XMultiServiceFactory;
55 using com::sun::star::beans::Property;
56 using com::sun::star::beans::XPropertySet;
57 using com::sun::star::beans::XPropertySetInfo;
58 using com::sun::star::beans::PropertyAttribute::READONLY;
59 using rtl::OUString;
62 Reference<XInterface> xforms::createInstance( const OUString& sServiceName )
64 Reference<XMultiServiceFactory> xFactory = utl::getProcessServiceFactory();
65 OSL_ENSURE( xFactory.is(), "can't get service factory" );
67 Reference<XInterface> xInstance = xFactory->createInstance( sServiceName );
68 OSL_ENSURE( xInstance.is(), "failed to create instance" );
70 return xInstance;
73 void xforms::copy( const Reference<XPropertySet>& xFrom,
74 Reference<XPropertySet>& xTo )
76 OSL_ENSURE( xFrom.is(), "no source" );
77 OSL_ENSURE( xTo.is(), "no target" );
79 // get property names & infos, and iterate over target properties
80 Sequence<Property> aProperties =
81 xTo->getPropertySetInfo()->getProperties();
82 sal_Int32 nProperties = aProperties.getLength();
83 const Property* pProperties = aProperties.getConstArray();
84 Reference<XPropertySetInfo> xFromInfo = xFrom->getPropertySetInfo();
85 for( sal_Int32 n = 0; n < nProperties; n++ )
87 const OUString& rName = pProperties[n].Name;
89 // if both set have the property, copy the value
90 // (catch and ignore exceptions, if any)
91 if( xFromInfo->hasPropertyByName( rName ) )
93 try
95 Property aProperty = xFromInfo->getPropertyByName( rName );
96 if ( ( aProperty.Attributes & READONLY ) == 0 )
97 xTo->setPropertyValue(rName, xFrom->getPropertyValue( rName ));
99 catch( const Exception& )
101 // ignore any errors; we'll copy as good as we can
104 // else: no property? then ignore.