diff options
Diffstat (limited to 'ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/model/complex')
13 files changed, 1292 insertions, 0 deletions
diff --git a/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/model/complex/All.java b/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/model/complex/All.java new file mode 100644 index 000000000000..cb1de8adf2b9 --- /dev/null +++ b/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/model/complex/All.java @@ -0,0 +1,96 @@ +/************************************************************** +* +* 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.model.complex; + +import org.apache.openoffice.ooxml.schema.model.base.INodeVisitor; +import org.apache.openoffice.ooxml.schema.model.base.Location; +import org.apache.openoffice.ooxml.schema.model.base.Node; +import org.apache.openoffice.ooxml.schema.model.base.NodeType; + +/** Representation of the 'all' XML schema element. All its children are + * expected to occur in any order. By default each child is optional but with + * a min=1 attribute the children can be made mandatory. + */ +public class All + extends Node +{ + public All ( + final Node aParent, + final Location aLocation) + { + super(aParent, null, aLocation); + + assert(CheckParent(aParent)); + } + + + + + /** Occurrence values of an 'all' node must be + * min=(0,1) + * max=1. + */ + private static boolean CheckParent (final Node aParent) + { + if (aParent == null) + return false; + if (aParent.GetNodeType() != NodeType.OccurrenceIndicator) + // Missing occurrence parent means that min and max have the default + // values of 0 and 1, which is valid. + return true; + + final OccurrenceIndicator aIndicator = (OccurrenceIndicator)aParent; + if (aIndicator.GetMinimum() > 1) + return false; + else if (aIndicator.GetMaximum() != 1) + return false; + else + return true; + } + + + + + @Override + public void AcceptVisitor (final INodeVisitor aVisitor) + { + aVisitor.Visit(this); + } + + + + + @Override + public NodeType GetNodeType() + { + return NodeType.All; + } + + + + + @Override + public String toString () + { + return "all"; + } +} diff --git a/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/model/complex/Any.java b/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/model/complex/Any.java new file mode 100644 index 000000000000..cc2573b86d46 --- /dev/null +++ b/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/model/complex/Any.java @@ -0,0 +1,112 @@ +/************************************************************** +* +* 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.model.complex; + +import org.apache.openoffice.ooxml.schema.model.base.INodeVisitor; +import org.apache.openoffice.ooxml.schema.model.base.Location; +import org.apache.openoffice.ooxml.schema.model.base.Node; +import org.apache.openoffice.ooxml.schema.model.base.NodeType; + +/** Representation of the 'any' XML schema element. It specifies that its + * children conform to a non-standard schema. If it is unknown than the + * children are to be ignored. + */ +public class Any + extends Node +{ + public enum ProcessContents + { + lax, + skip, + strict + } + + public Any ( + final Node aParent, + final Location aLocation, + final String sProcessContents, + final String sNamespace) + { + super(aParent, null, aLocation); + meProcessContents = ProcessContents.valueOf(sProcessContents); + maNamespaces = sNamespace.split("\\s+"); + } + + + + @Override + public NodeType GetNodeType () + { + return NodeType.Any; + } + + + + + @Override + public void AcceptVisitor (final INodeVisitor aVisitor) + { + aVisitor.Visit(this); + } + + + public ProcessContents GetProcessContentsFlag () + { + return meProcessContents; + } + + + + + public String[] GetNamespaces () + { + return maNamespaces; + } + + + + + @Override + public String toString () + { + final StringBuffer aBuffer = new StringBuffer(); + aBuffer.append("any processContents="); + aBuffer.append(meProcessContents.toString()); + aBuffer.append(", namespaces="); + boolean bFirst = true; + for (final String sNamespace : maNamespaces) + { + if (bFirst) + bFirst = false; + else + aBuffer.append('|'); + aBuffer.append(sNamespace); + } + return aBuffer.toString(); + } + + + + + private final ProcessContents meProcessContents; + private final String[] maNamespaces; +} diff --git a/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/model/complex/Choice.java b/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/model/complex/Choice.java new file mode 100644 index 000000000000..ab00f1237e3e --- /dev/null +++ b/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/model/complex/Choice.java @@ -0,0 +1,68 @@ +/************************************************************** +* +* 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.model.complex; + +import org.apache.openoffice.ooxml.schema.model.base.INodeVisitor; +import org.apache.openoffice.ooxml.schema.model.base.Location; +import org.apache.openoffice.ooxml.schema.model.base.Node; +import org.apache.openoffice.ooxml.schema.model.base.NodeType; + +/** Representation of the 'choice' XML schema element. + * With the default max value (1) only one of its children may occur. + */ +public class Choice + extends Node +{ + public Choice ( + final Node aParent, + final Location aLocation) + { + super(aParent, null, aLocation); + } + + + + + @Override + public NodeType GetNodeType () + { + return NodeType.Choice; + } + + + + + @Override + public void AcceptVisitor (final INodeVisitor aVisitor) + { + aVisitor.Visit(this); + } + + + + + @Override + public String toString () + { + return "choice"; + } +} diff --git a/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/model/complex/ComplexContent.java b/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/model/complex/ComplexContent.java new file mode 100644 index 000000000000..0ca462ffc56d --- /dev/null +++ b/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/model/complex/ComplexContent.java @@ -0,0 +1,65 @@ +/************************************************************** +* +* 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.model.complex; + +import org.apache.openoffice.ooxml.schema.model.base.INodeVisitor; +import org.apache.openoffice.ooxml.schema.model.base.Location; +import org.apache.openoffice.ooxml.schema.model.base.Node; +import org.apache.openoffice.ooxml.schema.model.base.NodeType; + +public class ComplexContent + extends Node +{ + public ComplexContent ( + final Node aParent, + final Location aLocation) + { + super(aParent, null, aLocation); + } + + + + + @Override + public void AcceptVisitor (final INodeVisitor aVisitor) + { + aVisitor.Visit(this); + } + + + + + @Override + public NodeType GetNodeType() + { + return NodeType.ComplexContent; + } + + + + + @Override + public String toString () + { + return "complex content"; + } +} diff --git a/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/model/complex/ComplexType.java b/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/model/complex/ComplexType.java new file mode 100644 index 000000000000..7ea0de9404d1 --- /dev/null +++ b/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/model/complex/ComplexType.java @@ -0,0 +1,72 @@ +/************************************************************** +* +* 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.model.complex; + +import org.apache.openoffice.ooxml.schema.model.base.INodeVisitor; +import org.apache.openoffice.ooxml.schema.model.base.Location; +import org.apache.openoffice.ooxml.schema.model.base.Node; +import org.apache.openoffice.ooxml.schema.model.base.NodeType; +import org.apache.openoffice.ooxml.schema.model.base.QualifiedName; + +/** Representation of the 'complexType' XML schema element. It specifies the + * structure of its children. + */ +public class ComplexType + extends Node +{ + public ComplexType ( + final Node aParent, + final QualifiedName aName, + final Location aLocation) + { + super(aParent, aName, aLocation); + + assert(aName!=null); + } + + + + + @Override + public NodeType GetNodeType () + { + return NodeType.ComplexType; + } + + + + + @Override + public void AcceptVisitor (final INodeVisitor aVisitor) + { + aVisitor.Visit(this); + } + + + + + @Override + public String toString () + { + return "complex type "+GetName().GetDisplayName(); + } +} diff --git a/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/model/complex/ComplexTypeReference.java b/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/model/complex/ComplexTypeReference.java new file mode 100644 index 000000000000..28266a4a5219 --- /dev/null +++ b/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/model/complex/ComplexTypeReference.java @@ -0,0 +1,100 @@ +/************************************************************** +* +* 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.model.complex; + +import org.apache.openoffice.ooxml.schema.model.base.INode; +import org.apache.openoffice.ooxml.schema.model.base.INodeReference; +import org.apache.openoffice.ooxml.schema.model.base.INodeVisitor; +import org.apache.openoffice.ooxml.schema.model.base.Location; +import org.apache.openoffice.ooxml.schema.model.base.Node; +import org.apache.openoffice.ooxml.schema.model.base.NodeType; +import org.apache.openoffice.ooxml.schema.model.base.QualifiedName; +import org.apache.openoffice.ooxml.schema.model.schema.SchemaBase; + +public class ComplexTypeReference + extends Node + implements INodeReference +{ + ComplexTypeReference ( + final Node aParent, + final QualifiedName aReferencedTypeName, + final Location aLocation) + { + super(aParent, null, aLocation); + maReferencedTypeName = aReferencedTypeName; + } + + + + + public ComplexType GetReferencedComplexType (final SchemaBase aSchema) + { + final Node aType = aSchema.GetTypeForName(maReferencedTypeName); + if (aType == null) + throw new RuntimeException(); + else if (aType.GetNodeType() != NodeType.ComplexType) + throw new RuntimeException(); + else + return (ComplexType)aType; + } + + + + + + public QualifiedName GetReferencedTypeName () + { + return maReferencedTypeName; + } + + + + + @Override + public INode GetReferencedNode (final SchemaBase aSchema) + { + return GetReferencedComplexType(aSchema); + } + + + + + @Override + public void AcceptVisitor (final INodeVisitor aVisitor) + { + aVisitor.Visit(this); + } + + + + + @Override + public NodeType GetNodeType () + { + return NodeType.SimpleTypeReference; + } + + + + + private final QualifiedName maReferencedTypeName; +} diff --git a/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/model/complex/Element.java b/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/model/complex/Element.java new file mode 100644 index 000000000000..27c00fe6cf8b --- /dev/null +++ b/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/model/complex/Element.java @@ -0,0 +1,109 @@ +/************************************************************** +* +* 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.model.complex; + +import org.apache.openoffice.ooxml.schema.model.base.INodeVisitor; +import org.apache.openoffice.ooxml.schema.model.base.Location; +import org.apache.openoffice.ooxml.schema.model.base.Node; +import org.apache.openoffice.ooxml.schema.model.base.NodeType; +import org.apache.openoffice.ooxml.schema.model.base.QualifiedName; + +/** Representation of the 'element' XML schema element. + */ +public class Element + extends Node +{ + /** Create a new element that represents a transition to aTypeName when a + * start tag of aElementName is processed. + */ + public Element ( + final Node aParent, + final QualifiedName aElementName, + final QualifiedName aTypeName, + final Location aLocation) + { + super(aParent, aElementName, aLocation); + maElementName = aElementName; + maTypeName = aTypeName; + } + + + + + public QualifiedName GetElementName () + { + return maElementName; + } + + + + + public QualifiedName GetTypeName () + { + return maTypeName; + } + + + + + @Override + public int compareTo (final Node aOther) + { + if (aOther.GetNodeType() != NodeType.Element) + throw new RuntimeException("can not compare Element object to non-Element object"); + else + return maElementName.compareTo(((Element)aOther).maElementName); + } + + + + + @Override + public NodeType GetNodeType () + { + return NodeType.Element; + } + + + + + @Override + public void AcceptVisitor (final INodeVisitor aVisitor) + { + aVisitor.Visit(this); + } + + + + + @Override + public String toString () + { + return "element " + maElementName.GetDisplayName() +" -> " + maTypeName.GetDisplayName(); + } + + + + + private final QualifiedName maElementName; + private final QualifiedName maTypeName; +} diff --git a/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/model/complex/ElementReference.java b/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/model/complex/ElementReference.java new file mode 100644 index 000000000000..48b2e7fa356f --- /dev/null +++ b/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/model/complex/ElementReference.java @@ -0,0 +1,106 @@ +/************************************************************** +* +* 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.model.complex; + +import org.apache.openoffice.ooxml.schema.model.base.INode; +import org.apache.openoffice.ooxml.schema.model.base.INodeReference; +import org.apache.openoffice.ooxml.schema.model.base.INodeVisitor; +import org.apache.openoffice.ooxml.schema.model.base.Location; +import org.apache.openoffice.ooxml.schema.model.base.Node; +import org.apache.openoffice.ooxml.schema.model.base.NodeType; +import org.apache.openoffice.ooxml.schema.model.base.QualifiedName; +import org.apache.openoffice.ooxml.schema.model.schema.SchemaBase; + +public class ElementReference + extends Element + implements INodeReference +{ + public ElementReference ( + final Node aParent, + final QualifiedName aReferencedElementName, + final Location aLocation) + { + super(aParent, null, null, aLocation); + + maReferencedElementName = aReferencedElementName; + } + + + + + public QualifiedName GetReferencedElementName () + { + return maReferencedElementName; + } + + + + + public Element GetReferencedElement (final SchemaBase aSchema) + { + final Element aElement = aSchema.TopLevelElements.Get(maReferencedElementName); + if (aElement == null) + throw new RuntimeException("can not find element "+maReferencedElementName.GetDisplayName()); + return aElement; + } + + + + + @Override + public INode GetReferencedNode (final SchemaBase aSchema) + { + return GetReferencedElement(aSchema); + } + + + + + @Override + public NodeType GetNodeType () + { + return NodeType.ElementReference; + } + + + + + @Override + public void AcceptVisitor (final INodeVisitor aVisitor) + { + aVisitor.Visit(this); + } + + + + + @Override + public String toString () + { + return "element reference to "+maReferencedElementName.GetDisplayName(); + } + + + + + private final QualifiedName maReferencedElementName; +} diff --git a/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/model/complex/Extension.java b/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/model/complex/Extension.java new file mode 100644 index 000000000000..749c608f6c27 --- /dev/null +++ b/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/model/complex/Extension.java @@ -0,0 +1,160 @@ +/************************************************************** +* +* 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.model.complex; + +import java.util.Vector; + +import org.apache.openoffice.ooxml.schema.model.base.INode; +import org.apache.openoffice.ooxml.schema.model.base.INodeReference; +import org.apache.openoffice.ooxml.schema.model.base.INodeVisitor; +import org.apache.openoffice.ooxml.schema.model.base.Location; +import org.apache.openoffice.ooxml.schema.model.base.Node; +import org.apache.openoffice.ooxml.schema.model.base.NodeType; +import org.apache.openoffice.ooxml.schema.model.base.QualifiedName; +import org.apache.openoffice.ooxml.schema.model.schema.SchemaBase; + +/** Representation of the 'extension' XML schema element. + * It extends a complex base type. + */ +public class Extension + extends Node + implements INodeReference +{ + public Extension ( + final Node aParent, + final QualifiedName aBaseTypeName, + final Location aLocation) + { + super(aParent, null, aLocation); + maBaseTypeName = aBaseTypeName; + } + + + + + @Override + public void AcceptVisitor (final INodeVisitor aVisitor) + { + aVisitor.Visit(this); + } + + + + + @Override + public NodeType GetNodeType() + { + return NodeType.Extension; + } + + + + + public QualifiedName GetBaseTypeName() + { + return maBaseTypeName; + } + + + + + public INode GetBaseType (final SchemaBase aSchema) + { + return aSchema.GetTypeForName(maBaseTypeName); + } + + + + + @Override + public INode GetReferencedNode (final SchemaBase aSchema) + { + return GetBaseType(aSchema); + } + + + + + public Vector<INode> GetTypeNodes (final SchemaBase aSchemaBase) + { + final Vector<INode> aNodes = new Vector<>(); + + AddNodes(aSchemaBase.GetTypeForName(maBaseTypeName), aNodes, aSchemaBase); + for (final INode aChild : GetChildren()) + AddNodes(aChild, aNodes, aSchemaBase); + + return aNodes; + } + + + + + @Override + public String toString () + { + return "extension of base type "+maBaseTypeName.GetDisplayName(); + } + + + + + private void AddNodes ( + final INode aParent, + final Vector<INode> aNodes, + final SchemaBase aSchemaBase) + { + INode aNode = aParent; + while (true) + { + switch (aNode.GetNodeType()) + { + case Extension: + aNode = ((Extension)aNode).GetBaseType(aSchemaBase); + break; + + case ComplexContent: + case SimpleContent: + case ComplexType: + switch(aNode.GetChildCount()) + { + case 0: + return; + case 1: + aNode = aNode.GetOnlyChild(); + break; + default: + throw new RuntimeException(); + } + break; + + default: + aNodes.add(aNode); + return; + } + } + } + + + + + public QualifiedName maBaseTypeName; +} diff --git a/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/model/complex/Group.java b/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/model/complex/Group.java new file mode 100644 index 000000000000..4358c20849a5 --- /dev/null +++ b/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/model/complex/Group.java @@ -0,0 +1,70 @@ +/************************************************************** +* +* 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.model.complex; + +import org.apache.openoffice.ooxml.schema.model.base.INodeVisitor; +import org.apache.openoffice.ooxml.schema.model.base.Location; +import org.apache.openoffice.ooxml.schema.model.base.Node; +import org.apache.openoffice.ooxml.schema.model.base.NodeType; +import org.apache.openoffice.ooxml.schema.model.base.QualifiedName; + +/** Represents the 'group' XML schema element. + * The concepts of groups are similar to macros. + */ +public class Group + extends Node +{ + public Group ( + final Node aParent, + final QualifiedName aName, + final Location aLocation) + { + super(aParent, aName, aLocation); + } + + + + + @Override + public NodeType GetNodeType () + { + return NodeType.Group; + } + + + + + @Override + public void AcceptVisitor (final INodeVisitor aVisitor) + { + aVisitor.Visit(this); + } + + + + + @Override + public String toString () + { + return "group "+GetName().GetDisplayName(); + } +} diff --git a/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/model/complex/GroupReference.java b/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/model/complex/GroupReference.java new file mode 100644 index 000000000000..048308ca9940 --- /dev/null +++ b/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/model/complex/GroupReference.java @@ -0,0 +1,109 @@ +/************************************************************** +* +* 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.model.complex; + +import org.apache.openoffice.ooxml.schema.model.base.INode; +import org.apache.openoffice.ooxml.schema.model.base.INodeReference; +import org.apache.openoffice.ooxml.schema.model.base.INodeVisitor; +import org.apache.openoffice.ooxml.schema.model.base.Location; +import org.apache.openoffice.ooxml.schema.model.base.Node; +import org.apache.openoffice.ooxml.schema.model.base.NodeType; +import org.apache.openoffice.ooxml.schema.model.base.QualifiedName; +import org.apache.openoffice.ooxml.schema.model.schema.SchemaBase; + +public class GroupReference + extends Node + implements INodeReference +{ + public GroupReference ( + final Node aParent, + final QualifiedName aReferencedGroupName, + final Location aLocation) + { + super(aParent, null, aLocation); + + maReferencedGroupName = aReferencedGroupName; + } + + + + + public QualifiedName GetReferencedGroupName () + { + return maReferencedGroupName; + } + + + + + public Group GetReferencedGroup (final SchemaBase aSchemaBase) + { + final Node aType = aSchemaBase.GetTypeForName(maReferencedGroupName); + if (aType == null) + throw new RuntimeException("there is no type named '"+maReferencedGroupName+"' in the schema"); + else if (aType.GetNodeType()!=NodeType.Group) + throw new RuntimeException("name '"+maReferencedGroupName+"' references a "+aType.GetNodeType()+" not a group"); + else + return (Group)aType; + } + + + + + @Override + public INode GetReferencedNode (final SchemaBase aSchemaBase) + { + return GetReferencedGroup(aSchemaBase); + } + + + + + @Override + public NodeType GetNodeType () + { + return NodeType.GroupReference; + } + + + + + @Override + public void AcceptVisitor (final INodeVisitor aVisitor) + { + aVisitor.Visit(this); + } + + + + + @Override + public String toString () + { + return "group reference to "+maReferencedGroupName.GetDisplayName(); + } + + + + + private final QualifiedName maReferencedGroupName; +} diff --git a/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/model/complex/OccurrenceIndicator.java b/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/model/complex/OccurrenceIndicator.java new file mode 100644 index 000000000000..dcc41bfbb7ce --- /dev/null +++ b/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/model/complex/OccurrenceIndicator.java @@ -0,0 +1,152 @@ +/************************************************************** +* +* 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.model.complex; + +import org.apache.openoffice.ooxml.schema.model.base.INodeVisitor; +import org.apache.openoffice.ooxml.schema.model.base.Location; +import org.apache.openoffice.ooxml.schema.model.base.Node; +import org.apache.openoffice.ooxml.schema.model.base.NodeType; + +/** An occurrence indicator is based on a minimum and a maximum value. + * The minimum value is 0 or larger. If it is 0 then the child node is optional. + * The maximum value is at least as large as the minimum value. + * It can be 'unbounded' in which case the child node can appear any number of times. + * 'Unbounded' is internally stored as -1. + * + * An OccurrenceIndicator represents the minOccur and maxOccur attributes of + * XML schema elements. + * + * There is usually exactly one child. + */ +public class OccurrenceIndicator + extends Node +{ + public static int unbounded = -1; + + public OccurrenceIndicator ( + final Node aParent, + final String sMinimum, + final String sMaximum, + final Location aLocation) + { + super(aParent, null, aLocation); + + mnMinimum = ParseValue(sMinimum); + mnMaximum = ParseValue(sMaximum); + + assert(mnMinimum>=0); + assert(mnMaximum==unbounded || mnMaximum>=mnMinimum); + } + + + + + @Override + public NodeType GetNodeType () + { + return NodeType.OccurrenceIndicator; + } + + + + + /** Return a string version of the minimum value for textual display. + */ + public String GetDisplayMinimum () + { + return Integer.toString(mnMinimum); + } + + + + + /** Return a string version of the maximum value for textual display. + */ + public String GetDisplayMaximum () + { + if (mnMaximum == unbounded) + return "unbounded"; + else + return Integer.toString(mnMaximum); + } + + + + + public int GetMinimum () + { + return mnMinimum; + } + + + + + public int GetMaximum () + { + return mnMaximum; + } + + + + + @Override + public void AcceptVisitor (final INodeVisitor aVisitor) + { + aVisitor.Visit(this); + } + + + + + @Override + public String toString () + { + return String.format("occurrence %s to %s", + GetDisplayMinimum(), + GetDisplayMaximum()); + } + + + + + private static int ParseValue (final String sValue) + { + if (sValue == null) + { + // Missing values default to 1. + return 1; + } + else + switch (sValue) + { + case "0" : return 0; + case "1" : return 1; + case "unbounded" : return unbounded; + default: return Integer.parseInt(sValue); + } + } + + + + private final int mnMinimum; + private final int mnMaximum; +} diff --git a/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/model/complex/Sequence.java b/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/model/complex/Sequence.java new file mode 100644 index 000000000000..da01a8c15e28 --- /dev/null +++ b/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/model/complex/Sequence.java @@ -0,0 +1,73 @@ +/************************************************************** +* +* 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.model.complex; + +import org.apache.openoffice.ooxml.schema.model.base.INodeVisitor; +import org.apache.openoffice.ooxml.schema.model.base.Location; +import org.apache.openoffice.ooxml.schema.model.base.Node; +import org.apache.openoffice.ooxml.schema.model.base.NodeType; +import org.apache.openoffice.ooxml.schema.model.base.QualifiedName; + +/** Representation of a 'sequence' XML schema element. + * It defines an order on its children. + */ + public class Sequence + extends Node +{ + public Sequence ( + final Node aParent, + final QualifiedName aName, + final Location aLocation) + { + super(aParent, aName, aLocation); + } + + + + + @Override + public NodeType GetNodeType () + { + return NodeType.Sequence; + } + + + + + @Override + public void AcceptVisitor (final INodeVisitor aVisitor) + { + aVisitor.Visit(this); + } + + + + + @Override + public String toString () + { + if (GetName() != null) + return "sequence "+GetName().GetDisplayName(); + else + return "sequence"; + } +} |