Nucleus performs one basic operation: resolving component names. Given the name of a component, Nucleus does its best to find or create that component and return it.

Within Nucleus, certain components can contain other components, forming a component hierarchy. For example, the name /services/logs/FileLogger is resolved by looking in the root container for a component called services, looking in the services container for a component called logs, and looking in the logs container for a component called FileLogger. Nucleus recognizes any component that implements atg.naming.NameContext as a container of other components, thereby allowing that component to participate in the naming hierarchy.

Nucleus can also resolve names relative to some NameContext. For example, Nucleus can resolve the name ../db/Connections relative to the “logs” NameContext, which in the end translates to /services/db/Connections.

Name resolution in itself is not a difficult task. The real power of Nucleus is its ability to create new components and hook them up to other components automatically. This function is invoked when Nucleus is asked to resolve a name for which no component yet exists. In such a case, Nucleus searches for the appropriate configuration file that describes how that component should be created, and what other components need to be found to allow that component to operate.

When Nucleus is started, it is given a configuration path – a list of configuration directories that contain the configuration files of various components. Within the configuration directories, Nucleus expects to find a configuration file corresponding to the name of the component. For example, if Nucleus is trying to create a component called /services/logs/FileLogger, and the configuration root directory is <ATG2007.3dir>/DAS/config, then Nucleus expects to find a file called <ATG2007.3dir>/DAS/config/services/logs/FileLogger.properties. That file should contain the base configuration of the FileLogger component.

The configuration file is a properties file that follows the key=value format expected by the class java.util.Properties. For example:

$class=somepackage.FileLogger
fileName=/work/logs/log1
maximumFileSize=20000

The properties file lists the property values that should be used to initialize the new component. For example, when this component is created, its fileName property will be set to /work/logs/log1, and its maximumFileSize property will be set to 20000.

The properties file also includes special properties that are read only by Nucleus. These special properties begin with a $ character. In the above example, the $class property is required by Nucleus to determine what class of object to create for the component. So when Nucleus is asked to resolve the name /services/logs/FileLogger, it will create a new object of class somepackage.FileLogger, bind that object into the naming hierarchy, and set its fileName and maximumFileSize properties. The newly created component remains in the namespace, so the next time Nucleus resolves that same name it will retrieve the same component without having to create it again.

The above example demonstrates how Nucleus sets simple property values, such as Strings and integers. Nucleus can also set property values that are themselves other components in Nucleus. This is done by specifying the name of the component in the properties file. For example, if for some reason the FileLogger component required a pointer to a Scheduler component, then it would include scheduler as one of its properties. The properties file might then look like this:

$class=somepackage.FileLogger
fileName=/work/logs/log1
maximumFileSize=20000
scheduler=/services/Scheduler

While Nucleus is initializing the FileLogger, it encounters the component name /services/Scheduler and attempts to resolve it. This may itself lead to creating the Scheduler component from its own configuration, which might then cause other components to be created. When all of the components are finally created and resolved, then the scheduler property is set and the initialization of the FileLogger component is complete.

In summary, the primary function of Nucleus is to resolve names. While resolving names, Nucleus may be required to create and configure components from properties files. While reading those properties files, Nucleus may encounter other component names that it must then resolve, possibly by creating more components. This automatic name resolution and component creation function allows developers to develop components without writing the code that actually creates those components and hooks them up, thereby pushing the configuration and assembly of the application to a separate level.

 
loading table of contents...