Tuesday, September 11, 2012

Creating Our Own ATG Dynamo Server Admin Interface



The Oracle ATG Web Commerce platform includes ATG Dynamo Server Admin, an HTML-based interface that lets you inspect individual components at runtime. The default interface displays a component by listing its contained children and the values of its properties. Individual components can override this default behavior and provide their own servlets to act as the interface for that component. These custom servlets can also subclass the default servlet, so that it looks like the normal default servlet, possibly with some additional information.

In order for a component to define a custom administration interface, it must implement atg.nucleus.AdminableService. When the administration interface is asked to display a particular component, it first checks to see if the component implements AdminableService. If it does, Nucleus calls getAdminServlet to get the servlet that displays the component’s administration interface, then passes the call off to that servlet. If the component does not implement getAdminServlet, Nucleus uses the default administrative servlet to display the component and its properties in the Component Browser.

The default administrative servlet is called atg.nucleus.ServiceAdminServlet. It contains a number of methods that can be overridden, as well as a number of methods that perform useful functions, such as formatting object values into HTML.


Creating Administration Servlets


GenericService already implements AdminServlet by creating an instance of ServiceAdminServlet when asked for the administration servlet. Subclasses of GenericService should override createAdminServlet.

 For example:


protected Servlet createAdminServlet ()
  {
    class AdminServlet extends ServiceAdminServlet {
      public AdminServlet (Object pService) {
        super (pService, getNucleus ());
      }

      protected void printAdmin (HttpServletRequest pRequest,
                                 HttpServletResponse pResponse,
                                 ServletOutputStream pOut)
           throws ServletException, IOException
      {
        pOut.println ("<h1>This is my special admin section</h1>");
      }
    }

    return new AdminServlet (this);
  }


This implementation uses an inner class that extends ServiceAdminServlet. The inner class overrides printAdmin to print out a line of HTML. The default servlet calls printAdmin to insert service-specific HTML between the listing of child components and the listing of property values. This is the easiest way for a service to provide its own administrative servlet.



Formatting Object Values



When a custom administrative servlet prints its output, you might want it to format object values into HTML output. The default administrative servlet ServiceAdminServlet provides a method that can be called by subclasses to do this formatting:

protected String formatObject (Object pObject,
                               HttpServletRequest pRequest);



This formatting method takes several steps to format the object:

1.It checks whether the object is a component that implements NameContextElement. If so, it  
   returns an anchor tag that contains a link to that component.

2.It checks whether the object implements atg.nucleus.ValueFormatter. If so, it calls the object’s
   formatValue() method and returns the result.

3.If the object is of type java.lang.Class, it returns an anchor tag that contains a link to the API
   documentation for that class.

4.If the object is of type java.lang.File, it returns an anchor tag that points to that file.

5.Otherwise, it uses the object’s toString() method.

The default administrative servlet uses this method to format the values of the properties that it displays.



ValueFormatter:



As mentioned above, objects can customize their HTML representations in ATG Dynamo Server Admin by implementing atg.nucleus.ValueFormatter. This interface has two methods:

public String formatValue ();
public String formatLongValue ();

If you use the Component Browser, you might notice that property values can take on two forms. In the main page that lists all properties, only the short form of the value is shown. But when you then click on the property, the property is shown to you in its own page. On this page, the long form of the value is shown.

For example, the short form of a Hashtable entry might simply declare that it is a Hashtable, while the long form might display all the keys and values in the Hashtable.

No comments:

Popular Posts