001/**
002 * Copyright 2010-2015 The Kuali Foundation
003 *
004 * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
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 */
016package org.kuali.common.jute.tree;
017
018import static com.google.common.base.Preconditions.checkNotNull;
019
020import java.util.List;
021
022public final class ImmutableNode<T> extends MutableNode<T> {
023
024        private static final String UOE_MSG = "not supported for immutable node's";
025
026        public static <T> ImmutableNode<T> copyOf(Node<T> node) {
027                if (node instanceof ImmutableNode) {
028                        return (ImmutableNode<T>) node;
029                } else {
030                        return new ImmutableNode<T>(node);
031                }
032        }
033
034        public ImmutableNode(Node<T> node) {
035                checkNotNull(node);
036                super.setElement(node.getElement());
037                List<Node<T>> children = node.getChildren();
038                for (Node<T> child : children) {
039                        super.add(children.size(), copyOf(child));
040                }
041        }
042
043        @Override
044        public void setElement(T element) {
045                throw new UnsupportedOperationException(UOE_MSG);
046        }
047
048        @Override
049        public void add(List<MutableNode<T>> children) {
050                throw new UnsupportedOperationException(UOE_MSG);
051        }
052
053        @Override
054        public void add(MutableNode<T> child1, MutableNode<T> child2) {
055                throw new UnsupportedOperationException(UOE_MSG);
056        }
057
058        @Override
059        public void add(MutableNode<T> child1, MutableNode<T> child2, MutableNode<T> child3) {
060                throw new UnsupportedOperationException(UOE_MSG);
061        }
062
063        @Override
064        public void add(MutableNode<T> child1, MutableNode<T> child2, MutableNode<T> child3, MutableNode<T> child4) {
065                throw new UnsupportedOperationException(UOE_MSG);
066        }
067
068        @Override
069        public void add(MutableNode<T> child1, MutableNode<T> child2, MutableNode<T> child3, MutableNode<T> child4, MutableNode<T> child5) {
070                throw new UnsupportedOperationException(UOE_MSG);
071        }
072
073        @Override
074        public void add(MutableNode<T> child) {
075                throw new UnsupportedOperationException(UOE_MSG);
076        }
077
078        @Override
079        public void add(int index, MutableNode<T> child) {
080                throw new UnsupportedOperationException(UOE_MSG);
081        }
082
083        @Override
084        public void remove(MutableNode<T> child) {
085                throw new UnsupportedOperationException(UOE_MSG);
086        }
087
088        @Override
089        public void remove(int index) {
090                throw new UnsupportedOperationException(UOE_MSG);
091        }
092
093        @Override
094        public void removeAllChildren() {
095                throw new UnsupportedOperationException(UOE_MSG);
096        }
097
098        @Override
099        public void removeFromParent() {
100                throw new UnsupportedOperationException(UOE_MSG);
101        }
102
103}