Source Code Cross Referenced for Schema.java in  » Library » Apache-commons-betwixt-0.8-src » org » apache » commons » betwixt » schema » 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 » Library » Apache commons betwixt 0.8 src » org.apache.commons.betwixt.schema 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:
018:        package org.apache.commons.betwixt.schema;
019:
020:        import java.beans.IntrospectionException;
021:        import java.util.ArrayList;
022:        import java.util.Collection;
023:        import java.util.Iterator;
024:        import java.util.List;
025:
026:        import org.apache.commons.betwixt.ElementDescriptor;
027:        import org.apache.commons.betwixt.XMLBeanInfo;
028:        import org.apache.commons.betwixt.XMLIntrospector;
029:
030:        /**
031:         * Model for top level element in an XML Schema
032:         * 
033:         * @author <a href='http://jakarta.apache.org/'>Jakarta Commons Team</a>
034:         * @version $Revision: 438373 $
035:         */
036:        public class Schema {
037:
038:            private List elements = new ArrayList();
039:            private List complexTypes = new ArrayList();
040:            private List simpleTypes = new ArrayList();
041:
042:            private XMLIntrospector introspector;
043:
044:            public Schema() {
045:                this (new XMLIntrospector());
046:            }
047:
048:            public Schema(XMLIntrospector introspector) {
049:                this .introspector = introspector;
050:            }
051:
052:            /**
053:             * Introspects the given type giving an <code>XMLBeanInfo</code>.
054:             * @param type Class to introspect, not null
055:             * @return <code>XMLBeanInfo</code>, not null
056:             * @throws IntrospectionException
057:             */
058:            public XMLBeanInfo introspect(Class type)
059:                    throws IntrospectionException {
060:                return introspector.introspect(type);
061:            }
062:
063:            /**
064:             * Gets the complex types defined
065:             * @return list of <code>ComplexType</code>'s not null
066:             */
067:            public List getComplexTypes() {
068:                return complexTypes;
069:            }
070:
071:            /**
072:             * Adds a new complex type to those defined
073:             * @param complexType not null
074:             */
075:            public void addComplexType(GlobalComplexType complexType) {
076:                complexTypes.add(complexType);
077:            }
078:
079:            /**
080:             * Gets the elements definied
081:             * @return list of <code>Element</code>s not null
082:             */
083:            public List getElements() {
084:                return elements;
085:            }
086:
087:            /**
088:             * Adds a new element to those defined.
089:             * @param element not null
090:             */
091:            public void addElement(GlobalElement element) {
092:                elements.add(element);
093:            }
094:
095:            /**
096:             * Gets the simple types defined.
097:             * @return list of <code>SimpleType</code>s not null
098:             */
099:            public List getSimpleTypes() {
100:                return simpleTypes;
101:            }
102:
103:            /**
104:             * Adds a new simple type to those defined.
105:             * @param simpleType
106:             */
107:            public void addSimpleType(SimpleType simpleType) {
108:                simpleTypes.add(simpleType);
109:            }
110:
111:            /**
112:             * Adds global (top level) element and type declarations matching the given descriptor.
113:             * @param elementDescriptor ElementDescriptor not null
114:             */
115:            public void addGlobalElementType(
116:                    TranscriptionConfiguration configuration,
117:                    ElementDescriptor elementDescriptor)
118:                    throws IntrospectionException {
119:                // need to create a global element declaration and a complex type 
120:                // use the fully qualified class name as the type name
121:                GlobalElement element = new GlobalElement(elementDescriptor
122:                        .getLocalName(), configuration
123:                        .getSchemaTypeNamingStrategy().nameSchemaType(
124:                                elementDescriptor));
125:                addElement(element);
126:                addGlobalComplexType(configuration, elementDescriptor);
127:            }
128:
129:            /**
130:             * Adds a new global complex type definition matching the given element descriptor.
131:             * If this element descriptor has already been mapped to a global type then 
132:             * that is returned.
133:             * @since 0.7
134:             * @param configuration <code>TranscriptionConfiguration</code>, not null
135:             * @param elementDescriptor <code>ElementDescriptor</code>, not null
136:             * @return <code>GlobalComplexType</code>
137:             * @throws IntrospectionException
138:             */
139:            public GlobalComplexType addGlobalComplexType(
140:                    TranscriptionConfiguration configuration,
141:                    ElementDescriptor elementDescriptor)
142:                    throws IntrospectionException {
143:                GlobalComplexType type = null;
144:                for (Iterator it = complexTypes.iterator(); it.hasNext();) {
145:                    GlobalComplexType complexType = (GlobalComplexType) it
146:                            .next();
147:                    if (complexType.matches(elementDescriptor)) {
148:                        type = complexType;
149:                        break;
150:                    }
151:                }
152:                if (type == null) {
153:                    type = new GlobalComplexType(configuration,
154:                            elementDescriptor, this );
155:                    addComplexType(type);
156:                    type.fill(configuration, elementDescriptor, this );
157:                }
158:                return type;
159:            }
160:
161:            public boolean equals(Object obj) {
162:                boolean result = false;
163:                if (obj instanceof  Schema) {
164:                    Schema schema = (Schema) obj;
165:                    result = equalContents(elements, schema.elements)
166:                            && equalContents(complexTypes, schema.complexTypes)
167:                            && equalContents(simpleTypes, schema.simpleTypes);
168:                }
169:                return result;
170:            }
171:
172:            private boolean equalContents(Collection one, Collection two) {
173:                // doesn't check cardinality but should be ok
174:                if (one.size() != two.size()) {
175:                    return false;
176:                }
177:                for (Iterator it = one.iterator(); it.hasNext();) {
178:                    Object object = it.next();
179:                    if (!two.contains(object)) {
180:                        return false;
181:                    }
182:                }
183:                return true;
184:            }
185:
186:            public int hashCode() {
187:                return 0;
188:            }
189:
190:            public String toString() {
191:                StringBuffer buffer = new StringBuffer();
192:                buffer.append("<?xml version='1.0'?>");
193:                buffer
194:                        .append("<xsd:schema xmlns:xsd='http://www.w3c.org/2001/XMLSchema'>");
195:
196:                for (Iterator it = simpleTypes.iterator(); it.hasNext();) {
197:                    buffer.append(it.next());
198:                }
199:
200:                for (Iterator it = complexTypes.iterator(); it.hasNext();) {
201:                    buffer.append(it.next());
202:                }
203:
204:                for (Iterator it = elements.iterator(); it.hasNext();) {
205:                    buffer.append(it.next());
206:                }
207:                buffer.append("</xsd:schema>");
208:                return buffer.toString();
209:            }
210:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.