KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > template > QNameAwareObjectWrapper


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.repo.template;
18
19 import java.util.Map JavaDoc;
20
21 import org.alfresco.service.namespace.QNameMap;
22
23 import freemarker.template.DefaultObjectWrapper;
24 import freemarker.template.ObjectWrapper;
25 import freemarker.template.SimpleHash;
26 import freemarker.template.TemplateModel;
27 import freemarker.template.TemplateModelException;
28
29 /**
30  * @author Kevin Roast
31  */

32 public class QNameAwareObjectWrapper extends DefaultObjectWrapper
33 {
34     /**
35      * Override to support wrapping of a QNameNodeMap by our custom wrapper object
36      */

37     public TemplateModel wrap(Object JavaDoc obj) throws TemplateModelException
38     {
39         if (obj instanceof QNameMap)
40         {
41             return new QNameHash((QNameMap)obj, this);
42         }
43         else
44         {
45             return super.wrap(obj);
46         }
47     }
48     
49     
50     /**
51      * Inner class to support clone of QNameNodeMap
52      */

53     class QNameHash extends SimpleHash
54     {
55         /**
56          * Constructor
57          *
58          * @param map
59          * @param wrapper
60          */

61         public QNameHash(QNameMap map, ObjectWrapper wrapper)
62         {
63             super(map, wrapper);
64         }
65         
66         /**
67          * Override to support clone of a QNameNodeMap object
68          */

69         protected Map JavaDoc copyMap(Map JavaDoc map)
70         {
71             if (map instanceof QNameMap)
72             {
73                 return (Map JavaDoc)((QNameMap)map).clone();
74             }
75             else
76             {
77                 return super.copyMap(map);
78             }
79         }
80     }
81 }
82
Popular Tags