Source Code Cross Referenced for ArrayERProperty.java in  » 6.0-JDK-Modules » jaxb-impl » com » sun » xml » bind » v2 » runtime » property » 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 » 6.0 JDK Modules » jaxb impl » com.sun.xml.bind.v2.runtime.property 
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-2007 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:        package com.sun.xml.bind.v2.runtime.property;
038:
039:        import java.io.IOException;
040:        import java.util.Collection;
041:
042:        import javax.xml.namespace.QName;
043:        import javax.xml.stream.XMLStreamException;
044:
045:        import com.sun.xml.bind.api.AccessorException;
046:        import com.sun.xml.bind.v2.util.QNameMap;
047:        import com.sun.xml.bind.v2.model.runtime.RuntimePropertyInfo;
048:        import com.sun.xml.bind.v2.runtime.JAXBContextImpl;
049:        import com.sun.xml.bind.v2.runtime.Name;
050:        import com.sun.xml.bind.v2.runtime.XMLSerializer;
051:        import com.sun.xml.bind.v2.runtime.reflect.Lister;
052:        import com.sun.xml.bind.v2.runtime.reflect.Accessor;
053:        import com.sun.xml.bind.v2.runtime.unmarshaller.ChildLoader;
054:        import com.sun.xml.bind.v2.runtime.unmarshaller.TagName;
055:        import com.sun.xml.bind.v2.runtime.unmarshaller.Loader;
056:        import com.sun.xml.bind.v2.runtime.unmarshaller.Receiver;
057:        import com.sun.xml.bind.v2.runtime.unmarshaller.Scope;
058:        import com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext;
059:        import com.sun.xml.bind.v2.runtime.unmarshaller.XsiNilLoader;
060:
061:        import org.xml.sax.SAXException;
062:
063:        /**
064:         * Commonality between {@link ArrayElementProperty} and {@link ArrayReferenceNodeProperty}.
065:         *
066:         * Mostly handles the unmarshalling of the wrapper element.
067:         *
068:         * @author Kohsuke Kawaguchi
069:         */
070:        abstract class ArrayERProperty<BeanT, ListT, ItemT> extends
071:                ArrayProperty<BeanT, ListT, ItemT> {
072:
073:            /**
074:             * Wrapper tag name if any, or null.
075:             */
076:            protected final Name wrapperTagName;
077:
078:            /**
079:             * True if the wrapper tag name is nillable.
080:             * Always false if {@link #wrapperTagName}==null.
081:             */
082:            protected final boolean isWrapperNillable;
083:
084:            protected ArrayERProperty(JAXBContextImpl grammar,
085:                    RuntimePropertyInfo prop, QName tagName,
086:                    boolean isWrapperNillable) {
087:                super (grammar, prop);
088:                if (tagName == null)
089:                    this .wrapperTagName = null;
090:                else
091:                    this .wrapperTagName = grammar.nameBuilder
092:                            .createElementName(tagName);
093:                this .isWrapperNillable = isWrapperNillable;
094:            }
095:
096:            /**
097:             * Used to handle the collection wrapper element.
098:             */
099:            private static final class ItemsLoader extends Loader {
100:
101:                private final Accessor acc;
102:                private final Lister lister;
103:
104:                public ItemsLoader(Accessor acc, Lister lister,
105:                        QNameMap<ChildLoader> children) {
106:                    super (false);
107:                    this .acc = acc;
108:                    this .lister = lister;
109:                    this .children = children;
110:                }
111:
112:                @Override
113:                public void startElement(UnmarshallingContext.State state,
114:                        TagName ea) throws SAXException {
115:                    UnmarshallingContext context = state.getContext();
116:                    context.startScope(1);
117:                    // inherit the target so that our children can access its target
118:                    state.target = state.prev.target;
119:
120:                    // start it now, so that even if there's no children we can still return empty collection
121:                    context.getScope(0).start(acc, lister);
122:                }
123:
124:                private final QNameMap<ChildLoader> children;
125:
126:                @Override
127:                public void childElement(UnmarshallingContext.State state,
128:                        TagName ea) throws SAXException {
129:                    ChildLoader child = children.get(ea.uri, ea.local);
130:                    if (child != null) {
131:                        state.loader = child.loader;
132:                        state.receiver = child.receiver;
133:                    } else {
134:                        super .childElement(state, ea);
135:                    }
136:                }
137:
138:                @Override
139:                public void leaveElement(UnmarshallingContext.State state,
140:                        TagName ea) throws SAXException {
141:                    state.getContext().endScope(1);
142:                }
143:
144:                @Override
145:                public Collection<QName> getExpectedChildElements() {
146:                    return children.keySet();
147:                }
148:            }
149:
150:            public final void serializeBody(BeanT o, XMLSerializer w,
151:                    Object outerPeer) throws SAXException, AccessorException,
152:                    IOException, XMLStreamException {
153:                ListT list = acc.get(o);
154:
155:                if (list != null) {
156:                    if (wrapperTagName != null) {
157:                        w.startElement(wrapperTagName, null);
158:                        w.endNamespaceDecls(list);
159:                        w.endAttributes();
160:                    }
161:
162:                    serializeListBody(o, w, list);
163:
164:                    if (wrapperTagName != null)
165:                        w.endElement();
166:                } else {
167:                    // list is null
168:                    if (isWrapperNillable) {
169:                        w.startElement(wrapperTagName, null);
170:                        w.writeXsiNilTrue();
171:                        w.endElement();
172:                    } // otherwise don't print the wrapper tag name
173:                }
174:            }
175:
176:            /**
177:             * Serializses the items of the list.
178:             * This method is invoked after the necessary wrapper tag is produced (if necessary.)
179:             *
180:             * @param list
181:             *      always non-null.
182:             */
183:            protected abstract void serializeListBody(BeanT o, XMLSerializer w,
184:                    ListT list) throws IOException, XMLStreamException,
185:                    SAXException, AccessorException;
186:
187:            /**
188:             * Creates the unmarshaller to unmarshal the body.
189:             */
190:            protected abstract void createBodyUnmarshaller(
191:                    UnmarshallerChain chain, QNameMap<ChildLoader> loaders);
192:
193:            public final void buildChildElementUnmarshallers(
194:                    UnmarshallerChain chain, QNameMap<ChildLoader> loaders) {
195:                if (wrapperTagName != null) {
196:                    UnmarshallerChain c = new UnmarshallerChain(chain.context);
197:                    QNameMap<ChildLoader> m = new QNameMap<ChildLoader>();
198:                    createBodyUnmarshaller(c, m);
199:                    Loader loader = new ItemsLoader(acc, lister, m);
200:                    if (isWrapperNillable || chain.context.allNillable)
201:                        loader = new XsiNilLoader(loader);
202:                    loaders.put(wrapperTagName, new ChildLoader(loader, null));
203:                } else {
204:                    createBodyUnmarshaller(chain, loaders);
205:                }
206:            }
207:
208:            /**
209:             * {@link Receiver} that puts the child object into the {@link Scope} object.
210:             */
211:            protected final class ReceiverImpl implements  Receiver {
212:                private final int offset;
213:
214:                protected ReceiverImpl(int offset) {
215:                    this .offset = offset;
216:                }
217:
218:                public void receive(UnmarshallingContext.State state, Object o)
219:                        throws SAXException {
220:                    state.getContext().getScope(offset).add(acc, lister, o);
221:                }
222:            }
223:        }
ww_w_.j__a_v__a_2___s__.c__om___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.