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 #ifndef EXTENSIONS_SOURCE_PROPCTRLR_XSDVALIDATIONHELPER_HXX
29 #define EXTENSIONS_SOURCE_PROPCTRLR_XSDVALIDATIONHELPER_HXX
30 
31 #include "eformshelper.hxx"
32 #include "xsddatatypes.hxx"
33 
34 /** === begin UNO includes === **/
35 #include <com/sun/star/xsd/XDataType.hpp>
36 #include <com/sun/star/beans/XPropertySet.hpp>
37 /** === end UNO includes === **/
38 #include <rtl/ref.hxx>
39 
40 //........................................................................
41 namespace pcr
42 {
43 //........................................................................
44 
45     class XSDDataType;
46 	//====================================================================
47 	//= XSDValidationHelper
48 	//====================================================================
49     class XSDValidationHelper : public EFormsHelper
50 	{
51     private:
52         bool    m_bInspectingFormattedField;
53     public:
54         bool    isInspectingFormattedField() const { return m_bInspectingFormattedField; }
55 
56     public:
57         XSDValidationHelper(
58             ::osl::Mutex& _rMutex,
59             const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxIntrospectee,
60             const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& _rxContextDocument
61         );
62 
63         /** retrieves the names of all XForms models in the document the control lives in
64         */
65         void    getAvailableDataTypeNames( ::std::vector< ::rtl::OUString >& /* [out] */ _rNames ) const SAL_THROW(());
66 
67         /** retrieves a particular data type given by name
68         */
69         ::rtl::Reference< XSDDataType >
70                 getDataTypeByName( const ::rtl::OUString& _rName ) const SAL_THROW(());
71 
72         /** retrieves the DataType instance which the control model is currently validated against
73 
74             If there is a binding set at our control model, which at the same time acts as validator,
75             and if this validator is bound to an XDataType, then this data type is retrieved here.
76         */
77         ::rtl::Reference< XSDDataType >
78                 getValidatingDataType( ) const SAL_THROW(());
79 
80         /** retrieves the name of the data type which the control model is currently validated against
81 
82             @seealso getValidatingDataType
83         */
84         ::rtl::OUString
85                 getValidatingDataTypeName( ) const SAL_THROW(());
86 
87         /** binds the validator to a new data type
88 
89             To be called with an active binding only.
90         */
91         void    setValidatingDataTypeByName( const ::rtl::OUString& _rName ) const SAL_THROW(());
92 
93         /** removes the data type given by name from the data type repository
94         */
95         bool    removeDataTypeFromRepository( const ::rtl::OUString& _rName ) const SAL_THROW(());
96 
97         /** creates a new data type, which is a clone of an existing data type
98         */
99         bool    cloneDataType( const ::rtl::Reference< XSDDataType >& _pDataType, const ::rtl::OUString& _rNewName ) const SAL_THROW(());
100 
101         /** retrieves the name of the basic data type which has the given class
102         */
103         ::rtl::OUString
104                 getBasicTypeNameForClass( sal_Int16 _eClass ) const SAL_THROW(());
105 
106         /** copy a data type from one model to another
107 
108             If a data type with the given name already exists in the target model, then nothing
109             happens. In particular, the facets of the data type are not copied.
110         */
111         void    copyDataType( const ::rtl::OUString& _rFromModel, const ::rtl::OUString& _rToModel,
112                     const ::rtl::OUString& _rDataTypeName ) const SAL_THROW(());
113 
114         /** finds (and sets) a default format for the formatted field we're inspecting,
115             according to the current data type the control value is evaluated against
116         */
117         void findDefaultFormatForIntrospectee() SAL_THROW(());
118 
119     private:
120         /** retrieves the data type repository associated with the current model
121         */
122         ::com::sun::star::uno::Reference< ::com::sun::star::xforms::XDataTypeRepository >
123                 getDataTypeRepository() const SAL_THROW((::com::sun::star::uno::Exception));
124 
125         /** retrieves the data type repository associated with any model
126         */
127         ::com::sun::star::uno::Reference< ::com::sun::star::xforms::XDataTypeRepository >
128                 getDataTypeRepository( const ::rtl::OUString& _rModelName ) const SAL_THROW((::com::sun::star::uno::Exception));
129 
130         /** retrieves the data type object for the given name
131         */
132         ::com::sun::star::uno::Reference< ::com::sun::star::xsd::XDataType >
133             getDataType( const ::rtl::OUString& _rName ) const
134                 SAL_THROW((::com::sun::star::uno::Exception));
135 
136         /** retrieves the name of the basic data type which has the given class, in the given repository
137         */
138         ::rtl::OUString
139                 getBasicTypeNameForClass(
140                     sal_Int16 _nClass,
141                     ::com::sun::star::uno::Reference< ::com::sun::star::xforms::XDataTypeRepository > _rxRepository
142                 ) const SAL_THROW(());
143 	};
144 
145 //........................................................................
146 } // namespace pcr
147 //........................................................................
148 
149 #endif // EXTENSIONS_SOURCE_PROPCTRLR_XSDVALIDATIONHELPER_HXX
150 
151