Source Code Cross Referenced for AttributeGroupUnmarshaller.java in  » Database-ORM » castor » org » exolab » castor » xml » schema » reader » 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 » Database ORM » castor » org.exolab.castor.xml.schema.reader 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Redistribution and use of this software and associated documentation
003:         * ("Software"), with or without modification, are permitted provided
004:         * that the following conditions are met:
005:         *
006:         * 1. Redistributions of source code must retain copyright
007:         *    statements and notices.  Redistributions must also contain a
008:         *    copy of this document.
009:         *
010:         * 2. Redistributions in binary form must reproduce the
011:         *    above copyright notice, this list of conditions and the
012:         *    following disclaimer in the documentation and/or other
013:         *    materials provided with the distribution.
014:         *
015:         * 3. The name "Exolab" must not be used to endorse or promote
016:         *    products derived from this Software without prior written
017:         *    permission of Intalio, Inc.  For written permission,
018:         *    please contact info@exolab.org.
019:         *
020:         * 4. Products derived from this Software may not be called "Exolab"
021:         *    nor may "Exolab" appear in their names without prior written
022:         *    permission of Intalio, Inc. Exolab is a registered
023:         *    trademark of Intalio, Inc.
024:         *
025:         * 5. Due credit should be given to the Exolab Project
026:         *    (http://www.exolab.org/).
027:         *
028:         * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS
029:         * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
030:         * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
031:         * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
032:         * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
033:         * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
034:         * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
035:         * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
036:         * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
037:         * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
038:         * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
039:         * OF THE POSSIBILITY OF SUCH DAMAGE.
040:         *
041:         * Copyright 1999-2002 (C) Intalio Inc. All Rights Reserved.
042:         *
043:         * $Id: AttributeGroupUnmarshaller.java 6230 2006-09-19 07:56:07Z wguttmn $
044:         */package org.exolab.castor.xml.schema.reader;
045:
046:        //-- imported classes and packages
047:        import org.exolab.castor.xml.AttributeSet;
048:        import org.exolab.castor.xml.Namespaces;
049:        import org.exolab.castor.xml.XMLException;
050:        import org.exolab.castor.xml.schema.Annotation;
051:        import org.exolab.castor.xml.schema.AttributeDecl;
052:        import org.exolab.castor.xml.schema.AttributeGroup;
053:        import org.exolab.castor.xml.schema.AttributeGroupDecl;
054:        import org.exolab.castor.xml.schema.AttributeGroupReference;
055:        import org.exolab.castor.xml.schema.Schema;
056:        import org.exolab.castor.xml.schema.SchemaException;
057:        import org.exolab.castor.xml.schema.SchemaNames;
058:        import org.exolab.castor.xml.schema.Wildcard;
059:
060:        /**
061:         * A class for Unmarshalling AttributeGroups
062:         * @author <a href="mailto:kvisco@intalio.com">Keith Visco</a>
063:         * @version $Revision: 6230 $ $Date: 2005-12-13 14:58:48 -0700 (Tue, 13 Dec 2005) $
064:         **/
065:        public class AttributeGroupUnmarshaller extends ComponentReader {
066:
067:            //--------------------/
068:            //- Member Variables -/
069:            //--------------------/
070:
071:            /**
072:             * The current ComponentReader
073:             **/
074:            private ComponentReader unmarshaller;
075:
076:            /**
077:             * The current branch depth
078:             **/
079:            private int depth = 0;
080:
081:            /**
082:             * The AttributeGroup we are constructing
083:             **/
084:            private AttributeGroup _attributeGroup = null;
085:
086:            private boolean allowAnnotation = true;
087:            private boolean foundAnyAttribute = false;
088:            private boolean isRef = false;
089:
090:            private Schema _schema = null;
091:
092:            //----------------/
093:            //- Constructors -/
094:            //----------------/
095:
096:            /**
097:             * Creates a new AttributeGroupUnmarshaller
098:             * @param schema the Schema to which the AttributeGroup belongs
099:             * @param atts the AttributeList
100:             **/
101:            public AttributeGroupUnmarshaller(Schema schema, AttributeSet atts)
102:                    throws XMLException {
103:                super ();
104:                this ._schema = schema;
105:
106:                String ref = atts.getValue(SchemaNames.REF_ATTR);
107:                if (ref != null) {
108:                    if (ref.length() > 0) {
109:                        isRef = true;
110:                        _attributeGroup = new AttributeGroupReference(schema,
111:                                ref);
112:                    } else {
113:                        String err = "The value of the '"
114:                                + SchemaNames.REF_ATTR
115:                                + "' attribute for attribute group must contain a "
116:                                + "valid value.";
117:                        throw new SchemaException(err);
118:                    }
119:                } else {
120:                    AttributeGroupDecl attDecl = new AttributeGroupDecl(schema);
121:                    _attributeGroup = attDecl;
122:
123:                    //-- handle attributes
124:                    attDecl.setName(atts.getValue(SchemaNames.NAME_ATTR));
125:                    attDecl.setId(atts.getValue(SchemaNames.ID_ATTR));
126:                }
127:
128:            } //-- AttributeGroupUnmarshaller
129:
130:            //-----------/
131:            //- Methods -/
132:            //-----------/
133:
134:            /**
135:             * Returns the name of the element that this ComponentReader
136:             * handles
137:             * @return the name of the element that this ComponentReader
138:             * handles
139:             **/
140:            public String elementName() {
141:                return SchemaNames.ATTRIBUTE_GROUP;
142:            } //-- elementName
143:
144:            /**
145:             * Returns the AttributeGroup created by this
146:             * AttributeGroupUnmarshaller
147:             *
148:             * @return the AttributeGroup created by this
149:             * AttributeGroupUnmarshaller
150:             **/
151:            public AttributeGroup getAttributeGroup() {
152:                return _attributeGroup;
153:            } //-- getAttributeGroup
154:
155:            /**
156:             * Returns the Object created by this ComponentReader
157:             * @return the Object created by this ComponentReader
158:             **/
159:            public Object getObject() {
160:                return getAttributeGroup();
161:            } //-- getObject
162:
163:            /**
164:             * Signals the start of an element with the given name.
165:             *
166:             * @param name the NCName of the element. It is an error
167:             * if the name is a QName (ie. contains a prefix).
168:             * @param namespace the namespace of the element. This may be null.
169:             * Note: A null namespace is not the same as the default namespace unless
170:             * the default namespace is also null.
171:             * @param atts the AttributeSet containing the attributes associated
172:             * with the element.
173:             * @param nsDecls the namespace declarations being declared for this 
174:             * element. This may be null.
175:             **/
176:            public void startElement(String name, String namespace,
177:                    AttributeSet atts, Namespaces nsDecls) throws XMLException {
178:                //-- Do delagation if necessary
179:                if (unmarshaller != null) {
180:                    unmarshaller.startElement(name, namespace, atts, nsDecls);
181:                    ++depth;
182:                    return;
183:                }
184:
185:                //-- <anyAttribute>
186:                if (SchemaNames.ANY_ATTRIBUTE.equals(name)) {
187:                    if (foundAnyAttribute)
188:                        error("an anyAttribute element can appear only once as a child "
189:                                + "of an 'AttributeGroup'.");
190:                    foundAnyAttribute = true;
191:                    allowAnnotation = true;
192:                    unmarshaller = new WildcardUnmarshaller(_attributeGroup,
193:                            _schema, name, atts, getResolver());
194:                }
195:                //-- attribute declarations
196:                else if (SchemaNames.ATTRIBUTE.equals(name)) {
197:                    allowAnnotation = false;
198:
199:                    if (isRef)
200:                        error("AttributeGroup references may not have children.");
201:
202:                    unmarshaller = new AttributeUnmarshaller(_schema, atts,
203:                            getResolver());
204:                }
205:                //-- element declarations
206:                else if (SchemaNames.ATTRIBUTE_GROUP.equals(name)) {
207:                    allowAnnotation = false;
208:                    if (isRef)
209:                        error("AttributeGroup references may not have children.");
210:                    unmarshaller = new AttributeGroupUnmarshaller(_schema, atts);
211:                } else if (name.equals(SchemaNames.ANNOTATION)) {
212:                    if (!allowAnnotation)
213:                        outOfOrder(name);
214:                    unmarshaller = new AnnotationUnmarshaller(atts);
215:                } else
216:                    illegalElement(name);
217:
218:                unmarshaller.setDocumentLocator(getDocumentLocator());
219:            } //-- startElement
220:
221:            /**
222:             * Signals to end of the element with the given name.
223:             *
224:             * @param name the NCName of the element. It is an error
225:             * if the name is a QName (ie. contains a prefix).
226:             * @param namespace the namespace of the element.
227:             **/
228:            public void endElement(String name, String namespace)
229:                    throws XMLException {
230:
231:                //-- Do delagation if necessary
232:                if ((unmarshaller != null) && (depth > 0)) {
233:                    unmarshaller.endElement(name, namespace);
234:                    --depth;
235:                    return;
236:                }
237:
238:                //-- have unmarshaller perform any necessary clean up
239:                unmarshaller.finish();
240:
241:                //-- <anyAttribute>
242:                if (SchemaNames.ANY_ATTRIBUTE.equals(name)) {
243:                    Wildcard wildcard = ((WildcardUnmarshaller) unmarshaller)
244:                            .getWildcard();
245:                    try {
246:                        ((AttributeGroupDecl) _attributeGroup)
247:                                .setAnyAttribute(wildcard);
248:                    } catch (SchemaException e) {
249:                        throw new IllegalArgumentException(e.getMessage());
250:                    }
251:                }
252:
253:                //-- attribute declarations
254:                else if (SchemaNames.ATTRIBUTE.equals(name)) {
255:                    AttributeDecl attrDecl = ((AttributeUnmarshaller) unmarshaller)
256:                            .getAttribute();
257:
258:                    ((AttributeGroupDecl) _attributeGroup)
259:                            .addAttribute(attrDecl);
260:                }
261:                //-- attribute group references
262:                else if (SchemaNames.ATTRIBUTE_GROUP.equals(name)) {
263:
264:                    Object obj = unmarshaller.getObject();
265:
266:                    try {
267:                        ((AttributeGroupDecl) _attributeGroup)
268:                                .addReference((AttributeGroupReference) obj);
269:                    } catch (ClassCastException ex) {
270:                        String err = "AttributeGroups cannot contain new "
271:                                + "AttributeGroup definitions, only references to "
272:                                + "top-level AttributeGroups are allowed.";
273:                        error(err);
274:                    }
275:                }
276:                //-- annotation
277:                else if (SchemaNames.ANNOTATION.equals(name)) {
278:                    Annotation ann = ((AnnotationUnmarshaller) unmarshaller)
279:                            .getAnnotation();
280:                    _attributeGroup.addAnnotation(ann);
281:                }
282:
283:                unmarshaller = null;
284:            } //-- endElement
285:
286:            public void characters(char[] ch, int start, int length)
287:                    throws XMLException {
288:                //-- Do delagation if necessary
289:                if (unmarshaller != null) {
290:                    unmarshaller.characters(ch, start, length);
291:                }
292:            } //-- characters
293:
294:        } //-- AttributeGroupUnmarshaller
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.