xref: /AOO41X/main/xmloff/inc/xmloff/prhdlfac.hxx (revision ecfe53c5d1886e1e0d215b0d140d05282ab1c477)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _XMLOFF_PROPERTYHANDLERFACTORY_HXX
25 #define _XMLOFF_PROPERTYHANDLERFACTORY_HXX
26 
27 #include "sal/config.h"
28 #include "xmloff/dllapi.h"
29 #include "sal/types.h"
30 
31 #ifndef __SGI_STL_MAP
32 #include <map>
33 #endif
34 #include <xmloff/uniref.hxx>
35 #include <xmloff/xmlprhdl.hxx>
36 
37 /**
38  This class is a base-class to create XMLPropertyHandler.
39  It creates PropertyHandler for given XML-types and store
40  them in an internal cache. They'll be deleted at destruction-
41  time.
42  For create your own PropertyHandler for specific XML-types
43  you have to override the virtual method GetPropertyHandler
44  ( see below ).
45 */
46 class XMLOFF_DLLPUBLIC XMLPropertyHandlerFactory : public UniRefBase
47 {
48 public:
49     virtual ~XMLPropertyHandlerFactory();
50 
51     /**
52     This method retrieves a PropertyHandler for the given XML-type.
53     To extend this method for more XML-types override this method
54     like the example below. If you call the method of the base-class
55     you get propertyhandler for basic-XML-types ( e.g. for color, percent, ... ).
56     Afetr that you could create your new XML-types. After creating a new type
57     you have to put the pointer into the cache via the method
58     PutHdlCache( sal_Int32 , XMLPropertyHandler* ).
59 
60     virtual const XMLPropertyHandler* GetPropertyHandler( sal_Int32 nType ) const
61     {
62         XMLPropertyHandler* pHdl = XMLPropertyHandlerFactory::GetPropertyHandler( nType );
63 
64         if( !pHdl )
65         {
66             switch( nType )
67             {
68                 case XML_TYPE_XYZ :
69                     pHdl = new XML_xyz_PropHdl;
70                     break;
71                 case ...
72                 :
73                 :
74             }
75 
76             if( pHdl )
77                 PutHdlCache( nType, pHdl );
78         }
79 
80         return pHdl;
81     }
82     */
83     virtual const XMLPropertyHandler* GetPropertyHandler( sal_Int32 nType ) const;
84 
85     /** helper method to statically create a property handler; this will not
86      *  use the handler cache. This method should only be called in special
87      *  circumstances; calling GetPropertyHandler is almost always
88      *  preferable. */
89     static const XMLPropertyHandler* CreatePropertyHandler( sal_Int32 nType );
90 
91 protected:
92     /** Retrieves a PropertyHandler from the internal cache */
93     XMLPropertyHandler* GetHdlCache( sal_Int32 nType ) const;
94     /** Puts a PropertyHandler into the internal cache */
95     void PutHdlCache( sal_Int32 nType, const XMLPropertyHandler* pHdl ) const;
96 
97 private:
98     /** Retrieves ( creates if necessary ) PropertyHandler for
99         basic XML-types */
100     SAL_DLLPRIVATE const XMLPropertyHandler* GetBasicHandler( sal_Int32 nType )
101         const;
102 
103     typedef ::std::map< sal_Int32, XMLPropertyHandler* > CacheMap;
104     CacheMap maHandlerCache;
105 };
106 
107 #endif  // _XMLOFF_PROPERTYHANDLERFACTORY_HXX
108