From 85a710959fcf8a1e6c4f505dab482aa7c15c0726 Mon Sep 17 00:00:00 2001 From: miker Date: Thu, 2 Jun 2005 23:00:02 +0000 Subject: [PATCH] adding perl XSLT and (maybe?) finishing up the javascript one git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@314 9efc2488-bf62-4759-914b-345cdb29e865 --- examples/fieldmapper2javascript.xsl | 118 ++++++++++++------- examples/fieldmapper2perl.xsl | 224 ++++++++++++++++++++++++++++++++++++ examples/gen-fieldmapper.xml | 197 ++++++++++++++++++++++++++++--- 3 files changed, 481 insertions(+), 58 deletions(-) create mode 100644 examples/fieldmapper2perl.xsl diff --git a/examples/fieldmapper2javascript.xsl b/examples/fieldmapper2javascript.xsl index ec18e7a..8c8e5c7 100644 --- a/examples/fieldmapper2javascript.xsl +++ b/examples/fieldmapper2javascript.xsl @@ -76,6 +76,28 @@ function Fieldmapper(array) { } Fieldmapper.prototype.baseClass = Fieldmapper; Fieldmapper.prototype.obj_cache = {}; + +Fieldmapper.prototype.search function (type,field,value) { + + var list = user_request( + 'open-ils.proxy', + 'open-ils.proxy.proxy', + [ + mw.G.auth_ses[0], + 'open-ils.storage', + 'open-ils.storage.direct.' + type.db_type + '.search.' + field, + array + ] + )[0]; + if (type.cacheable) { + if (type.baseClass.obj_cache[type.classname] == null) + type.baseClass.obj_cache[type.classname] = {}; + for (var i in list) { + type.baseClass.obj_cache[type.classname][list[i].id()] = list[i]; + } + } + return list; +} Fieldmapper.prototype.clone = function() { var obj = new this.constructor(); @@ -126,6 +148,7 @@ FieldmapperException.toString = function() { + @@ -136,7 +159,7 @@ FieldmapperException.toString = function() { - + @@ -149,34 +172,6 @@ FieldmapperException.toString = function() { - - - - - -// accessor for : -.prototype. = function () { - - var _pos = .last_real_field + ; - - if (!instanceOf(this.array[_pos], Array)) { - this.array[_pos] = []; - - if (this.array[_pos].length == 0) { - /* get the real thing. - * search where .() - * equals this.(); - */ - } - - return this.array[_pos]; -} - - - - - - @@ -193,9 +188,9 @@ function (array) { this.uber = .baseClass.prototype; } -.prototype = new Fieldmapper(); +.prototype = new (); .prototype.constructor = ; -.baseClass = Fieldmapper; +.baseClass = ; .prototype.cachable = true; .prototype.fields = []; .last_real_field = 2; @@ -224,6 +219,7 @@ function (array) { + @@ -235,14 +231,14 @@ function (array) { .last_real_field++; .prototype.fields.push(""); .prototype. = function (new_value) { + if(arguments.length == 1) { this.array[] = new_value; } - - - + + + - if(arguments.length == 1) { this.array[] = new_value; } var val = this.array[]; if (!instanceOf(this.array[], )) { @@ -250,17 +246,51 @@ function (array) { this.array[] = new (val); } } + + return this.array[]; +} + - return this.array[]; - - - if(arguments.length == 1) { this.array[] = new_value; } - return this.array[]; - - + + + + + + + + + + + + +// accessor for : +.prototype. = function () { + + var _pos = .last_real_field + ; + + if (!instanceOf(this.array[_pos], Array)) { + this.array[_pos] = []; + + if (this.array[_pos].length == 0) { + /* get the real thing. + * search where .() + * equals this.(); + */ + this.array[_pos] = this.uber.search( + , + "", + this.() + ); + } + + return this.array[_pos]; } + + + + diff --git a/examples/fieldmapper2perl.xsl b/examples/fieldmapper2perl.xsl new file mode 100644 index 0000000..202ced9 --- /dev/null +++ b/examples/fieldmapper2perl.xsl @@ -0,0 +1,224 @@ + + + + + + +package Fieldmapper; +use JSON; +use Data::Dumper; +use base 'OpenSRF::Application'; + +use OpenSRF::Utils::Logger; +my $log = 'OpenSRF::Utils::Logger'; + +sub new { + my $self = shift; + my $value = shift; + if (defined $value) { + if (!ref($value) or ref($value) ne 'ARRAY') { + # go fetch the object by id... + } + } else { + $value = []; + } + return bless $value => $self->class_name; +} + +sub decast { + my $self = shift; + return [ @$self ]; +} + +sub DESTROY {} + +sub class_name { + my $class_name = shift; + return ref($class_name) || $class_name; +} + +sub isnew { return $_[0][0]; } +sub ischanged { return $_[0][1]; } +sub isdeleted { return $_[0][2]; } + + + + +1; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +#------------------------------------------------------------------------------- +# Class definition for "" +#------------------------------------------------------------------------------- + +package ; +use base ""; + +{ my @real; + sub real_fields { + push @real, @_ if (@_); + return @real; + } +} + +{ my $last_real; + sub last_real_field : lvalue { + $last_real; + } +} + + +sub cdbi { + return ""; +} + + +sub json_hint { + return ""; +} + + +sub is_virtual { + + + return 1; + + + return 0; + + +} + + + + + + + + + + + + + + + + +# Accessor/mutator for ::: +__PACKAGE__->last_real_field()++; +__PACKAGE__->real_fields(""); +sub { + my $self = shift; + my $new_val = shift; + $self->[] = $new_val if (defined $new_val); + + + + + + + my $val = $self->[]; + + if (defined $self->[]) { + if (!UNIVERSAL::isa($self->[], )) { + $self->[] = ->new($val); + } + } + + + return $self->[]; +} + + +sub clear_ { + my $self = shift; + $self->[] = undef; + return 1; +} + + + + + + + + + + + + + + + + + + +# accessor for ::: +sub { + my $self = shift; + + my $_pos = ->last_real_field + ; + + if (!ref($self->[$_pos]) ne 'ARRAY') { + $self->[$_pos] = []; + + if (@{$self->[$_pos]} == 0) { + # get the real thing. + # search where -> == $self->; + } + + return $self->[$_pos]; +} + + + + + + + + diff --git a/examples/gen-fieldmapper.xml b/examples/gen-fieldmapper.xml index 8b43e2b..5e7fe93 100644 --- a/examples/gen-fieldmapper.xml +++ b/examples/gen-fieldmapper.xml @@ -1,4 +1,4 @@ - + - Fieldmapper - OpenILS::Storage::CDBI + Fieldmapper + Fieldmapper + OpenILS::Storage::CDBI - + --> - + + + action.survey_response + action.survey_response_id_seq + + + action_survey_response + + + Fieldmapper + Fieldmapper + OpenILS::Storage::CDBI + + + + + + + + + + + + + + + + + + + + - + + + + + - + + + action.survey_question + action.survey_question_id_seq + + + action_survey_question + + + Fieldmapper + Fieldmapper + OpenILS::Storage::CDBI + + + + + + + + + + - + + - + + + action.survey_answer + action.survey_answer_id_seq + + + action_survey_answer + + + Fieldmapper + Fieldmapper + OpenILS::Storage::CDBI + + + + + + + + + + + + + + + + + + actor.org_unit + actor.org_unit_id_seq + + + actor_org_unit + + + Fieldmapper + Fieldmapper + OpenILS::Storage::CDBI + + + + + + action_survey - Fieldmapper - OpenILS::Storage::CDBI + Fieldmapper + Fieldmapper + OpenILS::Storage::CDBI - - - + + + -- 2.11.0