Source Code Cross Referenced for AttributeGroupHandler.java in  » GIS » GeoTools-2.4.1 » org » geotools » xml » handlers » xsi » 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 » GIS » GeoTools 2.4.1 » org.geotools.xml.handlers.xsi 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *    GeoTools - OpenSource mapping toolkit
003:         *    http://geotools.org
004:         *    (C) 2004-2006, GeoTools Project Managment Committee (PMC)
005:         *    
006:         *    This library is free software; you can redistribute it and/or
007:         *    modify it under the terms of the GNU Lesser General Public
008:         *    License as published by the Free Software Foundation;
009:         *    version 2.1 of the License.
010:         *
011:         *    This library is distributed in the hope that it will be useful,
012:         *    but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         *    Lesser General Public License for more details.
015:         */
016:        package org.geotools.xml.handlers.xsi;
017:
018:        import java.util.HashSet;
019:        import java.util.Iterator;
020:        import java.util.LinkedList;
021:        import java.util.List;
022:
023:        import org.geotools.xml.XSIElementHandler;
024:        import org.geotools.xml.schema.Attribute;
025:        import org.geotools.xml.schema.AttributeGroup;
026:        import org.geotools.xml.schema.impl.AttributeGroupGT;
027:        import org.xml.sax.Attributes;
028:        import org.xml.sax.SAXException;
029:        import org.xml.sax.SAXNotRecognizedException;
030:
031:        /**
032:         * AttributeGroupHandler purpose.
033:         * 
034:         * <p>
035:         * Represents an 'attributeGroup' element.
036:         * </p>
037:         *
038:         * @author dzwiers, Refractions Research, Inc. http://www.refractions.net
039:         * @author $Author:$ (last modification)
040:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/xml/src/main/java/org/geotools/xml/handlers/xsi/AttributeGroupHandler.java $
041:         * @version $Id: AttributeGroupHandler.java 22266 2006-10-19 11:30:55Z acuster $
042:         */
043:        public class AttributeGroupHandler extends XSIElementHandler {
044:            /** 'attributeGroup' */
045:            public final static String LOCALNAME = "attributeGroup";
046:            private static int offset = 0;
047:            private String id;
048:            private String name;
049:            private String ref;
050:            private AnyAttributeHandler anyAttribute;
051:            private List attrDecs;
052:            private int hashCodeOffset = getOffset();
053:            private AttributeGroup cache = null;
054:
055:            /*
056:             * Helper method for hashCode
057:             */
058:            private static int getOffset() {
059:                return offset++;
060:            }
061:
062:            /**
063:             * @see java.lang.Object#hashCode()
064:             */
065:            public int hashCode() {
066:                return (LOCALNAME.hashCode()
067:                        * ((id == null) ? 1 : id.hashCode())
068:                        * ((ref == null) ? 1 : ref.hashCode()) * ((name == null) ? 1
069:                        : name.hashCode()))
070:                        + hashCodeOffset;
071:            }
072:
073:            /**
074:             * @see org.geotools.xml.XSIElementHandler#getHandler(java.lang.String,
075:             *      java.lang.String)
076:             */
077:            public XSIElementHandler getHandler(String namespaceURI,
078:                    String localName) throws SAXException {
079:                if (SchemaHandler.namespaceURI.equalsIgnoreCase(namespaceURI)) {
080:                    // child types
081:                    //
082:                    // attribute
083:                    if (AttributeHandler.LOCALNAME.equalsIgnoreCase(localName)) {
084:                        if (attrDecs == null) {
085:                            attrDecs = new LinkedList();
086:                        }
087:
088:                        AttributeHandler ah = new AttributeHandler();
089:                        attrDecs.add(ah);
090:
091:                        return ah;
092:                    }
093:
094:                    // attributeGroup
095:                    if (AttributeGroupHandler.LOCALNAME
096:                            .equalsIgnoreCase(localName)) {
097:                        if (attrDecs == null) {
098:                            attrDecs = new LinkedList();
099:                        }
100:
101:                        AttributeGroupHandler ah = new AttributeGroupHandler();
102:                        attrDecs.add(ah);
103:
104:                        return ah;
105:                    }
106:
107:                    // anyAttribute
108:                    if (AnyAttributeHandler.LOCALNAME
109:                            .equalsIgnoreCase(localName)) {
110:                        AnyAttributeHandler sth = new AnyAttributeHandler();
111:
112:                        if (anyAttribute == null) {
113:                            anyAttribute = sth;
114:                        } else {
115:                            throw new SAXNotRecognizedException(LOCALNAME
116:                                    + " may only have one child declaration.");
117:                        }
118:
119:                        return sth;
120:                    }
121:                }
122:
123:                return null;
124:            }
125:
126:            /**
127:             * @see org.geotools.xml.XSIElementHandler#startElement(java.lang.String,
128:             *      java.lang.String, org.xml.sax.Attributes)
129:             */
130:            public void startElement(String namespaceURI, String localName,
131:                    Attributes atts) {
132:                id = atts.getValue("", "id");
133:
134:                if (id == null) {
135:                    id = atts.getValue(namespaceURI, "id");
136:                }
137:
138:                name = atts.getValue("", "name");
139:
140:                if (name == null) {
141:                    name = atts.getValue(namespaceURI, "name");
142:                }
143:
144:                ref = atts.getValue("", "ref");
145:
146:                if (ref == null) {
147:                    ref = atts.getValue(namespaceURI, "ref");
148:                }
149:            }
150:
151:            /**
152:             * @see org.geotools.xml.XSIElementHandler#getLocalName()
153:             */
154:            public String getLocalName() {
155:                return LOCALNAME;
156:            }
157:
158:            /**
159:             * returns the 'name' attribute
160:             *
161:             */
162:            public String getName() {
163:                return name;
164:            }
165:
166:            /**
167:             * <p>
168:             * Reduces the memory imprint returning a smaller object
169:             * </p>
170:             *
171:             * @param parent
172:             *
173:             *
174:             * @throws SAXException
175:             */
176:            protected AttributeGroup compress(SchemaHandler parent)
177:                    throws SAXException {
178:                if (cache != null) {
179:                    return cache;
180:                }
181:
182:                String anyAttributeNamespace = (anyAttribute == null) ? null
183:                        : anyAttribute.getNamespace();
184:                Attribute[] attributes = null;
185:
186:                if (attrDecs != null) {
187:                    Iterator i = attrDecs.iterator();
188:                    HashSet h = new HashSet();
189:
190:                    while (i.hasNext()) {
191:                        Object o = i.next();
192:
193:                        if (o instanceof  AttributeHandler) {
194:                            h.add(((AttributeHandler) o).compress(parent));
195:                        } else {
196:                            AttributeGroupHandler agh = (AttributeGroupHandler) o;
197:                            AttributeGroup ag = agh.compress(parent);
198:
199:                            if ((ag != null) && (ag.getAttributes() != null)) {
200:                                Attribute[] aa = ag.getAttributes();
201:
202:                                for (int j = 0; j < aa.length; j++)
203:                                    h.add(aa[j]);
204:                            }
205:                        }
206:                    }
207:
208:                    attributes = (Attribute[]) h
209:                            .toArray(new Attribute[h.size()]);
210:                }
211:
212:                String name1 = this .name;
213:
214:                if ((ref != null) && !"".equalsIgnoreCase(ref)) {
215:                    AttributeGroup ag = parent.lookUpAttributeGroup(ref);
216:
217:                    if (ag == null) {
218:                        throw new SAXException("AttributeGroup '" + ref
219:                                + "' was refered and not found");
220:                    }
221:
222:                    name1 = ag.getName();
223:
224:                    if ((anyAttribute == null)
225:                            || "".equalsIgnoreCase(anyAttribute.getNamespace())) {
226:                        anyAttributeNamespace = ag.getAnyAttributeNameSpace();
227:                    }
228:
229:                    if (attributes != null) {
230:                        throw new SAXException(
231:                                "Cannot have a ref and children for an AttributeGroup");
232:                    }
233:
234:                    attributes = ag.getAttributes();
235:                }
236:
237:                cache = new AttributeGroupGT(id, name1, parent
238:                        .getTargetNamespace(), attributes,
239:                        anyAttributeNamespace);
240:
241:                return cache;
242:            }
243:
244:            /**
245:             * @see org.geotools.xml.XSIElementHandler#getHandlerType()
246:             */
247:            public int getHandlerType() {
248:                return DEFAULT;
249:            }
250:
251:            /**
252:             * @see org.geotools.xml.XSIElementHandler#endElement(java.lang.String,
253:             *      java.lang.String)
254:             */
255:            public void endElement(String namespaceURI, String localName) {
256:                // do nothing
257:            }
258:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.