Permalink
Browse files

Syntax improvements

  • Loading branch information...
1 parent ffffd5d commit eeea13fb5bc8750348c8742d6807f4305fdfb691 @ashewring ashewring committed Mar 13, 2012
@@ -1,18 +1,32 @@
package org.s23m.cell.communication.xml;
+import org.eclipse.xtext.xbase.lib.Functions.Function0;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.s23m.cell.communication.xml.dom.Namespace;
import org.s23m.cell.communication.xml.schema.Cardinality;
import org.s23m.cell.communication.xml.schema.ComplexType;
+import org.s23m.cell.communication.xml.schema.DataType;
import org.s23m.cell.communication.xml.schema.Element;
import org.s23m.cell.communication.xml.schema.ElementReference;
import org.s23m.cell.communication.xml.schema.Extension;
import org.s23m.cell.communication.xml.schema.Schema;
import org.s23m.cell.communication.xml.schema.Sequence;
+import org.s23m.cell.communication.xml.schema.SimpleType;
import org.s23m.cell.communication.xml.schema.Type;
@SuppressWarnings("all")
public class SchemaBuilder {
+ private static String S23M = "s23m";
+
+ private static String S23M_SCHEMA = "http://schemas.s23m.org/serialization/2012";
+
+ private static Namespace NS_S23M = new Function0<Namespace>() {
+ public Namespace apply() {
+ Namespace _namespace = new Namespace(SchemaBuilder.S23M, SchemaBuilder.S23M_SCHEMA);
+ return _namespace;
+ }
+ }.apply();
+
public static Schema schema(final Procedure1<? super Schema> initialiser) {
Schema _xblockexpression = null;
{
@@ -24,18 +38,24 @@ public static Schema schema(final Procedure1<? super Schema> initialiser) {
return _xblockexpression;
}
- public static ComplexType complexType(final Namespace targetNamespace, final String name, final Sequence sequence) {
- ComplexType _complexType = new ComplexType(targetNamespace, name, sequence);
+ public static SimpleType simpleType(final String nameAttribute, final DataType restrictionDataType) {
+ SimpleType _simpleType = new SimpleType(SchemaBuilder.NS_S23M, nameAttribute, restrictionDataType);
+ return _simpleType;
+ }
+
+ public static ComplexType complexType(final String name, final Sequence sequence) {
+ ComplexType _complexType = new ComplexType(SchemaBuilder.NS_S23M, name, sequence);
return _complexType;
}
- public static ComplexType complexType(final Namespace targetNamespace, final String name, final Extension ext) {
- ComplexType _complexType = new ComplexType(targetNamespace, name, ext);
+ public static ComplexType complexType(final String name, final Extension ext) {
+ ComplexType _complexType = new ComplexType(SchemaBuilder.NS_S23M, name, ext);
return _complexType;
}
- public static Extension withExtension(final ComplexType base, final Sequence sequence) {
- Extension _extension = new Extension(base, sequence);
+ public static Extension withExtension(final ComplexType base, final Procedure1<? super Sequence> initialiser) {
+ Sequence _sequence = SchemaBuilder.sequence(initialiser);
+ Extension _extension = new Extension(base, _sequence);
return _extension;
}
@@ -55,24 +75,24 @@ public static ElementReference element(final Element referencedElement) {
return _elementReference;
}
- public static Element element(final Namespace namespace, final String name, final Type type) {
+ public static Element element(final String name, final Type type) {
final Procedure1<Element> _function = new Procedure1<Element>() {
public void apply(final Element it) {
}
};
- Element _element = SchemaBuilder.element(namespace, name, type, _function);
+ Element _element = SchemaBuilder.element(name, type, _function);
return _element;
}
- public static Element element(final Namespace namespace, final String name, final Type type, final Procedure1<? super Element> initialiser) {
- Element _element = SchemaBuilder.element(namespace, name, type, Cardinality.EXACTLY_ONE, initialiser);
+ public static Element element(final String name, final Type type, final Procedure1<? super Element> initialiser) {
+ Element _element = SchemaBuilder.element(name, type, Cardinality.EXACTLY_ONE, initialiser);
return _element;
}
- public static Element element(final Namespace namespace, final String name, final Type type, final Cardinality cardinality, final Procedure1<? super Element> initialiser) {
+ public static Element element(final String name, final Type type, final Cardinality cardinality, final Procedure1<? super Element> initialiser) {
Element _xblockexpression = null;
{
- Element _element = new Element(namespace, name, type, cardinality);
+ Element _element = new Element(SchemaBuilder.NS_S23M, name, type, cardinality);
final Element result = _element;
initialiser.apply(result);
_xblockexpression = (result);
@@ -76,13 +76,6 @@ public Namespace apply() {
}
}.apply();
- private static Namespace NS_XSD = new Function0<Namespace>() {
- public Namespace apply() {
- Namespace _namespace = new Namespace(XmlSchemaTemplate.XSD, XmlSchemaTemplate.XSD_SCHEMA);
- return _namespace;
- }
- }.apply();
-
private XmlSchemaTerminology terminology;
private String semanticIdentity;
@@ -215,28 +208,28 @@ public void apply(final Schema it) {
private List<Element> createReusedElements() {
ArrayList<Element> _xblockexpression = null;
{
- SimpleType _simpleType = new SimpleType(XmlSchemaTemplate.NS_S23M, "uuid", DataType.STRING);
+ SimpleType _simpleType = SchemaBuilder.simpleType(this.uuid, DataType.STRING);
final SimpleType uuid = _simpleType;
final Procedure1<Sequence> _function = new Procedure1<Sequence>() {
public void apply(final Sequence it) {
{
List<Node> _children = it.getChildren();
String _uniqueRepresentationReference = XmlSchemaTemplate.this.terminology.uniqueRepresentationReference();
- Element _element = SchemaBuilder.element(XmlSchemaTemplate.NS_S23M, _uniqueRepresentationReference, uuid);
+ Element _element = SchemaBuilder.element(_uniqueRepresentationReference, uuid);
CollectionExtensions.<Element>operator_add(_children, _element);
List<Node> _children_1 = it.getChildren();
String _identifier = XmlSchemaTemplate.this.terminology.identifier();
- Element _element_1 = SchemaBuilder.element(XmlSchemaTemplate.NS_S23M, _identifier, uuid);
+ Element _element_1 = SchemaBuilder.element(_identifier, uuid);
CollectionExtensions.<Element>operator_add(_children_1, _element_1);
}
}
};
Sequence _sequence = SchemaBuilder.sequence(_function);
- ComplexType _complexType = SchemaBuilder.complexType(XmlSchemaTemplate.NS_S23M, this.identityReference, _sequence);
+ ComplexType _complexType = SchemaBuilder.complexType(this.identityReference, _sequence);
final ComplexType identityReference = _complexType;
- Element _element = SchemaBuilder.element(XmlSchemaTemplate.NS_S23M, this.semanticIdentity, identityReference);
+ Element _element = SchemaBuilder.element(this.semanticIdentity, identityReference);
final Element semanticIdentityElement = _element;
- Element _element_1 = SchemaBuilder.element(XmlSchemaTemplate.NS_S23M, this.category, identityReference);
+ Element _element_1 = SchemaBuilder.element(this.category, identityReference);
final Element categoryElement = _element_1;
final Procedure1<Sequence> _function_1 = new Procedure1<Sequence>() {
public void apply(final Sequence it) {
@@ -249,23 +242,22 @@ public void apply(final Sequence it) {
}
};
Sequence _sequence_1 = SchemaBuilder.sequence(_function_1);
- ComplexType _complexType_1 = SchemaBuilder.complexType(XmlSchemaTemplate.NS_S23M, this.category, _sequence_1);
+ ComplexType _complexType_1 = SchemaBuilder.complexType(this.category, _sequence_1);
final ComplexType categoryComplexType = _complexType_1;
final Procedure1<Sequence> _function_2 = new Procedure1<Sequence>() {
public void apply(final Sequence it) {
}
};
- Sequence _sequence_2 = SchemaBuilder.sequence(_function_2);
- Extension _withExtension = SchemaBuilder.withExtension(categoryComplexType, _sequence_2);
- ComplexType _complexType_2 = SchemaBuilder.complexType(XmlSchemaTemplate.NS_S23M, this.graph, _withExtension);
+ Extension _withExtension = SchemaBuilder.withExtension(categoryComplexType, _function_2);
+ ComplexType _complexType_2 = SchemaBuilder.complexType(this.graph, _withExtension);
final ComplexType graphComplexType = _complexType_2;
- Element _element_2 = SchemaBuilder.element(XmlSchemaTemplate.NS_S23M, this.isAbstract, identityReference);
- Element _element_3 = SchemaBuilder.element(XmlSchemaTemplate.NS_S23M, this.maxCardinality, identityReference);
- Element _element_4 = SchemaBuilder.element(XmlSchemaTemplate.NS_S23M, this.minCardinality, identityReference);
- Element _element_5 = SchemaBuilder.element(XmlSchemaTemplate.NS_S23M, this.isContainer, identityReference);
- Element _element_6 = SchemaBuilder.element(XmlSchemaTemplate.NS_S23M, this.isNavigable, identityReference);
- Element _element_7 = SchemaBuilder.element(XmlSchemaTemplate.NS_S23M, this.from, identityReference);
- Element _element_8 = SchemaBuilder.element(XmlSchemaTemplate.NS_S23M, this.to, identityReference);
+ Element _element_2 = SchemaBuilder.element(this.isAbstract, identityReference);
+ Element _element_3 = SchemaBuilder.element(this.maxCardinality, identityReference);
+ Element _element_4 = SchemaBuilder.element(this.minCardinality, identityReference);
+ Element _element_5 = SchemaBuilder.element(this.isContainer, identityReference);
+ Element _element_6 = SchemaBuilder.element(this.isNavigable, identityReference);
+ Element _element_7 = SchemaBuilder.element(this.from, identityReference);
+ Element _element_8 = SchemaBuilder.element(this.to, identityReference);
ArrayList<Element> _newArrayList = CollectionLiterals.<Element>newArrayList(semanticIdentityElement, categoryElement, _element_2, _element_3, _element_4, _element_5, _element_6, _element_7, _element_8);
_xblockexpression = (_newArrayList);
}
@@ -11,25 +11,37 @@ import org.s23m.cell.communication.xml.schema.Type
import org.s23m.cell.communication.xml.schema.ComplexType
import org.s23m.cell.communication.xml.schema.Extension
import org.s23m.cell.communication.xml.schema.ElementReference
+import org.s23m.cell.communication.xml.schema.SimpleType
+import org.s23m.cell.communication.xml.schema.DataType
class SchemaBuilder {
+ static String S23M = "s23m"
+
+ static String S23M_SCHEMA = "http://schemas.s23m.org/serialization/2012"
+
+ static Namespace NS_S23M = new Namespace(S23M, S23M_SCHEMA)
+
def static schema((Schema)=>void initialiser) {
val result = new Schema()
initialiser.apply(result)
result
}
- def static complexType(Namespace targetNamespace, String name, Sequence sequence) {
- new ComplexType(targetNamespace, name, sequence)
+ def static simpleType(String nameAttribute, DataType restrictionDataType) {
+ new SimpleType(NS_S23M, nameAttribute, restrictionDataType)
+ }
+
+ def static complexType(String name, Sequence sequence) {
+ new ComplexType(NS_S23M, name, sequence)
}
- def static complexType(Namespace targetNamespace, String name, Extension ext) {
- new ComplexType(targetNamespace, name, ext)
+ def static complexType(String name, Extension ext) {
+ new ComplexType(NS_S23M, name, ext)
}
- def static withExtension(ComplexType base, Sequence sequence) {
- new Extension(base, sequence)
+ def static withExtension(ComplexType base, (Sequence)=>void initialiser) {
+ new Extension(base, sequence(initialiser))
}
def static sequence((Sequence)=>void initialiser) {
@@ -42,20 +54,19 @@ class SchemaBuilder {
new ElementReference(referencedElement)
}
- def static element(Namespace namespace, String name, Type type) {
- element(namespace, name, type, [])
+ def static element(String name, Type type) {
+ element(name, type, [])
}
- def static element(Namespace namespace, String name, Type type, (Element)=>void initialiser) {
- element(namespace, name, type, Cardinality::EXACTLY_ONE, initialiser)
+ def static element(String name, Type type, (Element)=>void initialiser) {
+ element(name, type, Cardinality::EXACTLY_ONE, initialiser)
}
- def static element(Namespace namespace,
- String name,
+ def static element(String name,
Type type,
Cardinality cardinality,
(Element)=>void initialiser) {
- val result = new Element(namespace, name, type, cardinality)
+ val result = new Element(NS_S23M, name, type, cardinality)
initialiser.apply(result)
result
}
@@ -62,7 +62,6 @@ class XmlSchemaTemplate {
'attributeFormDefault="unqualified"'
static Namespace NS_S23M = new Namespace(S23M, S23M_SCHEMA)
- static Namespace NS_XSD = new Namespace(XSD, XSD_SCHEMA)
XmlSchemaTerminology terminology
@@ -141,23 +140,23 @@ class XmlSchemaTemplate {
// The target namespace is used during rendering of types and references
def private List<Element> createReusedElements() {
- val uuid = new SimpleType(NS_S23M, "uuid", DataType::STRING)
+ val uuid = simpleType(uuid, DataType::STRING)
- val identityReference = complexType(NS_S23M, identityReference, sequence [
- children += SchemaBuilder::element(NS_S23M, terminology.uniqueRepresentationReference, uuid)
- children += SchemaBuilder::element(NS_S23M, terminology.identifier, uuid)
+ val identityReference = complexType(identityReference, sequence [
+ children += SchemaBuilder::element(terminology.uniqueRepresentationReference, uuid)
+ children += SchemaBuilder::element(terminology.identifier, uuid)
])
- val semanticIdentityElement = SchemaBuilder::element(NS_S23M, semanticIdentity, identityReference)
+ val semanticIdentityElement = SchemaBuilder::element(semanticIdentity, identityReference)
- val categoryElement = SchemaBuilder::element(NS_S23M, category, identityReference)
+ val categoryElement = SchemaBuilder::element(category, identityReference)
- val categoryComplexType = complexType(NS_S23M, category, sequence [
+ val categoryComplexType = complexType(category, sequence [
children += semanticIdentityElement
children += categoryElement
])
- val graphComplexType = complexType(NS_S23M, graph, withExtension(categoryComplexType, sequence [
+ val graphComplexType = complexType(graph, withExtension(categoryComplexType, [
// TODO
]))
@@ -188,13 +187,13 @@ class XmlSchemaTemplate {
//SchemaBuilder::element(NS_XSD, model, model),
//SchemaBuilder::element(NS_XSD, function, function)
categoryElement,
- SchemaBuilder::element(NS_S23M, isAbstract, identityReference),
- SchemaBuilder::element(NS_S23M, maxCardinality, identityReference),
- SchemaBuilder::element(NS_S23M, minCardinality, identityReference),
- SchemaBuilder::element(NS_S23M, isContainer, identityReference),
- SchemaBuilder::element(NS_S23M, isNavigable, identityReference),
- SchemaBuilder::element(NS_S23M, from, identityReference),
- SchemaBuilder::element(NS_S23M, to, identityReference)
+ SchemaBuilder::element(isAbstract, identityReference),
+ SchemaBuilder::element(maxCardinality, identityReference),
+ SchemaBuilder::element(minCardinality, identityReference),
+ SchemaBuilder::element(isContainer, identityReference),
+ SchemaBuilder::element(isNavigable, identityReference),
+ SchemaBuilder::element(from, identityReference),
+ SchemaBuilder::element(to, identityReference)
)
}

0 comments on commit eeea13f

Please sign in to comment.