1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 package org.apache.openoffice.ooxml.schema.model.base; 23 24 import java.util.Vector; 25 26 /** Base class for the nodes in the type hierarchies that represent complex 27 * types, simple types, and attributes. 28 */ 29 public abstract class Node 30 implements INode, Comparable<Node> 31 { GetNodeType()32 abstract public NodeType GetNodeType (); 33 34 35 Node( final Node aParent, final QualifiedName aName, final Location aLocation)36 protected Node ( 37 final Node aParent, 38 final QualifiedName aName, 39 final Location aLocation) 40 { 41 maParent = aParent; 42 maName = aName; 43 44 maLocation = aLocation; 45 maAttributes = new Vector<>(); 46 maChildren = new Vector<>(); 47 } 48 49 50 51 52 @Override GetName()53 public QualifiedName GetName () 54 { 55 return maName; 56 } 57 58 59 60 GetParent()61 public Node GetParent () 62 { 63 return maParent; 64 } 65 66 67 68 69 /** Store the location in the schema files. This is used for debugging or the creation of documentation. 70 */ SetLocation( final Location aLocation)71 public void SetLocation ( 72 final Location aLocation) 73 { 74 maLocation = aLocation; 75 } 76 77 78 79 GetLocation()80 public Location GetLocation () 81 { 82 return maLocation; 83 } 84 85 86 87 AddAttribute(final INode aAttribute)88 public void AddAttribute (final INode aAttribute) 89 { 90 maAttributes.add(aAttribute); 91 } 92 93 94 95 96 @Override GetAttributeCount()97 public int GetAttributeCount () 98 { 99 return maAttributes.size(); 100 } 101 102 103 104 105 @Override GetAttributes()106 public Iterable<INode> GetAttributes () 107 { 108 return maAttributes; 109 } 110 111 112 ClearChildren()113 public void ClearChildren () 114 { 115 maChildren.clear(); 116 } 117 118 119 AddChild(final INode aChild)120 public void AddChild (final INode aChild) 121 { 122 maChildren.add(aChild); 123 } 124 125 126 127 GetChildren()128 public Iterable<INode> GetChildren () 129 { 130 return maChildren; 131 } 132 133 134 135 GetOnlyChild()136 public INode GetOnlyChild () 137 { 138 assert(maChildren.size() == 1); 139 return maChildren.get(0); 140 } 141 142 143 144 GetChildCount()145 public int GetChildCount () 146 { 147 return maChildren.size(); 148 } 149 150 151 152 153 @Override compareTo(final Node aOther)154 public int compareTo (final Node aOther) 155 { 156 if (maName==null || aOther.maName==null) 157 { 158 throw new RuntimeException("can not compare nodes that don't have a name"); 159 } 160 else 161 return maName.compareTo(aOther.maName); 162 } 163 164 165 166 167 private final Node maParent; 168 private final QualifiedName maName; 169 private Location maLocation; 170 private final Vector<INode> maAttributes; 171 private final Vector<INode> maChildren; 172 } 173