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.simple;
23 
24 import java.io.File;
25 import java.util.Map;
26 import java.util.Map.Entry;
27 import java.util.TreeMap;
28 
29 import org.apache.openoffice.ooxml.schema.misc.Log;
30 import org.apache.openoffice.ooxml.schema.model.schema.SchemaBase;
31 import org.apache.openoffice.ooxml.schema.model.simple.SimpleType;
32 
33 public class SimpleTypeContainer
34 {
Create( final SchemaBase aSchemaBase, final File aLogFile)35     public static SimpleTypeContainer Create (
36         final SchemaBase aSchemaBase,
37         final File aLogFile)
38     {
39         final SimpleTypeContainer aContainer = new SimpleTypeContainer(aLogFile);
40         for (final SimpleType aType : aSchemaBase.SimpleTypes.GetSorted())
41         {
42             aContainer.ProcessSimpleType(aType, aSchemaBase);
43         }
44         return aContainer;
45     }
46 
47 
48 
49 
GetSimpleTypeCount()50     public int GetSimpleTypeCount ()
51     {
52         return maSimpleTypes.size();
53     }
54 
55 
56 
57 
GetSimpleTypes()58     public Iterable<Entry<String,SimpleTypeDescriptor>> GetSimpleTypes ()
59     {
60         return maSimpleTypes.entrySet();
61     }
62 
63 
64 
65 
GetSimpleTypesSorted()66     public Iterable<Entry<String,SimpleTypeDescriptor>> GetSimpleTypesSorted ()
67     {
68         final Map<String,SimpleTypeDescriptor> aSortedSimpleTypes = new TreeMap<>();
69         aSortedSimpleTypes.putAll(maSimpleTypes);
70         return aSortedSimpleTypes.entrySet();
71     }
72 
73 
74 
75 
SimpleTypeContainer(final File aLogFile)76     private SimpleTypeContainer (final File aLogFile)
77     {
78         maSimpleTypes = new TreeMap<>();
79         maLog = new Log(aLogFile);
80     }
81 
82 
83 
84 
ProcessSimpleType( final SimpleType aType, final SchemaBase aSchemaBase)85     private void ProcessSimpleType (
86         final SimpleType aType,
87         final SchemaBase aSchemaBase)
88     {
89         maSimpleTypes.put(
90             aType.GetName().GetStateName(),
91             SimpleTypeDescriptorFactory.CreateSimpleTypeDescriptor(
92                 aType,
93                 aSchemaBase,
94                 maLog));
95     }
96 
97 
98 
99 
100     private final Map<String,SimpleTypeDescriptor> maSimpleTypes;
101     private final Log maLog;
102 }
103