Solstice::Application - An object representing a Solstice application.


Solstice documentation Contained in the Solstice distribution.

Index


Code Index:

NAME

Top

Solstice::Application - An object representing a Solstice application.

SYNOPSIS

Top

  # This is always subclassed, enhanced with accessors for data relevent to a specific instantiation of an application.
  use Solstice::Application;
  my $application = new Solstice::Application($app_name);
  my $name = $application->getName();
  my $version = $application->getVersion();
  my $namespace = $application->getNamespace();

  # Returns the StateTracker object for this instantiation of an application.
  my $state = $application->getState();

  # This can be used to put data personalized to the screen in the breadcrumbing.
  my $breadcrumb_info = $application->getStatePersonalInfo();




DESCRIPTION

Top

Export

No symbols exported.

Methods

new()

Creates a new Solstice::Application object.

getNavigationView()

Attempts to return the application's navigation view. Should be overridden in the subclass for custom behavior. This will be called unless some application code explicitly sets a navigation view.

Private Methods

_init($id) =item _init($name)

Initialize the application object

_getAccessorDefinition()

Modules Used

Solstice::Database.

AUTHOR

Top

Catalyst Group, <catalyst@u.washington.edu>

VERSION

Top

$Revision: 3364 $

COPYRIGHT

Top


Solstice documentation Contained in the Solstice distribution.
package Solstice::Application;

# $Id: Application.pm 3364 2006-05-05 07:18:21Z mcrawfor $

use 5.006_000;
use strict;
use warnings;

use base qw(Solstice::Model);

use Solstice::Configure;
use Solstice::Database;
use Solstice::Configure;
use Solstice::NamespaceService;

use constant TRUE    => 1;
use constant FALSE   => 0;
use constant SUCCESS => 1;
use constant FAIL    => undef;

my %application_cache;

our ($VERSION) = ('$Revision: 3364 $' =~ /^\$Revision:\s*([\d.]*)/);

sub new {
    my $obj = shift;
    my $input = shift;

    my $self = $obj->SUPER::new();

    if (defined $input and ref $input eq 'HASH') { #info passed as hash
        if($input->{'id'}){
            $self = $self->_init($input->{'id'});
        }elsif($input->{'namespace'}){
            $self = $self->_init($input->{'namespace'});
        }else{
            return;
        }

    } elsif (defined $input) { #pull from id/namespace
        $self = $self->_init($input);

    }else{ # no param - use namespace
        caller =~ m/^(\w+):.*$/;
        my $input = $1;

        if($input eq 'Solstice'){ #abstract superclass
            return undef;
        }else{
            $self = $self->_init($input);
        }
    }

    return $self;
}

sub getNavigationView {
    my $self = shift;

    my $namespace = Solstice::NamespaceService->new()->getAppNamespace();

    my $nav_view_package = $namespace.'::View::Navigation';

    my $nav_view;
    eval { 
        $self->loadModule($nav_view_package);
        $nav_view = $nav_view_package->new();
    };

    return $nav_view if $nav_view;
}

sub flushApplicationCache {
    %application_cache = ();
    return TRUE;
}


sub _loadApplicationData {
    my $self = shift;

    my $config = Solstice::Configure->new();
    my $db = Solstice::Database->new();
    my $db_name = $config->getDBName();

    $db->readQuery('SELECT application_id, name, namespace
                FROM '.$db_name.'.Application');

    while( my $row = $db->fetchRow() ){
        $application_cache{ $row->{'application_id'} } = $row;
        $application_cache{ $row->{'namespace'} } = $row;
    }

}

sub _addApplicationEntry {
    my $self = shift;
    my $namespace = shift;

    warn "Creating an entry for ${namespace}::Application in the Solstice Application table!";
    my $db = Solstice::Database->new();
    my $db_name = $self->getConfigService()->getDBName();
    $db->writeQuery("INSERT INTO $db_name.Application (name, namespace) VALUES (?,?)", $namespace, $namespace);

    $self->flushApplicationCache();
    $self->_loadApplicationData();
}

sub _init {
    my $self = shift;
    my $input = shift;

    return FAIL unless defined $input;

    $self->_loadApplicationData() unless %application_cache;

    if (!defined $application_cache{$input}) {
        #flush and reload application data to ensure some other thread has not 
        #already added this app
        $self->flushApplicationCache();
        $self->_loadApplicationData();

        #if the cache STILL doesn't have the app:
        if (!defined $application_cache{$input}) {
            $self->_addApplicationEntry($input);
        }
    }

    my $data = $application_cache{$input};

    return FAIL unless $data->{'application_id'};

    #swap out the package name if possible
    eval {
        $self->loadModule($data->{'namespace'}.'::Application');
    };
    unless($@){
        $self = bless {}, $data->{'namespace'}.'::Application';
    }

    $self->_setID($data->{'application_id'});
    $self->_setName($data->{'name'});
    $self->_setNamespace($data->{'namespace'});

    return $self;
}

sub _getAccessorDefinition {
    return [
    {
        name => 'Name',
        key  => '_name',
        type => 'String',
        private_set => TRUE,
    },
    {
        name => 'Namespace',
        key  => '_namespace',
        type => 'String',
        private_set => TRUE,
    },
    {
        name => 'Version',
        key  => '_version',
        type => 'Float',
        private_set => TRUE,
    },
    {
        name => '500Error',
        key  => '_500_error',
        type => 'Boolean',
    },
    ];
}

1;

__END__