Source Code Cross Referenced for SwingMLModelToContainerRegistry.java in  » XML-UI » SwingML » org » swingml » registry » 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 » XML UI » SwingML » org.swingml.registry 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.swingml.registry;
002:
003:        import java.awt.*;
004:        import java.util.*;
005:        import java.util.List;
006:
007:        import org.swingml.*;
008:        import org.swingml.system.*;
009:
010:        /**
011:         * This registry is used to register AbstractSwingMLModels to the Containers
012:         * they represent.
013:         * 
014:         * @author CrossLogic
015:         */
016:        public class SwingMLModelToContainerRegistry {
017:
018:            private static Map guidRegistry = new HashMap();
019:            private static Map modelKeyToGuidMap = new HashMap();
020:            private static long nextGuid = Long.MIN_VALUE;
021:
022:            /**
023:             * generate a key from the given model
024:             * 
025:             * @param model
026:             * @return
027:             */
028:            private static String generateKey(AbstractSwingMLModel model) {
029:                String result = null;
030:                if (model != null) {
031:                    result = generateKey(model.getName(), model.getId());
032:                }
033:                return result;
034:            }
035:
036:            private static String generateKey(String name, String id) {
037:                String result = null;
038:                if (name != null) {
039:                    result = name;
040:                    if (id != null) {
041:                        result += "::" + id;
042:                    }
043:                }
044:                return result;
045:            }
046:
047:            /**
048:             * Return the registered Container for the given name.
049:             * 
050:             * @param model
051:             * @return
052:             */
053:            public static Container getContainer(String name) {
054:                return getContainer(name, null);
055:            }
056:
057:            /**
058:             * Return the registered Container for the given name.
059:             * 
060:             * @param model
061:             * @return
062:             */
063:            public static Container getContainer(String name, String id) {
064:                Container result = null;
065:                synchronized (getModelKeyToGuidMap()) {
066:                    String modelKey = generateKey(name, id);
067:                    if (modelKey != null) {
068:                        List guidList = (List) getModelKeyToGuidMap().get(
069:                                modelKey);
070:                        if (guidList != null && !guidList.isEmpty()) {
071:                            Long guid = (Long) guidList
072:                                    .get(guidList.size() - 1);
073:                            AbstractSwingMLModel model = (AbstractSwingMLModel) getGuidRegistry()
074:                                    .get(guid);
075:                            if (model != null) {
076:                                result = model.getContainer();
077:                            }
078:                        }
079:                    }
080:                }
081:                return result;
082:            }
083:
084:            /**
085:             * Return the guid for the given value. Null, otherwise.
086:             * 
087:             * @param value
088:             * @return
089:             */
090:            private static Long getGuid(Container container) {
091:                Long result = null;
092:                synchronized (getGuidRegistry()) {
093:                    try {
094:                        Iterator schmiterator = getGuidRegistry().keySet()
095:                                .iterator();
096:                        while (schmiterator.hasNext()) {
097:                            Long guid = (Long) schmiterator.next();
098:                            AbstractSwingMLModel model = (AbstractSwingMLModel) getGuidRegistry()
099:                                    .get(guid);
100:                            if (model.getContainer() != null
101:                                    && model.getContainer().equals(container)) {
102:                                result = guid;
103:                                break;
104:                            }
105:                        }
106:                    } catch (Exception e) {
107:                        e.printStackTrace();
108:                    }
109:                }
110:                return result;
111:            }
112:
113:            private static Map getGuidRegistry() {
114:                return guidRegistry;
115:            }
116:
117:            /**
118:             * Return the registered AbstractSwingMLModel for the given container.
119:             * 
120:             * @param container
121:             * @return
122:             */
123:            public static AbstractSwingMLModel getModel(Container container) {
124:                AbstractSwingMLModel result = null;
125:                synchronized (getGuidRegistry()) {
126:                    Long guid = getGuid(container);
127:                    if (guid != null) {
128:                        try {
129:                            result = (AbstractSwingMLModel) getGuidRegistry()
130:                                    .get(guid);
131:                        } catch (Exception e) {
132:                            SwingMLLogger
133:                                    .getInstance()
134:                                    .log(ILogCapable.ERROR,
135:                                            "Invalid SwingMLModel registered with a container.");
136:                            SwingMLLogger.getInstance().log(ILogCapable.ERROR,
137:                                    e);
138:                        }
139:                    }
140:                }
141:                return result;
142:            }
143:
144:            /**
145:             * Return the registered AbstractSwingMLModel for the given container.
146:             * 
147:             * @param container
148:             * @return
149:             */
150:            public static AbstractSwingMLModel getModel(String containerName) {
151:                return getModel(containerName, null);
152:            }
153:
154:            /**
155:             * Return the registered AbstractSwingMLModel for the given container.
156:             * 
157:             * @param container
158:             * @return
159:             */
160:            public static AbstractSwingMLModel getModel(String containerName,
161:                    String id) {
162:                AbstractSwingMLModel result = null;
163:                Container container = getContainer(generateKey(containerName,
164:                        id));
165:                if (container != null) {
166:                    result = getModel(container);
167:                }
168:                return result;
169:            }
170:
171:            public static Map getModelKeyToGuidMap() {
172:                return modelKeyToGuidMap;
173:            }
174:
175:            private static Long getNextGuid() {
176:                if (nextGuid == Long.MAX_VALUE) {
177:                    nextGuid = Long.MIN_VALUE;
178:                }
179:                return new Long(nextGuid++);
180:            }
181:
182:            public static long getRegistryCount() {
183:                long result = -1;
184:                synchronized (getGuidRegistry()) {
185:                    result = getGuidRegistry().size();
186:                }
187:                return result;
188:            }
189:
190:            /**
191:             * Register the given model with the given Container.
192:             * 
193:             * @param model
194:             * @param container
195:             */
196:            public static void register(AbstractSwingMLModel model) {
197:                synchronized (getGuidRegistry()) {
198:                    if (model.getName() != null && model.getName().length() > 0) {
199:                        Long guid = model.getGuid();
200:                        if (guid == null) {
201:                            guid = getNextGuid();
202:                            model.setGuid(guid);
203:                        }
204:                        if (!getGuidRegistry().containsKey(guid)) {
205:                            getGuidRegistry().put(guid, model);
206:                            String modelKey = generateKey(model);
207:                            if (modelKey != null) {
208:                                List guidList = (List) getModelKeyToGuidMap()
209:                                        .get(modelKey);
210:                                if (guidList == null) {
211:                                    guidList = new ArrayList();
212:                                }
213:                                guidList.add(guid);
214:                                getModelKeyToGuidMap().put(modelKey, guidList);
215:                            }
216:                        }
217:                    }
218:                }
219:            }
220:
221:            /**
222:             * Remove the registration of the given AbstractSwingMLModel from the
223:             * registry.
224:             * 
225:             * @param model
226:             */
227:            public static void unregister(AbstractSwingMLModel model) {
228:                synchronized (getGuidRegistry()) {
229:                    Long guid = model.getGuid();
230:                    if (guid != null) {
231:
232:                        getGuidRegistry().remove(guid);
233:                        String modelKey = generateKey(model);
234:                        List guidList = (List) getModelKeyToGuidMap().get(
235:                                modelKey);
236:                        guidList.remove(guid);
237:                        if (guidList.isEmpty()) {
238:                            getModelKeyToGuidMap().remove(modelKey);
239:                        }
240:                    }
241:                }
242:            }
243:
244:            /**
245:             * Remove the registration of the given Container from the registry.
246:             * 
247:             * @param model
248:             */
249:            public static void unregister(Container container) {
250:                AbstractSwingMLModel model = getModel(container);
251:                if (model != null) {
252:                    unregister(model);
253:                }
254:            }
255:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.