Source Code Cross Referenced for XRegisteredComponentFactory.java in  » XML-UI » XUI » net » xoetrope » optional » 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 » XUI » net.xoetrope.optional.registry 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.xoetrope.optional.registry;
002:
003:        import net.xoetrope.xui.XComponentConstructor;
004:        import net.xoetrope.xui.XComponentFactory;
005:        import java.awt.Component;
006:        import net.xoetrope.xui.XResourceManager;
007:        import java.io.Reader;
008:        import net.xoetrope.xui.XProjectManager;
009:        import net.xoetrope.xml.XmlElement;
010:        import net.xoetrope.xml.XmlSource;
011:        import net.xoetrope.xui.build.BuildProperties;
012:        import net.xoetrope.debug.DebugLogger;
013:        import java.util.Vector;
014:        import java.util.Hashtable;
015:
016:        /**
017:         * A component factory that builds components based upon some XML configuration
018:         * files.
019:         * <p> Copyright (c) Xoetrope Ltd., 2002-2004</p>
020:         * <p> $Revision: 1.7 $</p>
021:         * <p> License: see License.txt</p>
022:         */
023:        public class XRegisteredComponentFactory implements 
024:                XComponentConstructor {
025:            protected Hashtable propertiesRegister;
026:
027:            public XRegisteredComponentFactory() {
028:                propertiesRegister = new Hashtable();
029:                read();
030:            }
031:
032:            /**
033:             * A generic factory for adding XComponents. The component is constructed, positioned and
034:             * added to the parent panel if one exists. The component is named with a counter value
035:             * to uniquely identify the control.
036:             * When a ScrollPane is addd it becomes the parent.
037:             * @param cf the calling component factory
038:             * @param type  a constant identifying the type of component to be created
039:             * @param content the component text/content
040:             */
041:            public Component constructComponent(XComponentFactory cf, int type,
042:                    String content) {
043:                throw new UnsupportedOperationException();
044:            }
045:
046:            /**
047:             * A generic factory for adding XComponents. The component is constructed, positioned and
048:             * added to the parent panel if one exists. The component is named with a counter value
049:             * to uniquely identify the control.
050:             * When a ScrollPane is addd it becomes the parent.
051:             * @param cf the calling component factory
052:             * @param type  a name identifying the type of component to be created
053:             * @param content the component text/content
054:             */
055:            public Component constructComponent(XComponentFactory cf,
056:                    String type, String content) {
057:                Component comp = null;
058:
059:                ComponentAdapter componentDescription = (ComponentAdapter) propertiesRegister
060:                        .get(type);
061:                try {
062:                    comp = (Component) componentDescription.clazz.newInstance();
063:                    componentDescription.setProperty(comp, "content", content,
064:                            "String");
065:                } catch (IllegalAccessException ex) {
066:                    ex.printStackTrace();
067:                } catch (InstantiationException ex) {
068:                    ex.printStackTrace();
069:                }
070:
071:                return comp;
072:            }
073:
074:            /**
075:             * A generic factory method  for adding non component elements.
076:             * @param cf the calling component factory
077:             * @param type the object type
078:             * @param name  a name identifying the element to be created
079:             * @param content the component text/content
080:             * @param attribs the element attributes if any
081:             */
082:            public Object addElement(XComponentFactory cf, String type,
083:                    String name, String content, Hashtable attribs) {
084:                throw new UnsupportedOperationException();
085:            }
086:
087:            /**
088:             * Notify the component factories that some of their settings may have changed
089:             */
090:            public void update() {
091:                throw new UnsupportedOperationException();
092:            }
093:
094:            /**
095:             * Set the package name for the factory's widgets. This factory ignores the
096:             * default package name as the classes/componentes being instantiated can come
097:             * from different packages and their package must be fully specified.
098:             */
099:            public void setPackageName(String defPackage) {
100:                throw new UnsupportedOperationException();
101:            }
102:
103:            /**
104:             * Get the adapter for a particular component type. The adapter can be used
105:             * to get and set properties of the component.
106:             * @param type the name by which the component is specified and referenced
107:             * @return the adapter
108:             */
109:            public ComponentAdapter getComponentAdapter(String type) {
110:                return (ComponentAdapter) propertiesRegister.get(type);
111:            }
112:
113:            /**
114:             * Read the component registry. The format is described in the components.xsd
115:             * schema.
116:             */
117:            protected void read() {
118:                String registryFile = XProjectManager.getCurrentProject()
119:                        .getStartupParam("ComponentRegistry");
120:                if ((registryFile == null) || (registryFile.length() == 0))
121:                    registryFile = "components";
122:
123:                try {
124:                    Reader r = XResourceManager.getBufferedReader(registryFile
125:                            + ".xml", null);
126:                    read(r);
127:                } catch (Exception ex) {
128:                    ex.printStackTrace();
129:                }
130:            }
131:
132:            /**
133:             * Read the component registry. The format is described in the components.xsd
134:             * schema.
135:             * @param reader the reader from which to read the file
136:             */
137:            public void read(Reader reader) {
138:                try {
139:                    XmlElement regRoot = XmlSource.read(reader);
140:
141:                    Vector componentNodes = regRoot.getChildren();
142:                    int numComponents = componentNodes.size();
143:                    for (int i = 0; i < numComponents; i++) {
144:                        XmlElement componentNode = (XmlElement) componentNodes
145:                                .elementAt(i);
146:                        try {
147:                            String componentName = componentNode
148:                                    .getAttribute("name");
149:                            ComponentAdapter ca = new ComponentAdapter(
150:                                    componentNode.getAttribute("class"),
151:                                    componentNode.getAttribute("ui"));
152:                            Vector propertyNodes = componentNode.getChildren();
153:                            int numProperties = propertyNodes.size();
154:                            for (int j = 0; j < numProperties; j++) {
155:                                XmlElement propertyNode = (XmlElement) componentNode
156:                                        .elementAt(j);
157:                                String type = propertyNode.getAttribute("type");
158:                                String name = propertyNode.getAttribute("name");
159:                                String method = propertyNode
160:                                        .getAttribute("method");
161:                                String attribStr = propertyNode
162:                                        .getAttribute("attrib");
163:                                boolean attributed = ((attribStr != null) && (attribStr
164:                                        .equals("true")));
165:                                if ((method == null) || (method.length() == 0))
166:                                    method = type
167:                                            + name.substring(0, 1)
168:                                                    .toUpperCase()
169:                                            + name.substring(1);
170:                                String paramType = "String";
171:                                if (type.equals("set") || type.equals("both")) {
172:                                    Vector params = propertyNode.getChildren();
173:                                    if (params.size() > 0)
174:                                        paramType = ((XmlElement) params
175:                                                .elementAt(0))
176:                                                .getAttribute("type");
177:                                }
178:                                ca.addProperty(type, name, method, paramType,
179:                                        attributed);
180:                            }
181:                            propertiesRegister.put(componentName, ca);
182:                        } catch (Exception ex) {
183:                            ex.printStackTrace();
184:                        }
185:                    }
186:                } catch (Exception ex) {
187:                    if (BuildProperties.DEBUG)
188:                        DebugLogger
189:                                .logError("Unable to setup the component registry");
190:                }
191:            }
192:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.