1 /* |
1 /* |
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
97 } |
97 } |
98 |
98 |
99 @Override |
99 @Override |
100 public void startElement(UnmarshallingContext.State state, TagName ea) throws SAXException { |
100 public void startElement(UnmarshallingContext.State state, TagName ea) throws SAXException { |
101 UnmarshallingContext context = state.getContext(); |
101 UnmarshallingContext context = state.getContext(); |
102 if (state.target == null) |
102 if (state.getTarget() == null) |
103 state.target = new State(context); |
103 state.setTarget(new State(context)); |
104 |
104 |
105 State s = (State) state.target; |
105 State s = (State) state.getTarget(); |
106 try { |
106 try { |
107 s.declarePrefixes(context, context.getNewlyDeclaredPrefixes()); |
107 s.declarePrefixes(context, context.getNewlyDeclaredPrefixes()); |
108 s.handler.startElement(ea.uri, ea.local, ea.getQname(), ea.atts); |
108 s.handler.startElement(ea.uri, ea.local, ea.getQname(), ea.atts); |
109 } catch (SAXException e) { |
109 } catch (SAXException e) { |
110 context.handleError(e); |
110 context.handleError(e); |
112 } |
112 } |
113 } |
113 } |
114 |
114 |
115 @Override |
115 @Override |
116 public void childElement(UnmarshallingContext.State state, TagName ea) throws SAXException { |
116 public void childElement(UnmarshallingContext.State state, TagName ea) throws SAXException { |
117 state.loader = this; |
117 state.setLoader(this); |
118 State s = (State) state.prev.target; |
118 State s = (State) state.getPrev().getTarget(); |
119 s.depth++; |
119 s.depth++; |
120 state.target = s; |
120 state.setTarget(s); |
121 } |
121 } |
122 |
122 |
123 @Override |
123 @Override |
124 public void text(UnmarshallingContext.State state, CharSequence text) throws SAXException { |
124 public void text(UnmarshallingContext.State state, CharSequence text) throws SAXException { |
125 if(text.length()==0) |
125 if(text.length()==0) |
126 return; // there's no point in creating an empty Text node in DOM. |
126 return; // there's no point in creating an empty Text node in DOM. |
127 try { |
127 try { |
128 State s = (State) state.target; |
128 State s = (State) state.getTarget(); |
129 s.handler.characters(text.toString().toCharArray(),0,text.length()); |
129 s.handler.characters(text.toString().toCharArray(),0,text.length()); |
130 } catch( SAXException e ) { |
130 } catch( SAXException e ) { |
131 state.getContext().handleError(e); |
131 state.getContext().handleError(e); |
132 throw e; |
132 throw e; |
133 } |
133 } |
134 } |
134 } |
135 |
135 |
136 @Override |
136 @Override |
137 public void leaveElement(UnmarshallingContext.State state, TagName ea) throws SAXException { |
137 public void leaveElement(UnmarshallingContext.State state, TagName ea) throws SAXException { |
138 State s = (State) state.target; |
138 State s = (State) state.getTarget(); |
139 UnmarshallingContext context = state.getContext(); |
139 UnmarshallingContext context = state.getContext(); |
140 |
140 |
141 try { |
141 try { |
142 s.handler.endElement(ea.uri, ea.local, ea.getQname()); |
142 s.handler.endElement(ea.uri, ea.local, ea.getQname()); |
143 s.undeclarePrefixes(context.getNewlyDeclaredPrefixes()); |
143 s.undeclarePrefixes(context.getNewlyDeclaredPrefixes()); |