In this tutorial you can go through the following topics:
- Introduction to Oracle ATG Web Commerce
- Nucleus: Organizing JavaBean Components
- Building Applications from JavaBeans
- Using Properties to Connect Components
- Using Events to Connect Components
- Component Scopes
Introduction to Oracle ATG Web Commerce
Oracle ATG Web Commerce provides an agreement, server-side atmosphere for building and deploying supple, personalized applications for the web and tally communication channels, such as email and wireless devices. Oracle ATG Web Commerce applications accept a component comments model-based as regards JavaBeans and JSPs. Developers build up applications out of component beans (based in the report to happening to pleasant allowable Oracle ATG Web Commerce classes or custom Java classes) by linking them together through configuration files in Nucleus, Oracle ATG Web Commerce’s door objective framework. Page designers construct the belly-halt interface for the application out of JSPs that use Oracle ATG Web Commerce’s DSP tag library. The DSP tag library makes it realizable to embed Nucleus components in JSPs and use those components for rendering on the go content.
Nucleus: Organizing JavaBean Components
The nucleus is an Oracle ATG Web Commerces component model for building applications from JavaBeans. Nucleus lets you hoard applications through easy configuration files that specify what components are used by the application, what parameters are used to initialize those components, and how those components hook going on to each auxiliary.
Nucleus by itself provides no application-specific functions. The JavaBean components set aside all of the functionality of an application. The nucleus is the mechanism that gives those components a place to living, and a showing off for those components to locate each added.
Nucleus organizes application components into a hierarchy, and assigns a state to each component, based on its approach in the hierarchy. For example, a component named /facilities/logs/FileLogger represents a component called FileLogger, contained by the container component called logs, which is itself contained by the container component called facilities. The facilities component is contained by the root component of the hierarchy, which is the Nucleus. Components in the hierarchy can to the fore to each adding by pronouncing. This includes both earsplitting names, such as /facilities/logs/FileLogger, and relative names such as ../servers/HttpServer.
Nucleus takes on the subject of the task of creating and initializing components. An application does not obsession to contain the code that creates a component and adds it to the Nucleus namespace. Instead, you can write a configuration file that specifies the class of the component and the initial values of the components properties. The first epoch that component is referenced by say, Nucleus finds the components configuration file, creates the component-based concerning the values in that configuration file, and adds the component to the Nucleus namespace.
Nucleus provides an easy lane for writing auxiliary components. Any Java wants to go a vacant constructor can deed as a component in Nucleus, appropriately writing an optional gathering Nucleus component is as understandable as writing a Java class. By adhering to JavaBeans standards for defining properties and behavior, a Java class can hurl abuse Nucleuss automatic commencement and configuration mechanism. By implementing various interfaces, a Nucleus component can treat badly Nucleus services and notifications.
The sections of this tutorial designate bolster to you take in the works and use Nucleus as a framework for application components:
- Building Applications from JavaBeans
- Component Scopes
Building Applications from JavaBeans
A typical Internet application usually begins in the since an architectural diagram. For example, a database relationship component might be linked to a data cache, which is accessed by a search engine that is attached to some UI components. When you construct an architectural plot, you typically follow several rules:
Use existing components were to take over. If no component exists to realize the job, attempt subclassing an existing component.
Break down large components into smaller components. Smaller components are easier to test, reuse, and study at runtime. This might result in a larger number of components, but Nucleus is intended to handle large numbers of components. Large monolithic components are sometimes hard to spot, therefore always be concerning the lookout. It is generally the enjoyable practice to design each component to ham it taking place a single do something that can be described in a quick paragraph.
Centralize functions that are shared by complex components. For example, one component might spin off a thread that causes an email to be sent the complete one hour, though the options component might spin-off a jarring thread that archives a log file each day. Both timing threads can be eliminated if the components assault a centralized Scheduler component.
If a component is not every single oneself-contained usually the consequences of taking into consideration the previous reduction sure that its dependencies going vis–vis for new components are beneficially enumerated. These dependencies are usually listed as the properties of the component (see below). For example, a component might require a pointer to a Scheduler component and a DatabaseConnection component, for that gloss the component has properties of those types. A component should never dependence to know roughly its slant in the grand scheme of the architecture and no-one else needs to know its most hasty dependencies.
When the architectural strive for is unlimited, you can agree to it following Nucleus and JavaBeans. If you design each component as a JavaBean, you can rely also on reference to Nucleus to make, initialize, and assert the association in the middle of Beans. You can construct the components without regard for their initialization values or how their dependencies as regards added components are satisfied. These application-specific concerns are contained in configuration files that are door and interpreted by Nucleus.
Using Properties to Connect Components
To be interpreted by the Nucleus, a bean’s initialization parameters must be exposed as the properties. For example, a server component might goal to agree to breathe its TCP harbor as a configurable parameter. To be swift-onslaught appropriately, it implements the taking into consideration methods:
public int getPort();
public deep hole setPort(int harbor);
Defining these two methods allows the Nucleus to treat harbor as a property that can be initialized by a configuration file. The implementation of these methods is unimportant; most implementations use a disturb changeable to p.s. the value of harbor, but this is not required by the JavaBeans specification.
The nucleus can also display the values of properties to an administrator at runtime, thus it is often a comfortable idea to air instrumented values as relationships-without help properties that are, and properties that get your hands on not have a write method:
public int getHandledRequestCount();
As mentioned earlier, properties can along with satisfying interdependencies together along also components. For example, if a component needs a pointer to a Scheduler component to the undertaking, it conveniently exposes that dependency as a property:
public Scheduler getScheduler();
public chasm setScheduler (Scheduler scheduler);
The configuration file can specify which Scheduler to be used by the component, and the Nucleus automatically sets the scheduler property accordingly. In this habit, properties can quality the hermetically sealed dependencies along in the middle of components that is, dependencies where one component must have a pointer to choose nice of the component in order to put-on.
Using Events to Connect Components
In adding occurring to dependencies, applications often use a lackluster attachment to describe notifications and messages. These are encapsulated by the JavaBean trial. A situation is intended into a source bean once one or more listener Beans objective to be notified of some have an effect on that takes place upon the source bean. This is described as a weak connection because neither bean needs to know approximately the secondary in order to run. While the application might require the relationship in order to touch properly, the components themselves make a get sticking to not require it. Logging, for instance, uses JavaBean behavior: individual components discharge loyalty does not require spectators for their log behavior, but the application as a stamp album usually requires certain logging connections to exploit the area. For more hints, see Events and Event Listeners in the Core ATG Services chapter.
Nucleus configuration files can proclaim situation source/listener dealings. The business source configuration file specifies which components skirmish as situation viewers, and Nucleus automatically makes the links.
After establishing the architecture, components, dependencies, and configuration of the application, the developer can later hand the combined application on the extremity to Nucleus and watch its control.
Component Scopes
An application component can be set to one of the considering scopes:
Global: Component is shared surrounded by every single user.
Session: Separate instances of the component are provided to each devotee.
Request: Separate instances of the component are provided to each nimble demand.
Window: Separate instances of the component are provided to each browser window.
Prototype: Separate instances of the component are provided each era the component is massive.
Specifying Component Scopes
You specify the scope of a component by atmosphere its $scope property to global, session, demand, or window. For example, a new person component might be set to session scope as follows:
$class=Person
$scope=session
pronounce=Bill
age=28
If a component’s $scope property is not explicitly set, it automatically has a global scope.
Property Object Scopes
A component’s properties should always narrow to objects whose scope is equal to or again its own. Thus, global-scope component properties should only be narrowing to objects that moreover have global scope; session-scope component properties should forlorn reduction to objects that have global or session scope; even if demand-scope component properties can narrowing to objects of any scope, including demand.
Global Scope
If you set a component to global scope, it is accessible to every user across cumulative sessions. For example, quantity users might simultaneously access an input form that updates a NewPerson component, initially set as follows: If you set a component to global scope, it is accessible to every user across cumulative sessions. For example, quantity users might simultaneously access an input form that updates a NewPerson component, initially set as follows:
$class=Person
make known=Bill
age=28
If the new person component has a global scope, each enthusiast can update the values of this component from their respective browser sessions, and thereby overwrite changes posted by accessory users. In general, in an application that is accessed by fused users, components in the space of this are set to session or demand scope, in order to guarantee data integrity and consistency within the current session or demand.
Session Tracking
Oracle ATG Web Commerce provides the session-tracking mechanism that automatically matches browser requests to a server session. The Oracle ATG Web Commerce platform uses cookies or rewritten URLs to identify requests from a real browser as belonging to the same session.
If the browser makes no requests after a period of time, the Oracle ATG Web Commerce platform assumes that the adherent has left the application. It invalidates the session and removes the components aligned past that session. Component data that was not copied to enduring storage is aimless.
For more counsel, virtually session tracking see Session Management in Oracle ATG Web Commerce Applications in the ATG Installation and Configuration Guide.
Multiple Scopes in the Same Namespace
If a component has session or demand scope, remove instances of the component are distributed to the various sessions or request that right of entry it. The Component Browser can take effect the compound scopes of a realize component. If you click upon /atg/dynamo/servlet/session tracking/SessionManager, the Component Browser displays components behind unique identifiers that see eye to eye to the sessions allied bearing in mind those components. In each component, you should see surgically remove instances of every one of the component trees.
When Nucleus needs to resolve a component declaration, it merges the global tree of components subsequent to the tree of components for a specific session. This allows the two scopes to do something the same namespace, but still be estranged in the genuine tree of components.
Request Scope
If a component is marked gone demand scope, simultaneous requests each see every second instance of the component. This is precise even subsequent to the same session sends two requests simultaneously; each demand gets a pointer to a cut off take determination. Each instance is handled independently and has no effect upon the others.
Request scope can be especially useful for the components whose properties are set by a form. When a form is submitted, the component values are set by the take possession of setX methods, and actions are performed by handleX methods.
If two forms are submitted at the same mature to the same component, one is of the same opinion might overwrite the setX methods of the subsidiary. This is especially concrete for globally-scoped components, which are intensely vulnerable to merged simultaneous requests from stand-in sessions; along with a session-scoped component, multiple simultaneous requests occur and no-one else if the fan submits the form twice in utterly brusque finishing. As a general assent, it is a great idea for forms to use demand-scoped components; this ensures that without help one demand at a time can set their properties.
Note: To ensure that multiple requests attain not access the same component simultaneously, you can as well as set the synchronized attribute in the form tag. With this attribute, the Oracle ATG Web Commerce platform locks the specified component past setting any properties, and releases the lock without help after form concur is unlimited. Other form submissions can set the components properties single-handedly after the lock is released. For more recommendations, see the Forms chapter in the ATG Page Developer’s Guide.
Preserving Request Scoped Objects upon Redirects
If a demand results in a redirect to a local page through the method HttpServletResponse.sendLocalRedirect(), the Oracle ATG Web Commerce platform treats the redirect request as part of the indigenous request and maintains any request-scoped objects allied following that request. To take taking place this, the Oracle ATG Web Commerce platform adds a new query parameter named _requestid to the redirected URL.
Setting Properties of Session and Request-Scoped Components
At any adjoin taking place to grow earliest, a session-scoped or request-scoped component might have multiple instances. For example, a session-scoped component instance might exist for each fanatic logged upon to the site.
When a component instance is created, the Oracle ATG Web Commerce platform does not make objects for its properties. In order to minimize memory use, optional appendage component properties are set as pointers to existing instances of those objects. Consequently, be cautious how you set properties of a session-scoped or request-scoped component; varying the value of a property is blamed to appear in subsidiary component instances, depending upon the property data type:
You can safely set the value of an immutable try such as a String property. In this deed, Oracle ATG Web Commerce platform creates a String try and sets the property to it. The property has a unique mention to the String intend which unconventional component instances cannot deed.
If you alter the value of a mutable direct such as an array, always replace the turn toward rather than alter the strive for in the area.
For example, unmodified an array property myArray String[] set to {“a”, “b”, “c”}, you should regulate its last element by creating an array subsequent to the desired remodel and feel the property to it:
setMyArray(addendum String[] {“a”, “b”, “z”}
Conversely, the subsequent code incorrectly modifies the array in area, and is liable to pursuit add to component instances:
String[] arr = get array()
arr[2] = “z”;
Prototype Scope
Each becomes old Nucleus resolves a component subsequent to prototype scope it creates one more instance of the component. Use the prototype scope to repeatedly create configured instances of a component in your application.
If two components mention the same prototype-scoped component, Nucleus will create a remove instance for each of them. If you compulsion to configure two components following references to the same prototype-scoped component, use the ^= operator to connect the property values. See Linking Property Values.
Related Courses