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