KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > explorer > resolver > lib > PanelResolver


1 /*====================================================================
2
3 Objectweb Explorer Framework
4 Copyright (C) 2000-2004 INRIA - USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Jerome Moroy, Philippe Merle.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26 package org.objectweb.util.explorer.resolver.lib;
27
28 import org.objectweb.util.explorer.api.Entry;
29 import org.objectweb.util.explorer.core.common.api.BadParamException;
30 import org.objectweb.util.explorer.core.common.api.Description;
31 import org.objectweb.util.explorer.core.common.api.ExplorerConstants;
32 import org.objectweb.util.explorer.core.common.lib.ClassesInheritance;
33 import org.objectweb.util.explorer.core.panel.api.CompositePanelDescription;
34 import org.objectweb.util.explorer.core.panel.api.PanelDescription;
35 import org.objectweb.util.explorer.core.panel.lib.BasicCompositePanelDescription;
36
37 /**
38  *
39  *
40  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jérôme Moroy</a>,
41  * <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>.
42  *
43  * @version 0.1
44  */

45 public class PanelResolver
46      extends AbstractPropertyResolver
47 {
48
49     //==================================================================
50
//
51
// Internal States.
52
//
53
// ==================================================================
54

55     // ==================================================================
56
//
57
// Constructors.
58
//
59
// ==================================================================
60

61     // ==================================================================
62
//
63
// Internal methods.
64
//
65
// ==================================================================
66

67     /* (non-Javadoc)
68      * @see org.objectweb.util.explorer.resolver.lib.AbstractPropertyResolver#getPropertyType()
69      */

70     protected String JavaDoc getPropertyType() {
71         return ExplorerConstants.PANEL_PROPERTY;
72     }
73
74     /**
75      * Tries to find a panel description for the given key.
76      * @param key The storage key
77      * @return The associated description (or null if no description is found).
78      */

79     protected PanelDescription getPanelDesc(Object JavaDoc key){
80         return (PanelDescription)getPropertyProvider().getPropertyDescription(getPropertyType(), key);
81     }
82     
83     /**
84      * Provides a panel for the given entry
85      * @param entry The entry for which a panel needs to be computed.
86      * @return The associated panel description.
87      */

88     protected Description getPanelDescription(Entry currentEntry){
89         CompositePanelDescription desc = null;
90         if(currentEntry!=null && currentEntry.getValue()!=null){
91             Class JavaDoc[] javaTypes = ClassesInheritance.getInheritedClasses(currentEntry.getValue().getClass());
92             String JavaDoc[] roleIds = getRoleProvider().getInheritedRoleIds(getRoleManager().getCurrentRoleIds());
93             for (int i = 0; i < javaTypes.length; i++) {
94                 for (int j = 0; j < roleIds.length; j++) {
95                     Object JavaDoc key = null;
96                     try {
97                         key = getKeyProvider().computeKey(new String JavaDoc[]{getTypeSystemId(),javaTypes[i].getName(),roleIds[j]});
98                     } catch (BadParamException e) {
99                         getTrace().warn("Bad key param: " + e.getMessage());
100                     }
101                     if(key!=null){
102                         PanelDescription newPanelDesc = getPanelDesc(key);
103                         if(newPanelDesc!=null){
104                             if(desc==null){
105                                 desc = new BasicCompositePanelDescription();
106                             }
107                             desc.addPanelDescription(newPanelDesc);
108                         }
109                         if(newPanelDesc!=null) break;
110                     }
111                 }
112                 if(desc!=null && !desc.inheritTypePanel()) break;
113             }
114         }
115         return desc;
116     }
117     
118     // ==================================================================
119
//
120
// Public methods for PropertyResolver interface.
121
//
122
// ==================================================================
123

124     /* (non-Javadoc)
125      * @see org.objectweb.util.explorer.resolver.api.PropertyResolver#resolve(java.lang.String, org.objectweb.util.explorer.api.Entry, org.objectweb.util.explorer.api.Entry)
126      */

127     public Description resolve(String JavaDoc propertyType, Entry currentEntry, Entry parentEntry) {
128         return getPanelDescription(currentEntry);
129     }
130
131 }
132
133
134
Popular Tags