User's Manual

58 Chapter 8. WAF Application Development Tutorial
e.getFactory().registerInstantiator
(Binder.BASE_DATA_OBJECT_TYPE,
new DomainObjectInstantiator() {
protected final DomainObject doNewInstance
(final DataObject data) {
return new Binder(data);
}
});
}
}
Example 8-7. binder/src/com/example/binder/Initializer
In the section above, you deļ¬ned object-relational mapping metadata. The PDLInitializer serves
to load that metadata into the runtime. This allows the persistence layer to interpret requests for the
data behind your persistent object types.
The Binder and Note persistent object types have corresponding domain classes written in Java. The
domain APIs will return the Java objects, but to do so we must map the object type to something that
can instantiate the Java class.
public void init(final DomainInitEvent e) {
super.init(e);
e.getFactory().registerInstantiator
(Binder.BASE_DATA_OBJECT_TYPE,
new DomainObjectInstantiator() {
protected final DomainObject doNewInstance
(final DataObject data) {
return new Binder(data);
}
});
}
Example 8-8. Coupling data objects to domain object instantiators
When your package is loaded, the package tool will store the initializer class name you provide in the
database. When the CCM runtime starts up, it will read out all the registered initializers and run them
in order to prepare the environment.
8.9. Creating a Web Interface
WAF uses the Servlet API for handling web requests. Any standard servlet, adapted to use the WAF
servlet facilities (com.arsdigita.web.BaseApplicationServlet and related classes), can be
used to serve your content. For our example application, we will use a basic Servlet to create our
UI . For information on how to create a UI for your application using Bebop, refer to Chapter 12
Presentation (Bebop) Tutorial.
package com.example.binder;
import com.arsdigita.web.Application;
import com.arsdigita.web.BaseApplicationServlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;