001: /*
002: * Copyright 1999-2004 The Apache Software Foundation
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.apache.commons.jxpath.ri.model.beans;
017:
018: import org.apache.commons.jxpath.ri.QName;
019: import org.apache.commons.jxpath.ri.compiler.NodeTest;
020: import org.apache.commons.jxpath.ri.model.NodePointer;
021:
022: /**
023: * A Pointer that points to the "lang" attribute of a JavaBean. The value
024: * of the attribute is based on the locale supplied to it in the constructor.
025: *
026: * @author Dmitri Plotnikov
027: * @version $Revision: 1.13 $ $Date: 2004/04/01 02:55:32 $
028: */
029: public class LangAttributePointer extends NodePointer {
030: public LangAttributePointer(NodePointer parent) {
031: super (parent);
032: }
033:
034: public QName getName() {
035: return new QName("xml", "lang");
036: }
037:
038: public String getNamespaceURI() {
039: return null;
040: }
041:
042: public boolean isCollection() {
043: return false;
044: }
045:
046: public int getLength() {
047: return 1;
048: }
049:
050: public Object getBaseValue() {
051: return parent.getLocale().toString().replace('_', '-');
052: }
053:
054: public Object getImmediateNode() {
055: return getBaseValue();
056: }
057:
058: public boolean isLeaf() {
059: return true;
060: }
061:
062: /**
063: * Throws UnsupportedOperationException.
064: */
065: public void setValue(Object value) {
066: throw new UnsupportedOperationException(
067: "Cannot change locale using the 'lang' attribute");
068: }
069:
070: /**
071: */
072: public String asPath() {
073: StringBuffer buffer = new StringBuffer();
074: if (parent != null) {
075: buffer.append(parent.asPath());
076: if (buffer.length() == 0
077: || buffer.charAt(buffer.length() - 1) != '/') {
078: buffer.append('/');
079: }
080: }
081: buffer.append("@xml:lang");
082: return buffer.toString();
083: }
084:
085: public int hashCode() {
086: return 0;
087: }
088:
089: public boolean equals(Object object) {
090: if (object == this ) {
091: return true;
092: }
093:
094: if (!(object instanceof LangAttributePointer)) {
095: return false;
096: }
097:
098: return true;
099: }
100:
101: public boolean testNode(NodeTest test) {
102: return false;
103: }
104:
105: public int compareChildNodePointers(NodePointer pointer1,
106: NodePointer pointer2) {
107: // Won't happen - lang attributes don't have children
108: return 0;
109: }
110: }
|