[MOBY-guts] biomoby commit

Mark Wilkinson mwilkinson at pub.open-bio.org
Wed Apr 14 19:56:59 UTC 2004


mwilkinson
Wed Apr 14 15:56:59 EDT 2004
Update of /home/repository/moby/moby-live/Perl/MOBY/Client
In directory pub.open-bio.org:/tmp/cvs-serv13353/Perl/MOBY/Client

Modified Files:
	Central.pm CollectionArticle.pm ServiceInstance.pm 
	SimpleArticle.pm 
Log Message:
CommonSubs now includes support for services that use Secondary Parameter's.  I am also almost finished writing an OO-interface for building/deconstructing MOBY objects, so that people don't have to learn the XML::DOM API. This is incomplete and untested yet, so don't shoot me if it doesn't work.  See the docs for CommonSubs 'complexServiceInputParser' for details on how to manage services that use multiple inputs and/or secondary parameters.  As soon as I get this OO interface working I will create an equivalent subroutine that parses the input into objects (but I wont remove this routine, so it wont break you servies if you use it)

moby-live/Perl/MOBY/Client Central.pm,1.73,1.74 CollectionArticle.pm,1.6,1.7 ServiceInstance.pm,1.10,1.11 SimpleArticle.pm,1.3,1.4
===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY/Client/Central.pm,v
retrieving revision 1.73
retrieving revision 1.74
diff -u -r1.73 -r1.74
--- /home/repository/moby/moby-live/Perl/MOBY/Client/Central.pm	2004/03/26 16:10:40	1.73
+++ /home/repository/moby/moby-live/Perl/MOBY/Client/Central.pm	2004/04/14 19:56:59	1.74
@@ -1487,7 +1487,19 @@
 				}
 			}
 		}	
-		
+        my @SECONDARIES;
+        my $secs = $Service->getElementsByTagName("secondaryArticles");  # there should only be one, but... who knows what 
+        for my $in(0..$secs->getLength-1){
+            my $current = $secs->item($in);
+            
+            foreach my $param($current->getChildNodes){  # child nodes will be "Parameter" tag names
+                next unless $param->getNodeType == ELEMENT_NODE && $param->getTagName eq "Parameter";
+                my $THIS;
+                $THIS = MOBY::Client::SecondaryArticle->new(XML_DOM => $param);
+                push @SECONDARIES, $THIS;
+            }
+        }
+    
         my $Instance = MOBY::Client::ServiceInstance->new(
             authority => $AuthURI,
 			authoritative => $authoritative,
@@ -1498,6 +1510,7 @@
             category => $cat,
 			input => \@INPUTS,
             output => \@OUTPUTS,
+            secondary => \@SECONDARIES,
             description => $Description,
 			registry	=> $Registry,
 			XML => $Service->toString,
@@ -1597,7 +1610,7 @@
 		#</MOBYRegistration>
 	my ($self, $xml) = @_;
 	my $Parser = new XML::DOM::Parser;
-	
+	#print STDERR $xml;
 	my $doc = $Parser->parse($xml);
 	my $Object = $doc->getDocumentElement();
 	my $obj = $Object->getTagName;
@@ -1608,7 +1621,8 @@
 	my $reg = MOBY::Client::Registration->new(
 		success		=> $success,
 		message 	=> $message,
-		registration_id	=> $id,);
+		registration_id	=> $id,
+        id => $id);
 	return $reg;	
 }
 

===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY/Client/CollectionArticle.pm,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- /home/repository/moby/moby-live/Perl/MOBY/Client/CollectionArticle.pm	2003/12/02 00:23:23	1.6
+++ /home/repository/moby/moby-live/Perl/MOBY/Client/CollectionArticle.pm	2004/04/14 19:56:59	1.7
@@ -19,9 +19,42 @@
 
 =head1 DESCRIPTION
 
