Welcome to the "trac"-ing site of soap4r!
[soap4r] [httpclient] [openpgp4u] [pkcs1] [logger] [csv] [vtr]

root/tags/RELEASE_1_0_0/lib/XMLSchemaDatatypes.rb

Revision 2, 2.9 kB (checked in by nakahiro, 8 years ago)

SOAP4R initial release.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to author date id revision
Line 
1 =begin
2 SOAP4R
3 Copyright (C) 2000 NAKAMURA Hiroshi.
4
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free Software
7 Foundation; either version 2 of the License, or (at your option) any later
8 version.
9
10 This program is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
12 PRATICULAR PURPOSE. See the GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along with
15 this program; if not, write to the Free Software Foundation, Inc., 675 Mass
16 Ave, Cambridge, MA 02139, USA.
17 =end
18
19 ###
20 ## XMLSchamaDatatypes general definitions.
21 #
22 module XSD
23   Namespace = 'http://www.w3.org/1999/XMLSchema/'
24   InstanceNamespace = 'http://www.w3.org/1999/XMLSchema/instance/'
25 end
26
27
28 ###
29 ## The base class of all datatypes with Namespace.
30 #
31 class NSDBase
32   public
33
34   attr_reader :typeName
35   attr_accessor :namespace
36
37   def initialize( typeName, namespace )
38     @typeName = typeName
39     @namespace = namespace
40   end
41 end
42
43
44 ###
45 ## The base class of XSD datatypes.
46 #
47 class XSDBase < NSDBase
48   include XSD
49
50   public
51
52   attr_accessor :data
53
54   def initialize( typeName )
55     super( typeName, Namespace )
56     @data = nil
57   end
58
59   def to_s()
60     @data.to_s
61   end
62 end
63
64
65 ###
66 ## Basic datatypes.
67 #
68 class XSDNull < XSDBase
69   def initialize()
70     super( 'null' )
71   end
72 end
73
74 class XSDBoolean < XSDBase
75   public
76
77   def initialize( initBoolean = false )
78     super( 'boolean' )
79     set( initBoolean )
80   end
81
82   def set( newBoolean )
83     if newBoolean.is_a?( String )
84       if newBoolean.downcase == 'true'
85         @data = true
86       else
87         @data = false
88       end
89     else
90       @data = newBoolean ? true : false
91     end
92   end
93 end
94
95 class XSDString < XSDBase
96   public
97
98   def initialize( initString = nil )
99     super( 'string' )
100     set( initString ) if initString
101   end
102
103   def set( newString )
104     @data = String.new( newString )
105   end
106 end
107
108 class XSDDecimal < XSDBase
109   public
110
111   def initialize( initDecimal = nil )
112     super( 'decimal' )
113     set( initDecimal ) if initDecimal
114   end
115
116   def set( newDecimal )
117     @data = newDecimal.to_f
118   end
119 end
120
121 class XSDTimeInstant < XSDBase
122   require 'parsedate2'
123
124   public
125
126   def initialize( initTimeInstant = nil )
127     super( 'timeInstant' )
128     set( initTimeInstant ) if initTimeInstant
129   end
130
131   def set( newTimeInstant )
132     if ( newTimeInstant.is_a?( Time ))
133       @data = newTimeInstant.dup
134     else
135       ( year, mon, mday, hour, min, sec, zone, wday ) = ParseDate.parsedate( newTimeInstant.to_s )
136       @data = Time.mktime( year, mon, mday, hour, min, sec )
137     end
138   end
139 end
140
141
142 ###
143 ## Derived types
144 #
145 class XSDInteger < XSDDecimal
146   public
147
148   def initialize( initInteger = nil )
149     super()
150     @typeName = 'int'
151     set( initInteger ) if initInteger
152   end
153
154   def set( newInteger )
155     @data = newInteger.to_i
156   end
157 end
Note: See TracBrowser for help on using the browser.