/*
 * JBoss, Home of Professional Open Source
 * Copyright 2011, Red Hat, Inc. and/or its affiliates, and individual
 * contributors by the @authors tag. See the copyright.txt in the
 * distribution for a full listing of individual contributors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jboss.solder.config.xml.parser;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * represents an XML element
 *
 * @author Stuart Douglas <stuart@baileyroberts.com.au>
 */
public class SaxNode {

    public SaxNode(String name, String uri, Map<String, String> attributes, SaxNode parent, String document, int lineNo) {
        this.name = name;
        this.namespaceUri = uri;
        this.attributes = attributes;
        this.parent = parent;
        this.document = document;
        this.lineNo = lineNo;
    }

    String innerText;
    final String namespaceUri;
    final String name;
    final Map<String, String> attributes;
    final String document;
    final int lineNo;
    List<SaxNode> children = new ArrayList<SaxNode>();
    final SaxNode parent;

    public String getInnerText() {
        if (innerText != null && innerText.length() == 0) {
            return null;
        }
        return innerText;
    }

    public void setInnerText(String innerText) {
        this.innerText = innerText.trim();
    }

    public String getNamespaceUri() {
        return namespaceUri;
    }

    public String getName() {
        return name;
    }

    public Map<String, String> getAttributes() {
        return attributes;
    }

    public String getDocument() {
        return document;
    }

    public int getLineNo() {
        return lineNo;
    }

    public void addChild(SaxNode node) {
        this.children.add(node);
    }

    public List<SaxNode> getChildren() {
        return Collections.unmodifiableList(children);
    }

    public SaxNode getParent() {
        return parent;
    }

}
