Clean up uses of Any::getValue() in extensions

Change-Id: I67b9127d8aa67a702086ef5bc61372ae54c2142e
This commit is contained in:
Stephan Bergmann
2016-06-10 18:55:25 +02:00
parent e4eb0f6ece
commit 177afb1ec3
5 changed files with 24 additions and 28 deletions

View File

@@ -25,6 +25,7 @@
#include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/sdb/DatabaseContext.hpp> #include <com/sun/star/sdb/DatabaseContext.hpp>
#include <comphelper/processfactory.hxx> #include <comphelper/processfactory.hxx>
#include <o3tl/any.hxx>
#include <o3tl/make_unique.hxx> #include <o3tl/make_unique.hxx>
using namespace ::com::sun::star::uno; using namespace ::com::sun::star::uno;
@@ -116,7 +117,7 @@ BibConfig::BibConfig()
case 5: pValues[nProp] >>= sQueryText ; break; case 5: pValues[nProp] >>= sQueryText ; break;
case 6: pValues[nProp] >>= sQueryField; break; case 6: pValues[nProp] >>= sQueryField; break;
case 7: case 7:
bShowColumnAssignmentWarning = *static_cast<sal_Bool const *>(pValues[nProp].getValue()); bShowColumnAssignmentWarning = *o3tl::doAccess<bool>(pValues[nProp]);
break; break;
} }
} }

View File

