private String genTypeRef ( StructureDefinition sd , ElementDefinition ed , String id , ElementDefinition . TypeRefComponent typ ) { if ( typ . hasProfile ( ) ) { if ( typ . getCode ( ) . equals ( "Reference" ) ) return genReference ( "" , typ ) ; else if ( ProfileUtilities . getChildList ( sd , ed ) . size ( ) > 0 ) { // inline anonymous type - give it a name and factor it out innerTypes . add ( new ImmutablePair < StructureDefinition , ElementDefinition > ( sd , ed ) ) ; return simpleElement ( sd , ed , id ) ; } else { String ref = getTypeName ( typ ) ; datatypes . add ( ref ) ; return simpleElement ( sd , ed , ref ) ; } } else if ( typ . getCodeElement ( ) . getExtensionsByUrl ( ToolingExtensions . EXT_RDF_TYPE ) . size ( ) > 0 ) { String xt = null ; try { xt = typ . getCodeElement ( ) . getExtensionString ( ToolingExtensions . EXT_RDF_TYPE ) ; } catch ( FHIRException e ) { e . printStackTrace ( ) ; } // TODO: Remove the next line when the type of token gets switched to string // TODO: Add a rdf-type entry for valueInteger to xsd:integer (instead of int) ST td_entry = tmplt ( PRIMITIVE_ELEMENT_DEFN_TEMPLATE ) . add ( "typ" , xt . replace ( "xsd:token" , "xsd:string" ) . replace ( "xsd:int" , "xsd:integer" ) ) ; StringBuilder facets = new StringBuilder ( ) ; if ( ed . hasMinValue ( ) ) { Type mv = ed . getMinValue ( ) ; facets . append ( tmplt ( MINVALUE_TEMPLATE ) . add ( "val" , mv . primitiveValue ( ) ) . render ( ) ) ; } if ( ed . hasMaxValue ( ) ) { Type mv = ed . getMaxValue ( ) ; facets . append ( tmplt ( MAXVALUE_TEMPLATE ) . add ( "val" , mv . primitiveValue ( ) ) . render ( ) ) ; } if ( ed . hasMaxLength ( ) ) { int ml = ed . getMaxLength ( ) ; facets . append ( tmplt ( MAXLENGTH_TEMPLATE ) . add ( "val" , ml ) . render ( ) ) ; } if ( ed . hasPattern ( ) ) { Type pat = ed . getPattern ( ) ; facets . append ( tmplt ( PATTERN_TEMPLATE ) . add ( "val" , pat . primitiveValue ( ) ) . render ( ) ) ; } td_entry . add ( "facets" , facets . toString ( ) ) ; return td_entry . render ( ) ; } else if ( typ . getCode ( ) == null ) { ST primitive_entry = tmplt ( PRIMITIVE_ELEMENT_DEFN_TEMPLATE ) ; primitive_entry . add ( "typ" , "xsd:string" ) ; return primitive_entry . render ( ) ; } else if ( typ . getCode ( ) . equals ( "xhtml" ) ) { return tmplt ( XHTML_TYPE_TEMPLATE ) . render ( ) ; } else { datatypes . add ( typ . getCode ( ) ) ; return simpleElement ( sd , ed , typ . getCode ( ) ) ; } }
Generate a type reference