1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_forms.hxx"
30 
31 #include "FormsCollection.hxx"
32 #include "services.hxx"
33 #include <comphelper/sequence.hxx>
34 #include <tools/debug.hxx>
35 #include <com/sun/star/form/XForm.hpp>
36 #include <rtl/logfile.hxx>
37 
38 //.........................................................................
39 namespace frm
40 {
41 //.........................................................................
42 using namespace ::com::sun::star::lang;
43 using namespace ::com::sun::star::uno;
44 using namespace ::com::sun::star::form;
45 using namespace ::com::sun::star::container;
46 using namespace ::com::sun::star::util;
47 
48 //------------------------------------------------------------------
49 DBG_NAME(OFormsCollection)
50 //------------------------------------------------------------------
51 InterfaceRef SAL_CALL OFormsCollection_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
52 {
53 	return *(new OFormsCollection(_rxFactory));
54 }
55 
56 //------------------------------------------------------------------------------
57 ::rtl::OUString SAL_CALL OFormsCollection::getServiceName() throw(RuntimeException)
58 {
59 	return FRM_SUN_FORMS_COLLECTION;
60 }
61 
62 //------------------------------------------------------------------------------
63 Sequence< sal_Int8 > SAL_CALL OFormsCollection::getImplementationId(  ) throw(RuntimeException)
64 {
65 	return OImplementationIds::getImplementationId(getTypes());
66 }
67 
68 //------------------------------------------------------------------------------
69 Sequence<Type> SAL_CALL OFormsCollection::getTypes() throw(RuntimeException)
70 {
71 	return concatSequences(OInterfaceContainer::getTypes(), FormsCollectionComponentBase::getTypes(), OFormsCollection_BASE::getTypes());
72 }
73 
74 //------------------------------------------------------------------
75 OFormsCollection::OFormsCollection(const Reference<XMultiServiceFactory>& _rxFactory)
76     :FormsCollectionComponentBase( m_aMutex )
77     ,OInterfaceContainer( _rxFactory, m_aMutex, XForm::static_type() )
78     ,OFormsCollection_BASE()
79 {
80 	DBG_CTOR(OFormsCollection, NULL);
81 }
82 
83 //------------------------------------------------------------------------------
84 OFormsCollection::OFormsCollection( const OFormsCollection& _cloneSource )
85     :FormsCollectionComponentBase( m_aMutex )
86     ,OInterfaceContainer( m_aMutex, _cloneSource )
87     ,OFormsCollection_BASE()
88 {
89 	DBG_CTOR( OFormsCollection, NULL );
90 }
91 
92 //------------------------------------------------------------------------------
93 OFormsCollection::~OFormsCollection()
94 {
95 	DBG_DTOR(OFormsCollection, NULL);
96 	if (!FormsCollectionComponentBase::rBHelper.bDisposed)
97 	{
98 		acquire();
99 		dispose();
100 	}
101 }
102 
103 //------------------------------------------------------------------------------
104 Any SAL_CALL OFormsCollection::queryAggregation(const Type& _rType) throw(RuntimeException)
105 {
106 	Any aReturn = OFormsCollection_BASE::queryInterface(_rType);
107 	if (!aReturn.hasValue())
108 	{
109 		aReturn = OInterfaceContainer::queryInterface(_rType);
110 
111 		if (!aReturn.hasValue())
112 			aReturn = FormsCollectionComponentBase::queryAggregation(_rType);
113 	}
114 
115 	return aReturn;
116 }
117 
118 //------------------------------------------------------------------------------
119 ::rtl::OUString SAL_CALL OFormsCollection::getImplementationName() throw(RuntimeException)
120 {
121 	return ::rtl::OUString::createFromAscii("com.sun.star.comp.forms.OFormsCollection");
122 }
123 
124 //------------------------------------------------------------------------------
125 sal_Bool SAL_CALL OFormsCollection::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException)
126 {
127 	Sequence<rtl::OUString> aSupported = getSupportedServiceNames();
128 	const rtl::OUString* pSupported = aSupported.getConstArray();
129 	for (sal_Int32 i=0; i<aSupported.getLength(); ++i, ++pSupported)
130 		if (pSupported->equals(_rServiceName))
131 			return sal_True;
132 	return sal_False;
133 }
134 
135 //------------------------------------------------------------------------------
136 StringSequence SAL_CALL OFormsCollection::getSupportedServiceNames() throw(RuntimeException)
137 {
138 	StringSequence aReturn(2);
139 
140 	aReturn.getArray()[0] = FRM_SUN_FORMS_COLLECTION;
141 	aReturn.getArray()[1] = ::rtl::OUString::createFromAscii("com.sun.star.form.FormComponents");
142 
143 	return aReturn;
144 }
145 
146 // XCloneable
147 //------------------------------------------------------------------------------
148 Reference< XCloneable > SAL_CALL OFormsCollection::createClone(  ) throw (RuntimeException)
149 {
150     OFormsCollection* pClone = new OFormsCollection( *this );
151     osl_incrementInterlockedCount( &pClone->m_refCount );
152     pClone->clonedFrom( *this );
153     osl_decrementInterlockedCount( &pClone->m_refCount );
154     return pClone;
155 }
156 
157 // OComponentHelper
158 //------------------------------------------------------------------------------
159 void OFormsCollection::disposing()
160 {
161 	{
162 		RTL_LOGFILE_CONTEXT( aLogger, "forms::OFormsCollection::disposing" );
163 		OInterfaceContainer::disposing();
164 	}
165 	FormsCollectionComponentBase::disposing();
166 	m_xParent = NULL;
167 }
168 
169 //XChild
170 //------------------------------------------------------------------------------
171 void OFormsCollection::setParent(const InterfaceRef& Parent) throw( NoSupportException, RuntimeException )
172 {
173 	::osl::MutexGuard aGuard( m_aMutex );
174 	m_xParent = Parent;
175 }
176 
177 //------------------------------------------------------------------------------
178 InterfaceRef  OFormsCollection::getParent() throw( RuntimeException )
179 {
180 	return m_xParent;
181 }
182 
183 //.........................................................................
184 }	// namespace frm
185 //.........................................................................
186 
187