1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  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. import org.apache.commons.jxpath.ri.QName;
  18. import org.apache.commons.jxpath.ri.model.NodePointer;
  19. /**
  20. * An iterator of attributes of a JavaBean. Returns bean properties as
  21. * well as the "xml:lang" attribute.
  22. *
  23. * @author Dmitri Plotnikov
  24. * @version $Revision: 1.8 $ $Date: 2004/02/29 14:17:41 $
  25. */
  26. public class BeanAttributeIterator extends PropertyIterator {
  27. private NodePointer parent;
  28. private int position = 0;
  29. private boolean includeXmlLang;
  30. public BeanAttributeIterator(PropertyOwnerPointer parent, QName name) {
  31. super(
  32. parent,
  33. (name.getPrefix() == null
  34. && (name.getName() == null || name.getName().equals("*")))
  35. ? null
  36. : name.toString(),
  37. false,
  38. null);
  39. this.parent = parent;
  40. includeXmlLang =
  41. (name.getPrefix() != null && name.getPrefix().equals("xml"))
  42. && (name.getName().equals("lang")
  43. || name.getName().equals("*"));
  44. }
  45. public NodePointer getNodePointer() {
  46. if (includeXmlLang && position == 1) {
  47. return new LangAttributePointer(parent);
  48. }
  49. else {
  50. return super.getNodePointer();
  51. }
  52. }
  53. public int getPosition() {
  54. return position;
  55. }
  56. public boolean setPosition(int position) {
  57. this.position = position;
  58. if (includeXmlLang) {
  59. if (position == 1) {
  60. return true;
  61. }
  62. else {
  63. return super.setPosition(position - 1);
  64. }
  65. }
  66. else {
  67. this.position = position;
  68. return super.setPosition(position);
  69. }
  70. }
  71. }