Developing with ATG: Part II

30 11 2007

In this next edition of our series on developing with ATG we continue our discussion about nucleus components. Lets review what we know about a nucleus components so far. A component in nucleus is nothing more then a named instance of javabean. In our first post Developing with ATG: Part I we learned that the name of the component is derived from the name of the property file used to configure the component. Place a file in the <DYNAMO_HOME>/localconfig/acme/HelloWord directory and your component will have an absolute name “/acme/HelloWord”. To be a little more precise this component will have the name “HelloWorld” within the name context “/acme”. We’ll get into the reason for this distinction some other time when we discuss naming contexts and relative names.

In component models like nucleus an important operation is component resolution. We need a mechanism to obtain references to other components running within the framework. To do this in nucleus all you need is a what is referred to as a name resolver. The atg.naming.NameResolver interface defines the name resolution contract and a call to the method resolveName(String) will resolve a component by its name. The following code demonstrates how we would resolve our HelloWorld component:

HelloWorld hw =
  (HelloWorld) nameResolver.resolveName("/acme/HelloWorld");

Name resolution using relative names is also possible. Relative names are names which do not being with the ‘/’ character. These names resolve components relative to a naming context. Using the ‘.’ and ‘..’ tokens in you name allows one to resolve components in the current naming context or the parent naming context respectively similar to navigating among files in a filesystem. Finally although rarely used using the ‘…’ token in the name can be used to search up the naming contexts until a component with the specified name is found.

There only a handful of classes that implement the NameResolver interface. Two important ones that come to mind are atg.nucleus.Nucleus and atg.servlet.DynamoHttpServletRequest. We’ll take about how to get access to the DynamoHttpServletRequest in another discussion but suffice to say now that you can get access to an instance of Nucleus by calling the static method Nucleus.getGlobalNucleus().

Another us of names is in the configuration files. Properties of any javabean you write can reference nucleus components using just there name. This is best demonstrated in the following example. Say for example you have a bean which has a property called helloWorld which reference an instance of our HelloWorld class. The following property exemplified how the helloWorld property could be configure when this bean is instantiated by nucleus. Note the absolute name of the component used in the property file, although relative names will work as well.

By the way if you wanted to use the Java Naming and Directory(JNDI) API to obtain a reference to a component in nucleus you could do so as well. Just prefix the name of the component you want to lookup with ‘dynamo:’. The code below demonstrates this:

 try {
   Context ctx = new InitialContext();
   HelloWorld hw =
     (HelloWorld) ctx.lookup("dynamo:/acme/HelloWorld");
} catch(NamingException ne) {

Naming and name resolution form the foundation of the nucleus component model allowing developers to assemble independent components into large more sophisticated software systems. This is demonstrated by some of the complex applications built using nucleus like ATGs flagship eCommerce product. In our next article we’ll provide some insight into some of the predefined components which make up the component framework.




One response

11 08 2010
Zhou Wu

Could you put the links for other parts here (or somewhere can be easily found)?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: