3 xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
4 xmlns:opensrf="http://opensrf.org/xmlns/opensrf"
5 xmlns:cdbi="http://opensrf.org/xmlns/opensrf/cdbi"
6 xmlns:perl="http://opensrf.org/xmlns/opensrf/perl"
7 xmlns:javascript="http://opensrf.org/xmlns/opensrf/javascript"
8 xmlns:c="http://opensrf.org/xmlns/opensrf/c">
9 <xsl:output method="text" />
10 <xsl:strip-space elements="xsl:*"/>
11 <xsl:variable name="last_field_pos"/>
13 <xsl:template match="/">
17 use base 'OpenSRF::Application';
19 use OpenSRF::Utils::Logger;
20 my $log = 'OpenSRF::Utils::Logger';
26 if (!ref($value) or ref($value) ne 'ARRAY') {
27 # go fetch the object by id...
32 return bless $value => $self->class_name;
43 my $class_name = shift;
44 return ref($class_name) || $class_name;
47 sub isnew { return $_[0][0]; }
48 sub ischanged { return $_[0][1]; }
49 sub isdeleted { return $_[0][2]; }
52 <xsl:apply-templates select="opensrf:fieldmapper/opensrf:classes"/>
61 <!-- sub-templates -->
62 <xsl:template match="opensrf:fieldmapper/opensrf:classes">
63 <xsl:for-each select="opensrf:class">
64 <xsl:sort select="@id"/>
65 <xsl:apply-templates select="."/>
66 <xsl:apply-templates select="opensrf:links/opensrf:link[@type='has_many']"/>
73 <xsl:template match="opensrf:class">
74 <xsl:apply-templates select="@perl:class"/>
75 <xsl:apply-templates select="opensrf:fields"/>
81 <xsl:template match="opensrf:fields">
82 <xsl:apply-templates select="opensrf:field"/>
89 <xsl:template match="@perl:class">
91 #-------------------------------------------------------------------------------
92 # Class definition for "<xsl:value-of select="."/>"
93 #-------------------------------------------------------------------------------
95 package <xsl:value-of select="."/>;
96 use base "<xsl:value-of select="../perl:superclass"/>";
100 push @real, @_ if (@_);
106 sub last_real_field : lvalue {
111 <xsl:if test="../@cdbi:class">
113 return "<xsl:value-of select="../@cdbi:class"/>";
118 return "<xsl:value-of select="../@id"/>";
124 <xsl:when test="../@virutal">
139 <!-- scalar valued fields and "has_a" relationships -->
140 <xsl:template match="opensrf:field">
142 <xsl:variable name="num"><xsl:number/></xsl:variable>
143 <xsl:variable name="field_pos" select="$num + 2"/>
144 <xsl:variable name="last_field_pos" select="$field_pos + 1"/>
145 <xsl:variable name="field_name" select="@name"/>
146 <xsl:variable name="classname" select="../../@perl:class"/>
148 # Accessor/mutator for <xsl:value-of select="$classname"/>::<xsl:value-of select="$field_name"/>:
149 __PACKAGE__->last_real_field()++;
150 __PACKAGE__->real_fields("<xsl:value-of select="$field_name"/>");
151 sub <xsl:value-of select="$field_name"/> {
154 $self->[<xsl:value-of select="$field_pos"/>] = $new_val if (defined $new_val);
156 <xsl:if test="../../opensrf:links/opensrf:link[@field=$field_name and @type='has_a']">
157 <!-- We have a fkey on this field. Go fetch the referenced object. -->
160 select="../../opensrf:links/opensrf:link[@field=$field_name and @type='has_a']/@source"/>
163 select="//*[@id=$source]/@perl:class"/>
165 my $val = $self->[<xsl:value-of select="$field_pos"/>];
167 if (defined $self->[<xsl:value-of select="$field_pos"/>]) {
168 if (!UNIVERSAL::isa($self->[<xsl:value-of select="$field_pos"/>], <xsl:value-of select="$sourceclass"/>)) {
169 $self->[<xsl:value-of select="$field_pos"/>] = <xsl:value-of select="$sourceclass"/>->new($val);
174 return $self->[<xsl:value-of select="$field_pos"/>];
178 sub clear_<xsl:value-of select="$field_name"/> {
180 $self->[<xsl:value-of select="$field_pos"/>] = undef;
191 <!-- "has_many" relationships -->
192 <xsl:template match="opensrf:links/opensrf:link[@type='has_many']">
193 <xsl:variable name="num"><xsl:number/></xsl:variable>
194 <xsl:variable name="source"><xsl:value-of select="@source"/></xsl:variable>
195 <xsl:variable name="sourceclass"><xsl:value-of select="//*[@id=$source]/@perl:class"/></xsl:variable>
196 <xsl:variable name="classname"><xsl:value-of select="../../@perl:class"/></xsl:variable>
197 <xsl:variable name="id"><xsl:value-of select="../../@id"/></xsl:variable>
198 <xsl:variable name="fkey" select="//*[@id=$source]/opensrf:links/opensrf:link[@type='has_a' and @source=$id]/@field"/>
199 <xsl:variable name="pkey" select="../../opensrf:fields/opensrf:field[@cdbi:primary='true']/@name"/>
201 # accessor for <xsl:value-of select="$classname"/>::<xsl:value-of select="@field"/>:
202 sub <xsl:value-of select="@field"/> {
205 my $_pos = <xsl:value-of select="$classname"/>->last_real_field + <xsl:value-of select="$num"/>;
207 if (!ref($self->[$_pos]) ne 'ARRAY') {
210 if (@{$self->[$_pos]} == 0) {
211 # get the real thing.
212 # search where <xsl:value-of select="$sourceclass"/>-><xsl:value-of select="$fkey"/> == $self-><xsl:value-of select="$pkey"/>;
215 return $self->[$_pos];