Source Code Cross Referenced for ItsNatComponentManagerImpl.java in  » Ajax » ItsNat » org » itsnat » impl » comp » 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 » Ajax » ItsNat » org.itsnat.impl.comp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:          ItsNat Java Web Application Framework
003:          Copyright (C) 2007 Innowhere Software Services S.L., Spanish Company
004:          Author: Jose Maria Arranz Santamaria
005:
006:          This program is free software: you can redistribute it and/or modify
007:          it under the terms of the GNU Affero General Public License as published by
008:          the Free Software Foundation, either version 3 of the License, or
009:          (at your option) any later version. See the GNU Affero General Public 
010:          License for more details. See the copy of the GNU Affero General Public License
011:          included in this program. If not, see <http://www.gnu.org/licenses/>.
012:         */
013:
014:        package org.itsnat.impl.comp;
015:
016:        import java.lang.ref.WeakReference;
017:        import java.util.HashMap;
018:        import java.util.Iterator;
019:        import java.util.LinkedList;
020:        import java.util.Map;
021:        import java.util.WeakHashMap;
022:        import javax.swing.ButtonGroup;
023:        import org.itsnat.comp.ItsNatButtonGroup;
024:        import org.itsnat.comp.ItsNatComponent;
025:        import org.itsnat.comp.ItsNatComponentManager;
026:        import org.itsnat.comp.free.ItsNatFreeButtonNormal;
027:        import org.itsnat.comp.free.ItsNatFreeCheckBox;
028:        import org.itsnat.comp.free.ItsNatFreeComboBox;
029:        import org.itsnat.comp.free.ItsNatFreeInclude;
030:        import org.itsnat.comp.free.ItsNatFreeLabel;
031:        import org.itsnat.comp.free.ItsNatFreeListMultSel;
032:        import org.itsnat.comp.free.ItsNatFreeRadioButton;
033:        import org.itsnat.comp.free.ItsNatFreeTable;
034:        import org.itsnat.comp.free.ItsNatFreeTree;
035:        import org.itsnat.comp.ItsNatLabelRenderer;
036:        import org.itsnat.comp.ItsNatListCellRenderer;
037:        import org.itsnat.comp.ItsNatListStructure;
038:        import org.itsnat.comp.ItsNatTableCellRenderer;
039:        import org.itsnat.comp.ItsNatTableHeaderCellRenderer;
040:        import org.itsnat.comp.ItsNatTableStructure;
041:        import org.itsnat.comp.ItsNatTreeCellRenderer;
042:        import org.itsnat.comp.ItsNatTreeStructure;
043:        import org.itsnat.comp.CreateItsNatComponentListener;
044:        import org.itsnat.comp.free.ItsNatFreeButtonNormalLabel;
045:        import org.itsnat.comp.free.ItsNatFreeCheckBoxLabel;
046:        import org.itsnat.comp.free.ItsNatFreeRadioButtonLabel;
047:        import org.itsnat.core.ItsNatDOMException;
048:        import org.itsnat.core.ItsNatDocument;
049:        import org.itsnat.core.ItsNatException;
050:        import org.itsnat.core.NameValue;
051:        import org.itsnat.impl.comp.free.ItsNatFreeButtonNormalDefaultImpl;
052:        import org.itsnat.impl.comp.free.ItsNatFreeButtonNormalLabelImpl;
053:        import org.itsnat.impl.comp.free.factory.FactoryItsNatFreeButtonNormalDefaultImpl;
054:        import org.itsnat.impl.comp.free.factory.FactoryItsNatFreeCheckBoxDefaultImpl;
055:        import org.itsnat.impl.comp.free.factory.FactoryItsNatFreeComboBoxImpl;
056:        import org.itsnat.impl.comp.free.factory.FactoryItsNatFreeIncludeImpl;
057:        import org.itsnat.impl.comp.free.factory.FactoryItsNatFreeLabelImpl;
058:        import org.itsnat.impl.comp.free.factory.FactoryItsNatFreeListMultSelImpl;
059:        import org.itsnat.impl.comp.free.factory.FactoryItsNatFreeRadioButtonDefaultImpl;
060:        import org.itsnat.impl.comp.free.factory.FactoryItsNatFreeTableImpl;
061:        import org.itsnat.impl.comp.free.factory.FactoryItsNatFreeTreeImpl;
062:        import org.itsnat.impl.comp.free.ItsNatFreeCheckBoxDefaultImpl;
063:        import org.itsnat.impl.comp.free.ItsNatFreeCheckBoxLabelImpl;
064:        import org.itsnat.impl.comp.free.ItsNatFreeComboBoxImpl;
065:        import org.itsnat.impl.comp.free.ItsNatFreeIncludeImpl;
066:        import org.itsnat.impl.comp.free.ItsNatFreeLabelImpl;
067:        import org.itsnat.impl.comp.free.ItsNatFreeListMultSelImpl;
068:        import org.itsnat.impl.comp.free.ItsNatFreeRadioButtonDefaultImpl;
069:        import org.itsnat.impl.comp.free.ItsNatFreeRadioButtonLabelImpl;
070:        import org.itsnat.impl.comp.free.ItsNatFreeTableImpl;
071:        import org.itsnat.impl.comp.free.ItsNatFreeTreeImpl;
072:        import org.itsnat.impl.comp.free.factory.FactoryItsNatFreeButtonNormalLabelImpl;
073:        import org.itsnat.impl.comp.free.factory.FactoryItsNatFreeCheckBoxLabelImpl;
074:        import org.itsnat.impl.comp.free.factory.FactoryItsNatFreeRadioButtonLabelImpl;
075:        import org.itsnat.impl.core.DocumentTemplateImpl;
076:        import org.itsnat.impl.core.ItsNatDocumentImpl;
077:        import org.itsnat.impl.core.ItsNatServletImpl;
078:        import org.itsnat.impl.core.MarkupTemplateVersionImpl;
079:        import org.itsnat.impl.core.listener.AutoBuildCompMutationEventBeforeAfterListener;
080:        import org.itsnat.impl.core.listener.CleanListenersMutationEventBeforeAfterListener;
081:        import org.itsnat.impl.core.listener.MutationEventListenerImpl;
082:        import org.w3c.dom.Document;
083:        import org.w3c.dom.Element;
084:        import org.w3c.dom.Node;
085:
086:        /**
087:         *
088:         * @author jmarranz
089:         */
090:        public abstract class ItsNatComponentManagerImpl implements 
091:                ItsNatComponentManager {
092:            protected static final Map FACTORIES = new HashMap(); // No sincronizamos porque va a ser siempre usada en modo lectura
093:            static {
094:                addFactory(new FactoryItsNatFreeButtonNormalDefaultImpl());
095:                addFactory(new FactoryItsNatFreeButtonNormalLabelImpl());
096:                addFactory(new FactoryItsNatFreeCheckBoxDefaultImpl());
097:                addFactory(new FactoryItsNatFreeCheckBoxLabelImpl());
098:                addFactory(new FactoryItsNatFreeComboBoxImpl());
099:                addFactory(new FactoryItsNatFreeIncludeImpl());
100:                addFactory(new FactoryItsNatFreeLabelImpl());
101:                addFactory(new FactoryItsNatFreeListMultSelImpl());
102:                addFactory(new FactoryItsNatFreeRadioButtonDefaultImpl());
103:                addFactory(new FactoryItsNatFreeRadioButtonLabelImpl());
104:                addFactory(new FactoryItsNatFreeTableImpl());
105:                addFactory(new FactoryItsNatFreeTreeImpl());
106:            }
107:
108:            protected static void addFactory(FactoryItsNatComponentImpl factory) {
109:                FACTORIES.put(factory.getKey(), factory);
110:            }
111:
112:            protected static FactoryItsNatComponentImpl getFactory(
113:                    String compName) {
114:                return (FactoryItsNatComponentImpl) FACTORIES.get(compName);
115:            }
116:
117:            protected ItsNatDocumentImpl itsNatDoc;
118:            protected WeakHashMap buttonGroupsByName; // Un ItsNatButtonGroup necesita estar asociado a un radio button si ninguno lo referencia se puede perder, así evitamos memory leaks por recreación de radio buttons
119:            protected WeakHashMap buttonGroupsByButtonGroup; // " 
120:            protected Map components;
121:            protected Map excludedNodesAsComponents;
122:
123:            /** Creates a new instance of ItsNatComponentManagerImpl */
124:            public ItsNatComponentManagerImpl(ItsNatDocumentImpl itsNatDoc) {
125:                this .itsNatDoc = itsNatDoc;
126:            }
127:
128:            public ItsNatDocument getItsNatDocument() {
129:                return itsNatDoc;
130:            }
131:
132:            public ItsNatDocumentImpl getItsNatDocumentImpl() {
133:                return itsNatDoc;
134:            }
135:
136:            public Map getComponentMap() {
137:                if (components == null)
138:                    this .components = new HashMap();
139:                return components;
140:            }
141:
142:            public Map getExcludedNodesAsComponentsMap() {
143:                if (excludedNodesAsComponents == null)
144:                    this .excludedNodesAsComponents = new HashMap();
145:                return excludedNodesAsComponents;
146:            }
147:
148:            public WeakHashMap getButtonGroupsByNameMap() {
149:                if (buttonGroupsByName == null)
150:                    this .buttonGroupsByName = new WeakHashMap(); // Ahorramos memoria si no se usan componentes
151:                return buttonGroupsByName;
152:            }
153:
154:            public WeakHashMap getButtonGroupsByButtonGroupMap() {
155:                if (buttonGroupsByButtonGroup == null)
156:                    this .buttonGroupsByButtonGroup = new WeakHashMap(); // Ahorramos memoria si no se usan componentes
157:                return buttonGroupsByButtonGroup;
158:            }
159:
160:            public ItsNatButtonGroup getItsNatButtonGroup(String name) {
161:                if ((name == null) || name.equals(""))
162:                    return null;
163:
164:                Map buttonGroups = getButtonGroupsByNameMap();
165:                ItsNatButtonGroupImpl itsNatButtonGroup = null;
166:                WeakReference weakButtonGrp = (WeakReference) buttonGroups
167:                        .get(name);
168:                if (weakButtonGrp != null)
169:                    itsNatButtonGroup = (ItsNatButtonGroupImpl) weakButtonGrp
170:                            .get(); // puede ser null
171:                if (itsNatButtonGroup == null)
172:                    itsNatButtonGroup = addButtonGroup(name);
173:                return itsNatButtonGroup;
174:            }
175:
176:            public ItsNatButtonGroup getItsNatButtonGroup(ButtonGroup group) {
177:                if (group == null)
178:                    return null;
179:
180:                Map buttonGroups = getButtonGroupsByButtonGroupMap();
181:                ItsNatButtonGroupImpl itsNatButtonGroup = null;
182:                WeakReference weakButtonGrp = (WeakReference) buttonGroups
183:                        .get(group);
184:                if (weakButtonGrp != null)
185:                    itsNatButtonGroup = (ItsNatButtonGroupImpl) weakButtonGrp
186:                            .get(); // puede ser null
187:                if (itsNatButtonGroup == null)
188:                    itsNatButtonGroup = addButtonGroup(group);
189:                return itsNatButtonGroup;
190:            }
191:
192:            public ItsNatButtonGroup createItsNatButtonGroup() {
193:                return addButtonGroup(new ButtonGroup());
194:            }
195:
196:            public ItsNatButtonGroupImpl addButtonGroup(String name) {
197:                // Suponemos que el nombre pasado no es usado por otro (ya se ha comprobado).
198:
199:                return addButtonGroup(new ButtonGroup(), name);
200:            }
201:
202:            public ItsNatButtonGroupImpl addButtonGroup(ButtonGroup group) {
203:                // Suponemos que el ButtonGroup pasado no es usado por otro (ya se ha comprobado).
204:
205:                // El nombre lo generamos para que sea único
206:                String name = "buttonGroup_" + itsNatDoc.generateUniqueId();
207:                return addButtonGroup(group, name);
208:            }
209:
210:            public ItsNatButtonGroupImpl addButtonGroup(ButtonGroup group,
211:                    String name) {
212:                ItsNatButtonGroupImpl itsNatButtonGroup = new ItsNatButtonGroupImpl(
213:                        name, group);
214:                return addButtonGroup(itsNatButtonGroup);
215:            }
216:
217:            public ItsNatButtonGroupImpl addButtonGroup(
218:                    ItsNatButtonGroupImpl itsNatButtonGroup) {
219:                // Suponemos que el ItsNatButtonGroupImpl pasado es nuevo (ya se ha comprobado).
220:
221:                WeakReference weakButtonGrp = new WeakReference(
222:                        itsNatButtonGroup);
223:
224:                Map buttonGroupsByName = getButtonGroupsByNameMap();
225:                buttonGroupsByName.put(itsNatButtonGroup.getName(),
226:                        weakButtonGrp); // El objeto String name está sujeto por el propio ItsNatButtonGroupImpl, si este se pierde se pierde su Id y la entrada en el mapa lo cual es deseable
227:
228:                Map buttonGroupsByButtonGroup = getButtonGroupsByButtonGroupMap();
229:                buttonGroupsByButtonGroup.put(itsNatButtonGroup
230:                        .getButtonGroup(), weakButtonGrp); // El ButtonGroup Swing está sujeto por el propio ItsNatButtonGroupImpl, si este se pierde se pierde su entrada en el mapa lo cual es deseable       
231:
232:                return itsNatButtonGroup;
233:            }
234:
235:            public void removeItsNatComponent(ItsNatComponent comp,
236:                    boolean dispose) {
237:                removeItsNatComponent(comp);
238:                if (dispose)
239:                    comp.dispose();
240:            }
241:
242:            public void removeItsNatComponent(ItsNatComponent comp) {
243:                Map components = getComponentMap();
244:                components.remove(comp.getNode());
245:            }
246:
247:            public ItsNatComponent removeItsNatComponent(Node node) {
248:                ItsNatComponent comp = findItsNatComponent(node);
249:                if (comp == null)
250:                    return null;
251:                removeItsNatComponent(comp);
252:                return comp;
253:            }
254:
255:            public ItsNatComponent removeItsNatComponent(String id) {
256:                Document doc = getItsNatDocument().getDocument();
257:                Element node = doc.getElementById(id);
258:                return removeItsNatComponent(node);
259:            }
260:
261:            public void removeExcludedNodeAsItsNatComponent(Node node) {
262:                Map nodes = getExcludedNodesAsComponentsMap();
263:                nodes.remove(node);
264:            }
265:
266:            public ItsNatComponent findItsNatComponentById(String id) {
267:                Document doc = getItsNatDocument().getDocument();
268:                Element node = doc.getElementById(id);
269:                return findItsNatComponent(node);
270:            }
271:
272:            public ItsNatComponent findItsNatComponent(Node node) {
273:                if (node == null)
274:                    return null;
275:
276:                if (node.getNodeType() != Node.ELEMENT_NODE)
277:                    return null; // Sólo Element son componentes, así aceleramos la búsqueda
278:
279:                Map components = getComponentMap();
280:                return (ItsNatComponent) components.get(node);
281:            }
282:
283:            public boolean isExcludedNodeAsItsNatComponent(Node node) {
284:                if (node.getNodeType() != Node.ELEMENT_NODE)
285:                    return true; // Sólo pueden ser componentes los Element, otro tipo de nodos son excluidos por defecto
286:
287:                Map nodes = getExcludedNodesAsComponentsMap();
288:                return nodes.containsKey(node);
289:            }
290:
291:            public void addItsNatComponent(ItsNatComponent comp) {
292:                if (comp == null)
293:                    return;
294:
295:                Map components = getComponentMap();
296:                components.put(comp.getNode(), comp);
297:            }
298:
299:            public void addExcludedNodeAsItsNatComponent(Node node) {
300:                if (node.getNodeType() != Node.ELEMENT_NODE)
301:                    throw new ItsNatException("Only Element can be components");
302:
303:                Map nodes = getExcludedNodesAsComponentsMap();
304:                nodes.put(node, null);
305:            }
306:
307:            public ItsNatComponent createItsNatComponent(Node node) {
308:                return createItsNatComponent(node, null, null);
309:            }
310:
311:            public ItsNatComponent createItsNatComponent(Node node,
312:                    String componentType, NameValue[] artifacts) {
313:                return createItsNatComponent(node, componentType, artifacts,
314:                        true);
315:            }
316:
317:            public ItsNatComponent createItsNatComponentById(String id) {
318:                return createItsNatComponentById(id, null, null);
319:            }
320:
321:            public ItsNatComponent createItsNatComponentById(String id,
322:                    String compType, NameValue[] artifacts) {
323:                Document doc = getItsNatDocument().getDocument();
324:                Element node = doc.getElementById(id);
325:                return createItsNatComponent(node, compType, artifacts);
326:            }
327:
328:            public ItsNatComponent createItsNatComponent(Node node,
329:                    String componentType, NameValue[] artifacts,
330:                    boolean ignoreIsComponentAttr) {
331:                if (node == null)
332:                    return null;
333:
334:                if (node.getNodeType() != Node.ELEMENT_NODE)
335:                    return null; // Sólo Element pueden ser componentes a día de hoy
336:                Element element = (Element) node;
337:
338:                if (componentType == null) // Esto incluye el caso de creación explícita del usuario pero no especifica el componentType, pero sin embargo está en el HTML
339:                    componentType = getCompTypeAttribute(element); // Puede ser null            
340:
341:                ItsNatDocumentImpl itsNatDoc = getItsNatDocumentImpl();
342:                DocumentTemplateImpl docTemplate = itsNatDoc
343:                        .getDocumentTemplateImpl();
344:                ItsNatServletImpl servlet = docTemplate.getItsNatServletImpl();
345:
346:                ItsNatComponent comp = null;
347:                Iterator createCompIterator = null;
348:                boolean hasCustomCreators = false;
349:
350:                createCompIterator = servlet
351:                        .getCreateItsNatComponentListenerIterator();
352:                if (createCompIterator != null) {
353:                    hasCustomCreators = true;
354:                    comp = processBeforeCreateItsNatComponentListener(
355:                            createCompIterator, node, componentType, artifacts);
356:                }
357:
358:                if (comp == null) {
359:                    createCompIterator = docTemplate
360:                            .getCreateItsNatComponentListenerIterator();
361:                    if (createCompIterator != null) {
362:                        hasCustomCreators = true;
363:                        comp = processBeforeCreateItsNatComponentListener(
364:                                createCompIterator, node, componentType,
365:                                artifacts);
366:                    }
367:                }
368:
369:                if (comp == null) {
370:                    comp = newItsNatComponent(element, componentType,
371:                            artifacts, ignoreIsComponentAttr);
372:                }
373:
374:                if (comp == null)
375:                    return null;
376:
377:                if (hasCustomCreators) {
378:                    // Permitimos así que el usuario pueda crear sus propios componentes
379:                    // que serán instanciados cuando sea llamado este método
380:                    // incluso podría substituir a los que hay por defecto segun el nodo
381:                    // Ver más arriba la llamada a before()
382:
383:                    createCompIterator = servlet
384:                            .getCreateItsNatComponentListenerIterator();
385:                    if (createCompIterator != null) {
386:                        comp = processAfterCreateItsNatComponentListener(
387:                                createCompIterator, comp);
388:                        if (comp == null)
389:                            return null; // Componente rechazado
390:                    }
391:
392:                    createCompIterator = docTemplate
393:                            .getCreateItsNatComponentListenerIterator();
394:                    if (createCompIterator != null) {
395:                        comp = processAfterCreateItsNatComponentListener(
396:                                createCompIterator, comp);
397:                        if (comp == null)
398:                            return null; // Componente rechazado                
399:                    }
400:                }
401:
402:                return comp; // Puede ser null
403:            }
404:
405:            public ItsNatComponent processBeforeCreateItsNatComponentListener(
406:                    Iterator it, Node node, String componentType,
407:                    NameValue[] artifacts) {
408:                ItsNatComponent comp = null;
409:
410:                // Permitimos así que el usuario pueda crear sus propios componentes
411:                // que serán instanciados cuando sea llamado este método
412:                // incluso podría substituir a los que hay por defecto segun el nodo
413:                // No debería añadirse nuevos listeners cuando ya haya documentos cargados
414:                // El programador debería tener en cuenta que se puede llamar a before/after en multihilo
415:                // aunque con un sólo hilo por documento.
416:
417:                // Aunque se usa una colección del DocumentTemplate y servlet no hay problema de hilos
418:                // mientras no se modifique concurrentemente la lista, esto no debería
419:                // ocurrir, el usuario debe registrar sus CreateItsNatComponentListener
420:                // en tiempo de creación del template (init() del Servlet).
421:                while (it.hasNext()) {
422:                    CreateItsNatComponentListener listener = (CreateItsNatComponentListener) it
423:                            .next();
424:                    comp = listener
425:                            .before(node, componentType, artifacts, this );
426:                    if (comp != null)
427:                        break;
428:                }
429:
430:                return comp;
431:            }
432:
433:            public ItsNatComponent processAfterCreateItsNatComponentListener(
434:                    Iterator it, ItsNatComponent comp) {
435:                // Permitimos así que el usuario pueda crear sus propios componentes
436:                // que serán instanciados cuando sea llamado este método
437:                // incluso podría substituir a los que hay por defecto segun el nodo
438:                // Ver más arriba la llamada a before()        
439:                while (it.hasNext()) {
440:                    CreateItsNatComponentListener listener = (CreateItsNatComponentListener) it
441:                            .next();
442:                    comp = listener.after(comp);
443:                    if (comp == null)
444:                        return null; // Componente rechazado
445:                }
446:                return comp;
447:            }
448:
449:            public ItsNatComponent addItsNatComponent(Node node) {
450:                return addItsNatComponent(node, null, null);
451:            }
452:
453:            public ItsNatComponent addItsNatComponent(Node node,
454:                    String componentType, NameValue[] artifacts) {
455:                return addItsNatComponent(node, componentType, artifacts,
456:                        false, true);
457:            }
458:
459:            public ItsNatComponent addItsNatComponentById(String id) {
460:                return addItsNatComponentById(id, null, null);
461:            }
462:
463:            public ItsNatComponent addItsNatComponentById(String id,
464:                    String compType, NameValue[] artifacts) {
465:                Document doc = getItsNatDocument().getDocument();
466:                Element node = doc.getElementById(id);
467:                return addItsNatComponent(node, compType, artifacts);
468:            }
469:
470:            public ItsNatComponent addItsNatComponent(Node node,
471:                    String componentType, NameValue[] artifacts,
472:                    boolean autoBuildMode, boolean ignoreIsComponentAttr) {
473:                if (node == null)
474:                    return null;
475:
476:                if (isExcludedNodeAsItsNatComponent(node))
477:                    return null;
478:
479:                if (autoBuildMode) {
480:                    if (findItsNatComponent(node) != null) // para evitar añadir dos veces
481:                        return null;
482:                } else if (getItsNatDocumentImpl().isDebugMode()) {
483:                    // Detecta que el usuario explícitamente añade dos componentes al mismo nodo
484:                    // ralentiza un poco por eso no se efectúa el chequeo en modo normal
485:                    if (findItsNatComponent(node) != null)
486:                        throw new ItsNatDOMException(
487:                                "Component already added to this node", node);
488:                }
489:
490:                ItsNatComponent component = createItsNatComponent(node,
491:                        componentType, artifacts, ignoreIsComponentAttr); // puede ser null
492:                addItsNatComponent(component); // Si es null no hace nada
493:                return component; // puede ser null
494:            }
495:
496:            public ItsNatComponent[] buildItsNatComponents() {
497:                Document doc = getItsNatDocument().getDocument();
498:                return buildItsNatComponents(doc);
499:            }
500:
501:            public ItsNatComponent[] buildItsNatComponents(Node node) {
502:                LinkedList listComp = new LinkedList();
503:
504:                buildItsNatComponents(node, listComp);
505:
506:                return (ItsNatComponent[]) listComp
507:                        .toArray(new ItsNatComponent[listComp.size()]);
508:            }
509:
510:            public void buildItsNatComponentsInternal() {
511:                Document doc = getItsNatDocument().getDocument();
512:                buildItsNatComponents(doc, null);
513:            }
514:
515:            public LinkedList buildItsNatComponents(Node node,
516:                    LinkedList listComp) {
517:                // Primero procesamos el propio nodo pues si es un componente
518:                // puede crear y eliminar nodos hijo, luego procesamos los hijos tal y como ha quedado
519:
520:                ItsNatComponent comp = addItsNatComponent(node, null, null,
521:                        true, false); // Si no puede ser un componente no hace nada
522:                if (comp != null) {
523:                    if (listComp == null)
524:                        listComp = new LinkedList(); // Se crea cuando se necesita
525:                    listComp.add(comp);
526:                }
527:
528:                Node child = node.getFirstChild();
529:                while (child != null) {
530:                    listComp = buildItsNatComponents(child, listComp);
531:                    child = child.getNextSibling();
532:                }
533:
534:                return listComp;
535:            }
536:
537:            public ItsNatComponent[] removeItsNatComponents(boolean dispose) {
538:                Map components = getComponentMap();
539:                if (!components.isEmpty()) {
540:                    ItsNatComponent[] listRes = new ItsNatComponent[components
541:                            .size()];
542:                    int i = 0;
543:                    for (Iterator it = components.entrySet().iterator(); it
544:                            .hasNext();) {
545:                        Map.Entry entry = (Map.Entry) it.next();
546:                        ItsNatComponent comp = (ItsNatComponent) entry
547:                                .getValue();
548:                        if (dispose)
549:                            comp.dispose();
550:                        listRes[i] = comp;
551:                        i++;
552:                    }
553:                    components.clear();
554:                    return listRes;
555:                } else
556:                    return null;
557:            }
558:
559:            public ItsNatComponent[] removeItsNatComponents(Node node,
560:                    boolean dispose) {
561:                LinkedList listComp = new LinkedList();
562:                removeItsNatComponents(node, dispose, listComp);
563:
564:                return (ItsNatComponent[]) listComp
565:                        .toArray(new ItsNatComponent[listComp.size()]);
566:            }
567:
568:            public void removeItsNatComponents(Node node, boolean dispose,
569:                    LinkedList listComp) {
570:                // Primero los hijos por si acaso
571:                Node child = node.getFirstChild();
572:                while (child != null) {
573:                    removeItsNatComponents(child, dispose, listComp);
574:                    child = child.getNextSibling();
575:                }
576:
577:                ItsNatComponent comp = findItsNatComponent(node);
578:                if (comp != null) {
579:                    removeItsNatComponent(comp, dispose);
580:                    if (listComp != null)
581:                        listComp.add(comp);
582:                }
583:            }
584:
585:            public void initAutoBuildComponents() {
586:                buildItsNatComponentsInternal();
587:
588:                // Registramos un listener tal que las mutaciones en el documento 
589:                // desde ahora se manifiesten en añadido o quitado automático de componentes
590:                // Registramos después de hacer la llamada buildItsNatComponents();
591:                // porque se hace de arriba abajo tal que aunque el componente añada y quite
592:                // nodos que puedan tener a su vez componentes posteriormente se procesan
593:                // los hijos del nodo-componente tal y como quedan tras crear el componente
594:                // Si el componente creara/borrara nodos con posibles componentes en otro lugar diferente a bajo sí mismo
595:                // no se detectaría pero no hay ningún componente que haga esto.
596:                // En dicho caso se registraría antes este listener aunque ralentiza más pues hay que evitar
597:                // añadir componentes cuando ya se han añadido
598:
599:                MutationEventListenerImpl mutEventListener = getItsNatDocumentImpl()
600:                        .getMutationEventListener();
601:                mutEventListener
602:                        .setAutoBuildCompMutationEventBeforeAfterListener(new AutoBuildCompMutationEventBeforeAfterListener(
603:                                this ));
604:            }
605:
606:            public static String getCompTypeAttribute(Element element) {
607:                String value = element.getAttributeNS(
608:                        MarkupTemplateVersionImpl.ITSNAT_NAMESPACE, "compType");
609:                if (value.equals(""))
610:                    return null;
611:                return value;
612:            }
613:
614:            public static boolean isComponentAttribute(Element element) {
615:                String value = element.getAttributeNS(
616:                        MarkupTemplateVersionImpl.ITSNAT_NAMESPACE,
617:                        "isComponent");
618:                return value.equals("true");
619:            }
620:
621:            public static boolean explicitIsNotComponentAttribute(
622:                    Element element) {
623:                // En este caso es true sólo cuando isComponent existe y está puesto como "false" explícitamente
624:                String value = element.getAttributeNS(
625:                        MarkupTemplateVersionImpl.ITSNAT_NAMESPACE,
626:                        "isComponent");
627:                return value.equals("false");
628:            }
629:
630:            public ItsNatLabelRenderer createDefaultItsNatLabelRenderer() {
631:                return new ItsNatLabelRendererDefaultImpl(this );
632:            }
633:
634:            public ItsNatListCellRenderer createDefaultItsNatListCellRenderer() {
635:                return new ItsNatListCellRendererDefaultImpl(this );
636:            }
637:
638:            public ItsNatTableCellRenderer createDefaultItsNatTableCellRenderer() {
639:                return new ItsNatTableCellRendererDefaultImpl(this );
640:            }
641:
642:            public ItsNatTableHeaderCellRenderer createDefaultItsNatTableHeaderCellRenderer() {
643:                return new ItsNatTableHeaderCellRendererDefaultImpl(this );
644:            }
645:
646:            public ItsNatTreeCellRenderer createDefaultItsNatTreeCellRenderer() {
647:                return new ItsNatTreeCellRendererDefaultImpl(this );
648:            }
649:
650:            public ItsNatFreeInclude createItsNatFreeInclude(Element element,
651:                    NameValue[] artifacts) {
652:                return new ItsNatFreeIncludeImpl(element, artifacts, this );
653:            }
654:
655:            public ItsNatFreeLabel createItsNatFreeLabel(Element element,
656:                    NameValue[] artifacts) {
657:                return new ItsNatFreeLabelImpl(element, artifacts, this );
658:            }
659:
660:            public ItsNatFreeButtonNormal createItsNatFreeButtonNormal(
661:                    Element element, NameValue[] artifacts) {
662:                return new ItsNatFreeButtonNormalDefaultImpl(element,
663:                        artifacts, this );
664:            }
665:
666:            public ItsNatFreeButtonNormalLabel createItsNatFreeButtonNormalLabel(
667:                    Element element, NameValue[] artifacts) {
668:                return new ItsNatFreeButtonNormalLabelImpl(element, artifacts,
669:                        this );
670:            }
671:
672:            public ItsNatFreeCheckBox createItsNatFreeCheckBox(Element element,
673:                    NameValue[] artifacts) {
674:                return new ItsNatFreeCheckBoxDefaultImpl(element, artifacts,
675:                        this );
676:            }
677:
678:            public ItsNatFreeCheckBoxLabel createItsNatFreeCheckBoxLabel(
679:                    Element element, NameValue[] artifacts) {
680:                return new ItsNatFreeCheckBoxLabelImpl(element, artifacts, this );
681:            }
682:
683:            public ItsNatFreeRadioButton createItsNatFreeRadioButton(
684:                    Element element, NameValue[] artifacts) {
685:                return new ItsNatFreeRadioButtonDefaultImpl(element, artifacts,
686:                        this );
687:            }
688:
689:            public ItsNatFreeRadioButtonLabel createItsNatFreeRadioButtonLabel(
690:                    Element element, NameValue[] artifacts) {
691:                return new ItsNatFreeRadioButtonLabelImpl(element, artifacts,
692:                        this );
693:            }
694:
695:            public ItsNatFreeComboBox createItsNatFreeComboBox(Element element,
696:                    ItsNatListStructure structure, NameValue[] artifacts) {
697:                return new ItsNatFreeComboBoxImpl(element, structure,
698:                        artifacts, this );
699:            }
700:
701:            public ItsNatFreeListMultSel createItsNatFreeListMultSel(
702:                    Element element, ItsNatListStructure structure,
703:                    NameValue[] artifacts) {
704:                return new ItsNatFreeListMultSelImpl(element, structure,
705:                        artifacts, this );
706:            }
707:
708:            public ItsNatFreeTable createItsNatFreeTable(Element element,
709:                    ItsNatTableStructure structure, NameValue[] artifacts) {
710:                return new ItsNatFreeTableImpl(element, structure, artifacts,
711:                        this );
712:            }
713:
714:            public ItsNatFreeTree createItsNatFreeTree(Element element,
715:                    NameValue[] artifacts) {
716:                return new ItsNatFreeTreeImpl(element, artifacts, this );
717:            }
718:
719:            public ItsNatFreeTree createItsNatFreeTree(Element element,
720:                    boolean treeTable, boolean rootless,
721:                    ItsNatTreeStructure structure, NameValue[] artifacts) {
722:                return new ItsNatFreeTreeImpl(treeTable, rootless, element,
723:                        structure, artifacts, this );
724:            }
725:
726:            public ItsNatComponent newItsNatComponent(Element element,
727:                    String compType, NameValue[] artifacts,
728:                    boolean ignoreIsComponentAttr) {
729:                if (compType == null)
730:                    return null;
731:
732:                FactoryItsNatComponentImpl factory = getFactory(compType); // Los "free"
733:                if (factory == null)
734:                    return null;
735:
736:                return factory.createItsNatComponent(element, compType,
737:                        artifacts, ignoreIsComponentAttr, this );
738:            }
739:
740:            public static boolean declaredAsComponent(Element element) {
741:                String type = getCompTypeAttribute(element);
742:                return (type != null);
743:            }
744:
745:            public ItsNatListStructure createDefaultItsNatListStructure() {
746:                return ItsNatListStructureDefaultImpl
747:                        .newItsNatListStructureDefault();
748:            }
749:
750:            public ItsNatTableStructure createDefaultItsNatTableStructure() {
751:                return ItsNatTableStructureDefaultImpl
752:                        .newItsNatTableStructureDefault();
753:            }
754:
755:            public ItsNatTreeStructure createDefaultItsNatTreeStructure() {
756:                return ItsNatTreeStructureDefaultImpl
757:                        .newItsNatTreeStructureDefault();
758:            }
759:
760:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.