-This describes the Collection articles from the findService Response of MOBY Central
-(i.e. the description of the service), it DOES NOT create collection articles
-as provided by a service provider (i.e. simple articles containing data)
+This describes the Collection articles from either the findService Response of MOBY Central
+(i.e. the description of the service), or Collection articles
+as provided in a service invocation or response message
+(i.e. simple articles containing data)
+
+Basically it parses the following part of a findService response:
+
+ <Collection articleName="foo">
+  <Simple>
+     <objectType>someNbject</objectType>
+     <Namespace>someNamespace</Namespace>
+     <Namespace>someNamespace2</Namespace>
+  </Simple>
+  <Simple>
+     <objectType>someNbject</objectType>
+     <Namespace>someNamespace</Namespace>
+     <Namespace>someNamespace2</Namespace>
+  </Simple>
+ </Collection>
+
+OR  it parses the following part of a service invocation or response message:
+
+ <Collection articleName="foo">
+  <Simple>
+    <SomeObject namespace='someNamespace' id='someID'>.....</SomeObject>
+  </Simple>
+  <Simple>
+    <SomeObject namespace='someNamespace' id='someID'>.....</SomeObject>
+  </Simple>
+ </Collection>
+
+
+The articleName is retrieved with ->articleName
+The contained Simples are retrieved as MOBY::Client::SimpleArticle objects
+using the ->Simples method call.
+
 
 =head1 AUTHORS
 
@@ -38,8 +71,11 @@
  Usage     :	my $IN = MOBY::Client::CollectionArticle->new(%args)
  Function  :	create CollectionArticle object
  Returns   :	MOBY::Client::SimpleArticle object
- Args      :    articleName => $articleName (optional)
-                Simples => $objectType (required)
+ Args      :    either of the following two methods may be used to auto-generate the
+                object by passing the appropriate XML node as a string, or XML::DOM node object
+                
+                XML => $XML
+                XML_DOM => $XML::DOM::NODE
 
 =cut
 
@@ -76,6 +112,29 @@
 =cut
 
 
+
+=head2 XML
+
+ Title     :	XML
+ Usage     :   $SA = $SA->XML($XML)
+ Function  :	set/reset all parameters for this object from the XML
+ Returns   :	MOBY::Client::SimpleArticle
+ Arguments :    (optional) XML fragment from and including <Simple>...</Simple>
+
+=cut
+
+
+=head2 XML_DOM
+
+ Title     :	XML_DOM
+ Usage     :	$namespaces = $SA->XML_DOM($XML_DOM_NODE)
+ Function  :	set/reset all parameters for this object from the XML::DOM node for <Simple>
+ Returns   :	MOBY::Client::SimpleArticle
+ Arguments :    (optional) an $XML::DOM node from the <Simple> article of a DOM
+
+=cut
+
+
 =head2 isSimple
 
  Title     :	isSimple
@@ -104,6 +163,17 @@
 =cut
 
 
