Sun GlassFish Enterprise Server v3 Application Development Guide

Built- in Factories for Custom Resources

The Enterprise Server provides built-in factories for the following types of custom resources:

Template sun-resources.xml files for these built-in factories and a README file are available at as-install/lib/install/templates/resources/custom/. For more information about the sun-resources.xml file, see the Sun GlassFish Enterprise Server v3 Application Deployment Guide.

JavaBeanFactory

To create a custom resource that provides instances of a JavaBean class, follow these steps:

  1. Set the custom resource's factory class to org.glassfish.resources.custom.factory.JavaBeanFactory.

  2. Create a property in the custom resource for each setter method in the JavaBean class.

    For example, if the JavaBean class has a method named setAccount, specify a property named account and give it a value.

  3. Make sure the JavaBean class is accessible to the Enterprise Server.

    For example, you can place the JavaBean class in the as-install/lib directory.

PropertiesFactory

To create a custom resource that provides properties to applications, set the custom resource's factory class to org.glassfish.resources.custom.factory.PropertiesFactory, then specify one or both of the following:

PrimitiviesAndStringFactory

To create a custom resource that provides Java primitives to applications, follow these steps:

  1. Set the custom resource's factory class to org.glassfish.resources.custom.factory.PrimitivesAndStringFactory.

  2. Set the custom resource's resource type to one of the following or its fully qualified wrapper class name equivalent:

    • int

    • integer

    • long

    • double

    • float

    • char

    • character

    • short

    • byte

    • boolean

    • String

  3. Create a property in the custom resource named value and give it the value needed by the application.

    For example, If the application requires a double of value 22.1, create a property with the name value and the value 22.1.

URLFactory

To create a custom resource that provides URL instances to applications, follow these steps:

  1. Set the custom resource's factory class to org.glassfish.resources.custom.factory.URLFactory.

  2. Choose which of the following constructors to use:

    • URL(protocol, host, port, file)

    • URL(protocol, host, file)

    • URL(spec)

  3. Define properties according to the chosen constructor.

    For example, for the first constructor, define properties named protocol, host, port, and file. Example values might be http, localhost, 8085, and index.html, respectively.

    For the third constructor, define a property named spec and assign it the value of the entire URL.