Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include "datatyperepository.hxx"
22 : #include "datatypes.hxx"
23 : #include "frm_resource.hrc"
24 : #include "frm_resource.hxx"
25 : #include "frm_strings.hxx"
26 : #include "property.hrc"
27 :
28 : #include <tools/debug.hxx>
29 : #include <comphelper/enumhelper.hxx>
30 :
31 : #include <functional>
32 : #include <algorithm>
33 : #include <o3tl/compat_functional.hxx>
34 :
35 : //........................................................................
36 : namespace xforms
37 : {
38 : //........................................................................
39 :
40 : using ::com::sun::star::uno::Reference;
41 : using ::com::sun::star::uno::RuntimeException;
42 : using ::com::sun::star::uno::Any;
43 : using ::com::sun::star::uno::Type;
44 : using ::com::sun::star::uno::makeAny;
45 : using ::com::sun::star::uno::Sequence;
46 : using ::com::sun::star::util::VetoException;
47 : using ::com::sun::star::container::NoSuchElementException;
48 : using ::com::sun::star::container::ElementExistException;
49 : using ::com::sun::star::container::XEnumeration;
50 : using ::com::sun::star::lang::WrappedTargetException;
51 : using ::com::sun::star::xsd::XDataType;
52 : using namespace frm;
53 :
54 : //====================================================================
55 : //= ODataTypeRepository
56 : //====================================================================
57 : DBG_NAME( ODataTypeRepository )
58 : //--------------------------------------------------------------------
59 0 : ODataTypeRepository::ODataTypeRepository( )
60 : {
61 : DBG_CTOR( ODataTypeRepository, NULL );
62 :
63 : // insert some basic types
64 0 : ::rtl::OUString sName( FRM_RES_STRING( RID_STR_DATATYPE_STRING ) );
65 0 : m_aRepository[ sName ] = new OStringType( sName, ::com::sun::star::xsd::DataTypeClass::STRING );
66 :
67 0 : sName = FRM_RES_STRING( RID_STR_DATATYPE_URL );
68 0 : m_aRepository[ sName ] = new OStringType( sName, ::com::sun::star::xsd::DataTypeClass::anyURI );
69 :
70 0 : sName = FRM_RES_STRING( RID_STR_DATATYPE_BOOLEAN );
71 0 : m_aRepository[ sName ] = new OBooleanType( sName );
72 :
73 0 : sName = FRM_RES_STRING( RID_STR_DATATYPE_DECIMAL );
74 0 : m_aRepository[ sName ] = new ODecimalType( sName, ::com::sun::star::xsd::DataTypeClass::DECIMAL );
75 :
76 0 : sName = FRM_RES_STRING( RID_STR_DATATYPE_FLOAT );
77 0 : m_aRepository[ sName ] = new ODecimalType( sName, ::com::sun::star::xsd::DataTypeClass::FLOAT );
78 :
79 0 : sName = FRM_RES_STRING( RID_STR_DATATYPE_DOUBLE );
80 0 : m_aRepository[ sName ] = new ODecimalType( sName, ::com::sun::star::xsd::DataTypeClass::DOUBLE );
81 :
82 0 : sName = FRM_RES_STRING( RID_STR_DATATYPE_DATE );
83 0 : m_aRepository[ sName ] = new ODateType( sName );
84 :
85 0 : sName = FRM_RES_STRING( RID_STR_DATATYPE_TIME );
86 0 : m_aRepository[ sName ] = new OTimeType( sName );
87 :
88 0 : sName = FRM_RES_STRING( RID_STR_DATATYPE_DATETIME );
89 0 : m_aRepository[ sName ] = new ODateTimeType( sName );
90 :
91 0 : sName = FRM_RES_STRING( RID_STR_DATATYPE_YEAR );
92 0 : m_aRepository[ sName ] = new OShortIntegerType( sName, ::com::sun::star::xsd::DataTypeClass::gYear );
93 :
94 0 : sName = FRM_RES_STRING( RID_STR_DATATYPE_MONTH );
95 0 : m_aRepository[ sName ] = new OShortIntegerType( sName, ::com::sun::star::xsd::DataTypeClass::gMonth );
96 :
97 0 : sName = FRM_RES_STRING( RID_STR_DATATYPE_DAY );
98 0 : m_aRepository[ sName ] = new OShortIntegerType( sName, ::com::sun::star::xsd::DataTypeClass::gDay );
99 0 : }
100 :
101 : //--------------------------------------------------------------------
102 0 : ODataTypeRepository::~ODataTypeRepository( )
103 : {
104 : DBG_DTOR( ODataTypeRepository, NULL );
105 0 : }
106 :
107 : //--------------------------------------------------------------------
108 0 : ODataTypeRepository::Repository::iterator ODataTypeRepository::implLocate( const ::rtl::OUString& _rName, bool _bAllowMiss ) SAL_THROW( ( NoSuchElementException ) )
109 : {
110 0 : Repository::iterator aTypePos = m_aRepository.find( _rName );
111 0 : if ( aTypePos == m_aRepository.end() && !_bAllowMiss )
112 0 : throw NoSuchElementException( ::rtl::OUString(), *this );
113 :
114 0 : return aTypePos;
115 : }
116 :
117 : //--------------------------------------------------------------------
118 0 : Reference< XDataType > SAL_CALL ODataTypeRepository::getBasicDataType( sal_Int16 dataTypeClass ) throw (NoSuchElementException, RuntimeException)
119 : {
120 0 : Reference< XDataType > xReturn;
121 :
122 0 : for ( Repository::const_iterator lookup = m_aRepository.begin();
123 0 : ( lookup != m_aRepository.end() ) && ! xReturn.is();
124 : ++lookup
125 : )
126 : {
127 0 : if ( lookup->second->getIsBasic() && ( lookup->second->getTypeClass() == dataTypeClass ) )
128 0 : xReturn = lookup->second.get();
129 : }
130 :
131 0 : if ( !xReturn.is() )
132 0 : throw NoSuchElementException( ::rtl::OUString(), *this );
133 :
134 0 : return xReturn;
135 : }
136 :
137 : //--------------------------------------------------------------------
138 0 : Reference< XDataType > SAL_CALL ODataTypeRepository::cloneDataType( const ::rtl::OUString& sourceName, const ::rtl::OUString& newName ) throw (NoSuchElementException, ElementExistException, RuntimeException)
139 : {
140 0 : ::osl::MutexGuard aGuard( m_aMutex );
141 :
142 0 : Repository::iterator aTypePos = implLocate( newName, true );
143 0 : if ( aTypePos != m_aRepository.end() )
144 0 : throw ElementExistException( ::rtl::OUString(), *this );
145 :
146 0 : aTypePos = implLocate( sourceName );
147 0 : OXSDDataType* pClone = aTypePos->second->clone( newName );
148 0 : m_aRepository[ newName ] = pClone;
149 :
150 0 : return pClone;
151 : }
152 :
153 : //--------------------------------------------------------------------
154 0 : void SAL_CALL ODataTypeRepository::revokeDataType( const ::rtl::OUString& typeName ) throw (NoSuchElementException, VetoException, RuntimeException)
155 : {
156 0 : ::osl::MutexGuard aGuard( m_aMutex );
157 :
158 0 : Repository::iterator aTypePos = implLocate( typeName );
159 0 : if ( aTypePos->second->getIsBasic() )
160 0 : throw VetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "This is a built-in type and cannot be removed." ) ), *this );
161 : // TODO: localize this error message
162 :
163 0 : m_aRepository.erase( aTypePos );
164 0 : }
165 :
166 : //--------------------------------------------------------------------
167 0 : Reference< XDataType > SAL_CALL ODataTypeRepository::getDataType( const ::rtl::OUString& typeName ) throw (NoSuchElementException, RuntimeException)
168 : {
169 0 : ::osl::MutexGuard aGuard( m_aMutex );
170 0 : return implLocate( typeName, false )->second.get();
171 : }
172 :
173 :
174 : //--------------------------------------------------------------------
175 0 : Reference< XEnumeration > SAL_CALL ODataTypeRepository::createEnumeration( ) throw (RuntimeException)
176 : {
177 0 : return new ::comphelper::OEnumerationByName( this );
178 : }
179 :
180 : //--------------------------------------------------------------------
181 0 : Any SAL_CALL ODataTypeRepository::getByName( const ::rtl::OUString& aName ) throw (NoSuchElementException, WrappedTargetException, RuntimeException)
182 : {
183 0 : return makeAny( getDataType( aName ) );
184 : }
185 :
186 : //--------------------------------------------------------------------
187 0 : Sequence< ::rtl::OUString > SAL_CALL ODataTypeRepository::getElementNames( ) throw (RuntimeException)
188 : {
189 0 : ::osl::MutexGuard aGuard( m_aMutex );
190 :
191 0 : Sequence< ::rtl::OUString > aNames( m_aRepository.size() );
192 : ::std::transform(
193 : m_aRepository.begin(),
194 : m_aRepository.end(),
195 : aNames.getArray(),
196 : ::o3tl::select1st< Repository::value_type >()
197 0 : );
198 0 : return aNames;
199 : }
200 :
201 : //--------------------------------------------------------------------
202 0 : sal_Bool SAL_CALL ODataTypeRepository::hasByName( const ::rtl::OUString& aName ) throw (RuntimeException)
203 : {
204 0 : ::osl::MutexGuard aGuard( m_aMutex );
205 0 : return m_aRepository.find( aName ) != m_aRepository.end();
206 : }
207 :
208 : //--------------------------------------------------------------------
209 0 : Type SAL_CALL ODataTypeRepository::getElementType( ) throw (RuntimeException)
210 : {
211 0 : return ::getCppuType( static_cast< Reference< XDataType >* >( NULL ) );
212 : }
213 :
214 : //--------------------------------------------------------------------
215 0 : sal_Bool SAL_CALL ODataTypeRepository::hasElements( ) throw (RuntimeException)
216 : {
217 0 : return !m_aRepository.empty();
218 : }
219 :
220 : //--------------------------------------------------------------------
221 : // type specific implementation of registerProperties, using explicit
222 : // template instantiations
223 :
224 : template<>
225 0 : void OValueLimitedType<com::sun::star::util::Date>::registerProperties()
226 : {
227 0 : OValueLimitedType_Base::registerProperties();
228 :
229 0 : REGISTER_VOID_PROP( XSD_MAX_INCLUSIVE_DATE, m_aMaxInclusive, ValueType );
230 0 : REGISTER_VOID_PROP( XSD_MAX_EXCLUSIVE_DATE, m_aMaxExclusive, ValueType );
231 0 : REGISTER_VOID_PROP( XSD_MIN_INCLUSIVE_DATE, m_aMinInclusive, ValueType );
232 0 : REGISTER_VOID_PROP( XSD_MIN_EXCLUSIVE_DATE, m_aMinExclusive, ValueType );
233 0 : }
234 :
235 : template<>
236 0 : void OValueLimitedType<com::sun::star::util::Time>::registerProperties()
237 : {
238 0 : OValueLimitedType_Base::registerProperties();
239 :
240 0 : REGISTER_VOID_PROP( XSD_MAX_INCLUSIVE_TIME, m_aMaxInclusive, ValueType );
241 0 : REGISTER_VOID_PROP( XSD_MAX_EXCLUSIVE_TIME, m_aMaxExclusive, ValueType );
242 0 : REGISTER_VOID_PROP( XSD_MIN_INCLUSIVE_TIME, m_aMinInclusive, ValueType );
243 0 : REGISTER_VOID_PROP( XSD_MIN_EXCLUSIVE_TIME, m_aMinExclusive, ValueType );
244 0 : }
245 :
246 : template<>
247 0 : void OValueLimitedType<com::sun::star::util::DateTime>::registerProperties()
248 : {
249 0 : OValueLimitedType_Base::registerProperties();
250 :
251 0 : REGISTER_VOID_PROP( XSD_MAX_INCLUSIVE_DATE_TIME, m_aMaxInclusive, ValueType );
252 0 : REGISTER_VOID_PROP( XSD_MAX_EXCLUSIVE_DATE_TIME, m_aMaxExclusive, ValueType );
253 0 : REGISTER_VOID_PROP( XSD_MIN_INCLUSIVE_DATE_TIME, m_aMinInclusive, ValueType );
254 0 : REGISTER_VOID_PROP( XSD_MIN_EXCLUSIVE_DATE_TIME, m_aMinExclusive, ValueType );
255 0 : }
256 :
257 : template<>
258 0 : void OValueLimitedType<double>::registerProperties()
259 : {
260 0 : OValueLimitedType_Base::registerProperties();
261 :
262 0 : REGISTER_VOID_PROP( XSD_MAX_INCLUSIVE_DOUBLE, m_aMaxInclusive, ValueType );
263 0 : REGISTER_VOID_PROP( XSD_MAX_EXCLUSIVE_DOUBLE, m_aMaxExclusive, ValueType );
264 0 : REGISTER_VOID_PROP( XSD_MIN_INCLUSIVE_DOUBLE, m_aMinInclusive, ValueType );
265 0 : REGISTER_VOID_PROP( XSD_MIN_EXCLUSIVE_DOUBLE, m_aMinExclusive, ValueType );
266 0 : }
267 :
268 : template<>
269 0 : void OValueLimitedType<sal_Int16>::registerProperties()
270 : {
271 0 : OValueLimitedType_Base::registerProperties();
272 :
273 0 : REGISTER_VOID_PROP( XSD_MAX_INCLUSIVE_INT, m_aMaxInclusive, ValueType );
274 0 : REGISTER_VOID_PROP( XSD_MAX_EXCLUSIVE_INT, m_aMaxExclusive, ValueType );
275 0 : REGISTER_VOID_PROP( XSD_MIN_INCLUSIVE_INT, m_aMinInclusive, ValueType );
276 0 : REGISTER_VOID_PROP( XSD_MIN_EXCLUSIVE_INT, m_aMinExclusive, ValueType );
277 0 : }
278 : //........................................................................
279 : } // namespace xforms
280 : //........................................................................
281 :
282 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|