+=head2 isSecondary
+
+ Title     :	isSecondary
+ Usage     :	$boolean = $IN->isSecondary()
+ Function  :	is this a SecondaryArticle type?
+                (yes, I know this is obvious)
+ Returns   :	0 (true)
+
+=cut
+
+
 {
 	# Encapsulated:
 	# DATA
@@ -115,6 +185,7 @@
                       articleName   => [undef,      'read/write'],
                       Simples       => [[],         'read/write'],
                       isSimple      => [0,          'read'      ],
+                      isSecondary   => [0,          'read'      ],
                       isCollection  => [1,          'read'      ],
                       XML           => [undef,      'read/write'],
                       XML_DOM       => [undef,      'read/write'],
@@ -188,7 +259,7 @@
 
 sub createFromXML {
     my ($self) = @_;
-    my $p = XML::DOM->new;
+    my $p = XML::DOM::Parser->new;
     my $doc = $p->parse($self->XML);
     my $root = $doc->getDocumentElement;
     return 0 unless ($root && ($root->getTagName eq "Collection"));
@@ -198,6 +269,7 @@
 sub createFromDOM {
     my ($self, $dom) = @_;
     return 0 unless ($dom && ($dom->getTagName eq "Collection"));
+    $self->XML($dom->toString); # set the string version of the DOM
     $self->articleName("");
     $self->Simples([]);
     
@@ -209,7 +281,7 @@
     for my $n(0..$objects->getLength - 1){
         foreach my $child($objects->item($n)->getChildNodes){
             next unless $child->getNodeType == ELEMENT_NODE;
-            $self->addSimple(MOBY::Client::SimpleArticle->new(XML_DOM => $objects->item($n)));
+            $self->addSimple(MOBY::Client::SimpleArticle->new(articleName=>$self->articleName, XML_DOM => $objects->item($n)));
         }
     }
     return $self;

===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY/Client/ServiceInstance.pm,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- /home/repository/moby/moby-live/Perl/MOBY/Client/ServiceInstance.pm	2004/03/18 23:10:34	1.10
+++ /home/repository/moby/moby-live/Perl/MOBY/Client/ServiceInstance.pm	2004/04/14 19:56:59	1.11
@@ -186,6 +186,7 @@
                       type          => [undef,      'read/write'],
 					  input			=> [[], 		'read/write'], # listref of Simple and Collection articles
                       output        => [[],			'read/write'], # listref of Simple and Collection articles
+                      secondary     => [[],			'read/write'], # listref of SecondaryArticles
                       category      => [undef,      'read/write'],
                       description   => [undef,      'read/write'],
 					  registry		=> ['MOBY_Central', 		'read/write'],

===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY/Client/SimpleArticle.pm,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- /home/repository/moby/moby-live/Perl/MOBY/Client/SimpleArticle.pm	2003/12/02 00:23:23	1.3
+++ /home/repository/moby/moby-live/Perl/MOBY/Client/SimpleArticle.pm	2004/04/14 19:56:59	1.4
@@ -18,9 +18,30 @@
 
 =head1 DESCRIPTION
 
-This describes the Simple articles from the findService Response of MOBY Central
-(i.e. the description of the service), it DOES NOT create simple articles
-as provided by a service provider (i.e. simple articles containing data)
+This describes the Simple articles from either the findService Response of MOBY Central
+(i.e. the description of the service), or Simple articles
+as provided in a service invocation or response message
+(i.e. simple articles containing data)
+
+Basically it parses the following part of a findService response:
+
+<Simple articleName='foo'>
+    <objectType>someNbject</objectType>
+    <Namespace>someNamespace</Namespace>
+    <Namespace>someNamespace2</Namespace>
+</Simple>
+
+OR  it parses the following part of a service invocation or response message:
+
+<Simple articleName='foo'>
+    <SomeObject namespace='someNamespace' id='someID'>.....</SomeObject>
+</Simple>
+
+The articleName is retrieved with ->articleName
+The namespace(s) are retrieved with ->namespaces
+The objectType is retrieved with ->objectType
+the id (if instantiated) is retrieved with ->id
+
 
 =head1 AUTHORS
 
@@ -37,11 +58,12 @@
  Usage     :	my $SA = MOBY::Client::SimpleArticle->new(%args)
  Function  :	create SimpleArticle object
  Returns   :	MOBY::Client::SimpleArticle object
- Args      :    articleName => $articleName (optional)
-                objectType => $objectType (required)
-                namespaces => \@namesapces (optional)
-                XML_DOM => $XML_DOM node of the simple article (optional)
-                XML  => $XML XML string representing the simple article (optional)
+ Args      :    either of the following two methods may be used to auto-generate the
+                object by passing the appropriate XML node as a string, or XML::DOM node object
+                
+                XML => $XML
+                XML_DOM => $XML::DOM::NODE
+
 
 =cut
 
@@ -76,27 +98,27 @@
 
 =cut
 
-#
-#=head2 XML
-#
-# Title     :	XML
-# Usage     :   $SA = $SA->XML($XML)
-# Function  :	set/reset all parameters for this object from the XML
-# Returns   :	MOBY::Client::SimpleArticle
-# Arguments :    (optional) XML fragment from and including <Simple>...</Simple>
-#
-#=cut
-#
-#
-#=head2 XML_DOM
-#
-# Title     :	XML_DOM
-# Usage     :	$namespaces = $SA->XML_DOM($XML_DOM_NODE)
-# Function  :	set/reset all parameters for this object from the XML::DOM node for <Simple>
-# Returns   :	MOBY::Client::SimpleArticle
-# Arguments :    (optional) an $XML::DOM node from the <Simple> article of a DOM
-#
-#=cut
+
+=head2 XML
+
+ Title     :	XML
+ Usage     :   $SA = $SA->XML($XML)
+ Function  :	set/reset all parameters for this object from the XML
+ Returns   :	MOBY::Client::SimpleArticle
+ Arguments :    (optional) XML fragment from and including <Simple>...</Simple>
+
+=cut
+
+
+=head2 XML_DOM
+
+ Title     :	XML_DOM
+ Usage     :	$namespaces = $SA->XML_DOM($XML_DOM_NODE)
+ Function  :	set/reset all parameters for this object from the XML::DOM node for <Simple>
+ Returns   :	MOBY::Client::SimpleArticle
+ Arguments :    (optional) an $XML::DOM node from the <Simple> article of a DOM
+
+=cut
 
 
 =head2 addNamespace
@@ -136,6 +158,17 @@
 =cut
 
 
+=head2 isSecondary
+
+ Title     :	isSecondary
+ Usage     :	$boolean = $IN->isSecondary()
+ Function  :	is this a SecondaryArticle type?
+                (yes, I know this is obvious)
+ Returns   :	0 (true)
+
+=cut
+
+
 {
 	# Encapsulated:
 	# DATA
@@ -147,8 +180,10 @@
                       articleName   => [undef,      'read/write'],
                       objectType    => [undef,      'read/write'],
                       namespaces    => [[],         'read/write'],
+                      id            => [undef,         'read/write'],
                       XML_DOM       => [undef,      'read/write'],
                       XML           => [undef,      'read/write'],
+                      isSecondary   => [0,          'read'      ],
                       isSimple      => [1,          'read'      ],
                       isCollection  => [0,          'read'      ],
 				);
@@ -218,7 +253,7 @@
 
 sub createFromXML {
     my ($self) = @_;
-    my $p = XML::DOM->new;
+    my $p = XML::DOM::Parser->new;
     my $doc = $p->parse($self->XML);
     my $root = $doc->getDocumentElement;
     return 0 unless ($root && ($root->getTagName eq "Simple"));
@@ -228,7 +263,7 @@
 sub createFromDOM {
     my ($self, $dom) = @_;
     return 0 unless ($dom && ($dom->getTagName eq "Simple"));
-
+    $self->XML($dom->toString); # set the string version of the DOM
     $self->namespaces([]);  # reset!
     $self->articleName("");
     $self->objectType("");
@@ -236,7 +271,46 @@
     my $attr = $dom->getAttributeNode('articleName');
     my $articleName = "";
     $articleName = $attr->getValue if $attr;
-    $self->articleName($articleName);
+    $self->articleName($articleName) if $articleName;  # it may have already been set if this Simple is part of a Collection...
+    
+# fork here - it may be an instantiated object (coming from a service invocation/response)
+# or it may be a template object as in the SimpleArticle element of a registration call
+
+# if the objectType tag exists, then it is a template object
+    if (@{$dom->getElementsByTagName("objectType")}[0]){
+        return $self->_createTemplateArticle($dom)
+    }
+    else { return $self->_createInstantiatedArticle($dom)}
+# otherwise it should simpy contain an instantiated MOBY object
+    
+
+}
+
+sub _createInstantiatedArticle {
+    my ($self, $dom) = @_;
+    
+    # this will take a <Simple> node from a MOBY invocation message
+    # and extract the object-type and namespace from the
+    # contained data object
+
+    foreach my $child($dom->getChildNodes){ # there should be only one child node, and that is the data object itself; ignore whitespace
+        next unless $child->getNodeType == ELEMENT_NODE;
+        $self->objectType($child->getTagName);
+        my $attr = $child->getAttributeNode('namespace');
+        $self->addNamespace($attr->getValue) if $attr;
+        my $id = $child->getAttributeNode('id');
+        $self->id($id->getValue) if $id;
+    }
+    return $self;
+}
+
+sub _createTemplateArticle {
+    my ($self, $dom) = @_;
+    
+    # this will take a <Simple> node from a MOBY findServiceResponse
+    # message and extract the objectType and namespace array
+    # from the service signature.
+    
     my $objects = $dom->getElementsByTagName("objectType");
     foreach my $child($objects->item(0)->getChildNodes){  # there must be only one in a simple!  so take element 0
         next unless $child->getNodeType == TEXT_NODE;
@@ -254,7 +328,6 @@
     return $self;
 }
 
-
 sub AUTOLOAD {
     no strict "refs";
     my ($self, $newval) = @_;




More information about the MOBY-guts mailing list