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 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_ucb.hxx" 26 #include "cachemapobjectcontainer2.hxx" 27 #include "cachemapobject2.hxx" 28 #include "com/sun/star/uno/Reference.hxx" 29 #include "com/sun/star/uno/XWeak.hpp" 30 #include "cppuhelper/weakref.hxx" 31 #include "osl/mutex.hxx" 32 #include "rtl/ref.hxx" 33 #include "rtl/ustring.hxx" 34 35 using ucb::cachemap::Object2; 36 using ucb::cachemap::ObjectContainer2; 37 using namespace com::sun::star; 38 ObjectContainer2()39ObjectContainer2::ObjectContainer2() 40 {} 41 ~ObjectContainer2()42ObjectContainer2::~ObjectContainer2() SAL_THROW(()) 43 {} 44 get(rtl::OUString const & rKey)45rtl::Reference< Object2 > ObjectContainer2::get(rtl::OUString const & rKey) 46 { 47 rtl::Reference< Object2 > xElement; 48 { 49 osl::MutexGuard aGuard(m_aMutex); 50 Map::iterator aIt(m_aMap.find(rKey)); 51 if (aIt != m_aMap.end()) 52 xElement = static_cast< Object2 * >( 53 uno::Reference< uno::XWeak >( 54 aIt->second.get(), uno::UNO_QUERY). 55 get()); 56 if (!xElement.is()) 57 { 58 xElement = new Object2; 59 m_aMap[rKey] 60 = uno::WeakReference< Object2 >(xElement.get()); 61 } 62 } 63 return xElement; 64 } 65