Source Code Cross Referenced for AppConfigXmlUtils.java in  » ESB » open-esb » com » sun » jbi » jsf » util » 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 » ESB » open esb » com.sun.jbi.jsf.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         *  Copyright 1997-2008 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         *  The contents of this file are subject to the terms of either the GNU
007:         *  General Public License Version 2 only ("GPL") or the Common Development
008:         *  and Distribution License("CDDL") (collectively, the "License").  You
009:         *  may not use this file except in compliance with the License. You can obtain
010:         *  a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011:         *  or glassfish/bootstrap/legal/LICENSE.txt.  See the License for the specific
012:         *  language governing permissions and limitations under the License.
013:         *
014:         *  When distributing the software, include this License Header Notice in each
015:         *  file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016:         *  Sun designates this particular file as subject to the "Classpath" exception
017:         *  as provided by Sun in the GPL Version 2 section of the License file that
018:         *  accompanied this code.  If applicable, add the following below the License
019:         *  Header, with the fields enclosed by brackets [] replaced by your own
020:         *  identifying information: "Portions Copyrighted [year]
021:         *  [name of copyright owner]"
022:         *
023:         *  Contributor(s):
024:         *
025:         *  If you wish your version of this file to be governed by only the CDDL or
026:         *  only the GPL Version 2, indicate your decision by adding "[Contributor]
027:         *  elects to include this software in this distribution under the [CDDL or GPL
028:         *  Version 2] license."  If you don't indicate a single choice of license, a
029:         *  recipient has the option to distribute your version of this file under
030:         *  either the CDDL, the GPL Version 2 or to extend the choice of license to
031:         *  its licensees as provided above.  However, if you add GPL Version 2 code
032:         *  and therefore, elected the GPL Version 2 license, then the option applies
033:         *  only if the new code is made subject to such option by the copyright
034:         *  holder.
035:         */
036:        /*
037:         *  AppConfigXmlUtils.java
038:         */
039:        package com.sun.jbi.jsf.util;
040:
041:        import com.sun.jbi.jsf.bean.AppConfigField;
042:        import com.sun.jbi.ui.common.DOMUtil;
043:        import java.io.Reader;
044:        import java.io.StringReader;
045:        import java.util.ArrayList;
046:        import java.util.Collections;
047:        import java.util.Comparator;
048:        import java.util.List;
049:        import java.util.logging.Level;
050:        import java.util.logging.Logger;
051:        import org.w3c.dom.Document;
052:        import org.w3c.dom.Element;
053:        import org.w3c.dom.NodeList;
054:        import org.w3c.dom.Text;
055:
056:        /**
057:         * This class reads/writes the component configuration metadata list xml.
058:         *
059:         * @author   Sun Microsystems, Inc.
060:         */
061:        public final class AppConfigXmlUtils {
062:
063:            /**
064:             * creates list of objects
065:             *
066:             * @param xmlText  xml text
067:             * @return         list of objects
068:             */
069:            public static List<AppConfigField> readFromXml(String xmlText) {
070:                return readFromXml(new StringReader(xmlText));
071:            }
072:
073:            /**
074:             * return an Application Configuration field
075:             *
076:             * @param anAppConfigFieldElement  XML element describing one field
077:             * @return                         AppConfigField bean representing the
078:             *      field
079:             */
080:            private static AppConfigField createAppConfigField(
081:                    Element anAppConfigFieldElement) {
082:
083:                AppConfigField result = new AppConfigField();
084:
085:                String displayDescription = anAppConfigFieldElement
086:                        .getAttribute("displayDescription");
087:                result.setDisplayDescription(displayDescription);
088:
089:                String displayName = anAppConfigFieldElement
090:                        .getAttribute("displayName");
091:                result.setDisplayName(displayName);
092:
093:                String isPasswordFieldValue = anAppConfigFieldElement
094:                        .getAttribute("isPasswordField");
095:                if ("true".equalsIgnoreCase(isPasswordFieldValue)) {
096:                    result.setIsPassword(true);
097:                }
098:
099:                String isRequiredFieldValue = anAppConfigFieldElement
100:                        .getAttribute("isRequiredField");
101:
102:                if ("true".equalsIgnoreCase(isRequiredFieldValue)) {
103:                    result.setIsRequired(true);
104:                }
105:
106:                String name = anAppConfigFieldElement.getTagName();
107:                int offset = "ComponentConfig:".length();
108:                name = name.substring(offset);
109:                result.setName(name);
110:
111:                // TBD set default value...
112:                Text text = (Text) anAppConfigFieldElement.getFirstChild();
113:                if (null != text) {
114:                    String defaultValue = text.getData();
115:                    result.setValue(defaultValue);
116:                }
117:
118:                return result;
119:            }
120:
121:            /**
122:             * creates list of objects
123:             *
124:             * @param xmlReader  Reader
125:             * @return           list of objects
126:             */
127:            private static List<AppConfigField> readFromXml(Reader xmlReader) {
128:                ArrayList<AppConfigField> result = new ArrayList();
129:                Document xmlDoc = null;
130:
131:                try {
132:                    xmlDoc = DOMUtil.UTIL.buildDOMDocument(xmlReader);
133:
134:                } catch (Exception ex) {
135:                    sLog
136:                            .log(
137:                                    Level.FINE,
138:                                    ("AppConfigXmlUtils.readFromXml() caught ex=" + ex),
139:                                    ex);
140:                }
141:
142:                if (null != xmlDoc) {
143:
144:                    // construct the comp configuration list
145:                    // TBD change to use namespace aware approach (i.e. strip off "config:" prefix)
146:                    Element compConfigAppConfigElement = DOMUtil.UTIL
147:                            .getElement(xmlDoc,
148:                                    "componentConfig:ApplicationConfiguration");
149:                    if (null != compConfigAppConfigElement) {
150:                        NodeList compConfigAppConfigsList = compConfigAppConfigElement
151:                                .getChildNodes();
152:                        int size = compConfigAppConfigsList.getLength();
153:                        for (int i = 0; i < size; ++i) {
154:                            Element componentConfigurationMetadataElement = (Element) compConfigAppConfigsList
155:                                    .item(i);
156:                            if (null != componentConfigurationMetadataElement) {
157:                                AppConfigField field = createAppConfigField(componentConfigurationMetadataElement);
158:                                result.add(field);
159:                            }
160:                        }
161:                    } else {
162:                        sLog
163:                                .fine("AppConfigXmlUtils.readFromXml(), found no config:ApplicationConfiguration element");
164:                    }
165:                }
166:
167:                sort(result);
168:                return result;
169:            }
170:
171:            /**
172:             * sorts the list
173:             *
174:             * @param compConfigAppConfigsList  list
175:             */
176:            private static void sort(
177:                    List<AppConfigField> compConfigAppConfigsList) {
178:                try {
179:                    Collections.sort(compConfigAppConfigsList,
180:                            new Comparator() {
181:                                public int compare(Object o1, Object o2) {
182:                                    return ((AppConfigField) o1)
183:                                            .getDisplayName().compareTo(
184:                                                    ((AppConfigField) o2)
185:                                                            .getDisplayName());
186:                                }
187:                            });
188:                } catch (ClassCastException ccEx) {
189:                    sLog.log(Level.FINE,
190:                            ("AppConfigXmlUtils.sort() caught ccEx=" + ccEx),
191:                            ccEx);
192:                } catch (UnsupportedOperationException unsupEx) {
193:                    sLog
194:                            .log(
195:                                    Level.FINE,
196:                                    ("AppConfigXmlUtils.sort() caught unsupEx=" + unsupEx),
197:                                    unsupEx);
198:                }
199:            }
200:
201:            /**
202:             * prevents instantiation
203:             */
204:            private AppConfigXmlUtils() {
205:            }
206:
207:            /**
208:             * logger for com.sun.jbi.jsf
209:             */
210:            private static Logger sLog = JBILogger.getInstance();
211:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.