PageRenderTime 90ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/ample/languages/xmlschema/builtin/builtin.js

https://github.com/marsch/amplesdk
JavaScript | 159 lines | 126 code | 13 blank | 20 comment | 13 complexity | 40d69da2ff26243b03d2b95402a3ec42 MD5 | raw file
  1. /*
  2. * Ample SDK - JavaScript GUI Framework
  3. *
  4. * Copyright (c) 2009 Sergey Ilinsky
  5. * Dual licensed under the MIT and GPL licenses.
  6. * See: http://www.amplesdk.com/about/licensing/
  7. *
  8. */
  9. // Create Built-in datatypes XML Schema Item
  10. var oXSBuiltin_namespaceItem = new cXSNamespaceItem,
  11. oXSBuiltin_types = oXSBuiltin_namespaceItem.$types,
  12. oXSBuiltin_primitiveDataTypes = {};
  13. oXSBuiltin_namespaceItem.schemaNamespace = "http://www.w3.org/2001/XMLSchema";
  14. oXSModel.namespaces.$add(oXSBuiltin_namespaceItem.schemaNamespace);
  15. oXSModel.namespaceItems.$add(oXSBuiltin_namespaceItem);
  16. /* Builtin datatypes */
  17. function fXSBuiltin_createSimpleType(nType, nBaseType, aFacets, aMultiValueFacets) {
  18. var oType = new cXSSimpleTypeDefinition;
  19. // XSTypeDefinition interface
  20. oType.typeCategory = cXSTypeDefinition.SIMPLE_TYPE;
  21. oType.baseType = oXSBuiltin_types[nBaseType];
  22. oType.anonymous = false;
  23. // XSSimpleTypeDefinition interface
  24. if (nType == cXSConstants.ANYTYPE_DT || nType == cXSConstants.ANYSIMPLETYPE_DT)
  25. oType.variety = cXSSimpleTypeDefinition.VARIETY_ABSENT;
  26. else
  27. oType.variety = cXSSimpleTypeDefinition.VARIETY_ATOMIC;
  28. oType.builtInKind = nType;
  29. if (aFacets)
  30. for (var nIndex = 0; nIndex < aFacets.length; nIndex++)
  31. oType.facets.$add(aFacets[nIndex]);
  32. if (aMultiValueFacets)
  33. for (var nIndex = 0; nIndex < aMultiValueFacets.length; nIndex++)
  34. oType.multiValueFacets.$add(aMultiValueFacets[nIndex]);
  35. return oType;
  36. };
  37. function fXSBuiltin_createListType(nType, nItemType, aFacets, aMultiValueFacets) {
  38. var oType = new cXSSimpleTypeDefinition;
  39. // XSTypeDefinition interface
  40. oType.typeCategory = cXSTypeDefinition.SIMPLE_TYPE;
  41. oType.baseType = oXSBuiltin_types[cXSConstants.ANYSIMPLETYPE_DT];
  42. oType.anonymous = false;
  43. // XSSimpleTypeDefinition interface
  44. oType.variety = cXSSimpleTypeDefinition.VARIETY_LIST;
  45. oType.itemType = oXSBuiltin_types[nItemType];
  46. oType.builtInKind = nType;
  47. if (aFacets)
  48. for (var nIndex = 0; nIndex < aFacets.length; nIndex++)
  49. oType.facets.$add(aFacets[nIndex]);
  50. if (aMultiValueFacets)
  51. for (var nIndex = 0; nIndex < aMultiValueFacets.length; nIndex++)
  52. oType.multiValueFacets.$add(aMultiValueFacets[nIndex]);
  53. return oType;
  54. };
  55. function fXSBuiltin_createFacet(nFacet, sValue, bFixed) {
  56. var oFacet = new cXSFacet;
  57. oFacet.lexicalFacetValue = sValue;
  58. oFacet.fixed = !!bFixed;
  59. oFacet.facetKind = nFacet;
  60. return oFacet;
  61. };
  62. function fXSBuiltin_createMultiValueFacet(nFacet, aValues, bFixed) {
  63. var oFacet = new cXSMultiValueFacet;
  64. oFacet.fixed = !!bFixed;
  65. oFacet.facetKind = nFacet;
  66. for (var nIndex = 0; nIndex < aValues.length; nIndex++)
  67. oFacet.lexicalFacetValues.$add(aValues[nIndex]);
  68. return oFacet;
  69. };
  70. // Datatypes initialization
  71. oXSBuiltin_types["anyType"] = fXSBuiltin_createSimpleType(cXSConstants.ANYTYPE_DT, 0);
  72. oXSBuiltin_types["anySimpleType"] = fXSBuiltin_createSimpleType(cXSConstants.ANYSIMPLETYPE_DT, cXSConstants.ANYTYPE_DT);
  73. oXSBuiltin_types["anyAtomicType"] = fXSBuiltin_createSimpleType(cXSConstants.ANYATOMICTYPE_DT, cXSConstants.ANYSIMPLETYPE_DT);
  74. // primititve types
  75. oXSBuiltin_primitiveDataTypes[cXSConstants.ANYURI_DT] =
  76. oXSBuiltin_types["anyURI"] = fXSBuiltin_createSimpleType(cXSConstants.ANYURI_DT, cXSConstants.ANYATOMICTYPE_DT);
  77. oXSBuiltin_primitiveDataTypes[cXSConstants.BASE64BINARY_DT] =
  78. oXSBuiltin_types["base64Binary"] = fXSBuiltin_createSimpleType(cXSConstants.BASE64BINARY_DT, cXSConstants.ANYATOMICTYPE_DT);
  79. oXSBuiltin_primitiveDataTypes[cXSConstants.BOOLEAN_DT] =
  80. oXSBuiltin_types["boolean"] = fXSBuiltin_createSimpleType(cXSConstants.BOOLEAN_DT, cXSConstants.ANYATOMICTYPE_DT);
  81. oXSBuiltin_primitiveDataTypes[cXSConstants.DATE_DT] =
  82. oXSBuiltin_types["date"] = fXSBuiltin_createSimpleType(cXSConstants.DATE_DT, cXSConstants.ANYATOMICTYPE_DT);
  83. oXSBuiltin_primitiveDataTypes[cXSConstants.DATETIME_DT] =
  84. oXSBuiltin_types["dateTime"] = fXSBuiltin_createSimpleType(cXSConstants.DATETIME_DT, cXSConstants.ANYATOMICTYPE_DT);
  85. // Other built-in atomic types
  86. oXSBuiltin_types["dateTimeStamp"] = fXSBuiltin_createSimpleType(cXSConstants.DATETIMESTAMP_DT, cXSConstants.DATETIME_DT);
  87. oXSBuiltin_primitiveDataTypes[cXSConstants.DECIMAL_DT] =
  88. oXSBuiltin_types["decimal"] = fXSBuiltin_createSimpleType(cXSConstants.DECIMAL_DT, cXSConstants.ANYATOMICTYPE_DT);
  89. // Other built-in atomic types
  90. oXSBuiltin_types["integer"] = fXSBuiltin_createSimpleType(cXSConstants.INTEGER_DT, cXSConstants.DECIMAL_DT, [fXSBuiltin_createFacet(cXSSimpleTypeDefinition.FACET_FRACTIONDIGITS, '0', true)], [fXSBuiltin_createMultiValueFacet(cXSSimpleTypeDefinition.FACET_PATTERN, ['[\\-+]?[0-9]+'])]);
  91. oXSBuiltin_types["long"] = fXSBuiltin_createSimpleType(cXSConstants.LONG_DT, cXSConstants.INTEGER_DT, [fXSBuiltin_createFacet(cXSSimpleTypeDefinition.FACET_MININCLUSIVE, '-9223372036854775808'), fXSBuiltin_createFacet(cXSSimpleTypeDefinition.FACET_MAXINCLUSIVE, '9223372036854775807')]);
  92. oXSBuiltin_types["int"] = fXSBuiltin_createSimpleType(cXSConstants.INT_DT, cXSConstants.LONG_DT, [fXSBuiltin_createFacet(cXSSimpleTypeDefinition.FACET_MININCLUSIVE, '-2147483648'), fXSBuiltin_createFacet(cXSSimpleTypeDefinition.FACET_MAXINCLUSIVE, '2147483647')]);
  93. oXSBuiltin_types["short"] = fXSBuiltin_createSimpleType(cXSConstants.SHORT_DT, cXSConstants.INT_DT, [fXSBuiltin_createFacet(cXSSimpleTypeDefinition.FACET_MININCLUSIVE, '-32768'), fXSBuiltin_createFacet(cXSSimpleTypeDefinition.FACET_MAXINCLUSIVE, '32767')]);
  94. oXSBuiltin_types["byte"] = fXSBuiltin_createSimpleType(cXSConstants.BYTE_DT, cXSConstants.SHORT_DT, [fXSBuiltin_createFacet(cXSSimpleTypeDefinition.FACET_MININCLUSIVE, '-128'), fXSBuiltin_createFacet(cXSSimpleTypeDefinition.FACET_MAXINCLUSIVE, '127')]);
  95. oXSBuiltin_types["nonNegativeInteger"] = fXSBuiltin_createSimpleType(cXSConstants.NONNEGATIVEINTEGER_DT, cXSConstants.INTEGER_DT, [fXSBuiltin_createFacet(cXSSimpleTypeDefinition.FACET_MININCLUSIVE, '0')]);
  96. oXSBuiltin_types["positiveInteger"] = fXSBuiltin_createSimpleType(cXSConstants.POSITIVEINTEGER_DT, cXSConstants.NONNEGATIVEINTEGER_DT, [fXSBuiltin_createFacet(cXSSimpleTypeDefinition.FACET_MININCLUSIVE, '1')]);
  97. oXSBuiltin_types["unsignedLong"] = fXSBuiltin_createSimpleType(cXSConstants.UNSIGNEDLONG_DT, cXSConstants.NONNEGATIVEINTEGER_DT, [fXSBuiltin_createFacet(cXSSimpleTypeDefinition.FACET_MAXINCLUSIVE, '18446744073709551615')]);
  98. oXSBuiltin_types["unsignedInt"] = fXSBuiltin_createSimpleType(cXSConstants.UNSIGNEDINT_DT, cXSConstants.UNSIGNEDLONG_DT, [fXSBuiltin_createFacet(cXSSimpleTypeDefinition.FACET_MAXINCLUSIVE, '4294967295')]);
  99. oXSBuiltin_types["unsignedShort"] = fXSBuiltin_createSimpleType(cXSConstants.UNSIGNEDSHORT_DT, cXSConstants.UNSIGNEDINT_DT, [fXSBuiltin_createFacet(cXSSimpleTypeDefinition.FACET_MAXINCLUSIVE, '65535')]);
  100. oXSBuiltin_types["unsignedByte"] = fXSBuiltin_createSimpleType(cXSConstants.UNSIGNEDBYTE_DT, cXSConstants.UNSIGNEDSHORT_DT, [fXSBuiltin_createFacet(cXSSimpleTypeDefinition.FACET_MAXINCLUSIVE, '255')]);
  101. oXSBuiltin_types["nonPositiveInteger"] = fXSBuiltin_createSimpleType(cXSConstants.NONPOSITIVEINTEGER_DT, cXSConstants.INTEGER_DT, [fXSBuiltin_createFacet(cXSSimpleTypeDefinition.FACET_MAXINCLUSIVE, '0')]);
  102. oXSBuiltin_types["negativeInteger"] = fXSBuiltin_createSimpleType(cXSConstants.NEGATIVEINTEGER_DT, cXSConstants.NONPOSITIVEINTEGER_DT, [fXSBuiltin_createFacet(cXSSimpleTypeDefinition.FACET_MAXINCLUSIVE, '-1')]);
  103. oXSBuiltin_primitiveDataTypes[cXSConstants.DOUBLE_DT] =
  104. oXSBuiltin_types["double"] = fXSBuiltin_createSimpleType(cXSConstants.DOUBLE_DT, cXSConstants.ANYATOMICTYPE_DT);
  105. oXSBuiltin_primitiveDataTypes[cXSConstants.DURATION_DT] =
  106. oXSBuiltin_types["duration"] = fXSBuiltin_createSimpleType(cXSConstants.DURATION_DT, cXSConstants.ANYATOMICTYPE_DT);
  107. oXSBuiltin_types["dayTimeDuration"] = fXSBuiltin_createSimpleType(cXSConstants.DAYTIMEDURATION_DT, cXSConstants.DURATION_DT);
  108. oXSBuiltin_types["dayMonthDuration"]= fXSBuiltin_createSimpleType(cXSConstants.DAYMONTHDURATION_DT, cXSConstants.DURATION_DT);
  109. oXSBuiltin_primitiveDataTypes[cXSConstants.FLOAT_DT] =
  110. oXSBuiltin_types["float"] = fXSBuiltin_createSimpleType(cXSConstants.FLOAT_DT, cXSConstants.ANYATOMICTYPE_DT);
  111. oXSBuiltin_primitiveDataTypes[cXSConstants.GDAY_DT] =
  112. oXSBuiltin_types["gDay"] = fXSBuiltin_createSimpleType(cXSConstants.GDAY_DT, cXSConstants.ANYATOMICTYPE_DT);
  113. oXSBuiltin_primitiveDataTypes[cXSConstants.GMONTH_DT] =
  114. oXSBuiltin_types["gMonth"] = fXSBuiltin_createSimpleType(cXSConstants.GMONTH_DT, cXSConstants.ANYATOMICTYPE_DT);
  115. oXSBuiltin_primitiveDataTypes[cXSConstants.GMONTHDAY_DT] =
  116. oXSBuiltin_types["gMonthDay"] = fXSBuiltin_createSimpleType(cXSConstants.GMONTHDAY_DT, cXSConstants.ANYATOMICTYPE_DT);
  117. oXSBuiltin_primitiveDataTypes[cXSConstants.GYEAR_DT] =
  118. oXSBuiltin_types["gYear"] = fXSBuiltin_createSimpleType(cXSConstants.GYEAR_DT, cXSConstants.ANYATOMICTYPE_DT);
  119. oXSBuiltin_primitiveDataTypes[cXSConstants.GYEARMONTH_DT] =
  120. oXSBuiltin_types["gYearMonth"] = fXSBuiltin_createSimpleType(cXSConstants.GYEARMONTH_DT, cXSConstants.ANYATOMICTYPE_DT);
  121. oXSBuiltin_primitiveDataTypes[cXSConstants.HEXBINARY_DT] =
  122. oXSBuiltin_types["hexBinary"] = fXSBuiltin_createSimpleType(cXSConstants.HEXBINARY_DT, cXSConstants.ANYATOMICTYPE_DT);
  123. oXSBuiltin_primitiveDataTypes[cXSConstants.NOTATION_DT] =
  124. oXSBuiltin_types["NOTATION"] = fXSBuiltin_createSimpleType(cXSConstants.NOTATION_DT, cXSConstants.ANYATOMICTYPE_DT);
  125. oXSBuiltin_primitiveDataTypes[cXSConstants.PRECISIONDECIMAL_DT] =
  126. oXSBuiltin_types["precisionDecimal"]= fXSBuiltin_createSimpleType(cXSConstants.PRECISIONDECIMAL_DT, cXSConstants.ANYATOMICTYPE_DT);
  127. oXSBuiltin_primitiveDataTypes[cXSConstants.QNAME_DT] =
  128. oXSBuiltin_types["QName"] = fXSBuiltin_createSimpleType(cXSConstants.QNAME_DT, cXSConstants.ANYATOMICTYPE_DT);
  129. oXSBuiltin_primitiveDataTypes[cXSConstants.STRING_DT] =
  130. oXSBuiltin_types["string"] = fXSBuiltin_createSimpleType(cXSConstants.STRING_DT, cXSConstants.ANYATOMICTYPE_DT, [fXSBuiltin_createFacet(cXSSimpleTypeDefinition.FACET_WHITESPACE, "preserve")]);
  131. // Other built-in atomic types
  132. oXSBuiltin_types["normalizedString"]= fXSBuiltin_createSimpleType(cXSConstants.NORMALIZEDSTRING_DT, cXSConstants.STRING_DT, [fXSBuiltin_createFacet(cXSSimpleTypeDefinition.FACET_WHITESPACE, "replace")]);
  133. oXSBuiltin_types["token"] = fXSBuiltin_createSimpleType(cXSConstants.TOKEN_DT, cXSConstants.NORMALIZEDSTRING_DT, [fXSBuiltin_createFacet(cXSSimpleTypeDefinition.FACET_WHITESPACE, "collapse")]);
  134. oXSBuiltin_types["language"] = fXSBuiltin_createSimpleType(cXSConstants.LANGUAGE_DT, cXSConstants.TOKEN_DT, [], [fXSBuiltin_createMultiValueFacet(cXSSimpleTypeDefinition.FACET_PATTERN, ['[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*'])]);
  135. oXSBuiltin_types["Name"] = fXSBuiltin_createSimpleType(cXSConstants.NAME_DT, cXSConstants.TOKEN_DT, [fXSBuiltin_createFacet(cXSSimpleTypeDefinition.FACET_WHITESPACE, "collapse")], [fXSBuiltin_createMultiValueFacet(cXSSimpleTypeDefinition.FACET_PATTERN, ['\\i\\c*'])]);
  136. oXSBuiltin_types["NCName"] = fXSBuiltin_createSimpleType(cXSConstants.NCNAME_DT, cXSConstants.NAME_DT, [fXSBuiltin_createFacet(cXSSimpleTypeDefinition.FACET_WHITESPACE, "collapse")], [fXSBuiltin_createMultiValueFacet(cXSSimpleTypeDefinition.FACET_PATTERN, ['[\\i-[:]][\\c-[:]]*'])]);
  137. oXSBuiltin_types["ENTITY"] = fXSBuiltin_createSimpleType(cXSConstants.ENITITY_DT, cXSConstants.NCNAME_DT, [fXSBuiltin_createFacet(cXSSimpleTypeDefinition.FACET_WHITESPACE, "collapse")]);
  138. oXSBuiltin_types["ID"] = fXSBuiltin_createSimpleType(cXSConstants.ID_DT, cXSConstants.NCNAME_DT, [fXSBuiltin_createFacet(cXSSimpleTypeDefinition.FACET_WHITESPACE, "collapse")]);
  139. oXSBuiltin_types["IDREF"] = fXSBuiltin_createSimpleType(cXSConstants.IDREF_DT, cXSConstants.NCNAME_DT, [fXSBuiltin_createFacet(cXSSimpleTypeDefinition.FACET_WHITESPACE, "collapse")]);
  140. oXSBuiltin_types["NMTOKEN"] = fXSBuiltin_createSimpleType(cXSConstants.NMTOKEN_DT, cXSConstants.TOKEN_DT, [fXSBuiltin_createFacet(cXSSimpleTypeDefinition.FACET_WHITESPACE, "collapse")], [fXSBuiltin_createMultiValueFacet(cXSSimpleTypeDefinition.FACET_PATTERN, ["\\c"])]);
  141. oXSBuiltin_primitiveDataTypes[cXSConstants.TIME_DT] =
  142. oXSBuiltin_types["time"] = fXSBuiltin_createSimpleType(cXSConstants.TIME_DT, cXSConstants.ANYATOMICTYPE_DT);
  143. // Built-in list types
  144. oXSBuiltin_types["ENTITIES"] = fXSBuiltin_createListType(cXSConstants.LIST_DT, cXSConstants.ENITITY_DT, [fXSBuiltin_createFacet(cXSSimpleTypeDefinition.FACET_WHITESPACE, "collapse"), fXSBuiltin_createFacet("minLength", '1')]);
  145. oXSBuiltin_types["IDREFS"] = fXSBuiltin_createListType(cXSConstants.LIST_DT, cXSConstants.IDREF_DT, [fXSBuiltin_createFacet(cXSSimpleTypeDefinition.FACET_WHITESPACE, "collapse"), fXSBuiltin_createFacet("minLength", '1')]);
  146. oXSBuiltin_types["NMTOKENS"] = fXSBuiltin_createListType(cXSConstants.LIST_DT, cXSConstants.NMTOKEN_DT, [fXSBuiltin_createFacet(cXSSimpleTypeDefinition.FACET_WHITESPACE, "collapse"), fXSBuiltin_createFacet("minLength", '1')]);