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:database="http://opensrf.org/xmlns/opensrf/database"
7 xmlns:perl="http://opensrf.org/xmlns/opensrf/perl"
8 xmlns:javascript="http://opensrf.org/xmlns/opensrf/javascript"
9 xmlns:c="http://opensrf.org/xmlns/opensrf/c">
10 <xsl:output method="text" />
11 <xsl:strip-space elements="xsl:*"/>
12 <xsl:variable name="last_field_pos"/>
14 <xsl:template match="/">
18 use base 'OpenSRF::Application';
20 use OpenSRF::Utils::Logger;
21 my $log = 'OpenSRF::Utils::Logger';
27 if (!ref($value) or ref($value) ne 'ARRAY') {
28 # go fetch the object by id...
33 return bless $value => $self->class_name;
44 my $class_name = shift;
45 return ref($class_name) || $class_name;
48 sub isnew { return $_[0][0]; }
49 sub ischanged { return $_[0][1]; }
50 sub isdeleted { return $_[0][2]; }
53 <xsl:apply-templates select="opensrf:fieldmapper/opensrf:classes"/>
62 <!-- sub-templates -->
63 <xsl:template match="opensrf:fieldmapper/opensrf:classes">
64 <xsl:for-each select="opensrf:class">
65 <xsl:sort select="@id"/>
66 <xsl:apply-templates select="."/>
67 <xsl:apply-templates select="opensrf:links/opensrf:link[@type='has_many']"/>
74 <xsl:template match="opensrf:class">
75 <xsl:apply-templates select="@perl:class"/>
76 <xsl:apply-templates select="opensrf:fields"/>
82 <xsl:template match="opensrf:fields">
83 <xsl:apply-templates select="opensrf:field"/>
90 <xsl:template match="@perl:class">
92 #-------------------------------------------------------------------------------
93 # Class definition for "<xsl:value-of select="."/>"
94 #-------------------------------------------------------------------------------
96 package <xsl:value-of select="."/>;
97 use base "<xsl:value-of select="../perl:superclass"/>";
101 push @real, @_ if (@_);
107 sub last_real_field : lvalue {
112 <xsl:if test="../@cdbi:class">
114 return "<xsl:value-of select="../@cdbi:class"/>";
119 return "<xsl:value-of select="../@id"/>";
125 <xsl:when test="../@virutal">
140 <!-- scalar valued fields and "has_a" relationships -->
141 <xsl:template match="opensrf:field">
143 <xsl:variable name="num"><xsl:number/></xsl:variable>
144 <xsl:variable name="field_pos" select="$num + 2"/>
145 <xsl:variable name="last_field_pos" select="$field_pos + 1"/>
146 <xsl:variable name="field_name" select="@name"/>
147 <xsl:variable name="classname" select="../../@perl:class"/>
149 # Accessor/mutator for <xsl:value-of select="$classname"/>::<xsl:value-of select="$field_name"/>:
150 __PACKAGE__->last_real_field()++;
151 __PACKAGE__->real_fields("<xsl:value-of select="$field_name"/>");
152 sub <xsl:value-of select="$field_name"/> {
155 $self->[<xsl:value-of select="$field_pos"/>] = $new_val if (defined $new_val);
157 <xsl:if test="../../opensrf:links/opensrf:link[@field=$field_name and @type='has_a']">
158 <!-- We have a fkey on this field. Go fetch the referenced object. -->
161 select="../../opensrf:links/opensrf:link[@field=$field_name and @type='has_a']/@source"/>
164 select="//*[@id=$source]/@perl:class"/>
166 my $val = $self->[<xsl:value-of select="$field_pos"/>];
168 if (defined $self->[<xsl:value-of select="$field_pos"/>]) {
169 if (!UNIVERSAL::isa($self->[<xsl:value-of select="$field_pos"/>], <xsl:value-of select="$sourceclass"/>)) {
170 $self->[<xsl:value-of select="$field_pos"/>] = <xsl:value-of select="$sourceclass"/>->new($val);
175 return $self->[<xsl:value-of select="$field_pos"/>];
179 sub clear_<xsl:value-of select="$field_name"/> {
181 $self->[<xsl:value-of select="$field_pos"/>] = undef;
192 <!-- "has_many" relationships -->
193 <xsl:template match="opensrf:links/opensrf:link[@type='has_many']">
194 <xsl:variable name="num"><xsl:number/></xsl:variable>
195 <xsl:variable name="source"><xsl:value-of select="@source"/></xsl:variable>
196 <xsl:variable name="sourceclass"><xsl:value-of select="//*[@id=$source]/@perl:class"/></xsl:variable>
197 <xsl:variable name="classname"><xsl:value-of select="../../@perl:class"/></xsl:variable>
198 <xsl:variable name="id"><xsl:value-of select="../../@id"/></xsl:variable>
199 <xsl:variable name="fkey" select="//*[@id=$source]/opensrf:links/opensrf:link[@type='has_a' and @source=$id]/@field"/>
200 <xsl:variable name="pkey" select="../../opensrf:fields/opensrf:field[@database:primary='true']/@name"/>
202 # accessor for <xsl:value-of select="$classname"/>::<xsl:value-of select="@field"/>:
203 sub <xsl:value-of select="@field"/> {
206 my $_pos = <xsl:value-of select="$classname"/>->last_real_field + <xsl:value-of select="$num"/>;
208 if (!ref($self->[$_pos]) ne 'ARRAY') {
211 if (@{$self->[$_pos]} == 0) {
212 # get the real thing.
213 # search where <xsl:value-of select="$sourceclass"/>-><xsl:value-of select="$fkey"/> == $self-><xsl:value-of select="$pkey"/>;
216 return $self->[$_pos];