Modified: 
openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/parser/SchemaParser.java
URL: 
http://svn.apache.org/viewvc/openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/parser/SchemaParser.java?rev=1603154&r1=1603153&r2=1603154&view=diff
==============================================================================
--- 
openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/parser/SchemaParser.java
 (original)
+++ 
openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/parser/SchemaParser.java
 Tue Jun 17 13:01:38 2014
@@ -688,9 +688,10 @@ public class SchemaParser
     {
         assert(HasOnlyAttributes("base", "value"));
 
+        final String sBaseType = GetAttributeValue("base");
         final Restriction aRestriction = new Restriction(
             aParent,
-            GetAttributeValue("base"),
+            CreateQualifiedName(sBaseType),
             GetLocation());
         
         while (true)
@@ -827,7 +828,7 @@ public class SchemaParser
                             break;
                             
                         case "restriction":
-                            aType.SetRestriction(ParseRestriction(aType));
+                            aType.AddChild(ParseRestriction(aType));
                             break;
 
                         case "union":
@@ -908,10 +909,10 @@ public class SchemaParser
         if (sFilename == null)
         {
             final String sNamespaceName = GetAttributeValue("namespace");
-            if (sNamespaceName.equals(XmlNamespace.NamespaceURI))
+            if (sNamespaceName.equals(XmlNamespace.URI))
             {
                 XmlNamespace.Apply(maSchemaBase);
-                maLocalNamespaceMap.put(XmlNamespace.NamespacePrefix, 
XmlNamespace.NamespaceURI);
+                maLocalNamespaceMap.put(XmlNamespace.Prefix, XmlNamespace.URI);
             }
             else
                 throw CreateErrorException("invalid import");

Modified: 
openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/parser/XmlNamespace.java
URL: 
http://svn.apache.org/viewvc/openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/parser/XmlNamespace.java?rev=1603154&r1=1603153&r2=1603154&view=diff
==============================================================================
--- 
openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/parser/XmlNamespace.java
 (original)
+++ 
openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/parser/XmlNamespace.java
 Tue Jun 17 13:01:38 2014
@@ -22,6 +22,7 @@
 package org.apache.openoffice.ooxml.schema.parser;
 
 import org.apache.openoffice.ooxml.schema.model.attribute.Attribute;
+import org.apache.openoffice.ooxml.schema.model.base.Location;
 import org.apache.openoffice.ooxml.schema.model.base.QualifiedName;
 import org.apache.openoffice.ooxml.schema.model.schema.SchemaBase;
 import org.apache.openoffice.ooxml.schema.model.simple.Restriction;
@@ -34,17 +35,17 @@ import org.apache.openoffice.ooxml.schem
  */
 public class XmlNamespace
 {
-    public static final String NamespaceURI = 
"http://www.w3.org/XML/1998/namespace";; 
-    public static final String NamespacePrefix = "xml";
+    public static final String URI = "http://www.w3.org/XML/1998/namespace";; 
+    public static final String Prefix = "xml";
 
     public static void Apply (final SchemaBase aSchemaBase)
     {
-        aSchemaBase.Namespaces.ProvideNamespace(NamespaceURI, NamespacePrefix);
+        aSchemaBase.Namespaces.ProvideNamespace(URI, Prefix);
         
-        final QualifiedName aStSpaceSimpleTypeName = new 
QualifiedName(NamespaceURI, NamespacePrefix, "ST__space");
+        final QualifiedName aStSpaceSimpleTypeName = new QualifiedName(URI, 
Prefix, "ST__space");
         aSchemaBase.Attributes.Add(
             new Attribute(
-                new QualifiedName(NamespaceURI, NamespacePrefix, "space"),
+                new QualifiedName(URI, Prefix, "space"),
                 aStSpaceSimpleTypeName,
                 "optional",
                 null,
@@ -52,10 +53,17 @@ public class XmlNamespace
                 FormDefault.unqualified,
                 null));
         
-        final SimpleType aType = new SimpleType(null, aStSpaceSimpleTypeName, 
null);
-        final Restriction aRestriction = new Restriction(aType, "xsd:token", 
null);
+        final SimpleType aType = new SimpleType(
+            null,
+            aStSpaceSimpleTypeName,
+            new Location());
+        final Restriction aRestriction = new Restriction(
+            aType,
+            new QualifiedName(XsdNamespace.URI, XsdNamespace.Prefix, "token"),
+            null);
         aRestriction.AddEnumeration("default");
         aRestriction.AddEnumeration("preserve");
+        aType.AddChild(aRestriction);
         aSchemaBase.SimpleTypes.Add(aType);
     }
 }

Added: 
openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/parser/XsdNamespace.java
URL: 
http://svn.apache.org/viewvc/openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/parser/XsdNamespace.java?rev=1603154&view=auto
==============================================================================
--- 
openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/parser/XsdNamespace.java
 (added)
+++ 
openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/parser/XsdNamespace.java
 Tue Jun 17 13:01:38 2014
@@ -0,0 +1,29 @@
+/**************************************************************
+*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*   http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*
+*************************************************************/
+
+package org.apache.openoffice.ooxml.schema.parser;
+
+
+public class XsdNamespace
+{
+    public static final String URI = "http://www.w3.org/2001/XMLSchema";;
+    public static final String Prefix = "xsd";
+}

Added: 
openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/simple/BlobNode.java
URL: 
http://svn.apache.org/viewvc/openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/simple/BlobNode.java?rev=1603154&view=auto
==============================================================================
--- 
openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/simple/BlobNode.java
 (added)
+++ 
openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/simple/BlobNode.java
 Tue Jun 17 13:01:38 2014
@@ -0,0 +1,110 @@
+package org.apache.openoffice.ooxml.schema.simple;
+
+import java.util.Map;
+
+import org.apache.openoffice.ooxml.schema.misc.Log;
+import org.apache.openoffice.ooxml.schema.model.simple.BuiltInType;
+import org.apache.openoffice.ooxml.schema.model.simple.Restriction;
+
+public class BlobNode
+    implements ISimpleTypeNode
+{
+    public BlobNode (final BuiltInType eType)
+    {
+        meType = eType;
+        mbIsList = false;
+        mnLengthRestriction = null;
+    }
+
+    
+    
+    
+    public BuiltInType GetBlobType ()
+    {
+        return meType;
+    }
+    
+    
+    
+    
+    @Override
+    public void ApplyRestriction (
+        final Restriction aRestriction,
+        final Map<String,Integer> aValueToIdMap)
+    {
+        if (aRestriction.GetFeatureBits() == 0)
+            return;
+        
+        if (aRestriction.GetFeatureBits() != Restriction.LengthBit)
+            throw new RuntimeException("unsupported restriction on blob: 
"+aRestriction);
+        
+        mnLengthRestriction = aRestriction.GetLength();
+    }
+    
+    
+    
+    
+    @Override
+    public void Print (final Log aLog)
+    {
+        aLog.printf("blob of type %s\n", meType);
+    }
+
+    
+    
+    
+    @Override
+    public boolean IsList ()
+    {
+        return mbIsList;
+    }
+    
+    
+    
+    
+    @Override
+    public void SetIsList ()
+    {
+        mbIsList = true;
+    }
+    
+    
+    
+    
+    @Override
+    public void AcceptVisitor (final ISimpleTypeNodeVisitor aVisitor)
+    {
+        aVisitor.Visit(this);
+    }
+    
+    
+    
+        
+    public enum RestrictionType
+    {
+        Length,
+        None;
+    }
+    public RestrictionType GetRestrictionType ()
+    {
+        if (mnLengthRestriction != null)
+            return RestrictionType.Length;
+        else
+            return RestrictionType.None;
+    }
+    
+    
+    
+    
+    public int GetLengthRestriction ()
+    {
+        return mnLengthRestriction;
+    }
+    
+    
+    
+    
+    private final BuiltInType meType;
+    private boolean mbIsList;
+    private Integer mnLengthRestriction;
+}

Added: 
openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/simple/DateTimeNode.java
URL: 
http://svn.apache.org/viewvc/openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/simple/DateTimeNode.java?rev=1603154&view=auto
==============================================================================
--- 
openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/simple/DateTimeNode.java
 (added)
+++ 
openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/simple/DateTimeNode.java
 Tue Jun 17 13:01:38 2014
@@ -0,0 +1,71 @@
+package org.apache.openoffice.ooxml.schema.simple;
+
+import java.util.Map;
+
+import org.apache.openoffice.ooxml.schema.misc.Log;
+import org.apache.openoffice.ooxml.schema.model.simple.BuiltInType;
+import org.apache.openoffice.ooxml.schema.model.simple.Restriction;
+
+public class DateTimeNode
+    implements ISimpleTypeNode
+{
+
+    public DateTimeNode (final BuiltInType eType)
+    {
+        mbIsList = false;
+    }
+
+
+    
+    
+    @Override
+    public void ApplyRestriction (
+        final Restriction aRestriction,
+        final Map<String,Integer> aValueToIdMap)
+    {
+        if (aRestriction.GetFeatureBits() == 0)
+            return;
+        System.out.println(aRestriction);
+    }
+    
+
+    
+    
+    @Override
+    public void Print (final Log aLog)
+    {
+        aLog.printf("date or time\n");
+    }
+
+
+
+
+    @Override
+    public boolean IsList ()
+    {
+        return mbIsList;
+    }
+    
+    
+    
+    
+    @Override
+    public void SetIsList ()
+    {
+        mbIsList = true;
+    }
+    
+    
+    
+    
+    @Override
+    public void AcceptVisitor (final ISimpleTypeNodeVisitor aVisitor)
+    {
+        aVisitor.Visit(this);
+    }
+    
+    
+    
+    
+    private boolean mbIsList;
+}

Added: 
openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/simple/EnumerationNode.java
URL: 
http://svn.apache.org/viewvc/openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/simple/EnumerationNode.java?rev=1603154&view=auto
==============================================================================
--- 
openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/simple/EnumerationNode.java
 (added)
+++ 
openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/simple/EnumerationNode.java
 Tue Jun 17 13:01:38 2014
@@ -0,0 +1,6 @@
+package org.apache.openoffice.ooxml.schema.simple;
+
+public class EnumerationNode
+{
+
+}

Added: 
openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/simple/ISimpleTypeNode.java
URL: 
http://svn.apache.org/viewvc/openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/simple/ISimpleTypeNode.java?rev=1603154&view=auto
==============================================================================
--- 
openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/simple/ISimpleTypeNode.java
 (added)
+++ 
openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/simple/ISimpleTypeNode.java
 Tue Jun 17 13:01:38 2014
@@ -0,0 +1,27 @@
+package org.apache.openoffice.ooxml.schema.simple;
+
+import java.util.Map;
+
+import org.apache.openoffice.ooxml.schema.misc.Log;
+import org.apache.openoffice.ooxml.schema.model.simple.Restriction;
+
+/** Represent a single node in the node tree of a simple type.
+ */
+public interface ISimpleTypeNode
+{
+    void ApplyRestriction (
+        final Restriction aNode,
+        final Map<String,Integer> aValueToIdMap);
+    void Print (final Log aLog);
+    
+    /** List elements are not represented by their own node (type).
+     *  There is only this flag that makes this node a list of the item type
+     *  which is represented by the node.  
+     */
+    boolean IsList ();
+    
+    /** Set the IsList flag.
+     */
+    void SetIsList ();
+    void AcceptVisitor (final ISimpleTypeNodeVisitor aVisitor);
+}

Added: 
openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/simple/ISimpleTypeNodeVisitor.java
URL: 
http://svn.apache.org/viewvc/openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/simple/ISimpleTypeNodeVisitor.java?rev=1603154&view=auto
==============================================================================
--- 
openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/simple/ISimpleTypeNodeVisitor.java
 (added)
+++ 
openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/simple/ISimpleTypeNodeVisitor.java
 Tue Jun 17 13:01:38 2014
@@ -0,0 +1,10 @@
+package org.apache.openoffice.ooxml.schema.simple;
+
+public interface ISimpleTypeNodeVisitor
+{
+    void Visit (final BlobNode aType);
+    void Visit (final DateTimeNode aType);
+    void Visit (final NumberNode<?> aType);
+    void Visit (final StringNode aType);
+    void Visit (final UnionNode aType);
+}

Added: 
openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/simple/NumberNode.java
URL: 
http://svn.apache.org/viewvc/openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/simple/NumberNode.java?rev=1603154&view=auto
==============================================================================
--- 
openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/simple/NumberNode.java
 (added)
+++ 
openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/simple/NumberNode.java
 Tue Jun 17 13:01:38 2014
@@ -0,0 +1,289 @@
+package org.apache.openoffice.ooxml.schema.simple;
+
+import java.util.Map;
+import java.util.Vector;
+
+import org.apache.openoffice.ooxml.schema.misc.Log;
+import org.apache.openoffice.ooxml.schema.model.simple.BuiltInType;
+import org.apache.openoffice.ooxml.schema.model.simple.Restriction;
+
+public class NumberNode<T extends Comparable<T>>
+    implements ISimpleTypeNode
+{
+    NumberNode (final BuiltInType eType)
+    {
+        meType = eType;
+        mbIsList = false;
+    }
+    
+    
+    
+    
+    public BuiltInType GetNumberType ()
+    {
+        return meType;
+    }
+    
+    
+    
+    
+    T ParseString (final String sValue)
+    {
+        switch(meType)
+        {
+            case Float:
+                return (T)(Float)Float.parseFloat(sValue);
+                
+            case Double:
+                return (T)(Double)Double.parseDouble(sValue);
+                
+            case Byte:
+                return (T)(Byte)Byte.parseByte(sValue);
+
+            case Int:
+            case UnsignedShort:
+                return (T)(Integer)Integer.parseInt(sValue);
+
+            case Short:
+            case UnsignedByte:
+                return (T)(Short)Short.parseShort(sValue);
+
+            case Long:
+            case UnsignedInt:
+            case Integer:
+                return (T)(Long)Long.parseLong(sValue);
+                
+            default:
+                throw new RuntimeException("unsupported type "+meType);
+        }
+    }
+    
+    
+    
+    
+    @Override
+    public void ApplyRestriction (
+        final Restriction aNode,
+        final Map<String,Integer> aValueToIdMap)
+    {
+        if (aNode.HasFeature(Restriction.MinExclusiveBit))
+            ApplyMinimum(ParseString(aNode.GetMinExclusive()), false);
+        if (aNode.HasFeature(Restriction.MinInclusiveBit))
+            ApplyMinimum(ParseString(aNode.GetMinInclusive()), true);
+
+        if (aNode.HasFeature(Restriction.MaxExclusiveBit))
+            ApplyMaximum(ParseString(aNode.GetMaxExclusive()), false);
+        if (aNode.HasFeature(Restriction.MaxInclusiveBit))
+            ApplyMaximum(ParseString(aNode.GetMaxInclusive()), true);
+        
+        if (aNode.HasFeature(Restriction.EnumerationBit))
+        {
+            final Vector<T> aValues = new Vector<>();
+            for (final String sEnumerationValue : aNode.GetEnumeration())
+                aValues.add(ParseString(sEnumerationValue));
+            ApplyEnumeration(aValues);
+        }
+    }
+
+    
+    
+
+    @Override
+    public void Print (final Log aLog)
+    {
+        aLog.printf("%s\n", toString());
+    }
+
+    
+    
+    
+    @Override
+    public String toString ()
+    {
+        final StringBuffer sMessage = new StringBuffer();
+        sMessage.append(meType);
+        if (maEnumeration != null)
+        {
+            sMessage.append(", restricted to values");
+            for (final T nValue : maEnumeration)
+            {
+                sMessage.append(' ');
+                sMessage.append(nValue);
+            }
+        }
+        else if (maMinimumValue!=null || maMaximumValue!=null)
+        {
+            sMessage.append(" restricted to ");
+          
+            if (maMinimumValue != null)
+            {
+                sMessage.append(maMinimumValue);
+                if (mbIsMinimumInclusive)
+                    sMessage.append(" <= ");
+                else
+                    sMessage.append(" < ");
+            }
+            sMessage.append("value");
+            if (maMaximumValue != null)
+            {
+                if (mbIsMaximumInclusive)
+                    sMessage.append(" <= ");
+                else
+                    sMessage.append(" < ");
+                sMessage.append(maMaximumValue);
+            }
+        }
+        else
+            sMessage.append(", not restricted");
+
+        return sMessage.toString();
+    }
+
+
+    
+    
+    private void ApplyMinimum (
+        final T nValue,
+        final boolean bIsInclusive)
+    {
+        if (maEnumeration != null)
+            throw new RuntimeException("minimum can not be applied to an 
enumeration");
+        else if (maMinimumValue != null)
+        {
+            final int nComparison = maMinimumValue.compareTo(nValue);
+            if (nComparison > 0)
+                throw new RuntimeException("second restriction tries to 
enlarge value space");
+            else if (nComparison == 0)
+                if (mbIsMinimumInclusive && ! bIsInclusive)
+                    throw new RuntimeException("second restriction tries to 
enlarge value space");
+        }
+        maMinimumValue = nValue;
+        mbIsMinimumInclusive = bIsInclusive;
+    }
+    
+    
+    
+    
+
+    private void ApplyMaximum (
+        final T nValue,
+        final boolean bIsInclusive)
+    {
+        if (maEnumeration != null)
+            throw new RuntimeException("maximum can not be applied to an 
enumeration");
+        else if (maMaximumValue != null)
+        {
+            final int nComparison = maMaximumValue.compareTo(nValue);
+            if (nComparison < 0)
+                throw new RuntimeException("second restriction tries to 
enlarge value space");
+            else if (nComparison == 0) 
+                if ( ! mbIsMaximumInclusive && bIsInclusive)
+                    throw new RuntimeException("second restriction tries to 
enlarge value space");
+        }
+        maMaximumValue = nValue;
+        mbIsMaximumInclusive = bIsInclusive;
+    }
+    
+
+    
+    
+    private void ApplyEnumeration (final Vector<T> aValues)
+    {
+        if (maEnumeration!=null || maMaximumValue!=null || 
maMinimumValue!=null)
+            throw new RuntimeException("can not apply enumeration to existing 
restriction");
+        maEnumeration = aValues;
+    }
+    
+    
+    
+
+    @Override
+    public boolean IsList ()
+    {
+        return mbIsList;
+    }
+    
+    
+    
+    
+    @Override
+    public void SetIsList ()
+    {
+        mbIsList = true;
+    }
+    
+    
+    
+    
+    @Override
+    public void AcceptVisitor (final ISimpleTypeNodeVisitor aVisitor)
+    {
+        aVisitor.Visit(this);
+    }
+    
+    
+    public enum RestrictionType
+    {
+        Size,
+        Enumeration,
+        None
+    }
+    public RestrictionType GetRestrictionType ()
+    {
+        if (maEnumeration != null)
+            return RestrictionType.Enumeration;
+        else if (maMinimumValue!=null || maMaximumValue!=null)
+            return RestrictionType.Size;
+        else
+            return RestrictionType.None;
+    }
+    
+    
+    
+    public Iterable<T> GetEnumerationRestriction ()
+    {
+        return maEnumeration;
+    }
+    
+    
+    
+    
+    public T GetMinimum ()
+    {
+        return maMinimumValue;
+    }
+
+    
+    
+    
+    public T GetMaximum ()
+    {
+        return maMaximumValue;
+    }
+    
+    
+    
+    public boolean IsMinimumInclusive ()
+    {
+        return mbIsMinimumInclusive;
+    }
+    
+    
+    
+    
+    public boolean IsMaximumInclusive ()
+    {
+        return mbIsMaximumInclusive;
+    }
+
+    
+    
+    
+    private final BuiltInType meType;
+    private T maMinimumValue;
+    private boolean mbIsMinimumInclusive;
+    private T maMaximumValue;
+    private boolean mbIsMaximumInclusive;
+    private Vector<T> maEnumeration;
+    private boolean mbIsList;
+}

Added: 
openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/simple/SimpleTypeContainer.java
URL: 
http://svn.apache.org/viewvc/openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/simple/SimpleTypeContainer.java?rev=1603154&view=auto
==============================================================================
--- 
openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/simple/SimpleTypeContainer.java
 (added)
+++ 
openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/simple/SimpleTypeContainer.java
 Tue Jun 17 13:01:38 2014
@@ -0,0 +1,81 @@
+package org.apache.openoffice.ooxml.schema.simple;
+
+import java.io.File;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.TreeMap;
+
+import org.apache.openoffice.ooxml.schema.misc.Log;
+import org.apache.openoffice.ooxml.schema.model.schema.SchemaBase;
+import org.apache.openoffice.ooxml.schema.model.simple.SimpleType;
+
+public class SimpleTypeContainer
+{
+    public static SimpleTypeContainer Create (
+        final SchemaBase aSchemaBase,
+        final File aLogFile)
+    {
+        final SimpleTypeContainer aContainer = new 
SimpleTypeContainer(aLogFile);
+        for (final SimpleType aType : aSchemaBase.SimpleTypes.GetSorted())
+        {
+            aContainer.ProcessSimpleType(aType, aSchemaBase);
+        }
+        return aContainer;
+    }
+    
+    
+    
+    
+    public int GetSimpleTypeCount ()
+    {
+        return maSimpleTypes.size();
+    }
+    
+    
+    
+    
+    public Iterable<Entry<String,SimpleTypeDescriptor>> GetSimpleTypes ()
+    {
+        return maSimpleTypes.entrySet();
+    }
+    
+    
+    
+    
+    public Iterable<Entry<String,SimpleTypeDescriptor>> GetSimpleTypesSorted ()
+    {
+        final Map<String,SimpleTypeDescriptor> aSortedSimpleTypes = new 
TreeMap<>();
+        aSortedSimpleTypes.putAll(maSimpleTypes);
+        return aSortedSimpleTypes.entrySet();
+    }
+    
+    
+    
+    
+    private SimpleTypeContainer (final File aLogFile)
+    {
+        maSimpleTypes = new TreeMap<>();
+        maLog = new Log(aLogFile);
+    }
+    
+    
+    
+    
+    private void ProcessSimpleType (
+        final SimpleType aType,
+        final SchemaBase aSchemaBase)
+    {
+        maSimpleTypes.put(
+            aType.GetName().GetStateName(), 
+            SimpleTypeDescriptorFactory.CreateSimpleTypeDescriptor(
+                aType,
+                aSchemaBase,
+                maLog));
+    }
+    
+    
+    
+    
+    private final Map<String,SimpleTypeDescriptor> maSimpleTypes;
+    private final Log maLog;
+}

Added: 
openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/simple/SimpleTypeDescriptor.java
URL: 
http://svn.apache.org/viewvc/openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/simple/SimpleTypeDescriptor.java?rev=1603154&view=auto
==============================================================================
--- 
openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/simple/SimpleTypeDescriptor.java
 (added)
+++ 
openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/simple/SimpleTypeDescriptor.java
 Tue Jun 17 13:01:38 2014
@@ -0,0 +1,65 @@
+package org.apache.openoffice.ooxml.schema.simple;
+
+import org.apache.openoffice.ooxml.schema.misc.Log;
+import org.apache.openoffice.ooxml.schema.model.base.QualifiedName;
+
+public class SimpleTypeDescriptor
+{
+    public SimpleTypeDescriptor (
+        final QualifiedName aName)
+    {
+        maName = aName;
+        maSubTypes = null;
+    }
+
+    
+    
+    
+    public QualifiedName GetName()
+    {
+        return maName;
+    }
+   
+    
+    
+    
+    public void SetSubTypes (final ISimpleTypeNode[] aSubTypes)
+    {
+        maSubTypes = aSubTypes;        
+    }
+
+    
+    
+    
+    public ISimpleTypeNode[] GetSubType ()
+    {
+        return maSubTypes;
+    }
+    
+    
+    
+    
+    @Override
+    public String toString ()
+    {
+        return "simple type "+maName;
+    }
+    
+    
+    
+    
+    public void Print (final Log aLog)
+    {
+        aLog.printf("%s\n", toString());
+        aLog.StartBlock();
+        for (final ISimpleTypeNode aSubType : maSubTypes)
+            aSubType.Print(aLog);
+        aLog.EndBlock();
+    }
+
+    
+    
+    
+    private final QualifiedName maName;
+    private ISimpleTypeNode[] maSubTypes;
+}

Added: 
openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/simple/SimpleTypeDescriptorFactory.java
URL: 
http://svn.apache.org/viewvc/openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/simple/SimpleTypeDescriptorFactory.java?rev=1603154&view=auto
==============================================================================
--- 
openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/simple/SimpleTypeDescriptorFactory.java
 (added)
+++ 
openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/simple/SimpleTypeDescriptorFactory.java
 Tue Jun 17 13:01:38 2014
@@ -0,0 +1,286 @@
+package org.apache.openoffice.ooxml.schema.simple;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.openoffice.ooxml.schema.misc.Log;
+import org.apache.openoffice.ooxml.schema.model.base.INode;
+import org.apache.openoffice.ooxml.schema.model.base.NodeType;
+import org.apache.openoffice.ooxml.schema.model.base.NodeVisitorAdapter;
+import org.apache.openoffice.ooxml.schema.model.schema.SchemaBase;
+import org.apache.openoffice.ooxml.schema.model.simple.BuiltIn;
+import org.apache.openoffice.ooxml.schema.model.simple.List;
+import org.apache.openoffice.ooxml.schema.model.simple.Restriction;
+import org.apache.openoffice.ooxml.schema.model.simple.SimpleType;
+import org.apache.openoffice.ooxml.schema.model.simple.SimpleTypeReference;
+import org.apache.openoffice.ooxml.schema.model.simple.Union;
+
+public class SimpleTypeDescriptorFactory
+    extends NodeVisitorAdapter
+{
+    class TypeCounter
+        extends NodeVisitorAdapter
+    {
+        public final Map<NodeType,Integer> Counters;
+        TypeCounter ()
+        {
+            Counters = new HashMap<>();
+            for (final NodeType eType : NodeType.values())
+                Counters.put(eType, 0);
+        }
+        @Override
+        public void Default (final INode aNode)
+        {
+            Counters.put(aNode.GetNodeType(), 
Counters.get(aNode.GetNodeType())+1);
+        }
+    }
+    
+    
+    
+    
+    public static SimpleTypeDescriptor CreateSimpleTypeDescriptor(
+        final SimpleType aSimpleType,
+        final SchemaBase aSchemaBase,
+        final Log aLog)
+    {
+        final SimpleTypeDescriptorFactory aFactory = new 
SimpleTypeDescriptorFactory(
+            aSchemaBase,
+            aLog);
+
+        aLog.AddComment("Simple type %s, defined at %s",
+            aSimpleType.GetName(),
+            aSimpleType.GetLocation().toString());
+        
+        final ISimpleTypeNode aSubType = 
aFactory.ProcessSimpleType(aSimpleType);
+        final SimpleTypeDescriptor aDescriptor = new 
SimpleTypeDescriptor(aSimpleType.GetName());
+        aSubType.AcceptVisitor(new SimpleTypeNodeVisitorAdapter ()
+        {
+            @Override public void Visit (final UnionNode aType)
+            {
+                aDescriptor.SetSubTypes(aType.GetChildren());
+            }
+            
+            @Override public void Default (final ISimpleTypeNode aType)
+            {
+                aDescriptor.SetSubTypes(new ISimpleTypeNode[]{aSubType});
+            }
+        });
+        
+        aDescriptor.Print(aLog);
+        aLog.printf("\n");
+        
+        return aDescriptor;
+    }
+    
+    
+    
+    
+    private SimpleTypeDescriptorFactory (
+        final SchemaBase aSchemaBase,
+        final Log aLog)
+    {
+        maSchemaBase = aSchemaBase;
+        maLog = aLog;
+        maResult = null;
+    }
+    
+    
+    
+    
+    ISimpleTypeNode ProcessSimpleType (final SimpleType aSimpleType)
+    {
+        return ApplyVisitor(aSimpleType);
+    }
+    
+    
+    
+    
+    @Override
+    public void Visit (final BuiltIn aNode)
+    {
+        assert(aNode.GetChildCount() == 0);
+        assert(maResult == null);
+        
+        maLog.AddComment("builtin %s", aNode.toString());
+
+        switch(aNode.GetBuiltInType())
+        {
+            case Double:
+                maResult = new NumberNode<Double>(aNode.GetBuiltInType());
+                break;
+            case Float:
+                maResult = new NumberNode<Float>(aNode.GetBuiltInType());
+                break;
+                
+            case Boolean:
+                maResult = new NumberNode<Boolean>(aNode.GetBuiltInType());
+            case Integer:
+                maResult = new NumberNode<Long>(aNode.GetBuiltInType());
+                break;
+            case Byte:
+                maResult = new NumberNode<Byte>(aNode.GetBuiltInType());
+            case Int:
+                maResult = new NumberNode<Integer>(aNode.GetBuiltInType());
+            case Long:
+                maResult = new NumberNode<Long>(aNode.GetBuiltInType());
+            case Short:
+                maResult = new NumberNode<Short>(aNode.GetBuiltInType());
+            case UnsignedByte:
+                maResult = new NumberNode<Integer>(aNode.GetBuiltInType());
+            case UnsignedInt:
+                maResult = new NumberNode<Long>(aNode.GetBuiltInType());
+            case UnsignedLong:
+                maResult = new NumberNode<Long>(aNode.GetBuiltInType());
+            case UnsignedShort:
+                maResult = new NumberNode<Integer>(aNode.GetBuiltInType());
+                break;
+                
+            case AnyURI:
+            case ID:
+            case NcName:
+            case String:
+            case Token:
+                maResult = new StringNode(aNode.GetBuiltInType()); 
+                break;
+                
+            case Base64Binary:
+            case HexBinary:
+                maResult = new BlobNode(aNode.GetBuiltInType());
+                break;
+
+            case DateTime:
+                maResult = new DateTimeNode(aNode.GetBuiltInType());
+                break;
+                
+            default:
+                throw new RuntimeException(aNode.toString()+" is not 
supported");
+        }
+    }
+    
+    
+    
+    
+    @Override
+    public void Visit (final List aNode)
+    {
+        maLog.AddComment("list of type %s", aNode.GetItemType().toString());
+        maLog.StartBlock();
+        final ISimpleTypeNode aItemType = 
ApplyVisitor(maSchemaBase.GetSimpleTypeForName(aNode.GetItemType()));
+        maLog.EndBlock();
+        
+        aItemType.SetIsList();
+        maResult = aItemType;
+    }
+    
+
+    
+    
+    @Override
+    public void Visit (final Restriction aNode)
+    {
+        assert(aNode.GetChildCount() == 0);
+        
+        maLog.AddComment("%s", aNode.toString());
+        
+        final INode aBaseType = 
maSchemaBase.GetSimpleTypeForName(aNode.GetBaseType());
+        if (aBaseType == null)
+            throw new RuntimeException("got no type for name 
"+aNode.GetBaseType());
+        maLog.StartBlock();
+        maResult = ApplyVisitor(aBaseType);
+        maLog.EndBlock();
+        maResult.ApplyRestriction(
+            aNode,
+            maSchemaBase.AttributeValueToIdMap);
+    }
+    
+    
+    
+    
+    @Override
+    public void Visit (final SimpleType aNode)
+    {
+        maLog.AddComment(aNode.toString());
+        
+        assert(aNode.GetChildCount() <= 1);
+        switch(aNode.GetChildCount())
+        {
+            case 0:
+                maResult = null;
+                break;                
+            case 1:
+                maLog.StartBlock();
+                maResult = ApplyVisitor(aNode.GetOnlyChild());
+                maLog.EndBlock();
+                break;
+            default:
+                throw new RuntimeException();
+        }
+    }
+    
+    
+    
+
+    @Override
+    public void Visit (final SimpleTypeReference aNode)
+    {
+        maLog.AddComment("reference to %s", aNode.GetReferencedTypeName());
+       
+        maLog.StartBlock();
+        maResult = ApplyVisitor(aNode.GetReferencedNode(maSchemaBase));
+        maLog.EndBlock();
+    }
+    
+    
+    
+
+    @Override
+    public void Visit (final Union aNode)
+    {
+        maLog.AddComment("union");
+
+        final UnionNode aUnion = new UnionNode();
+        
+        // Make sure that all children have compatible types and value sets.
+        maLog.StartBlock();
+
+        for (final INode aChild : aNode.GetChildren())
+        {
+            aUnion.AddNode(ApplyVisitor(aChild));
+        }
+
+        maLog.EndBlock();
+
+        maResult = aUnion;
+    }
+    
+    
+    
+    
+    @Override
+    public void Default (final INode aNode)
+    {
+        switch(aNode.GetNodeType())
+        {
+            default:
+                throw new RuntimeException(aNode.GetNodeType() +" is not yet 
supported");
+        }
+    }
+    
+    
+    
+    
+    ISimpleTypeNode ApplyVisitor (final INode aNode)
+    {
+        aNode.AcceptVisitor(this);
+        final ISimpleTypeNode aResult = maResult;
+        maResult = null;
+        return aResult;
+    }
+    
+
+    
+    
+    private final SchemaBase maSchemaBase;
+    private final Log maLog;
+    private ISimpleTypeNode maResult;
+}

Added: 
openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/simple/SimpleTypeNodeVisitorAdapter.java
URL: 
http://svn.apache.org/viewvc/openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/simple/SimpleTypeNodeVisitorAdapter.java?rev=1603154&view=auto
==============================================================================
--- 
openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/simple/SimpleTypeNodeVisitorAdapter.java
 (added)
+++ 
openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/simple/SimpleTypeNodeVisitorAdapter.java
 Tue Jun 17 13:01:38 2014
@@ -0,0 +1,39 @@
+package org.apache.openoffice.ooxml.schema.simple;
+
+public class SimpleTypeNodeVisitorAdapter
+    implements ISimpleTypeNodeVisitor
+{
+    @Override
+    public void Visit(BlobNode aType)
+    {
+        Default(aType);
+    }
+
+    @Override
+    public void Visit(DateTimeNode aType)
+    {
+        Default(aType);
+    }
+
+    @Override
+    public void Visit(NumberNode<?> aType)
+    {
+        Default(aType);
+    }
+    
+    @Override
+    public void Visit(StringNode aType)
+    {
+        Default(aType);
+    }
+
+    @Override
+    public void Visit(UnionNode aType)
+    {
+        Default(aType);
+    }
+    
+    public void Default (final ISimpleTypeNode aType)
+    {
+    }
+}

Added: 
openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/simple/StringNode.java
URL: 
http://svn.apache.org/viewvc/openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/simple/StringNode.java?rev=1603154&view=auto
==============================================================================
--- 
openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/simple/StringNode.java
 (added)
+++ 
openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/simple/StringNode.java
 Tue Jun 17 13:01:38 2014
@@ -0,0 +1,248 @@
+package org.apache.openoffice.ooxml.schema.simple;
+
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+
+import org.apache.openoffice.ooxml.schema.misc.Log;
+import org.apache.openoffice.ooxml.schema.model.simple.BuiltInType;
+import org.apache.openoffice.ooxml.schema.model.simple.Restriction;
+
+public class StringNode
+    implements ISimpleTypeNode
+{
+    public StringNode (
+        final BuiltInType eType)
+    {
+        meType = eType;
+        mbIsList = false;
+    }
+
+    
+    
+    
+    @Override
+    public void ApplyRestriction (
+        final Restriction aRestriction,
+        final Map<String,Integer> aValueToIdMap)
+    {
+        assert( ! aRestriction.HasFeature(
+            Restriction.MinExclusiveBit
+            | Restriction.MinInclusiveBit
+            | Restriction.MaxExclusiveBit
+            | Restriction.MaxInclusiveBit));
+        
+        if (aRestriction.HasFeature(Restriction.EnumerationBit))
+        {
+            if 
(aRestriction.HasFeature(Restriction.LengthBit|Restriction.MinLengthBit|Restriction.MaxLengthBit))
+                for (final String sValue : aRestriction.GetEnumeration())
+                    assert(CheckLengthRestriction(sValue, aRestriction));
+            maEnumerationValues = new TreeSet<>();
+            maEnumerationValueIds = new HashSet<>();
+            for (final String sValue : aRestriction.GetEnumeration())
+            {
+                if ( ! aValueToIdMap.containsKey(sValue))
+                    aValueToIdMap.put(sValue, aValueToIdMap.size());
+                maEnumerationValues.add(sValue);
+                maEnumerationValueIds.add(aValueToIdMap.get(sValue));
+            }
+        }
+        else if (aRestriction.HasFeature(Restriction.PatternBit))
+        {
+            msPattern = aRestriction.GetPattern();
+            // Make the regular expression understandable by Java (by replacing
+            // character class names like IsBasicLatin to InBasicLatin).
+            try
+            {
+                maPattern = Pattern.compile(msPattern.replace("\\p{Is", 
"\\p{In"), Pattern.UNICODE_CHARACTER_CLASS);
+            }
+            catch (PatternSyntaxException aException)
+            {
+                aException.printStackTrace();
+            }
+        }
+        else if 
(aRestriction.HasFeature(Restriction.LengthBit|Restriction.MinLengthBit|Restriction.MaxLengthBit))
+        {
+            if (aRestriction.HasFeature(Restriction.LengthBit))
+                mnMinimumLength = mnMaximumLength = aRestriction.GetLength();
+            if (aRestriction.HasFeature(Restriction.MinLengthBit))
+                mnMinimumLength = aRestriction.GetMinimumLength();
+            if (aRestriction.HasFeature(Restriction.MaxLengthBit))
+                mnMaximumLength = aRestriction.GetMaximumLength();
+        }
+        else
+        {
+            // no restriction.
+            assert(aRestriction.GetFeatureBits() == 0);
+        }
+    }
+    
+    
+    
+    
+    @Override
+    public void Print (final Log aLog)
+    {
+        aLog.println(toString());
+    }
+
+    
+    
+    
+    @Override
+    public String toString ()
+    {
+        final StringBuffer aBuffer = new StringBuffer();
+        aBuffer.append(String.format("string (%s)", meType));
+        if (maEnumerationValueIds != null)
+        {
+            aBuffer.append(" [");
+            boolean bIsFirst = true;
+            for (final String sValue : maEnumerationValues)
+            {
+                if (bIsFirst)
+                    bIsFirst = false;
+                else
+                    aBuffer.append(", ");
+                aBuffer.append(sValue);
+            }
+            aBuffer.append("]");
+        }
+        else if (maPattern != null)
+        {
+            aBuffer.append("pattern=\"");
+            aBuffer.append(maPattern);
+            aBuffer.append("\"");
+        }
+        return aBuffer.toString();
+    }
+    
+    
+    
+    
+    @Override
+    public boolean IsList ()
+    {
+        return mbIsList;
+    }
+    
+    
+    
+    
+    @Override
+    public void SetIsList ()
+    {
+        mbIsList = true;
+    }
+    
+    
+    
+    
+    /** Try to join the called and the given string types.
+     *  If that is possible then return the resulting type.
+     *  Otherwise return null.
+     */
+    public ISimpleTypeNode Join (final StringNode aType)
+    {
+        if (maEnumerationValues!=null && aType.maEnumerationValues!=null)
+        {
+            // Join the enumeration values.
+            maEnumerationValues.addAll(aType.maEnumerationValues);
+            maEnumerationValueIds.addAll(aType.maEnumerationValueIds);
+            return this;
+        }
+        else
+            return null;
+    }
+    
+    
+    public enum RestrictionType
+    {
+        Pattern,
+        Enumeration,
+        Length,
+        None
+    }
+    public RestrictionType GetRestrictionType ()
+    {
+        if (maEnumerationValueIds != null)
+            return RestrictionType.Enumeration;
+        else if (maPattern != null)
+            return RestrictionType.Pattern;
+        else if (mnMinimumLength != null)
+            return RestrictionType.Length;
+        else
+            return RestrictionType.None;
+    }
+    
+    
+    
+    
+    public Set<Integer> GetEnumerationRestriction ()
+    {
+        final Set<Integer> aSortedIds = new TreeSet<>();
+        aSortedIds.addAll(maEnumerationValueIds);
+        return aSortedIds;
+    }
+    
+    
+    
+    
+    public String GetPatternRestriction ()
+    {
+        return msPattern;
+    }
+    
+    
+    
+    
+    public int[] GetLengthRestriction ()
+    {
+        return new int[]{mnMinimumLength, mnMaximumLength};
+    }
+    
+    
+    
+    
+    private boolean CheckLengthRestriction (
+        final String sValue,
+        final Restriction aRestriction)
+    {
+        final int nValueLength = sValue.length(); 
+        if (aRestriction.HasFeature(Restriction.LengthBit))
+            return nValueLength == aRestriction.GetLength();
+        else if (aRestriction.HasFeature(Restriction.MinLengthBit | 
Restriction.MaxLengthBit))
+            return nValueLength>=aRestriction.GetMinimumLength()
+                && nValueLength<=aRestriction.GetMaximumLength();
+        else if (aRestriction.HasFeature(Restriction.MinLengthBit))
+            return nValueLength>=aRestriction.GetMinimumLength();
+        else if (aRestriction.HasFeature(Restriction.MaxLengthBit))
+            return nValueLength<=aRestriction.GetMaximumLength();
+        else
+            throw new RuntimeException();
+    }
+    
+    
+    
+    
+    @Override
+    public void AcceptVisitor (final ISimpleTypeNodeVisitor aVisitor)
+    {
+        aVisitor.Visit(this);
+    }
+    
+    
+    
+    
+    private final BuiltInType meType;
+    private Set<String> maEnumerationValues;
+    private Set<Integer> maEnumerationValueIds;
+    private Pattern maPattern;
+    private String msPattern;
+    private Integer mnMinimumLength;
+    private Integer mnMaximumLength;
+    private boolean mbIsList;
+}

Added: 
openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/simple/UnionNode.java
URL: 
http://svn.apache.org/viewvc/openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/simple/UnionNode.java?rev=1603154&view=auto
==============================================================================
--- 
openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/simple/UnionNode.java
 (added)
+++ 
openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/simple/UnionNode.java
 Tue Jun 17 13:01:38 2014
@@ -0,0 +1,130 @@
+package org.apache.openoffice.ooxml.schema.simple;
+
+import java.util.Map;
+import java.util.Vector;
+
+import org.apache.openoffice.ooxml.schema.misc.Log;
+import org.apache.openoffice.ooxml.schema.model.simple.Restriction;
+
+public class UnionNode
+    implements ISimpleTypeNode
+{
+    UnionNode ()
+    {
+        maTypes = new Vector<>();
+        mbIsList = false;
+    }
+    
+    
+    
+    
+    @Override
+    public void ApplyRestriction (
+        final Restriction aNode,
+        final Map<String,Integer> aValueToIdMap)
+    {
+        throw new RuntimeException("can not handle restriction on union");
+    }
+
+    
+    
+    
+    
+    public void AddNode (final ISimpleTypeNode aType)
+    {
+        if (aType instanceof UnionNode)
+        {
+            // Integrate union of child into this union.
+            final UnionNode aChildUnion = (UnionNode)aType;
+            for (final ISimpleTypeNode aChildChild : aChildUnion.maTypes)
+                maTypes.add(aChildChild);
+        }
+        else if (aType instanceof StringNode)
+        {
+            // Is there already a string child?
+            for (int nIndex=0; nIndex<maTypes.size(); ++nIndex)
+            {
+                final ISimpleTypeNode aChild = maTypes.get(nIndex);
+            
+                if (aChild instanceof StringNode)
+                {
+                    // Yes.  Can it be joined with the new child?
+                    final ISimpleTypeNode aNewChild = 
((StringNode)aChild).Join((StringNode)aType);
+                    if (aNewChild != null)
+                    {
+                        // Yes. Replace the child with the joined child.
+                        maTypes.set(nIndex, aNewChild);
+                        return;
+                    }
+                }
+            }
+            // When we reach this point then there was no join possible.
+            // Just add the new type.
+            maTypes.add(aType);
+            
+        }
+        else
+            maTypes.add(aType);
+    }
+    
+    
+    
+    
+    @Override
+    public void Print (final Log aLog)
+    {
+        aLog.printf("union of %d sub types\n", maTypes.size());
+        aLog.StartBlock();
+        for (final ISimpleTypeNode aType : maTypes)
+            aType.Print(aLog);
+        aLog.EndBlock();
+    }
+
+    
+    
+    
+    @Override
+    public boolean IsList ()
+    {
+        return mbIsList;
+    }
+    
+    
+    
+    
+    @Override
+    public void SetIsList ()
+    {
+        mbIsList = true;
+    }
+    
+    
+    
+    
+    @Override
+    public String toString ()
+    {
+        return "union";
+    }
+    
+    
+    ISimpleTypeNode[] GetChildren ()
+    {
+        return maTypes.toArray(new ISimpleTypeNode[maTypes.size()]);
+    }
+    
+
+    
+    
+    @Override
+    public void AcceptVisitor (final ISimpleTypeNodeVisitor aVisitor)
+    {
+        aVisitor.Visit(this);
+    }
+    
+    
+    
+    
+    private final Vector<ISimpleTypeNode> maTypes;
+    private boolean mbIsList;
+}


Reply via email to