Difference between revisions of "HowTo:Classes, APIs, and Naming Conventions"

From AgileApps Support Wiki
imported>Aeric
(Created page with "{{subst: HowTo Guide}}")
 
imported>Aeric
 
(17 intermediate revisions by the same user not shown)
Line 1: Line 1:
<noinclude>
<noinclude>
{{Orientation | audience | level | N}}
{{Orientation | Developers | Intermediate | 10}}
&lt;/noinclude>...First line here...
</noinclude>This guide provides background information that is useful for Java developers, going forward.
:* Activate the noinclude block so it doesn't appear when Guides are aggregated.
===Uses for Java Classes===
:* audience = Users, Designers, Developers
Java classes and the methods they contain provide powerful functionality as Page controllers, but they can be used in other ways, as well:
:* level = Beginner, Intermediate, Advanced
<blockquote>
:* N = 1, 2, 5, 10, 15, 20, 30 (minutes)
===Heading===
Top level heads in HowTo Guides are H3's, so they can be combined into a big PDF, one day.


====Handlers====
<!--
:;Custom Email Handlers: With a custom Email Handler, you intercept email messages sent to a special platform address, and process them however you need to.
:: ''Learn more:'' [[HowTo:Handle Incoming Emails Programmatically]]
-->
:;Custom Package Data Handlers: When a [[Package]] is created, it contains the skeleton for the database [[Objects]] that are included in the package. No data is included. In cases where data is needed, you can create a Package Data Handler with two methods defined by the interface. One tells the platform which data to include when a package is created. The other tells the platform what to do with the data when the package is installed.
:: ''Learn more:'' [[HowTo:Create a Data Handler to Add Data to a Package]]
</blockquote>
===Invoking Java APIs===
:* Ninety-nine percent of the time, the Java APIs you invoke will be from [{{DOCHOST}}/javadocs/com/platform/api/Functions.html com.platform.api.Functions] class.
:* Most APIs take an incoming [{{DOCHOST}}/javadocs/com/platform/api/Parameters.html com.platform.api.Parameters]
:* A Controller class creates a new Parameters instance, and can easily add all incoming HashMap arguments to it:
:::<tt>execute(HashMap valueMap) {</tt>
::::<tt>...</tt>
::::<tt>Parameters params = Functions.getParametersInstance();</tt>
::::<tt>params.add(valueMap);
:* Most APIs return a [{{DOCHOST}}/javadocs/com/platform/api/Result.html com.platform.api.Result] object:
::That object contains a ''list'' of Parameters objects (generally, records returned by a search)
::Loop on the [{{DOCHOST}}/javadocs/com/platform/api/ParametersIterator.html ParametersIterator] to process all of the results, or just grab the first one:
:::<tt>ParametersIterator it = result.getIterator();</tt>
:::<tt>Parameters result_params = it.next();</tt>
:* Since a [[Page]] takes a HashMap as an argument, a controller class is generally in the business of converting Result object values into the form the Page expects.
''Learn more:''
:* [[Parameters Class]]
:* [[Result Class]]
===Naming Conventions===
Naming conventions help to prevent confusions. Names are "handles" you use to mentally manipulate concepts. Here are some suggested conventions to help keep your thinking straight:
:* '''valueMap -''' HashMap instance passed to a Page
:* '''page_control -'''  passed to a Page in a valueMap
:* '''params -''' Parameters instance passed to an API
:* '''page_action -''' passed from a Page in the params
:* '''result -''' Result values passed back from an API (<tt>results</tt> is another possibility, since the value that comes back is actually a list.)
:* '''result_params -''' a Parameters object from the list (<tt>result</tt> is another possibility.)
<!--
===Wrap Up===
===Wrap Up===
...What you've done....
...What you've done....
Line 16: Line 54:
:''Learn more:''
:''Learn more:''
::* ...
::* ...
<!--
  No category for a HowTo Guide.
  They're reached from the index page in the Nav Bar.
  No point having an entry in the categories list, as well.
-->
-->
<br>
;Next:
: [[HowTo:Create a JSP Page and Java Controller]]

Latest revision as of 23:49, 15 May 2013

For:   Developers
Level: Intermediate
Time:  10 minutes

See more:
    ◾ HowTo Guides

This guide provides background information that is useful for Java developers, going forward.

Uses for Java Classes

Java classes and the methods they contain provide powerful functionality as Page controllers, but they can be used in other ways, as well:

Handlers

Custom Package Data Handlers
When a Package is created, it contains the skeleton for the database Objects that are included in the package. No data is included. In cases where data is needed, you can create a Package Data Handler with two methods defined by the interface. One tells the platform which data to include when a package is created. The other tells the platform what to do with the data when the package is installed.
Learn more: HowTo:Create a Data Handler to Add Data to a Package

Invoking Java APIs

  • A Controller class creates a new Parameters instance, and can easily add all incoming HashMap arguments to it:
execute(HashMap valueMap) {
...
Parameters params = Functions.getParametersInstance();
params.add(valueMap);
That object contains a list of Parameters objects (generally, records returned by a search)
Loop on the ParametersIterator to process all of the results, or just grab the first one:
ParametersIterator it = result.getIterator();
Parameters result_params = it.next();
  • Since a Page takes a HashMap as an argument, a controller class is generally in the business of converting Result object values into the form the Page expects.

Learn more:

Naming Conventions

Naming conventions help to prevent confusions. Names are "handles" you use to mentally manipulate concepts. Here are some suggested conventions to help keep your thinking straight:

  • valueMap - HashMap instance passed to a Page
  • page_control - passed to a Page in a valueMap
  • params - Parameters instance passed to an API
  • page_action - passed from a Page in the params
  • result - Result values passed back from an API (results is another possibility, since the value that comes back is actually a list.)
  • result_params - a Parameters object from the list (result is another possibility.)


Next
HowTo:Create a JSP Page and Java Controller