@@ -401,8 +401,7 @@ Reference< sdb::XColumn > BibliographyLoader::GetIdentifierColumn() const
Reference< sdb::XColumn > xReturn; Reference< sdb::XColumn > xReturn;
if (xColumns.is() && xColumns->hasByName(sIdentifierColumnName)) if (xColumns.is() && xColumns->hasByName(sIdentifierColumnName))
{ {
xReturn.set(*static_cast<Reference< XInterface > const *>( xReturn.set(xColumns->getByName(sIdentifierColumnName), UNO_QUERY);
xColumns->getByName(sIdentifierColumnName).getValue()), UNO_QUERY);
} }
return xReturn; return xReturn;
} }
@@ -435,7 +434,7 @@ static OUString lcl_AddProperty(const Reference< XNameAccess >& xColumns,
OUString uRet; OUString uRet;
Reference< sdb::XColumn > xCol; Reference< sdb::XColumn > xCol;
if (xColumns->hasByName(uColumnName)) if (xColumns->hasByName(uColumnName))
xCol.set(*static_cast<Reference< XInterface > const *>(xColumns->getByName(uColumnName).getValue()), UNO_QUERY); xCol.set(xColumns->getByName(uColumnName), UNO_QUERY);
if (xCol.is()) if (xCol.is())
uRet = xCol->getString(); uRet = xCol->getString();
return uRet; return uRet;
@@ -461,7 +460,7 @@ Any BibliographyLoader::getByName(const OUString& rName) throw
const OUString sIdentifierMapping = pDatMan->GetIdentifierMapping(); const OUString sIdentifierMapping = pDatMan->GetIdentifierMapping();
Reference< sdb::XColumn > xColumn; Reference< sdb::XColumn > xColumn;
if (xColumns->hasByName(sIdentifierMapping)) if (xColumns->hasByName(sIdentifierMapping))
xColumn.set(*static_cast<Reference< XInterface > const *>(xColumns->getByName(sIdentifierMapping).getValue()), UNO_QUERY); xColumn.set(xColumns->getByName(sIdentifierMapping), UNO_QUERY);
if (xColumn.is()) if (xColumn.is())
{ {
do do

View File

@@ -17,6 +17,9 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ */
#include <sal/config.h>
#include <o3tl/any.hxx>
#include <osl/mutex.hxx> #include <osl/mutex.hxx>
#include <sal/log.hxx> #include <sal/log.hxx>
#include <tools/diagnose_ex.h> #include <tools/diagnose_ex.h>
@@ -134,7 +137,7 @@ Reference< XConnection > getConnection(const Reference< XInterface > & xRowSe
if (!xFormProps.is()) if (!xFormProps.is())
return xConn; return xConn;
xConn.set(*static_cast<Reference< XInterface > const *>(xFormProps->getPropertyValue("ActiveConnection").getValue()), UNO_QUERY); xConn.set(xFormProps->getPropertyValue("ActiveConnection"), UNO_QUERY);
if (!xConn.is()) if (!xConn.is())
{ {
SAL_INFO("extensions.biblio", "no active connection"); SAL_INFO("extensions.biblio", "no active connection");
@@ -166,14 +169,13 @@ Reference< XNameAccess > getColumns(const Reference< XForm > & _rxForm)
{ {
try try
{ {
DBG_ASSERT((*static_cast<sal_Int32 const *>(xFormProps->getPropertyValue("CommandType").getValue())) == CommandType::TABLE, DBG_ASSERT(*o3tl::forceAccess<sal_Int32>(xFormProps->getPropertyValue("CommandType")) == CommandType::TABLE,
"::getColumns : invalid form (has no table as data source) !"); "::getColumns : invalid form (has no table as data source) !");
OUString sTable; OUString sTable;
xFormProps->getPropertyValue("Command") >>= sTable; xFormProps->getPropertyValue("Command") >>= sTable;
Reference< XNameAccess > xTables = xSupplyTables->getTables(); Reference< XNameAccess > xTables = xSupplyTables->getTables();
if (xTables.is() && xTables->hasByName(sTable)) if (xTables.is() && xTables->hasByName(sTable))
xSupplyCols.set( xSupplyCols.set(xTables->getByName(sTable), UNO_QUERY);
*static_cast<Reference< XInterface > const *>(xTables->getByName(sTable).getValue()), UNO_QUERY);
if (xSupplyCols.is()) if (xSupplyCols.is())
xReturn = xSupplyCols->getColumns(); xReturn = xSupplyCols->getColumns();
} }
@@ -1428,7 +1430,7 @@ void BibDataManager::propertyChange(const beans::PropertyChangeEvent& evt) throw
if( evt.NewValue.getValueType() == cppu::UnoType<io::XInputStream>::get()) if( evt.NewValue.getValueType() == cppu::UnoType<io::XInputStream>::get())
{ {
Reference< io::XDataInputStream > xStream( Reference< io::XDataInputStream > xStream(
*static_cast<const Reference< io::XInputStream > *>(evt.NewValue.getValue()), UNO_QUERY ); evt.NewValue, UNO_QUERY );
aUID <<= xStream->readUTF(); aUID <<= xStream->readUTF();
} }
else else
@@ -1472,13 +1474,12 @@ void BibDataManager::SetMeAsUidListener()
if(!theFieldName.isEmpty()) if(!theFieldName.isEmpty())
{ {
Reference< XPropertySet > xPropSet;
Any aElement; Any aElement;
aElement = xFields->getByName(theFieldName); aElement = xFields->getByName(theFieldName);
xPropSet = *static_cast<Reference< XPropertySet > const *>(aElement.getValue()); auto xPropSet = o3tl::doAccess<Reference<XPropertySet>>(aElement);
xPropSet->addPropertyChangeListener(FM_PROP_VALUE, this); (*xPropSet)->addPropertyChangeListener(FM_PROP_VALUE, this);
} }
} }
@@ -1516,13 +1517,12 @@ void BibDataManager::RemoveMeAsUidListener()
if(!theFieldName.isEmpty()) if(!theFieldName.isEmpty())
{ {
Reference< XPropertySet > xPropSet;
Any aElement; Any aElement;
aElement = xFields->getByName(theFieldName); aElement = xFields->getByName(theFieldName);
xPropSet = *static_cast<Reference< XPropertySet > const *>(aElement.getValue()); auto xPropSet = o3tl::doAccess<Reference<XPropertySet>>(aElement);
xPropSet->removePropertyChangeListener(FM_PROP_VALUE, this); (*xPropSet)->removePropertyChangeListener(FM_PROP_VALUE, this);
} }
} }

View File

@@ -129,8 +129,7 @@ void BibPosListener::cursorMoved(const lang::EventObject& /*aEvent*/) throw( uno
if(xValueAcc.is() && xValueAcc->hasByName(uTypeMapping)) if(xValueAcc.is() && xValueAcc->hasByName(uTypeMapping))
{ {
uno::Any aVal = xValueAcc->getByName(uTypeMapping); uno::Any aVal = xValueAcc->getByName(uTypeMapping);
uno::Reference< uno::XInterface > xInt = *static_cast<uno::Reference< uno::XInterface > const *>(aVal.getValue()); uno::Reference< sdb::XColumn > xCol(aVal, UNO_QUERY);
uno::Reference< sdb::XColumn > xCol(xInt, UNO_QUERY);
DBG_ASSERT(xCol.is(), "BibPosListener::cursorMoved : invalid column (no sdb::XColumn) !"); DBG_ASSERT(xCol.is(), "BibPosListener::cursorMoved : invalid column (no sdb::XColumn) !");
if (xCol.is()) if (xCol.is())
{ {

View File

@@ -24,6 +24,7 @@
#include <com/sun/star/util/XURLTransformer.hpp> #include <com/sun/star/util/XURLTransformer.hpp>
#include <com/sun/star/frame/FrameSearchFlag.hpp> #include <com/sun/star/frame/FrameSearchFlag.hpp>
#include <datman.hxx> #include <datman.hxx>
#include <o3tl/any.hxx>
#include <svx/svxids.hrc> #include <svx/svxids.hrc>
#include <svtools/miscopt.hxx> #include <svtools/miscopt.hxx>
#include <svtools/imgdef.hxx> #include <svtools/imgdef.hxx>
@@ -65,10 +66,9 @@ void BibToolBarListener::statusChanged(const css::frame::FeatureStateEvent& rEvt
pToolBar->EnableItem(nIndex,rEvt.IsEnabled); pToolBar->EnableItem(nIndex,rEvt.IsEnabled);
css::uno::Any aState=rEvt.State; css::uno::Any aState=rEvt.State;
if(aState.getValueType()==cppu::UnoType<bool>::get()) if(auto bChecked = o3tl::tryAccess<bool>(aState))
{ {
bool bChecked= *static_cast<sal_Bool const *>(aState.getValue()); pToolBar->CheckItem(nIndex, *bChecked);
pToolBar->CheckItem(nIndex, bChecked);
} }
} }
@@ -92,12 +92,11 @@ void BibTBListBoxListener::statusChanged(const css::frame::FeatureStateEvent& rE
pToolBar->EnableSourceList(rEvt.IsEnabled); pToolBar->EnableSourceList(rEvt.IsEnabled);
Any aState = rEvt.State; Any aState = rEvt.State;
if(aState.getValueType() == cppu::UnoType<Sequence<OUString>>::get()) if(auto pStringSeq = o3tl::tryAccess<Sequence<OUString>>(aState))
{ {
pToolBar->UpdateSourceList(false); pToolBar->UpdateSourceList(false);
pToolBar->ClearSourceList(); pToolBar->ClearSourceList();
Sequence<OUString> const * pStringSeq = static_cast<Sequence<OUString> const *>(aState.getValue());
const OUString* pStringArray = pStringSeq->getConstArray(); const OUString* pStringArray = pStringSeq->getConstArray();
sal_uInt32 nCount = pStringSeq->getLength(); sal_uInt32 nCount = pStringSeq->getLength();
@@ -131,11 +130,10 @@ void BibTBQueryMenuListener::statusChanged(const frame::FeatureStateEvent& rEvt)
pToolBar->EnableSourceList(rEvt.IsEnabled); pToolBar->EnableSourceList(rEvt.IsEnabled);
uno::Any aState=rEvt.State; uno::Any aState=rEvt.State;
if(aState.getValueType()==cppu::UnoType<Sequence<OUString>>::get()) if(auto pStringSeq = o3tl::tryAccess<Sequence<OUString>>(aState))
{ {
pToolBar->ClearFilterMenu(); pToolBar->ClearFilterMenu();
Sequence<OUString> const * pStringSeq = static_cast<Sequence<OUString> const *>(aState.getValue());
const OUString* pStringArray = pStringSeq->getConstArray(); const OUString* pStringArray = pStringSeq->getConstArray();
sal_uInt32 nCount = pStringSeq->getLength(); sal_uInt32 nCount = pStringSeq->getLength();
@@ -168,10 +166,9 @@ void BibTBEditListener::statusChanged(const frame::FeatureStateEvent& rEvt)throw
pToolBar->EnableQuery(rEvt.IsEnabled); pToolBar->EnableQuery(rEvt.IsEnabled);
uno::Any aState=rEvt.State; uno::Any aState=rEvt.State;
if(aState.getValueType()== ::cppu::UnoType<OUString>::get()) if(auto aStr = o3tl::tryAccess<OUString>(aState))
{ {
OUString aStr = *static_cast<OUString const *>(aState.getValue()); pToolBar->SetQueryString(*aStr);
pToolBar->SetQueryString(aStr);
} }
} }
} }