1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 #include "precompiled_configmgr.hxx"
29 #include "sal/config.h"
31 #include "com/sun/star/uno/Any.hxx"
32 #include "com/sun/star/uno/Reference.hxx"
33 #include "com/sun/star/uno/RuntimeException.hpp"
34 #include "com/sun/star/uno/Sequence.hxx"
35 #include "com/sun/star/uno/Type.hxx"
36 #include "com/sun/star/uno/TypeClass.hpp"
37 #include "com/sun/star/uno/XInterface.hpp"
38 #include "cppu/unotype.hxx"
39 #include "osl/diagnose.h"
40 #include "rtl/string.h"
41 #include "rtl/ustring.h"
42 #include "rtl/ustring.hxx"
43 #include "sal/types.h"
51 namespace css
= com::sun::star
;
55 bool isListType(Type type
) {
56 return type
>= TYPE_BOOLEAN_LIST
;
59 Type
elementType(Type type
) {
61 case TYPE_BOOLEAN_LIST
:
69 case TYPE_DOUBLE_LIST
:
71 case TYPE_STRING_LIST
:
73 case TYPE_HEXBINARY_LIST
:
74 return TYPE_HEXBINARY
;
77 throw css::uno::RuntimeException(
78 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("this cannot happen")),
79 css::uno::Reference
< css::uno::XInterface
>());
83 css::uno::Type
mapType(Type type
) {
86 return cppu::UnoType
< css::uno::Any
>::get();
88 return cppu::UnoType
< sal_Bool
>::get();
90 return cppu::UnoType
< sal_Int16
>::get();
92 return cppu::UnoType
< sal_Int32
>::get();
94 return cppu::UnoType
< sal_Int64
>::get();
96 return cppu::UnoType
< double >::get();
98 return cppu::UnoType
< rtl::OUString
>::get();
100 return cppu::UnoType
< css::uno::Sequence
< sal_Int8
> >::get();
101 case TYPE_BOOLEAN_LIST
:
102 return cppu::UnoType
< css::uno::Sequence
< sal_Bool
> >::get();
103 case TYPE_SHORT_LIST
:
104 return cppu::UnoType
< css::uno::Sequence
< sal_Int16
> >::get();
106 return cppu::UnoType
< css::uno::Sequence
< sal_Int32
> >::get();
108 return cppu::UnoType
< css::uno::Sequence
< sal_Int64
> >::get();
109 case TYPE_DOUBLE_LIST
:
110 return cppu::UnoType
< css::uno::Sequence
< double > >::get();
111 case TYPE_STRING_LIST
:
112 return cppu::UnoType
< css::uno::Sequence
< rtl::OUString
> >::get();
113 case TYPE_HEXBINARY_LIST
:
114 return cppu::UnoType
<
115 css::uno::Sequence
< css::uno::Sequence
< sal_Int8
> > >::get();
118 throw css::uno::RuntimeException(
119 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("this cannot happen")),
120 css::uno::Reference
< css::uno::XInterface
>());
124 Type
getDynamicType(css::uno::Any
const & value
) {
125 switch (value
.getValueType().getTypeClass()) {
126 case css::uno::TypeClass_VOID
:
128 case css::uno::TypeClass_BOOLEAN
:
130 case css::uno::TypeClass_BYTE
:
132 case css::uno::TypeClass_SHORT
:
134 case css::uno::TypeClass_UNSIGNED_SHORT
:
135 return value
.has
< sal_Int16
>() ? TYPE_SHORT
: TYPE_INT
;
136 case css::uno::TypeClass_LONG
:
138 case css::uno::TypeClass_UNSIGNED_LONG
:
139 return value
.has
< sal_Int32
>() ? TYPE_INT
: TYPE_LONG
;
140 case css::uno::TypeClass_HYPER
:
142 case css::uno::TypeClass_UNSIGNED_HYPER
:
143 return value
.has
< sal_Int64
>() ? TYPE_LONG
: TYPE_ERROR
;
144 case css::uno::TypeClass_FLOAT
:
145 case css::uno::TypeClass_DOUBLE
:
147 case css::uno::TypeClass_STRING
:
149 case css::uno::TypeClass_SEQUENCE
: //TODO
151 rtl::OUString
name(value
.getValueType().getTypeName());
152 if (name
.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("[]byte"))) {
153 return TYPE_HEXBINARY
;
154 } else if (name
.equalsAsciiL(
155 RTL_CONSTASCII_STRINGPARAM("[]boolean")))
157 return TYPE_BOOLEAN_LIST
;
158 } else if (name
.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("[]short")))
160 return TYPE_SHORT_LIST
;
161 } else if (name
.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("[]long")))
163 return TYPE_INT_LIST
;
164 } else if (name
.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("[]hyper")))
166 return TYPE_LONG_LIST
;
167 } else if (name
.equalsAsciiL(
168 RTL_CONSTASCII_STRINGPARAM("[]double")))
170 return TYPE_DOUBLE_LIST
;
171 } else if (name
.equalsAsciiL(
172 RTL_CONSTASCII_STRINGPARAM("[]string")))
174 return TYPE_STRING_LIST
;
175 } else if (name
.equalsAsciiL(
176 RTL_CONSTASCII_STRINGPARAM("[][]byte")))
178 return TYPE_HEXBINARY_LIST
;