001/*
002 *  Copyright 2012 Anyware Services
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
017package org.ametys.core.util.dom;
018
019import org.w3c.dom.Attr;
020import org.w3c.dom.DOMException;
021import org.w3c.dom.Element;
022import org.w3c.dom.Node;
023import org.w3c.dom.TypeInfo;
024
025/**
026 * Implementation of {@link Attr} for an AmetysObject's metadata.
027 */
028public class AmetysAttribute extends AbstractAmetysNode implements Attr
029{
030    private String _localName;
031    private String _value;
032    private String _qName;
033    private String _namespace;
034    private Element _ownerElement;
035    
036    /**
037     * Constructor.
038     * @param localName local name fir this attribute.
039     * @param qName qualified name for this attribute.
040     * @param namespaceURI namespace URI for this attribute.
041     * @param value attribute's value.
042     * @param ownerElement the owner {@link Element}.
043     */
044    public AmetysAttribute(String localName, String qName, String namespaceURI, String value, Element ownerElement)
045    {
046        _localName = localName;
047        _value = value;
048        _qName = qName;
049        _namespace = namespaceURI;
050        _ownerElement = ownerElement;
051    }
052    
053    @Override
054    public short getNodeType()
055    {
056        return Node.ATTRIBUTE_NODE;
057    }
058
059    @Override
060    public String getName()
061    {
062        return _qName;
063    }
064    
065    @Override
066    public boolean getSpecified()
067    {
068        return true;
069    }
070
071    @Override
072    public String getValue()
073    {
074        return _value;
075    }
076    
077    @Override
078    public String getNodeValue() throws DOMException
079    {
080        return getValue();
081    }
082
083    @Override
084    public Element getOwnerElement()
085    {
086        return _ownerElement;
087    }
088
089    @Override
090    public String getNodeName()
091    {
092        return getName();
093    }
094
095    @Override
096    public String getTextContent() throws DOMException
097    {
098        return getValue();
099    }
100    
101    @Override
102    public String getLocalName()
103    {
104        return _localName;
105    }
106    
107    @Override
108    public String getNamespaceURI()
109    {
110        return _namespace;
111    }
112
113    @Override
114    public void setValue(String value) throws DOMException
115    {
116        throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "setValue");
117    }
118
119    @Override
120    public TypeInfo getSchemaTypeInfo()
121    {
122        throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "getSchemaTypeInfo");
123    }
124
125    @Override
126    public boolean isId()
127    {
128        throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "isId");
129    }
130}