Source Code Cross Referenced for GenericCompositeGroup.java in  » Code-Analyzer » beautyJ » de » gulden » framework » amoda » generic » data » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Code Analyzer » beautyJ » de.gulden.framework.amoda.generic.data 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Project: AMODA - Abstract Modeled Application
003:         * Class:   de.gulden.framework.amoda.generic.data.GenericCompositeGroup
004:         * Version: snapshot-beautyj-1.1
005:         *
006:         * Date:    2004-09-29
007:         *
008:         * This is a snapshot version of the AMODA 0.2 development branch,
009:         * it is not released as a seperate version.
010:         * For AMODA, see http://amoda.berlios.de/.
011:         *  
012:         * This is licensed under the GNU Lesser General Public License (LGPL)
013:         * and comes with NO WARRANTY.
014:         *
015:         * Author:  Jens Gulden
016:         * Email:   amoda@jensgulden.de
017:         */
018:
019:        package de.gulden.framework.amoda.generic.data;
020:
021:        import de.gulden.framework.amoda.generic.behaviour.*;
022:        import de.gulden.framework.amoda.generic.core.GenericApplicationMemberAbstract;
023:        import de.gulden.framework.amoda.model.data.*;
024:        import de.gulden.framework.amoda.model.data.CompositeGroup;
025:        import java.lang.*;
026:        import java.util.*;
027:
028:        /**
029:         * Class GenericCompositeGroup.
030:         *  
031:         * @author  Jens Gulden
032:         * @version  snapshot-beautyj-1.1
033:         */
034:        public class GenericCompositeGroup extends
035:                GenericApplicationMemberAbstract implements  CompositeGroup {
036:
037:            // ------------------------------------------------------------------------
038:            // --- field                                                            ---
039:            // ------------------------------------------------------------------------
040:
041:            public Map all = new de.gulden.util.OrderedHashMap();
042:
043:            // ------------------------------------------------------------------------
044:            // --- methods                                                          ---
045:            // ------------------------------------------------------------------------
046:
047:            public void add(CompositeMember member) {
048:                member.setParent(this );
049:                all.put(member.getId(), member);
050:            }
051:
052:            public void clear() {
053:                for (Iterator it = all.values().iterator(); it.hasNext();) {
054:                    CompositeMember m = (CompositeMember) it.next();
055:                    m.setParent(null);
056:                }
057:                all.clear();
058:            }
059:
060:            public CompositeMember get(String id) {
061:                CompositeMember result = get(id, true);
062:                if (result == null) {
063:                    if (id.indexOf('.') != -1) {
064:                        result = getAbsolute(id);
065:                    }
066:                }
067:                return result;
068:            }
069:
070:            public CompositeMember get(String id, boolean deep) {
071:                CompositeMember m = (CompositeMember) getAll().get(id); // NO Direct access on all to allow overwriting getAll()
072:                if ((m == null) && (deep)) {
073:                    for (Iterator it = getGroups().values().iterator(); it
074:                            .hasNext();) {
075:                        CompositeGroup g = (CompositeGroup) it.next();
076:                        m = g.get(id, true);
077:                        if (m != null) {
078:                            return m;
079:                        }
080:                    }
081:                }
082:                return m;
083:            }
084:
085:            public Map getAll(Class type, boolean deep) {
086:                // type may be null
087:                de.gulden.util.OrderedHashMap all = (de.gulden.util.OrderedHashMap) getAll(); // don't use this.all, as getAll might be re-implemented
088:                Map map = (Map) all.clone();
089:                if (type != null) {
090:                    for (Iterator it = all.values().iterator(); it.hasNext();) {
091:                        Object o = it.next();
092:                        if (!type.isAssignableFrom(o.getClass())) {
093:                            map.remove(((CompositeMember) o).getId());
094:                        }
095:                    }
096:                }
097:                if (deep) {
098:                    Map groups = getGroups();
099:                    for (Iterator it = groups.values().iterator(); it.hasNext();) {
100:                        CompositeGroup g = (CompositeGroup) it.next();
101:                        map.putAll(g.getAll(type, true));
102:                    }
103:                }
104:                return map;
105:            }
106:
107:            public Map getEntries() {
108:                Map map = (Map) ((de.gulden.util.OrderedHashMap) all).clone();
109:                for (Iterator it = all.values().iterator(); it.hasNext();) {
110:                    Object o = it.next();
111:                    if (o instanceof  CompositeGroup) {
112:                        map.remove(((CompositeMember) o).getId());
113:                    }
114:                }
115:                return map;
116:            }
117:
118:            public Map getGroups() {
119:                Map map = (Map) ((de.gulden.util.OrderedHashMap) all).clone();
120:                for (Iterator it = all.values().iterator(); it.hasNext();) {
121:                    Object o = it.next();
122:                    if (!(o instanceof  CompositeGroup)) {
123:                        map.remove(((CompositeMember) o).getId());
124:                    }
125:                }
126:                return map;
127:            }
128:
129:            public Map getAll() {
130:                return all;
131:            }
132:
133:            public void setAll(Map _all) {
134:                clear();
135:                addAll(_all.values());
136:            }
137:
138:            public void addAll(Collection members) {
139:                for (Iterator it = members.iterator(); it.hasNext();) {
140:                    CompositeMember member = (CompositeMember) it.next();
141:                    this .add(member);
142:                }
143:            }
144:
145:            public int countMaxDepth() {
146:                de.gulden.framework.amoda.generic.behaviour.GenericCondition cond = new de.gulden.framework.amoda.generic.behaviour.GenericCondition() {
147:                    public boolean test() {
148:                        return true;
149:                    }
150:                };
151:                return countMaxDepth(cond);
152:            }
153:
154:            public int countMaxDepth(GenericCondition cond) {
155:                int depth = 0;
156:                Map subGroups = getGroups();
157:                for (Iterator it = subGroups.values().iterator(); it.hasNext();) {
158:                    GenericCompositeGroup g = (GenericCompositeGroup) it.next();
159:                    if (cond.test(g)) {
160:                        int gDepth = g.countMaxDepth(cond);
161:                        if ((gDepth > 0) && ((gDepth + 1) > depth)) {
162:                            depth = gDepth + 1;
163:                        }
164:                    }
165:                }
166:                if (depth == 0) { // no groups, or only empty ones
167:                    Map m = getEntries();
168:                    for (Iterator it = m.values().iterator(); (depth == 0)
169:                            && it.hasNext();) {
170:                        if (cond.test(it.next())) {
171:                            depth = 1; // set to 1 constantly to indicate that this group has art leaat one element
172:                        }
173:                    }
174:                }
175:                return depth;
176:            }
177:
178:            protected CompositeMember getAbsolute(String id) {
179:                StringTokenizer st = new StringTokenizer(id, ".", false);
180:                String tok = st.nextToken();
181:                CompositeGroup g = this ;
182:                while (st.hasMoreTokens()) { // not last entry yet: group name
183:                    Object member = g.get(tok, false);
184:                    if (member instanceof  CompositeGroup) {
185:                        g = (CompositeGroup) member; // drill into child group
186:                    } else { // also covers case member==null
187:                        return null;
188:                    }
189:                    tok = st.nextToken();
190:                }
191:                return g.get(tok);
192:            }
193:
194:        } // end GenericCompositeGroup
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.