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.compiler.NodeTest;
  19. import org.apache.commons.jxpath.ri.model.NodePointer;
  20. /**
  21. * A Pointer that points to the "lang" attribute of a JavaBean. The value
  22. * of the attribute is based on the locale supplied to it in the constructor.
  23. *
  24. * @author Dmitri Plotnikov
  25. * @version $Revision: 1.13 $ $Date: 2004/04/01 02:55:32 $
  26. */
  27. public class LangAttributePointer extends NodePointer {
  28. public LangAttributePointer(NodePointer parent) {
  29. super(parent);
  30. }
  31. public QName getName() {
  32. return new QName("xml", "lang");
  33. }
  34. public String getNamespaceURI() {
  35. return null;
  36. }
  37. public boolean isCollection() {
  38. return false;
  39. }
  40. public int getLength() {
  41. return 1;
  42. }
  43. public Object getBaseValue() {
  44. return parent.getLocale().toString().replace('_', '-');
  45. }
  46. public Object getImmediateNode() {
  47. return getBaseValue();
  48. }
  49. public boolean isLeaf() {
  50. return true;
  51. }
  52. /**
  53. * Throws UnsupportedOperationException.
  54. */
  55. public void setValue(Object value) {
  56. throw new UnsupportedOperationException(
  57. "Cannot change locale using the 'lang' attribute");
  58. }
  59. /**
  60. */
  61. public String asPath() {
  62. StringBuffer buffer = new StringBuffer();
  63. if (parent != null) {
  64. buffer.append(parent.asPath());
  65. if (buffer.length() == 0
  66. || buffer.charAt(buffer.length() - 1) != '/') {
  67. buffer.append('/');
  68. }
  69. }
  70. buffer.append("@xml:lang");
  71. return buffer.toString();
  72. }
  73. public int hashCode() {
  74. return 0;
  75. }
  76. public boolean equals(Object object) {
  77. if (object == this) {
  78. return true;
  79. }
  80. if (!(object instanceof LangAttributePointer)) {
  81. return false;
  82. }
  83. return true;
  84. }
  85. public boolean testNode(NodeTest test) {
  86. return false;
  87. }
  88. public int compareChildNodePointers(
  89. NodePointer pointer1,
  90. NodePointer pointer2)
  91. {
  92. // Won't happen - lang attributes don't have children
  93. return 0;
  94. }
  95. }