All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.codehaus.enunciate.modules.xml.schema.fmt Maven / Gradle / Ivy

Go to download

The Enunciate XML module generates the XML artifacts (schema, WSDL) for the Enunciated project.

The newest version!
[#ftl]
[#--
 Template library for schema generation.
--]

[#--
  The processSchema macro outputs a given schema

  @param schema The schema to output (instance of org.codehaus.enunciate.config.SchemaInfo)
--]
[#macro processSchema schema]

[#-- assign the prefix variable for the schema namespace --]
[#assign xs=prefix("http://www.w3.org/2001/XMLSchema")]
<${xs}:schema version="1.0"[#if schema.namespace?? && schema.namespace?length > 0] targetNamespace="${schema.namespace!("")}"[/#if]
  [#if schema.elementFormDefault??]elementFormDefault="${schema.elementFormDefault}" [/#if][#t]
  [#if schema.attributeFormDefault??]attributeFormDefault="${schema.attributeFormDefault}" [/#if][#t]
  [#list schema.referencedNamespaces as referencedNamespace]
    [#if referencedNamespace?? && referencedNamespace?length > 0 && !("http://www.w3.org/2001/XMLSchema" = referencedNamespace)]
  xmlns:${prefix(referencedNamespace)}="${referencedNamespace}"
    [/#if]
  [/#list]
  [#if schema.jaxbBindingVersion??]jxb:version="${schema.jaxbBindingVersion}" xmlns:jxb="http://java.sun.com/xml/ns/jaxb"[/#if]
  xmlns:${xs}="http://www.w3.org/2001/XMLSchema">
  [#if schema.doc?? || schema.appinfo??]
  <${xs}:annotation>
    [#if schema.doc??]
    <${xs}:documentation>
     
    
    [/#if]
    [#if schema.appinfo??]
    <${xs}:appinfo>
      ${schema.appinfo}
    
    [/#if]
  
  [/#if]
[#t]
  [#list schema.importedSchemas as importedSchema]
  <${xs}:import[#if importedSchema.namespace?? && importedSchema.namespace?length > 0] namespace="${importedSchema.namespace}"[/#if][#if importedSchema.location??] schemaLocation="${importedSchema.location}"[/#if]/>
  [/#list]

  [@processSchemaBody schema=schema/]

[/#macro]

[#--
  The processSchemaBody macro outputs the body of a given schema

  @param schema The schema to output (instance of org.codehaus.enunciate.config.SchemaInfo)
--]
[#macro processSchemaBody schema]
[#assign xs=prefix("http://www.w3.org/2001/XMLSchema")]
[#if schema.namespace??]
  [#assign tns=prefix(schema.namespace)]
[#else]
  [#assign tns=""]
[/#if]
  [#list schema.globalElements as globalElement]
    [#if !isFacetExcluded(globalElement)]
      [#if globalElement.typeDefinition.anonymous]
  <${xs}:element name="${globalElement.name}">
    [@processTypeDef typeDef=globalElement.typeDefinition/]
  
      [#else]
  <${xs}:element name="${globalElement.name}" type="${globalElement.typeDefinition.qname}"/>
      [/#if]
    [/#if]
  [/#list]
  [#list schema.localElementDeclarations as localElement]
    [#if !isDefinedGlobally(localElement)]
      [#if localElement.substitutionGroupQName??]
  <${xs}:element name="${localElement.name}" substitutionGroup="${localElement.substitutionGroupQName}"[#if localElement.defaultValue??] default="${localElement.defaultValue}"[/#if]/>
      [#elseif localElement.elementXmlType.anonymous && localElement.elementXmlType.typeDefinition??]
  <${xs}:element name="${localElement.name}">
    [@processTypeDef typeDef=localElement.elementXmlType.typeDefinition/]
  
      [#else]
  <${xs}:element name="${localElement.name}" type="${localElement.elementXmlType.qname}"[#if localElement.defaultValue??] default="${localElement.defaultValue}"[/#if]/>
      [/#if]
    [/#if]
  [/#list]
[#t]
  [#list schema.typeDefinitions as typeDefinition]
    [#if !typeDefinition.anonymous && !isFacetExcluded(typeDefinition)]
      [@processTypeDef typeDef=typeDefinition/]
    [/#if]
  [/#list]
[#t]
  [#list schema.implicitSchemaElements as implicitElement]
    [@processImplicitElement implicitElement=implicitElement/]
  [/#list]
[#t]
  [#list schema.implicitSchemaAttributes as implicitAttribute]
    [@processImplicitAttribute implicitAttribute=implicitAttribute/]
  [/#list]
[#t]
[/#macro]

[#--
  The "processTypeDef" macro outputs a given type definition.

  @param typeDef the type definition to output (instance of org.codehaus.enunciate.contract.jaxb.TypeDefinition)
--]
[#macro processTypeDef typeDef]
  [#--simple type definition--]
  [#if typeDef.simple]
<${xs}:simpleType[#if !typeDef.anonymous] name="${typeDef.name}"[/#if]>
    [#if typeDef.docValue?? || typeDef.value.referencesQNameEnum!false]
  <${xs}:annotation>
      [#if typeDef.docValue??]
    <${xs}:documentation>
      
    
      [/#if]
      [#if typeDef.value.referencesQNameEnum!false]
    <${xs}:documentation>
      See ${qnameForType(typeDef.value.QNameEnumRef)} for an enumeration of known values.
    
      [/#if]
  
    [/#if]
    [#if typeDef.value.xmlList]
  <${xs}:list itemType="${typeDef.baseType.qname}"/>
    [#else]
  <${xs}:restriction base="${typeDef.baseType.qname}"/>
    [/#if]


  [#--enum type definition--]
  [#elseif typeDef.enum]
<${xs}:simpleType[#if !typeDef.anonymous] name="${typeDef.name}"[/#if]>
    [#if typeDef.docValue??]
  <${xs}:annotation>
    <${xs}:documentation>
      
    
  
    [/#if]
  <${xs}:restriction base="${typeDef.baseType.qname}">
    [#list typeDef.enumValues?keys as enumKey] [#--todo: add the java doc comments for these enum values.--]
      [#if typeDef.enumValues[enumKey]??]
        [#if typeDef.QNameEnum!false]
          [#if !typeDef.uriBaseType]
    <${xs}:enumeration value="[#if typeDef.enumValues[enumKey].namespaceURI != ""]${prefix(typeDef.enumValues[enumKey].namespaceURI)}:[/#if]${typeDef.enumValues[enumKey].localPart}"/>
          [#else]
    <${xs}:enumeration value="${typeDef.enumValues[enumKey].namespaceURI}${typeDef.enumValues[enumKey].localPart}"/>
          [/#if]
        [#else]
    <${xs}:enumeration value="${typeDef.enumValues[enumKey]}"/>
        [/#if]
      [/#if]
    [/#list]
  


  [#--complex type definition--]
  [#elseif typeDef.complex]
<${xs}:complexType[#if !typeDef.anonymous] name="${typeDef.name}"[/#if][#if typeDef.final] final="#all"[/#if][#if typeDef.abstract] abstract="true"[/#if]>
    [#if typeDef.docValue??]
  <${xs}:annotation>
    <${xs}:documentation>
      
    
  
    [/#if]
    [#if typeDef.baseType?? && typeDef.baseType.map!false]
      [@processMapTypeSequence mapType=typeDef.baseType/]

    [#elseif typeDef.contentType.complex] [#--complex type with complex content.--]
      [#--if it's not implied, we need to declare the extension--]
      [#if !typeDef.baseObject]
  <${xs}:complexContent>
    <${xs}:extension base="${typeDef.baseType.qname}">
      [/#if]
      [#if !typeDef.contentType.empty]
      <${xs}:${typeDef.compositorName}>
        [#list typeDef.elements as element]
          [#if !accessorOverridesAnother(element) && !isFacetExcluded(element)]
            [#if element.wrapped]
        <${xs}:element name="${element.wrapperName}" minOccurs="0">
              [#if element.docValue??]
          <${xs}:annotation>
            <${xs}:documentation>
              
            
          
              [/#if]
          <${xs}:complexType>
            <${xs}:sequence>
            [/#if]
            [#if ((element.elementRefs!false) || (element.choices?size > 1))]
              <${xs}:choice minOccurs="0" maxOccurs="unbounded">
              [#list element.choices as elementChoice]
                [#if elementChoice.ref??]
                <${xs}:element ref="${elementChoice.ref}"/>
                [#elseif elementChoice.baseType.anonymous]
                <${xs}:element name="${elementChoice.name}">
                  [@processAnonymousType type=elementChoice.baseType/]
                
                [#else]
                <${xs}:element name="${elementChoice.name}" type="${elementChoice.baseType.qname}"[#if elementChoice.mimeType??] xmlns:xmime="http://www.w3.org/2005/05/xmlmime" xmime:expectedContentTypes="${elementChoice.mimeType}"[/#if]/>
                [/#if]
              [/#list]
              
            [#else]
              [#if element.ref??]
              <${xs}:element ref="${element.ref}" minOccurs="${element.minOccurs}"[#if "1" != element.maxOccurs] maxOccurs="${element.maxOccurs}"[/#if]>
                [#if element.docValue?? || element.referencesQNameEnum!false]
              <${xs}:annotation>
                  [#if element.docValue??]
                <${xs}:documentation>
                  
                
                  [/#if]
                  [#if element.referencesQNameEnum!false]
                <${xs}:documentation>
                  See ${qnameForType(element.QNameEnumRef)} for an enumeration of known values.
                
                  [/#if]
              
                [/#if]
              
              [#elseif element.baseType.anonymous]
              <${xs}:element name="${element.name}" minOccurs="${element.minOccurs}"[#if "1" != element.maxOccurs] maxOccurs="${element.maxOccurs}"[/#if]>
                [#if element.docValue?? || element.referencesQNameEnum!false]
              <${xs}:annotation>
                  [#if element.docValue??]
                <${xs}:documentation>
                  
                
                  [/#if]
                  [#if element.referencesQNameEnum!false]
                <${xs}:documentation>
                  See ${qnameForType(element.QNameEnumRef)} for an enumeration of known values.
                
                  [/#if]
              
                [/#if]
                [@processAnonymousType type=element.baseType/]
              
              [#elseif element.xmlList]
              <${xs}:element name="${element.name}" minOccurs="${element.minOccurs}"[#if "1" != element.maxOccurs] maxOccurs="${element.maxOccurs}"[/#if]>
                [#if element.docValue?? || element.referencesQNameEnum!false]
              <${xs}:annotation>
                  [#if element.docValue??]
                <${xs}:documentation>
                  
                
                  [/#if]
                  [#if element.referencesQNameEnum!false]
                <${xs}:documentation>
                  See ${qnameForType(element.QNameEnumRef)} for an enumeration of known values.
                
                  [/#if]
              
                [/#if]
                <${xs}:simpleType>
                  <${xs}:list itemType="${element.baseType.qname}"/>
                
              
              [#else]
              <${xs}:element name="${element.name}" type="${element.baseType.qname}" minOccurs="${element.minOccurs}"[#if "1" != element.maxOccurs] maxOccurs="${element.maxOccurs}"[/#if][#if element.mimeType??] xmlns:xmime="http://www.w3.org/2005/05/xmlmime" xmime:expectedContentTypes="${element.mimeType}"[/#if]>
                [#if element.docValue?? || element.referencesQNameEnum!false]
              <${xs}:annotation>
                  [#if element.docValue??]
                <${xs}:documentation>
                  
                
                  [/#if]
                  [#if element.referencesQNameEnum!false]
                <${xs}:documentation>
                  See ${qnameForType(element.QNameEnumRef)} for an enumeration of known values.
                
                  [/#if]
              
                [/#if]
              
              [/#if]
            [/#if]
            [#if element.wrapped]
            
          
        
            [/#if]
          [/#if]
        [/#list]
        [#if typeDef.anyElement??]
          [#if typeDef.anyElement.elementRefs?size = 0]
        <${xs}:any [#if typeDef.anyElement.lax]processContents="lax" [#else]processContents="skip" [/#if]namespace="##other"[#if typeDef.anyElement.collectionType] minOccurs="0" maxOccurs="unbounded"[/#if]/>
          [#else]
        <${xs}:choice minOccurs="0" maxOccurs="unbounded">
            [#list typeDef.anyElement.elementRefs as elementRef]
          <${xs}:element ref="${elementRef.ref}"/>
            [/#list]
          <${xs}:any [#if typeDef.anyElement.lax]processContents="lax" [#else]processContents="skip" [/#if]namespace="##other"/>
        
          [/#if]
        [/#if]
      
      [/#if]
[#t]
    [#--complex type with simple content--]
    [#elseif typeDef.contentType.simple]
  <${xs}:simpleContent>
    <${xs}:extension base="${typeDef.baseType.qname}">
    [/#if]
[#t]
    [#--list all the attributes.--]
    [#list typeDef.attributes as attribute]
      [#if !accessorOverridesAnother(attribute) && !isFacetExcluded(attribute)]
        [#if attribute.ref??]
      <${xs}:attribute[#if attribute.required] use="required"[/#if] ref="${attribute.ref}">
          [#if attribute.docValue?? || attribute.referencesQNameEnum!false]
        <${xs}:annotation>
            [#if attribute.docValue??]
          <${xs}:documentation>
            
          
            [/#if]
            [#if attribute.referencesQNameEnum!false]
          <${xs}:documentation>
            See ${qnameForType(attribute.QNameEnumRef)} for an enumeration of known values.
          
            [/#if]
        
          [/#if]
      
        [#elseif attribute.baseType.anonymous]
      <${xs}:attribute name="${attribute.name}"[#if attribute.required] use="required"[/#if]>
          [#if attribute.docValue?? || attribute.referencesQNameEnum!false]
        <${xs}:annotation>
            [#if attribute.docValue??]
          <${xs}:documentation>
            
          
            [/#if]
            [#if attribute.referencesQNameEnum!false]
          <${xs}:documentation>
            See ${qnameForType(attribute.QNameEnumRef)} for an enumeration of known values.
          
            [/#if]
        
          [/#if]
          [@processAnonymousType type=attribute.baseType/]
      
        [#else]
      <${xs}:attribute name="${attribute.name}"[#if attribute.required] use="required"[/#if] type="${attribute.baseType.qname}"[#if attribute.mimeType??] xmlns:xmime="http://www.w3.org/2005/05/xmlmime" xmime:expectedContentTypes="${attribute.mimeType}"[/#if]>
          [#if attribute.docValue?? || attribute.referencesQNameEnum!false]
        <${xs}:annotation>
            [#if attribute.docValue??]
          <${xs}:documentation>
            
          
            [/#if]
            [#if attribute.referencesQNameEnum!false]
          <${xs}:documentation>
            See ${qnameForType(attribute.QNameEnumRef)} for an enumeration of known values.
          
            [/#if]
        
          [/#if]
      
        [/#if]
      [/#if]
    [/#list]
    [#if typeDef.hasAnyAttribute]
      <${xs}:anyAttribute namespace="##other" processContents="skip">
        <${xs}:annotation>
          <${xs}:documentation>
            Any additional attributes.[#if typeDef.anyAttributeQNameEnumRef??] See ${qnameForType(typeDef.anyAttributeQNameEnumRef)} for an enumeration of known values.[/#if]
          
        
      
    [/#if]
[#t]
    [#if typeDef.contentType.simple]
    
  
    [#elseif !typeDef.baseObject]
    
  
    [/#if]


  [/#if]
[/#macro]
[#t]
[#macro processAnonymousType type]
  [#if type.map!(false)]
    [@processMapType mapType=type/]
  [#else]
    [@processTypeDef typeDef=type.typeDefinition/]
  [/#if]
[/#macro]
[#t]
[#macro processMapType mapType]
  <${xs}:complexType>
    [@processMapTypeSequence mapType=mapType/]
  
[/#macro]
[#t]
[#macro processMapTypeSequence mapType]
    <${xs}:sequence>
      <${xs}:element name="entry" minOccurs="0" maxOccurs="unbounded">
        <${xs}:complexType>
          <${xs}:sequence>
            [#if mapType.keyType.anonymous]
            <${xs}:element name="key" minOccurs="1">
              [@processAnonymousType type=mapType.keyType/]
            
            [#else]
            <${xs}:element name="key" minOccurs="1" type="${mapType.keyType.qname}"/>
            [/#if]
            [#if mapType.valueType.anonymous]
            <${xs}:element name="value" minOccurs="1">
              [@processAnonymousType type=mapType.valueType/]
            
            [#else]
            <${xs}:element name="value" minOccurs="1" type="${mapType.valueType.qname}"/>
            [/#if]
          
        
      
    
[/#macro]
[#t]
[#macro processImplicitElement implicitElement]
  [#if !isDefinedGlobally(implicitElement)]
    [#if implicitElement.typeQName??]
<${xs}:element name="${implicitElement.elementName}" type="${implicitElement.typeQName}"[#if implicitElement.mimeType??] xmlns:xmime="http://www.w3.org/2005/05/xmlmime" xmime:expectedContentTypes="${implicitElement.mimeType}"[/#if]>
      [#if implicitElement.elementDocs??]
  <${xs}:annotation>
    <${xs}:documentation>
      
    
  
      [/#if]

    [#elseif implicitElement.anonymousTypeDefinition??]
<${xs}:element name="${implicitElement.elementName}">
      [#if implicitElement.elementDocs??]
  <${xs}:annotation>
    <${xs}:documentation>
      
    
  
      [/#if]
  [@processTypeDef typeDef=implicitElement.anonymousTypeDefinition/]

    [#else]
      [#assign childElements=implicitElement.childElements]
<${xs}:element name="${implicitElement.elementName}" type="[#if tns != ""]${tns}:[/#if]${implicitElement.elementName}"[#if implicitElement.mimeType??] xmlns:xmime="http://www.w3.org/2005/05/xmlmime" xmime:expectedContentTypes="${implicitElement.mimeType}"[/#if]/>
<${xs}:complexType name="${implicitElement.elementName}">
      [#if implicitElement.elementDocs??]
  <${xs}:annotation>
    <${xs}:documentation>
      
    
  
      [/#if]
  <${xs}:sequence>
        [#list childElements as childElement]
    <${xs}:element name="${childElement.elementName}"[#if !childElement.xmlType.anonymous] type="${childElement.typeQName}"[/#if] minOccurs="${childElement.minOccurs}"[#if "1" != childElement.maxOccurs] maxOccurs="${childElement.maxOccurs}"[/#if][#if childElement.mimeType??] xmlns:xmime="http://www.w3.org/2005/05/xmlmime" xmime:expectedContentTypes="${childElement.mimeType}"[/#if]>
          [#if childElement.elementDocs??]
      <${xs}:annotation>
        <${xs}:documentation>
          
        
      
          [/#if]
          [#if childElement.xmlType.anonymous]
            [@processAnonymousType type=childElement.xmlType/]
          [/#if]
    
        [/#list]
  

    [/#if]
  [/#if]
[/#macro]
[#macro processImplicitAttribute implicitAttribute]
 [#if implicitAttribute.anonymousTypeDefinition??]
<${xs}:attribute name="${implicitAttribute.attributeName}">
    [#if implicitAttribute.attributeDocs??]
  <${xs}:annotation>
    <${xs}:documentation>
      
    
  
    [/#if]
  [@processTypeDef typeDef=implicitAttribute.anonymousTypeDefinition/]

 [#else]
<${xs}:attribute name="${implicitAttribute.attributeName}" type="${implicitAttribute.typeQName}"[#if implicitAttribute.mimeType??] xmlns:xmime="http://www.w3.org/2005/05/xmlmime" xmime:expectedContentTypes="${implicitAttribute.mimeType}"[/#if]>
    [#if implicitAttribute.attributeDocs??]
  <${xs}:annotation>
    <${xs}:documentation>
      
    
  
    [/#if]

 [/#if]
[/#macro]




© 2015 - 2025 Weber Informatics LLC | Privacy Policy