BPM-XPDL

 view release on metacpan or  search on metacpan

lib/BPM/XPDL.pm  view on Meta::CPAN

            for my $param (@{$afps->{FormalParameter}||[]})
            {   delete $param->{Index};
            }
        }
  
        # Condition/Xpression to Condition/Expression
        my $trs = $wfp->{Transitions} || {};
        for my $trans (@{$trs->{Transition} || []})
        {   my $cond = $trans->{Condition} or next;
            foreach ($cond->getChildrenByLocalName('Xpression'))
            {   $_->setNodeName('Expression');
                $_->setNamespace($ns, $prefix, 1);
            }
        }

        my $sets = $wfp->{ActivitySets} || {};
        foreach my $set (@{$sets->{ActivitySet} || []})
        {   my $strans = $set->{Transitions} || {};
            foreach my $trans (@{$strans->{Transition} || []})
            {   my $cond = $trans->{Condition} or next;
                foreach ($cond->getChildrenByLocalName('Xpression'))
                {   $_->setNodeName('Expression');
                    $_->setNamespace($ns, $prefix, 1);
                }
            }
        }

        # Order in WorkflowProcess changed.  This is a no-op for X::C
    }

    $data->{PackageHeader}{XPDLVersion} = '2.0';
    $data;
}

sub convert20to21($)
{   my ($self, $data) = @_;

    trace "Convert xpdl version from 2.0 to 2.1";

    # Tool has been removed from the spec.  However, it can still be
    # used in the old namespace, and I do not know how to convert it
    # to 2.1 structures (yet)

    my $ns = $self->namespace;
    my $prefix
      = $ns eq NS_XPDL_21 ? 'xpdl21'
      : panic;


    # do not walk more than one HASH level at a time, to avoid creation
    # of unused HASHes.
    my $wfps = $data->{WorkflowProcesses} || {};
    foreach my $wfp (@{$wfps->{WorkflowProcess} || []})
    {
        my $acts = $wfp->{Activities} || {};
        foreach my $act (@{$acts->{Activity} || []})
        {   # Rewrite Tool to Task/TaskApplication
            if(my $impl = $act->{Implementation})
            {   foreach my $tool (@{delete $impl->{Tool} || []})
                {  my %task = %$tool;
                   delete $task{PackageRef};         # ?relocate info?
                   delete $task{ExtendedAttributes}; # ?into DataMapping?
                   delete $task{Type};   # shouldn't be there, rem in 2.0
                   $impl->{Task}{TaskApplication} = \%task;
                }
            }
        }

        # Condition/Xpression to Condition/Expression
        my $trs = $wfp->{Transitions} || {};
        for my $trans (@{$trs->{Transition} || []})
        {   my $cond = $trans->{Condition} or next;
            foreach ($cond->getChildrenByLocalName('Expression'))
            {   $_->setNamespace($ns, $prefix, 1);
            }
        }

        my $sets = $wfp->{ActivitySets} || {};
        foreach my $set (@{$sets->{ActivitySet} || []})
        {   my $strans = $set->{Transitions} || {};
            foreach my $trans (@{$strans->{Transition} || []})
            {   my $cond = $trans->{Condition} or next;
                foreach ($cond->getChildrenByLocalName('Expression'))
                {   $_->setNamespace($ns, $prefix, 1);
                }
            }
        }
    }

    $data->{PackageHeader}{XPDLVersion} = '2.1';
    $data;
}

#----------


sub version()   {shift->{version}}
sub namespace() {shift->{namespace}}

#--------

sub create($)
{   my ($self, $data) = @_;
    my $doc  = XML::LibXML::Document->new('1.0', 'UTF-8');
    my $wr   = $self->writer('Package')
        or panic "cannot find Package type";

    my $root = $wr->($doc, $data);
    $doc->setDocumentElement($root);
    $doc;
}

1;



( run in 1.100 second using v1.01-cache-2.11-cpan-5511b514fd6 )