Update ooo320-m1
[ooovba.git] / configmgr / source / backend / emptylayer.cxx
blobbd174556ee495fcddc94823e3e01c04562a96132
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: emptylayer.cxx,v $
10 * $Revision: 1.9 $
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_configmgr.hxx"
34 #include "emptylayerimpl.hxx"
35 #include "emptylayer.hxx"
37 // -----------------------------------------------------------------------------
39 namespace configmgr
41 // -----------------------------------------------------------------------------
42 namespace backend
44 // -----------------------------------------------------------------------------
45 namespace uno = ::com::sun::star::uno;
46 // -----------------------------------------------------------------------------
47 // -----------------------------------------------------------------------------
49 uno::Reference< backenduno::XLayer > createEmptyLayer()
51 return new EmptyLayer();
53 // -----------------------------------------------------------------------------
55 bool checkEmptyLayer(uno::Reference< backenduno::XLayer > const & xLayer )
57 OSL_ENSURE(xLayer.is(),"Unexpected NULL Layer");
58 if (!xLayer.is()) return false;
60 RequireEmptyLayer * const pChecker = new RequireEmptyLayer;
61 uno::Reference< backenduno::XLayerHandler > xChecker(pChecker);
63 try
65 xLayer->readData(xChecker);
67 catch (uno::Exception &)
69 OSL_ENSURE(!pChecker->wasEmpty(), "Checking for empty layer: exception occurred after empty layer was ended");
72 return pChecker->wasEmpty();
75 // -----------------------------------------------------------------------------
76 // -----------------------------------------------------------------------------
78 EmptyLayer::~EmptyLayer( )
81 // -----------------------------------------------------------------------------
83 void SAL_CALL
84 EmptyLayer::readData( const uno::Reference< backenduno::XLayerHandler >& aHandler )
85 throw (backenduno::MalformedDataException, lang::NullPointerException, lang::WrappedTargetException, uno::RuntimeException)
87 if (aHandler.is())
89 aHandler->startLayer();
90 aHandler->endLayer();
92 else
93 throw lang::NullPointerException(rtl::OUString::createFromAscii("EmptyLayer: Null Handler"),*this);
95 // -----------------------------------------------------------------------------
96 // -----------------------------------------------------------------------------
98 RequireEmptyLayer::RequireEmptyLayer()
99 : m_bStarted(false)
100 , m_bInvalid(false)
101 , m_bEmpty(false)
104 // -----------------------------------------------------------------------------
106 RequireEmptyLayer::~RequireEmptyLayer( )
109 // -----------------------------------------------------------------------------
111 void SAL_CALL RequireEmptyLayer::startLayer( )
112 throw (backenduno::MalformedDataException, uno::RuntimeException)
114 m_bInvalid = false;
115 m_bEmpty = false;
117 if (m_bStarted) fail("Layer started twice");
118 m_bStarted = true;
120 // -----------------------------------------------------------------------------
122 void SAL_CALL RequireEmptyLayer::endLayer( )
123 throw (backenduno::MalformedDataException, uno::RuntimeException)
125 if (!m_bStarted) fail("Layer was not started");
126 m_bEmpty = !m_bInvalid;
127 m_bStarted = false;
129 // -----------------------------------------------------------------------------
131 void SAL_CALL RequireEmptyLayer::overrideNode( const rtl::OUString& /*aName*/, sal_Int16 /*aAttributes*/, sal_Bool /*bClear*/ )
132 throw (backenduno::MalformedDataException, uno::RuntimeException)
134 failNotEmpty();
136 // -----------------------------------------------------------------------------
138 void SAL_CALL RequireEmptyLayer::addOrReplaceNode( const rtl::OUString& /*aName*/, sal_Int16 /*aAttributes*/ )
139 throw (backenduno::MalformedDataException, uno::RuntimeException)
141 failNotEmpty();
143 // -----------------------------------------------------------------------------
145 void SAL_CALL RequireEmptyLayer::addOrReplaceNodeFromTemplate( const rtl::OUString& /*aName*/, const backenduno::TemplateIdentifier& /*aTemplate*/, sal_Int16 /*aAttributes*/)
146 throw (backenduno::MalformedDataException, uno::RuntimeException)
148 failNotEmpty();
150 // -----------------------------------------------------------------------------
152 void SAL_CALL RequireEmptyLayer::endNode( )
153 throw (backenduno::MalformedDataException, uno::RuntimeException)
155 failNotEmpty();
157 // -----------------------------------------------------------------------------
159 void SAL_CALL RequireEmptyLayer::dropNode( const rtl::OUString& /*aName*/ )
160 throw (backenduno::MalformedDataException, uno::RuntimeException)
162 failNotEmpty();
164 // -----------------------------------------------------------------------------
166 void SAL_CALL RequireEmptyLayer::addProperty( const rtl::OUString& /*aName*/, sal_Int16 /*aAttributes*/, const uno::Type& /*aType*/ )
167 throw (backenduno::MalformedDataException, uno::RuntimeException)
169 failNotEmpty();
171 // -----------------------------------------------------------------------------
173 void SAL_CALL RequireEmptyLayer::addPropertyWithValue( const rtl::OUString& /*aName*/, sal_Int16 /*aAttributes*/, const uno::Any& /*aValue*/ )
174 throw (backenduno::MalformedDataException, uno::RuntimeException)
176 failNotEmpty();
178 // -----------------------------------------------------------------------------
180 void SAL_CALL RequireEmptyLayer::overrideProperty( const rtl::OUString& /*aName*/, sal_Int16 /*aAttributes*/, const uno::Type& /*aType*/, sal_Bool /*bClear*/ )
181 throw (backenduno::MalformedDataException, uno::RuntimeException)
183 failNotEmpty();
185 // -----------------------------------------------------------------------------
187 void SAL_CALL RequireEmptyLayer::endProperty( )
188 throw (backenduno::MalformedDataException, uno::RuntimeException)
190 failNotEmpty();
192 // -----------------------------------------------------------------------------
194 void SAL_CALL RequireEmptyLayer::setPropertyValue( const uno::Any& /*aValue*/ )
195 throw (backenduno::MalformedDataException, uno::RuntimeException)
197 failNotEmpty();
199 // -----------------------------------------------------------------------------
201 void SAL_CALL RequireEmptyLayer::setPropertyValueForLocale( const uno::Any& /*aValue*/, const rtl::OUString& /*aLocale*/ )
202 throw (backenduno::MalformedDataException, uno::RuntimeException)
204 failNotEmpty();
206 // -----------------------------------------------------------------------------
208 void RequireEmptyLayer::fail(sal_Char const * pMsg)
210 if (!m_bStarted & !m_bInvalid) pMsg = "Layer was not started";
211 m_bInvalid = true;
212 m_bStarted = false;
214 OSL_ASSERT(pMsg);
215 rtl::OUString sMsg = rtl::OUString::createFromAscii(pMsg);
217 throw backenduno::MalformedDataException( sMsg, *this, uno::Any() );
220 // -----------------------------------------------------------------------------
221 // -----------------------------------------------------------------------------
223 // -----------------------------------------------------------------------------
224 } // namespace
226 // -----------------------------------------------------------------------------
227 } // namespace