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.attribute; 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.NodeType; 29 import org.apache.openoffice.ooxml.schema.model.base.QualifiedName; 30 import org.apache.openoffice.ooxml.schema.model.schema.SchemaBase; 31 import org.apache.openoffice.ooxml.schema.parser.FormDefault; 32 33 public class AttributeReference 34 extends AttributeBase 35 implements INodeReference 36 { AttributeReference( final QualifiedName aReferencedName, final String sUse, final String sDefault, final String sFixed, final FormDefault eFormDefault, final Location aLocation)37 public AttributeReference ( 38 final QualifiedName aReferencedName, 39 final String sUse, 40 final String sDefault, 41 final String sFixed, 42 final FormDefault eFormDefault, 43 final Location aLocation) 44 { 45 super(aReferencedName, sUse, sDefault, sFixed, eFormDefault, aLocation); 46 47 maReferencedName = aReferencedName; 48 } 49 50 51 52 GetReferencedAttribute(final SchemaBase aSchemaBase)53 public Attribute GetReferencedAttribute (final SchemaBase aSchemaBase) 54 { 55 final Attribute aAttribute = aSchemaBase.Attributes.Get(maReferencedName); 56 if (aAttribute == null) 57 { 58 throw new RuntimeException( 59 String.format( 60 "can not find attribute %s, referenced at %s", 61 maReferencedName.GetDisplayName(), 62 GetLocation())); 63 } 64 return aAttribute; 65 } 66 67 68 69 70 @Override GetReferencedNode(final SchemaBase aSchemaBase)71 public INode GetReferencedNode (final SchemaBase aSchemaBase) 72 { 73 return GetReferencedAttribute(aSchemaBase); 74 } 75 76 77 78 GetReferencedName()79 public QualifiedName GetReferencedName () 80 { 81 return maReferencedName; 82 } 83 84 85 86 87 @Override GetNodeType()88 public NodeType GetNodeType () 89 { 90 return NodeType.AttributeReference; 91 } 92 93 94 95 96 @Override AcceptVisitor(INodeVisitor aVisitor)97 public void AcceptVisitor(INodeVisitor aVisitor) 98 { 99 aVisitor.Visit(this); 100 } 101 102 103 104 105 @Override toString()106 public String toString () 107 { 108 return "attribute reference to "+maReferencedName; 109 } 110 111 112 113 114 private final QualifiedName maReferencedName; 115 } 116