Upload
nagu5184930
View
37
Download
3
Embed Size (px)
Citation preview
Application Packages Wrapped Neatly in a Bow
EIS Developer Forum
April 4, 2007
Agenda What are Application Packages
and Classes? Why would I want to use App
Packages/Classes? When would I use App
Packages/Classes? General Structure of an App
Class Exception Handling (try/catch) App Packages/Classes and App
Messaging in 8.48
What are Application Packages/Classes? It’s just PeopleCode Application Packages contain
Application Classes You can create your own classes
or extend the functionality of the existing PeopleCode classes
A subclass can inherit all the properties and methods of the class it extends.
Why would I want to use Application Packages/Classes? Provide all the advantages of true
object-oriented programming: easier to debug because all the pieces
are separate easier to maintain because
functionality is gathered into a single place
extensible by subclass Provide more structure Because the Tools team says
it’s a good idea!
When would I use an Application Package/Classes? To structure your existing
PeopleCode functions to make them easier to debug and maintain.
When would I use an Application Package/Classes?For example, consider this
FUNCLIB record…
It’s full of functions, but where do I find the one I want?
When would I use an Application Package/Classes?…compared to this Application
Class
The structure of the Application Package makes it easier to group similar functions.
When would I use an Application Package/Classes? To structure your existing
PeopleCode functions to make them easier to debug and maintain.
To extend the functionality of an existing PeopleCode class or a custom class.
When would I use an Application Package/Classes?
For example, a custom “Person” class could have these properties:
Name City State
Person class
class Person
method getBioDemo(&sEMPLID As string) Returns boolean;
property string Name;
property string City;
property string State;
end-class;
Person class getBioDemo methodmethod getBioDemo
/+ &sEMPLID as String +/
/+ Returns Boolean +/
Local boolean &bReturn;
Local string &sName, &sCity, &sState;
SQLExec("SELECT NAME_DISPLAY, CITY, STATE FROM PS_PERSONAL_DATA where EMPLID = :1", &sEMPLID, &sName, &sCity, &sState);
&Name = &sName;
&City = &sCity;
&State = &sState;
If All(&sName) Or All(&sCity) Or All(&sState) Then
&bReturn = True;
Else
&bReturn = False;
End-If;
Return &bReturn;
end-method;
Created automatically – don’t mess with these statements!
PeopleCode using Person classimport GBUT_PEOPLE:Person;
Local GBUT_PEOPLE:Person &personBioDemo;
&sEMPLID = GBUT_TEST_WRK.EMPLID.Value;&personBioDemo = create GBUT_PEOPLE:Person();
If &personBioDemo.getBioDemo(&sEMPLID) Then MessageBox(0, "", 0, 0, &personBioDemo.Name | "
lives in " | &personBioDemo.City | ", " | &personBioDemo.State);
Else MessageBox(0, "", 0, 0, "No Bio Demo Data Found");End-If;
Employee subclass extends Person class An Employee would have the
same properties as a Person along with additional attributes like Job Title.
By making Employee a subclass of Person, the Employee class has access to the properties/methods of Person as well as any additional properties/methods defined for Employee.
Employee subclass
class Employee extends GBUT_PEOPLE:Person
method getJobData(&sEMPLID As string) Returns boolean;
property string JobTitle;
end-class;
Employee subclass getJobData method
method getJobData
/+ &sEMPLID as String +/
/+ Returns Boolean +/
Local boolean &bReturn;
If %This.getBioDemo(&sEMPLID) Then
SQLExec("Select b.DESCR from PS_JOB a, PS_JOBCODE_TBL b where a.EMPLID = :1 and a.effdt = (select max(a_ed.effdt) from ps_job a_ed where a.emplid = a_ed.emplid and a.empl_rcd = a_ed.empl_rcd) and b.jobcode = a.jobcode", &sEMPLID, &sJobTitle);
If All(&sJobTitle) Then
&JobTitle = &sJobTitle;
&bReturn = True;
Else
&bReturn = False;
End-If;
Else
&bReturn = False;
End-If;
Return &bReturn;
end-method;
Created automatically – don’t mess with these statements!
This method is in class “Person”
PeopleCode using Employee subclassimport GBUT_PEOPLE:Employee;
Local GBUT_PEOPLE:Employee &employeeData;
&sEMPLID = GBUT_TEST_WRK.EMPLID.Value;&employeeData = create GBUT_PEOPLE:Employee();
If &employeeData.getJobData(&sEMPLID) Then MessageBox(0, "", 0, 0, &employeeData.Name | ", " |
&employeeData.JobTitle | ", lives in " | &employeeData.City | ", " | &employeeData.State);
Else MessageBox(0, "", 0, 0, "Either no BioDemo data or no job
title found");End-If;
General Structure of an Application Class Class name Class extensions Declaration of public external
interface Declaration of private instance
variables and methods Declaration of protected instance
variables and methods Definition of methods Constructors External function declarations
Class name A fully qualified name that is
formed hierarchically by the name of the top-level package that contains them, the package that contains that package and so on.
Must be unique within the App package.
class Employee extends GBUT_PEOPLE:Person method getJobData(&sEMPLID As string) Returns
boolean; property string JobTitle;end-class;
Class name ExampleApplication Packages
Application Classes
Class names
CRM:Address
CRM:Customer
CRM:Utilities:Address
CRM:Utilities:Incident
Class extension Represents the “is a” relationship. Inherits all the public methods and
properties of the class it extends. Before you can extend a class, you
must import it.
import GBUT_PEOPLE:Person;
class Employee extends GBUT_PEOPLE:Person method getJobData(&sEMPLID As string) Returns
boolean; property string JobTitle;end-class;
Declaration of public external interface Specifies the methods and
properties that the class provides to other PeopleCode programs.
class Employee extends GBUT_PEOPLE:Person method getJobData(&sEMPLID As string) Returns boolean; property string JobTitle;end-class;
Declaration of private instance variables and methods The private part of a class
declaration gives the declaration of any private methods, instance variable, and private class constants.
Private methods or instance variables cannot be overridden by subclasses because they are completely private to the declaring class.
Declaration of private instance variables and methodsclass Emailer method Emailer(&bDebug As boolean); method addAttachment(&sFile As string, &sTitle As string); method send() Returns boolean; … property string TU; property string CC; property string BC; property string Subject; property string Body; …private method getUserEMail(&sOPRID As string) Returns string; method getRoleEMail(&sROLENAME As string) Returns string; method errorThrower(&nMsgSetNum As number, &nMsgNum As
number, &aSubstitution As array of string); method isValid() Returns boolean; instance boolean &bInError; instance string ¤tMethod; …end-class;
Public
PrivateThese methods are not
available to programs outside class Emailer.
Declaration of protected instance variables and methods Fall between public and private. Can be accessed only by objects
of this application class and those derived from this application class.
Use protected methods and properties when you want to hide them from outside use, but allow the flexibility of using them in derived classes.
Declaration of private instance variables and methodsclass A; method A(); property string Q;protected method MP() Returns string; property string P;end-class;
Class b extends A; method B(); property string X;end-class;
Public Protected
method MP() is available only to class A and its subclasses (like Class b).
Definition of methods
Come after the definition of any global or component variables and external functions needed by the method
Passing parameters By value
method increment (&val as number, &text as string);
By referencemethod increment (&val as number out, &text as
string);
Constructors A constructor is a public method with
the same name as the class. A class that does not extend some
other class does not need any constructor.
Instantiate new objects of an app class by using the Create function. The function takes the name of the class and any parameters needed for the constructor method.
&employeeData = create GBUT_PEOPLE:Employee();
External function declarations Declare Function xyz PeopleCode
FUNCLIB_MISC.MISC_FUNCTIONS FieldFormula;
Allowed in application classes In the global and component
variable declarations After the class declaration (after the
end-class statement) Before the method definitions
Other AppClass Conceptsthat we aren’t going into today… Abstract Methods and Properties Interfaces Using Methods and Properties for
Collections Downcasting …
Please refer to PeopleBooks 8.48 > PeopleCode API reference > Application Classes for more information.
Exception Handling An exception can be defined as any unusual
event that requires special handling in your PeopleCode program.
For example, dividing by zero, referencing a method or property that doesn't exist, or trying to use a method or property on a null object are all exceptions that should be handled.
Exception handling is the processing you initiate when an exception occurs. You can handle errors in PeopleCode using the catch statement. The places in your code where you want exceptions handled must be enclosed by the try and end-try statements.
Exception Handling
The process of exception handling can be broken down as follows: An error occurs (either a hardware
or software error). The error is detected and an
exception is thrown (either by the system or by your program).
Your exception handler provides the response.
Exception Handling try SQLExec(&sCurrentDDL); catch Exception &cl %This.Result = "Error"; %This.errorThrower(20101, 13, Split(%This.Name |
"." | %This.currentMethod, ";" | %This.TableName |
";")); If &bInDebug Then &fLogFile = GetFile(&sLogFileName, "A", %FilePath_Absolute); &fLogFile.WriteLine(%Datetime | " | " |
%This.Name | "." | %This.currentMethod | " Error during doAlter"); &fLogFile.Close(); End-If; Return False; end-try;
Exception Handling
An exception to exception handling: Using functions that transfer the
end user to a new component, such as the DoModal, DoModalComponent, or Transfer functions (in some cases) inside a try block do not catch PeopleCode exceptions thrown in the new component.
Catches are only caught for exceptions thrown within the current component.
AppClasses and the LS 8.9 Upgrade Application Messaging changes in
the 8.48 version of PeopleTools A Node is still a Node and a
Message is still a Message, but… Message channels become Queues New objects: Services and
Service Operations Node Transactions (Routing tab in
8.21) become Routings Message Subscriptions become
Application Classes and Service Operation Handlers
AppClasses and the LS 8.9 Upgrade
AppClasses and the LS 8.9 Upgrade
For more information on this topic, sign up for one of the workshops to be held tomorrow (Thursday, April 5)
9:00 am – 12:00 pm1:00 pm – 4:00 pm
RP - EIS Training Room 1
Workshops on Friday
The End