01: /*
02: * Copyright 1999-2004 The Apache Software Foundation
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.apache.commons.jxpath.ri.model.beans;
17:
18: import org.apache.commons.jxpath.ri.QName;
19: import org.apache.commons.jxpath.ri.model.NodePointer;
20:
21: /**
22: * An iterator of attributes of a JavaBean. Returns bean properties as
23: * well as the "xml:lang" attribute.
24: *
25: * @author Dmitri Plotnikov
26: * @version $Revision: 1.8 $ $Date: 2004/02/29 14:17:41 $
27: */
28: public class BeanAttributeIterator extends PropertyIterator {
29: private NodePointer parent;
30: private int position = 0;
31: private boolean includeXmlLang;
32:
33: public BeanAttributeIterator(PropertyOwnerPointer parent, QName name) {
34: super (
35: parent,
36: (name.getPrefix() == null && (name.getName() == null || name
37: .getName().equals("*"))) ? null : name
38: .toString(), false, null);
39: this .parent = parent;
40: includeXmlLang = (name.getPrefix() != null && name.getPrefix()
41: .equals("xml"))
42: && (name.getName().equals("lang") || name.getName()
43: .equals("*"));
44: }
45:
46: public NodePointer getNodePointer() {
47: if (includeXmlLang && position == 1) {
48: return new LangAttributePointer(parent);
49: } else {
50: return super .getNodePointer();
51: }
52: }
53:
54: public int getPosition() {
55: return position;
56: }
57:
58: public boolean setPosition(int position) {
59: this .position = position;
60: if (includeXmlLang) {
61: if (position == 1) {
62: return true;
63: } else {
64: return super .setPosition(position - 1);
65: }
66: } else {
67: this.position = position;
68: return super.setPosition(position);
69: }
70: }
71: }
|