Class: JAXB2Ruby::TypeUtil

Inherits:
Object
  • Object
show all
Defined in:
lib/jaxb2ruby/type_util.rb

Overview

:nodoc:

Constant Summary collapse

JAVA_TO_SCHEMA =

Only includes types that aren’t annotated with @XmlSchemaType

{
  "java.lang.Boolean" => "boolean",
  "boolean" => "boolean",
  "byte" => "byte",
  # byte[]
  "[B" => "base64Binary",
  "double" => "double",
  "float" => "float",
  "java.lang.Integer" => "int",
  "int" => "int",
  "java.lang.Object" => "anySimpleType",
  "java.lang.String" => "string",
  "java.math.BigDecimal" => "decimal",
  "java.math.BigInteger" => "int",
  "javax.xml.datatype.Duration" => "duration",
  "javax.xml.datatype.XMLGregorianCalendar" => "dateTime",
  #"javax.xml.namespace.QName" => "NOTATION"
  "javax.xml.namespace.QName" => "QName",
  "java.lang.Long" => "long",
  "long" => "long",
  "short" => "short"
}
SCHEMA_TO_RUBY =
{
  "ID" => :ID,
  "IDREF" => :IDREF,
  "Name" => "String",
  "NCName" => "String",
  "NMTOKEN" => "String",
  "anySimpleType" => "Object",
  "anyType" => "Object",
  "anyURI" => "String",
  "base64Binary" => "String",
  "boolean" => :boolean,
  "byte" => "Integer",
  "date" => "Date",
  "dateTime" => "DateTime",
  "decimal" => "Float",  # BigDecimal
  "double" => "Float",
  "duration" => "String",
  "float"  => "Float",
  "gDay" => "String",
  "gMonth" => "String",
  "gMonthDay" => "String",
  "gYear" => "String",
  "gYearMonth" => "String",
  "hexBinary" => "String",
  "int" => "Integer",
  "integer" => "Integer",
  "long" => "Integer",
  "language" => "String",
  "nonNegativeInteger" => "Integer",
  "nonPositiveInteger" => "Integer",
  "normalizedString" => "String",
  "positiveInteger" => "Integer",
  "QName" => "String",
  "short" => "Integer",
  "string" => "String",
  "time" => "Time",
  "token" => "String",
  "unsignedByte" => "Integer",
  "unsignedInt" => "Integer",
  "unsignedLong" => "Integer",
  "unsignedShort" => "Integer"
}

Instance Method Summary collapse

Constructor Details

#initialize(schema2ruby) ⇒ TypeUtil

Returns a new instance of TypeUtil.



70
71
72
# File 'lib/jaxb2ruby/type_util.rb', line 70

def initialize(schema2ruby)
  @schema2ruby = SCHEMA_TO_RUBY.merge(schema2ruby || {})
end

Instance Method Details

#java2ruby(klass) ⇒ Object



86
87
88
# File 'lib/jaxb2ruby/type_util.rb', line 86

def java2ruby(klass)
  schema2ruby(java2schema(klass))
end

#java2schema(klass) ⇒ Object



78
79
80
# File 'lib/jaxb2ruby/type_util.rb', line 78

def java2schema(klass)
  JAVA_TO_SCHEMA[klass]
end

#schema2ruby(type) ⇒ Object



82
83
84
# File 'lib/jaxb2ruby/type_util.rb', line 82

def schema2ruby(type)
  @schema2ruby[type]
end

#schema_ruby_typesObject



74
75
76
# File 'lib/jaxb2ruby/type_util.rb', line 74

def schema_ruby_types
  @schema_types ||= SCHEMA_TO_RUBY.values.uniq
end