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 |
77 |
77 |
78 private final Loader itemLoader; |
78 private final Loader itemLoader; |
79 |
79 |
80 @Override |
80 @Override |
81 public void startElement(UnmarshallingContext.State state, TagName ea) { |
81 public void startElement(UnmarshallingContext.State state, TagName ea) { |
82 state.target = new ArrayList(); |
82 state.setTarget(new ArrayList()); |
83 } |
83 } |
84 |
84 |
85 @Override |
85 @Override |
86 public void leaveElement(UnmarshallingContext.State state, TagName ea) { |
86 public void leaveElement(UnmarshallingContext.State state, TagName ea) { |
87 state.target = toArray((List)state.target); |
87 state.setTarget(toArray((List)state.getTarget())); |
88 } |
88 } |
89 |
89 |
90 @Override |
90 @Override |
91 public void childElement(UnmarshallingContext.State state, TagName ea) throws SAXException { |
91 public void childElement(UnmarshallingContext.State state, TagName ea) throws SAXException { |
92 if(ea.matches("","item")) { |
92 if(ea.matches("","item")) { |
93 state.loader = itemLoader; |
93 state.setLoader(itemLoader); |
94 state.receiver = this; |
94 state.setReceiver(this); |
95 } else { |
95 } else { |
96 super.childElement(state,ea); |
96 super.childElement(state,ea); |
97 } |
97 } |
98 } |
98 } |
99 |
99 |
101 public Collection<QName> getExpectedChildElements() { |
101 public Collection<QName> getExpectedChildElements() { |
102 return Collections.singleton(new QName("","item")); |
102 return Collections.singleton(new QName("","item")); |
103 } |
103 } |
104 |
104 |
105 public void receive(UnmarshallingContext.State state, Object o) { |
105 public void receive(UnmarshallingContext.State state, Object o) { |
106 ((List)state.target).add(o); |
106 ((List)state.getTarget()).add(o); |
107 } |
107 } |
108 }; |
108 } |
109 |
109 |
110 protected Object toArray( List list ) { |
110 protected Object toArray( List list ) { |
111 int len = list.size(); |
111 int len = list.size(); |
112 Object array = Array.newInstance(itemType,len); |
112 Object array = Array.newInstance(itemType,len); |
113 for( int i=0; i<len; i++ ) |
113 for( int i=0; i<len; i++ ) |