merge the formfield patch from ooo-build
[ooovba.git] / configmgr / source / api2 / apifactoryimpl.cxx
blob8a64373153e0a5216820bf4a884a84d1e4df3a01
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: apifactoryimpl.cxx,v $
10 * $Revision: 1.13 $
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"
33 #include <stdio.h>
34 #include "apifactoryimpl.hxx"
36 #include "setobjects.hxx"
37 #include "groupobjects.hxx"
39 #include "configset.hxx"
40 #include "configpath.hxx"
41 #include "template.hxx"
42 #include "noderef.hxx"
43 #include "objectregistry.hxx"
44 #include "attributes.hxx"
46 namespace configmgr
48 namespace configapi
50 //-----------------------------------------------------------------------------
51 // class ReadOnlyObjectFactory
52 //-----------------------------------------------------------------------------
54 ReadOnlyObjectFactory::ReadOnlyObjectFactory(ApiProvider& rProvider,rtl::Reference<ObjectRegistry> pRegistry)
55 : Factory(pRegistry)
56 , m_rProvider(rProvider)
59 //-----------------------------------------------------------------------------
61 ReadOnlyObjectFactory::~ReadOnlyObjectFactory()
64 //-----------------------------------------------------------------------------
66 NodeElement* ReadOnlyObjectFactory::doCreateGroupMember(rtl::Reference< configuration::Tree > const& aTree, configuration::NodeRef const& aNode, configuration::Template* pSetElementTemplate)
68 OSL_ENSURE(!configuration::isEmpty(aTree.get()), "ERROR: trying to create a group member without a tree");
69 OSL_ENSURE(aNode.isValid(), "ERROR: trying to create a group member without a node");
70 OSL_ENSURE(aTree->isValidNode(aNode.getOffset()), "ERROR: node does not match tree , while trying to create a group member");
71 OSL_ENSURE(!aTree->isRootNode(aNode), "ERROR: trying to create a group member on a root node");
72 if (aTree->isRootNode(aNode))
73 return 0;
75 NodeElement* pRootElement = makeElement(aTree,aTree->getRootNode());
76 OSL_ENSURE(pRootElement, "Could not create root element of tree - cannot create group member object");
77 if (!pRootElement)
78 return 0;
80 uno::Reference<uno::XInterface> aRootRelease(pRootElement->getUnoInstance(), uno::UNO_REF_NO_ACQUIRE);
81 ApiTreeImpl& rRootContext = getImplementation(*pRootElement);
83 NodeElement * pResult = 0;
84 if (!pSetElementTemplate)
86 OInnerGroupInfo * pNewObject = new OInnerGroupInfo(rRootContext, aNode);
87 pNewObject->acquire();
88 pResult = &pNewObject->getElementClass();
90 else
92 OInnerSetInfo * pNewObject = new OInnerSetInfo(rRootContext, aNode);
93 pNewObject->acquire();
94 pResult = &pNewObject->getElementClass();
97 return pResult;
99 //-----------------------------------------------------------------------------
101 TreeElement* ReadOnlyObjectFactory::doCreateAccessRoot(rtl::Reference< configuration::Tree > const& aTree, configuration::Template* pSetElementTemplate, vos::ORef< OOptions >const& _xOptions)
103 OSL_ENSURE(!configuration::isEmpty(aTree.get()), "ERROR: trying to create a root object without a tree");
105 TreeElement * pResult = 0;
106 if (!pSetElementTemplate)
108 ORootElementGroupInfo * pNewObject = new ORootElementGroupInfo(m_rProvider, aTree, _xOptions);
109 pNewObject->acquire();
110 pResult = &pNewObject->getElementClass();
112 else
114 ORootElementSetInfo * pNewObject = new ORootElementSetInfo(m_rProvider, aTree, _xOptions);
115 pNewObject->acquire();
116 pResult = &pNewObject->getElementClass();
118 return pResult;
121 //-----------------------------------------------------------------------------
122 SetElement* ReadOnlyObjectFactory::doCreateSetElement(rtl::Reference< configuration::ElementTree > const& aElementTree, configuration::Template* pSetElementTemplate)
124 OSL_ENSURE(aElementTree.is(), "ERROR: trying to create a set element object without a tree");
126 rtl::Reference< configuration::Tree > aTree( aElementTree.get() );
127 OSL_ENSURE(!configuration::isEmpty(aTree.get()), "ERROR: trying to create a set element object without a tree");
129 ApiTreeImpl * pParentContext = 0;
130 uno::Reference<uno::XInterface> aParentRelease;
132 rtl::Reference< configuration::Tree > aParentTree = aTree->getContextTree();
133 if (!configuration::isEmpty(aParentTree.get()))
135 //configuration::NodeRef aParentNode = aTree.getContextNode();
136 configuration::NodeRef aParentRoot = aParentTree->getRootNode();
137 if (NodeElement* pParentRootElement = makeElement(aParentTree,aParentRoot) )
139 aParentRelease = uno::Reference<uno::XInterface>(pParentRootElement->getUnoInstance(), uno::UNO_REF_NO_ACQUIRE);
140 pParentContext = &getImplementation(*pParentRootElement);
144 SetElement * pResult = 0;
145 if (!pSetElementTemplate)
147 OSetElementGroupInfo * pNewObject = new OSetElementGroupInfo(aTree,m_rProvider,pParentContext);
148 pNewObject->acquire();
149 pResult = &pNewObject->getElementClass();
151 else
153 OSetElementSetInfo * pNewObject = new OSetElementSetInfo(aTree,m_rProvider,pParentContext);
154 pNewObject->acquire();
155 pResult = &pNewObject->getElementClass();
157 return pResult;
159 //-----------------------------------------------------------------------------
161 //-----------------------------------------------------------------------------
162 // class UpdateObjectFactory
163 //-----------------------------------------------------------------------------
165 UpdateObjectFactory::UpdateObjectFactory(ApiProvider& rProvider,rtl::Reference<ObjectRegistry> pRegistry)
166 : Factory(pRegistry)
167 , m_rProvider(rProvider)
170 //-----------------------------------------------------------------------------
172 UpdateObjectFactory::~UpdateObjectFactory()
175 //-----------------------------------------------------------------------------
177 bool UpdateObjectFactory::implIsReadOnly(rtl::Reference< configuration::Tree > const& aTree, configuration::NodeRef const& aNode)
179 OSL_ENSURE(!configuration::isEmpty(aTree.get()), "ERROR: trying to create an object without a tree");
180 OSL_ENSURE(aNode.isValid(), "ERROR: trying to create an object without a node");
181 OSL_ENSURE(aTree->isValidNode(aNode.getOffset()), "ERROR: node does not match tree , while trying to create an object");
183 return aTree->getAttributes(aNode).isReadonly();
185 //-----------------------------------------------------------------------------
187 NodeElement* UpdateObjectFactory::doCreateGroupMember(rtl::Reference< configuration::Tree > const& aTree, configuration::NodeRef const& aNode, configuration::Template* pSetElementTemplate)
189 OSL_ENSURE(!configuration::isEmpty(aTree.get()), "ERROR: trying to create a group member without a tree");
190 OSL_ENSURE(aNode.isValid(), "ERROR: trying to create a group member without a node");
191 OSL_ENSURE(aTree->isValidNode(aNode.getOffset()), "ERROR: node does not match tree , while trying to create a group");
193 NodeElement* pRootElement = makeElement(aTree,aTree->getRootNode());
194 OSL_ENSURE(pRootElement, "Could not create root element of tree - cannot create group member object");
195 if (!pRootElement)
196 return 0;
198 uno::Reference<uno::XInterface> aRootRelease(pRootElement->getUnoInstance(), uno::UNO_REF_NO_ACQUIRE);
199 ApiTreeImpl& rRootContext = getImplementation(*pRootElement);
201 NodeElement * pResult = 0;
203 if (implIsReadOnly(aTree,aNode))
205 if (!pSetElementTemplate)
207 OInnerGroupInfo * pNewObject = new OInnerGroupInfo(rRootContext, aNode);
208 pNewObject->acquire();
209 pResult = &pNewObject->getElementClass();
211 else
213 OInnerSetInfo * pNewObject = new OInnerSetInfo(rRootContext, aNode);
214 pNewObject->acquire();
215 pResult = &pNewObject->getElementClass();
218 else
220 if (!pSetElementTemplate)
222 OInnerGroupUpdate * pNewObject = new OInnerGroupUpdate(rRootContext, aNode);
223 pNewObject->acquire();
224 pResult = &pNewObject->getElementClass();
226 else if (pSetElementTemplate->isInstanceValue())
228 OInnerValueSetUpdate * pNewObject = new OInnerValueSetUpdate(rRootContext, aNode);
229 pNewObject->acquire();
230 pResult = &pNewObject->getElementClass();
232 else
234 OInnerTreeSetUpdate * pNewObject = new OInnerTreeSetUpdate(rRootContext, aNode);
235 pNewObject->acquire();
236 pResult = &pNewObject->getElementClass();
240 return pResult;
242 //-----------------------------------------------------------------------------
244 TreeElement* UpdateObjectFactory::doCreateAccessRoot(rtl::Reference< configuration::Tree > const& aTree, configuration::Template* pSetElementTemplate, vos::ORef< OOptions >const& _xOptions)
246 OSL_ENSURE(!configuration::isEmpty(aTree.get()), "ERROR: trying to create a root object without a tree");
248 TreeElement * pResult = 0;
249 if (implIsReadOnly(aTree,aTree->getRootNode()))
251 OSL_ENSURE(false, "WARNING: Trying to create an 'Update Access' on a read-only tree/node");
252 if (!pSetElementTemplate)
254 ORootElementGroupInfo * pNewObject = new ORootElementGroupInfo(m_rProvider, aTree, _xOptions);
255 pNewObject->acquire();
256 pResult = &pNewObject->getElementClass();
258 else
260 ORootElementSetInfo * pNewObject = new ORootElementSetInfo(m_rProvider, aTree, _xOptions);
261 pNewObject->acquire();
262 pResult = &pNewObject->getElementClass();
265 else
267 if (!pSetElementTemplate)
269 ORootElementGroupUpdate * pNewObject = new ORootElementGroupUpdate(m_rProvider, aTree, _xOptions);
270 pNewObject->acquire();
271 pResult = &pNewObject->getElementClass();
273 else if (pSetElementTemplate->isInstanceValue())
275 ORootElementValueSetUpdate * pNewObject = new ORootElementValueSetUpdate(m_rProvider, aTree, _xOptions);
276 pNewObject->acquire();
277 pResult = &pNewObject->getElementClass();
279 else
281 ORootElementTreeSetUpdate * pNewObject = new ORootElementTreeSetUpdate(m_rProvider, aTree, _xOptions);
282 pNewObject->acquire();
283 pResult = &pNewObject->getElementClass();
287 return pResult;
290 //-----------------------------------------------------------------------------
291 SetElement* UpdateObjectFactory::doCreateSetElement(rtl::Reference< configuration::ElementTree > const& aElementTree, configuration::Template* pSetElementTemplate)
293 OSL_ENSURE(aElementTree.is(), "ERROR: trying to create a set element object without a tree");
295 rtl::Reference< configuration::Tree > aTree( aElementTree.get() );
296 OSL_ENSURE(!configuration::isEmpty(aTree.get()), "ERROR: trying to create a set element object without a tree");
298 ApiTreeImpl * pParentContext = 0;
299 uno::Reference<uno::XInterface> aParentRelease;
301 rtl::Reference< configuration::Tree > aParentTree = aTree->getContextTree();
302 if (!configuration::isEmpty(aParentTree.get()))
304 //configuration::NodeRef aParentNode = aTree.getContextNode();
305 configuration::NodeRef aParentRoot = aParentTree->getRootNode();
306 if (NodeElement* pParentRootElement = makeElement(aParentTree,aParentRoot) )
308 aParentRelease = uno::Reference<uno::XInterface>(pParentRootElement->getUnoInstance(), uno::UNO_REF_NO_ACQUIRE);
309 pParentContext = &getImplementation(*pParentRootElement);
313 SetElement * pResult = 0;
314 if (implIsReadOnly(aTree,aTree->getRootNode()))
316 if (!pSetElementTemplate)
318 OSetElementGroupInfo * pNewObject = new OSetElementGroupInfo(aTree,m_rProvider,pParentContext);
319 pNewObject->acquire();
320 pResult = &pNewObject->getElementClass();
322 else
324 OSetElementSetInfo * pNewObject = new OSetElementSetInfo(aTree,m_rProvider,pParentContext);
325 pNewObject->acquire();
326 pResult = &pNewObject->getElementClass();
329 else
331 if (!pSetElementTemplate)
333 OSetElementGroupUpdate * pNewObject = new OSetElementGroupUpdate(aTree,m_rProvider,pParentContext);
334 pNewObject->acquire();
335 pResult = &pNewObject->getElementClass();
337 else if (pSetElementTemplate->isInstanceValue())
339 OSetElementValueSetUpdate * pNewObject = new OSetElementValueSetUpdate(aTree,m_rProvider,pParentContext);
340 pNewObject->acquire();
341 pResult = &pNewObject->getElementClass();
343 else
345 OSetElementTreeSetUpdate * pNewObject = new OSetElementTreeSetUpdate(aTree,m_rProvider,pParentContext);
346 pNewObject->acquire();
347 pResult = &pNewObject->getElementClass();
350 return pResult;
352 //-----------------------------------------------------------------------------