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.complex; 23 24 import org.apache.openoffice.ooxml.schema.model.base.INode; 25 import org.apache.openoffice.ooxml.schema.model.base.INodeReference; 26 import org.apache.openoffice.ooxml.schema.model.base.INodeVisitor; 27 import org.apache.openoffice.ooxml.schema.model.base.Location; 28 import org.apache.openoffice.ooxml.schema.model.base.Node; 29 import org.apache.openoffice.ooxml.schema.model.base.NodeType; 30 import org.apache.openoffice.ooxml.schema.model.base.QualifiedName; 31 import org.apache.openoffice.ooxml.schema.model.schema.SchemaBase; 32 33 public class ElementReference 34 extends Element 35 implements INodeReference 36 { ElementReference( final Node aParent, final QualifiedName aReferencedElementName, final Location aLocation)37 public ElementReference ( 38 final Node aParent, 39 final QualifiedName aReferencedElementName, 40 final Location aLocation) 41 { 42 super(aParent, null, null, aLocation); 43 44 maReferencedElementName = aReferencedElementName; 45 } 46 47 48 49 GetReferencedElementName()50 public QualifiedName GetReferencedElementName () 51 { 52 return maReferencedElementName; 53 } 54 55 56 57 GetReferencedElement(final SchemaBase aSchema)58 public Element GetReferencedElement (final SchemaBase aSchema) 59 { 60 final Element aElement = aSchema.TopLevelElements.Get(maReferencedElementName); 61 if (aElement == null) 62 throw new RuntimeException("can not find element "+maReferencedElementName.GetDisplayName()); 63 return aElement; 64 } 65 66 67 68 69 @Override GetReferencedNode(final SchemaBase aSchema)70 public INode GetReferencedNode (final SchemaBase aSchema) 71 { 72 return GetReferencedElement(aSchema); 73 } 74 75 76 77 78 @Override GetNodeType()79 public NodeType GetNodeType () 80 { 81 return NodeType.ElementReference; 82 } 83 84 85 86 87 @Override AcceptVisitor(final INodeVisitor aVisitor)88 public void AcceptVisitor (final INodeVisitor aVisitor) 89 { 90 aVisitor.Visit(this); 91 } 92 93 94 95 96 @Override toString()97 public String toString () 98 { 99 return "element reference to "+maReferencedElementName.GetDisplayName(); 100 } 101 102 103 104 105 private final QualifiedName maReferencedElementName; 106 } 107