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.schema; 23 24 import org.apache.openoffice.ooxml.schema.model.attribute.Attribute; 25 import org.apache.openoffice.ooxml.schema.model.attribute.AttributeGroup; 26 import org.apache.openoffice.ooxml.schema.model.base.Node; 27 import org.apache.openoffice.ooxml.schema.model.base.QualifiedName; 28 import org.apache.openoffice.ooxml.schema.model.complex.ComplexType; 29 import org.apache.openoffice.ooxml.schema.model.complex.Element; 30 import org.apache.openoffice.ooxml.schema.model.complex.Group; 31 import org.apache.openoffice.ooxml.schema.model.simple.SimpleType; 32 33 /** Front end of a shared SchemaBase object of a single master schema file (such 34 * as wml.xsd). 35 * Most important member is the TopLevelElements list of top level elements, 36 * which are unique to each master schema. 37 */ 38 public class Schema 39 { Schema( final String sShortName, final SchemaBase aBase)40 public Schema ( 41 final String sShortName, 42 final SchemaBase aBase) 43 { 44 msShortName = sShortName; 45 TopLevelElements = new TypeContainer<>(); 46 47 Namespaces = aBase.Namespaces; 48 ComplexTypes = aBase.ComplexTypes; 49 SimpleTypes = aBase.SimpleTypes; 50 Groups = aBase.Groups; 51 AttributeGroups = aBase.AttributeGroups; 52 Attributes = aBase.Attributes; 53 } 54 55 56 57 GetTypeForName(final QualifiedName aName)58 public Node GetTypeForName (final QualifiedName aName) 59 { 60 final String sTypeName = aName.GetDisplayName(); 61 62 if (ComplexTypes.Contains(sTypeName)) 63 return ComplexTypes.Get(sTypeName); 64 else if (SimpleTypes.Contains(sTypeName)) 65 return SimpleTypes.Get(sTypeName); 66 else if (Groups.Contains(sTypeName)) 67 return Groups.Get(sTypeName); 68 else if (TopLevelElements.Contains(sTypeName)) 69 return TopLevelElements.Get(sTypeName); 70 else 71 return null; 72 } 73 74 75 76 GetShortName()77 public String GetShortName () 78 { 79 return msShortName; 80 } 81 82 83 84 GetOptimizedSchema(final SchemaBase aSchemaBase)85 public Schema GetOptimizedSchema (final SchemaBase aSchemaBase) 86 { 87 final Schema aOptimizedSchema = new Schema(msShortName, aSchemaBase); 88 for (final Element aElement : TopLevelElements.GetUnsorted()) 89 { 90 aOptimizedSchema.TopLevelElements.Add(aElement); 91 } 92 93 return aOptimizedSchema; 94 } 95 96 97 98 99 private final String msShortName; 100 public final TypeContainer<Element> TopLevelElements; 101 public final NamespaceMap Namespaces; 102 public final TypeContainer<ComplexType> ComplexTypes; 103 public final TypeContainer<SimpleType> SimpleTypes; 104 public final TypeContainer<Group> Groups; 105 public final TypeContainer<AttributeGroup> AttributeGroups; 106 public final TypeContainer<Attribute> Attributes; 107 } 108