src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/property/SingleMapNodeProperty.java

changeset 707
31893650acaf
parent 650
121e938cb9c3
child 760
e530533619ec
equal deleted inserted replaced
706:1e9d08d74c48 707:31893650acaf
1 /* 1 /*
2 * Copyright (c) 1997, 2011, 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
146 146
147 @Override 147 @Override
148 public void startElement(UnmarshallingContext.State state, TagName ea) throws SAXException { 148 public void startElement(UnmarshallingContext.State state, TagName ea) throws SAXException {
149 // create or obtain the Map object 149 // create or obtain the Map object
150 try { 150 try {
151 target.set((BeanT)state.prev.target); 151 target.set((BeanT)state.getPrev().getTarget());
152 map.set(acc.get(target.get())); 152 map.set(acc.get(target.get()));
153 depthCounter++; 153 depthCounter++;
154 if(map.get() == null) { 154 if(map.get() == null) {
155 map.set(ClassFactory.create(mapImplClass)); 155 map.set(ClassFactory.create(mapImplClass));
156 } 156 }
157 map.get().clear(); 157 map.get().clear();
158 state.target = map.get(); 158 state.setTarget(map.get());
159 } catch (AccessorException e) { 159 } catch (AccessorException e) {
160 // recover from error by setting a dummy Map that receives and discards the values 160 // recover from error by setting a dummy Map that receives and discards the values
161 handleGenericException(e,true); 161 handleGenericException(e,true);
162 state.target = new HashMap(); 162 state.setTarget(new HashMap());
163 } 163 }
164 } 164 }
165 165
166 @Override 166 @Override
167 public void leaveElement(State state, TagName ea) throws SAXException { 167 public void leaveElement(State state, TagName ea) throws SAXException {
178 } 178 }
179 179
180 @Override 180 @Override
181 public void childElement(UnmarshallingContext.State state, TagName ea) throws SAXException { 181 public void childElement(UnmarshallingContext.State state, TagName ea) throws SAXException {
182 if(ea.matches(entryTag)) { 182 if(ea.matches(entryTag)) {
183 state.loader = entryLoader; 183 state.setLoader(entryLoader);
184 } else { 184 } else {
185 super.childElement(state,ea); 185 super.childElement(state,ea);
186 } 186 }
187 } 187 }
188 188
198 * The target will be set to a {@link Map}. 198 * The target will be set to a {@link Map}.
199 */ 199 */
200 private final Loader entryLoader = new Loader(false) { 200 private final Loader entryLoader = new Loader(false) {
201 @Override 201 @Override
202 public void startElement(UnmarshallingContext.State state, TagName ea) { 202 public void startElement(UnmarshallingContext.State state, TagName ea) {
203 state.target = new Object[2]; // this is inefficient 203 state.setTarget(new Object[2]); // this is inefficient
204 } 204 }
205 205
206 @Override 206 @Override
207 public void leaveElement(UnmarshallingContext.State state, TagName ea) { 207 public void leaveElement(UnmarshallingContext.State state, TagName ea) {
208 Object[] keyValue = (Object[])state.target; 208 Object[] keyValue = (Object[])state.getTarget();
209 Map map = (Map) state.prev.target; 209 Map map = (Map) state.getPrev().getTarget();
210 map.put(keyValue[0],keyValue[1]); 210 map.put(keyValue[0],keyValue[1]);
211 } 211 }
212 212
213 @Override 213 @Override
214 public void childElement(UnmarshallingContext.State state, TagName ea) throws SAXException { 214 public void childElement(UnmarshallingContext.State state, TagName ea) throws SAXException {
215 if(ea.matches(keyTag)) { 215 if(ea.matches(keyTag)) {
216 state.loader = keyLoader; 216 state.setLoader(keyLoader);
217 state.receiver = keyReceiver; 217 state.setReceiver(keyReceiver);
218 return; 218 return;
219 } 219 }
220 if(ea.matches(valueTag)) { 220 if(ea.matches(valueTag)) {
221 state.loader = valueLoader; 221 state.setLoader(valueLoader);
222 state.receiver = valueReceiver; 222 state.setReceiver(valueReceiver);
223 return; 223 return;
224 } 224 }
225 super.childElement(state,ea); 225 super.childElement(state,ea);
226 } 226 }
227 227
235 private final int index; 235 private final int index;
236 public ReceiverImpl(int index) { 236 public ReceiverImpl(int index) {
237 this.index = index; 237 this.index = index;
238 } 238 }
239 public void receive(UnmarshallingContext.State state, Object o) { 239 public void receive(UnmarshallingContext.State state, Object o) {
240 ((Object[])state.target)[index] = o; 240 ((Object[])state.getTarget())[index] = o;
241 } 241 }
242 } 242 }
243 243
244 private static final Receiver keyReceiver = new ReceiverImpl(0); 244 private static final Receiver keyReceiver = new ReceiverImpl(0);
245 private static final Receiver valueReceiver = new ReceiverImpl(1); 245 private static final Receiver valueReceiver = new ReceiverImpl(1);

mercurial