Update of /cvsroot/xdoclet/xdoclet/modules/sun/src/xdoclet/modules/sun/sunone/ejb
In directory 
sc8-pr-cvs1:/tmp/cvs-serv23022/xdoclet-all/xdoclet/modules/sun/src/xdoclet/modules/sun/sunone/ejb

Added Files:
        SunONESubTask.java XDocletModulesSunONEEjbMessages.java 
        SunONETagsHandler.java 
Log Message:
XDT-16: SunONE module, handles versions (iPlanet) 6.0 & 6.5 and (SunONE) 7.0
No web module at present, just generates ejb descriptors (and cmp mapping for 7.0)



--- NEW FILE: SunONESubTask.java ---
/*
 * Copyright (c) 2001, 2002 The XDoclet team
 * All rights reserved.
 */
package xdoclet.modules.sun.sunone.ejb;

import org.apache.commons.logging.Log;

import xdoclet.XDocletException;
import xdoclet.XDocletMessages;
import xdoclet.modules.ejb.dd.AbstractEjbDeploymentDescriptorSubTask;
import xdoclet.util.LogUtil;
import xdoclet.util.Translator;

/**
 * Generates configuration files for EJB jars in iPlanet/SunONE
 *
 * @author               <a href="mailto:[EMAIL PROTECTED]">Andrew Stevens</a>
 * @created              October 01, 2002
 * @ant.element          display-name="SunONE" name="sunone" 
parent="xdoclet.modules.ejb.EjbDocletTask"
 * @xdoclet.merge-file   file="ejb-env-entries-{0}.xml" description="Same as for 
&lt;deploymentdescriptor&gt; subtask
 *      (only used for MDBs)."
 * @xdoclet.merge-file   file="mdb-ejbrefs-{0}.xml" description="Same as for 
&lt;deploymentdescriptor&gt; subtask,
 *      except root element name is mdb-ejb-ref rather than ejb-ref (only used for 
MDBs)."
 * @xdoclet.merge-file   file="mdb-resourcerefs-{0}.xml" description="Same as for 
&lt;deploymentdescriptor&gt; subtask,
 *      except root element name is mdb-resource-ref rather than resource-ref (only 
used for MDBs)."
 * @xdoclet.merge-file   file="ejb-resource-env-refs-{0}.xml" description="Same as for 
&lt;deploymentdescriptor&gt;
 *      subtask (only used for MDBs)."
 * @xdoclet.merge-file   file="sunone-role-mappings.ent" description="An Unparsed XML 
Entity file that contains the
 *      &lt;role-mapping&gt; elements."
 * @xdoclet.merge-file   file="sunone-pm-descriptors.xml" description="An XML Document 
containing the
 *      &lt;pm-descriptors&gt; element."
 * @xdoclet.merge-file   file="sunone-ior-security-config-{0}.xml" description="An XML 
Document containing the
 *      &lt;ior-security-config&gt; element for a bean."
 * @version              $Revision: 1.1 $
 * @todo                 allow for overriding the CMP templates etc.
 * @todo                 secondary-table element is not currently supported in the cmp 
mappings file
 */
public class SunONESubTask extends AbstractEjbDeploymentDescriptorSubTask
{
    /**
     * The default template file - either ias-ejb-jar_xml.xdt or sun-ejb-jar_xml.xdt, 
depending on version.
     */
    private final static String DEFAULT_TEMPLATE_FILE_70 = 
"resources/sun-ejb-jar_xml.xdt";
    private final static String DEFAULT_TEMPLATE_FILE_60 = 
"resources/ias-ejb-jar_xml.xdt";

    /**
     * The default generated file name - either ias-ejb-jar.xml or sun-ejb-jar.xml, 
depending on version.
     */
    private final static String GENERATED_FILE_NAME_70 = "sun-ejb-jar.xml";
    private final static String GENERATED_FILE_NAME_60 = "ias-ejb-jar.xml";

    /**
     * Public ID of the iPlanet/SunONE-specific DD's DTD.
     */
    private final static String SUNONE_DD_PUBLICID_70 = "-//Sun Microsystems, 
Inc.//DTD Sun ONE Application Server 7.0 EJB 2.0//EN";
    private final static String SUNONE_DD_PUBLICID_60 = "-//Sun Microsystems, 
Inc.//DTD iAS Enterprise JavaBeans 1.0//EN";
    private final static String SUNONE_DD_PUBLICID_61 = "-//Sun Microsystems, 
Inc.//DTD iAS Enterprise JavaBeans 1.1//EN";

    /**
     * System ID of the iPlanet/SunONE-specific DD's DTD.
     */
    private final static String SUNONE_DD_SYSTEMID_70 = 
"http://www.sun.com/software/sunone/appserver/dtds/sun-ejb-jar_2_0-0.dtd";;
    private final static String SUNONE_DD_SYSTEMID_60 = 
"http://developer.iplanet.com/appserver/dtds/IASEjb_jar_1_0.dtd";;
    private final static String SUNONE_DD_SYSTEMID_61 = 
"http://developer.iplanet.com/appserver/dtds/IASEjb_jar_1_1.dtd";;

    /**
     * Path to the local copy of the iPlanet/SunONE-specific DD's DTD.
     */
    private final static String SUNONE_DD_DTD_FILE_NAME_70 = 
"resources/sun-ejb-jar_2_0-0.dtd";
    private final static String SUNONE_DD_DTD_FILE_NAME_60 = 
"resources/IASEjb_jar_1_0.dtd";
    private final static String SUNONE_DD_DTD_FILE_NAME_61 = 
"resources/IASEjb_jar_1_1.dtd";

    /**
     * The default CMP mappings template file - sun-cmp-mappings_xml.xdt
     */
    private final static String DEFAULT_CMP_TEMPLATE_FILE_70 = 
"resources/sun-cmp-mappings_xml.xdt";

    /**
     * The default generated CMP mappings file name.
     */
    private final static String GENERATED_CMP_FILE_NAME_70 = "sun-cmp-mappings.xml";
    private final static String GENERATED_CMP_FILE_NAME_60 = "???";
    // 6.0 CMP mappings are tricky; the filenames of the mapping files are specified
    // per-bean in <properties-file-location> elements in the ias-ejb-jar.xml
    // For now, you'll have to create them by hand.

    /**
     * Public ID of the iPlanet/SunONE-specific CMP mappings DTD.
     */
    private final static String SUNONE_CMP_PUBLICID_70 = "???";
    // not specified in the Developer's Guide

    /**
     * System ID of the iPlanet/SunONE-specific CMP mappings DTD.
     */
    private final static String SUNONE_CMP_SYSTEMID_70 = 
"http://www.sun.com/software/sunone/appserver/dtds/sun-cmp-mapping_1_0.dtd";;
    private final static String SUNONE_CMP_SYSTEMID_60 = 
"http://developer.iplanet.com/appserver/dtds/IASPersistence_manager_1_0.dtd";;

    /**
     * Path to the local copy of the iPlanet/SunONE-specific CMP mappings DTD.
     */
    private final static String SUNONE_CMP_FILE_NAME_70 = 
"resources/sun-cmp-mapping_1_0.dtd";
    private final static String SUNONE_CMP_FILE_NAME_60 = 
"resources/IASPersistence_manager_1_0.dtd";

    /**
     * The iPlanet/SunONE version.
     */
    private String  version = SunONEVersionTypes.VERSION_7_0;

    /**
     * Optional transaction manager type.
     */
    private String  transactionManagerType = null;

    /**
     * Optional CMP Resource JNDI name.
     */
    private String  cmpResourceJndiName = null;

    /**
     * Optional CMP Resource Principal name.
     */
    private String  cmpResourcePrincipalName = null;

    /**
     * Optional CMP Resource Principal password.
     */
    private String  cmpResourcePrincipalPassword = null;

    /**
     * CMP Schema filename (without .dbschema extension), produced by Sun's utilities
     */
    private String  cmpSchema = null;

    private String  cmpTemplateFile = null;

    private String  cmpDestinationFile = null;

    public SunONESubTask()
    {
        setValidateXML(true);
    }

    /**
     * Return the iPlanet/SunONE version.
     *
     * @return   The iPlanet/SunONE version
     */
    public String getVersion()
    {
        return version;
    }

    /**
     * Return the default transaction manager type.
     *
     * @return   The transaction manager type
     */
    public String getTransactionManagerType()
    {
        return transactionManagerType;
    }

    /**
     * Return the CMP Resource JNDI name.
     *
     * @return   The CMP Resource JNDI name
     */
    public String getCmpResourceJndiName()
    {
        return cmpResourceJndiName;
    }

    /**
     * Return the CMP Resource Principal name.
     *
     * @return   The CMP Resource Principal name
     */
    public String getCmpResourcePrincipalName()
    {
        return cmpResourcePrincipalName;
    }

    /**
     * Return the CMP Resource Principal password.
     *
     * @return   The CMP Resource Principal password
     */
    public String getCmpResourcePrincipalPassword()
    {
        return cmpResourcePrincipalPassword;
    }

    /**
     * Return the database schema filename (minus .dbschema extension), as captured 
using Sun's utilities.
     *
     * @return   The schema filename
     */
    public String getCmpSchema()
    {
        return cmpSchema;
    }

    /**
     * Gets the name of the sun-cmp-mappings.xml template file.
     *
     * @return   the custom template file
     */
    public String getCmpTemplateFile()
    {
        return cmpTemplateFile;
    }

    /**
     * Gets the destination filename of the CMP mappings file.
     *
     * @return   the destination filename
     */
    public String getCmpDestinationFile()
    {
        return cmpDestinationFile;
    }

    /**
     * The SunONE/iPlanet version. Supported versions are 6.0, 6.5 and 7.0.
     *
     * @param version      The new Version value
     * @ant.not-required   No, default is "7.0".
     */
    public void setVersion(SunONEVersionTypes version)
    {
        this.version = version.getValue();
    }

    /**
     * Optional default transaction manager type for all components. Allowed values 
are 'local' and 'global'.
     *
     * @param transactionManagerType  "local" or "global"
     * @ant.not-required              Only used for version = 6.5, and optional even 
then.
     */
    public void setTransactionManagerType(String transactionManagerType)
    {
        this.transactionManagerType = transactionManagerType;
    }

    /**
     * Specifies the absolute jndi-name of the database to be used for storing CMP 
beans in the EJB JAR file.
     *
     * @param cmpResourceJndiName  String containing the JNDI name
     * @ant.not-required           Only used for version = 7.0, and optional even then.
     */
    public void setCmpResourceJndiName(String cmpResourceJndiName)
    {
        this.cmpResourceJndiName = cmpResourceJndiName;
    }

    /**
     * Specifies the default sign-on name to the resource manager.
     *
     * @param cmpResourcePrincipalName  String containing the name
     * @ant.not-required                Only used if cmpResourceJndiName parameter is 
specified, and optional even then.
     */
    public void setCmpResourcePrincipalName(String cmpResourcePrincipalName)
    {
        this.cmpResourcePrincipalName = cmpResourcePrincipalName;
    }

    /**
     * Specifies the default password to the resource manager.
     *
     * @param cmpResourcePrincipalPassword  String containing the password
     * @ant.not-required                    Only used if the cmpResourcePrincipalName 
parameter is specified.
     */
    public void setCmpResourcePrincipalPassword(String cmpResourcePrincipalPassword)
    {
        this.cmpResourcePrincipalPassword = cmpResourcePrincipalPassword;
    }

    /**
     * Specifies the database schema filename (minus .dbschema extension), as captured 
using Sun's utilities.
     *
     * @param cmpSchema    String containing the schema name
     * @ant.not-required   Only used with CMP entity beans.
     */
    public void setCmpSchema(String cmpSchema)
    {
        this.cmpSchema = cmpSchema;
    }

    /**
     * Sets the name of the sun-cmp-mappings.xml template file.
     *
     * @param cmpTemplateFile  the name of the custom template file
     * @ant.not-required
     */
    public void setCmpTemplateFile(String cmpTemplateFile)
    {
        this.cmpTemplateFile = cmpTemplateFile;
    }

    /**
     * Sets the destination filename of the CMP mappings file.
     *
     * @param cmpDestinationFile  the destination filename
     * @ant.not-required
     */
    public void setCmpDestinationFile(String cmpDestinationFile)
    {
        this.cmpDestinationFile = cmpDestinationFile;
    }

    /**
     * Called to validate configuration parameters.
     *
     * @exception XDocletException  Description of Exception
     */
    public void validateOptions() throws XDocletException
    {
        // we don't call super.validateOptions() here, as the template file and
        // destination file may not have been set yet

        if (getVersion().equals(SunONEVersionTypes.VERSION_6_5)
            && getTransactionManagerType() != null) {
            if (!getTransactionManagerType().equals("local")
                && !getTransactionManagerType().equals("global")) {
                throw new 
XDocletException(Translator.getString(XDocletModulesSunONEEjbMessages.class,
                    XDocletModulesSunONEEjbMessages.INVALID_TRANSACTION_MANAGER_TYPE));
            }
        }
    }

    public void execute() throws XDocletException
    {
        if (getVersion().equals(SunONEVersionTypes.VERSION_6_0)) {
            if (getTemplateURL() == null)
                setTemplateURL(getClass().getResource(DEFAULT_TEMPLATE_FILE_60));
            if (getDestinationFile() == null)
                setDestinationFile(GENERATED_FILE_NAME_60);
            if (getPublicId() == null)
                setPublicId(SUNONE_DD_PUBLICID_60);
            if (getSystemId() == null)
                setSystemId(SUNONE_DD_SYSTEMID_60);
            if (getDtdURL() == null)
                setDtdURL(getClass().getResource(SUNONE_DD_DTD_FILE_NAME_60));
        }
        else if (getVersion().equals(SunONEVersionTypes.VERSION_6_5)) {
            if (getTemplateURL() == null)
                setTemplateURL(getClass().getResource(DEFAULT_TEMPLATE_FILE_60));
            if (getDestinationFile() == null)
                setDestinationFile(GENERATED_FILE_NAME_60);
            if (getPublicId() == null)
                setPublicId(SUNONE_DD_PUBLICID_61);
            if (getSystemId() == null)
                setSystemId(SUNONE_DD_SYSTEMID_61);
            if (getDtdURL() == null)
                setDtdURL(getClass().getResource(SUNONE_DD_DTD_FILE_NAME_61));
        }
        else if (getVersion().equals(SunONEVersionTypes.VERSION_7_0)) {
            if (getTemplateURL() == null)
                setTemplateURL(getClass().getResource(DEFAULT_TEMPLATE_FILE_70));
            if (getDestinationFile() == null)
                setDestinationFile(GENERATED_FILE_NAME_70);
            if (getPublicId() == null)
                setPublicId(SUNONE_DD_PUBLICID_70);
            if (getSystemId() == null)
                setSystemId(SUNONE_DD_SYSTEMID_70);
            if (getDtdURL() == null)
                setDtdURL(getClass().getResource(SUNONE_DD_DTD_FILE_NAME_70));
        }
        startProcess();

        if (atLeastOneCmpEntityBeanExists()) {
            if (getVersion().equals(SunONEVersionTypes.VERSION_7_0)) {
                if (getCmpTemplateFile() != null) {
                    setTemplateURL(getClass().getResource(getCmpTemplateFile()));
                }
                else {
                    
setTemplateURL(getClass().getResource(DEFAULT_CMP_TEMPLATE_FILE_70));
                }
                if (getCmpDestinationFile() != null) {
                    setDestinationFile(getCmpDestinationFile());
                }
                else {
                    setDestinationFile(GENERATED_CMP_FILE_NAME_70);
                }
                setPublicId(SUNONE_CMP_PUBLICID_70);
                setSystemId(SUNONE_CMP_SYSTEMID_70);
                setDtdURL(getClass().getResource(SUNONE_CMP_FILE_NAME_70));

                startProcess();
            }
        }
    }

    /**
     * @created   22 January 2003
     */
    public static class SunONEVersionTypes extends 
org.apache.tools.ant.types.EnumeratedAttribute
    {
        public final static String VERSION_6_0 = "6.0";
        public final static String VERSION_6_5 = "6.5";
        public final static String VERSION_7_0 = "7.0";

        /**
         * Gets the Values attribute of the SunONEVersionTypes object
         *
         * @return   The Values value
         */
        public String[] getValues()
        {
            return (new String[]{VERSION_6_0, VERSION_6_5, VERSION_7_0});
        }
    }

}

--- NEW FILE: XDocletModulesSunONEEjbMessages.java ---
/*
 * Copyright (c) 2001, 2002 The XDoclet team
 * All rights reserved.
 */
package xdoclet.modules.sun.sunone.ejb;

/**
 * @author    <a href="mailto:[EMAIL PROTECTED]">Andrew Stevens</a>
 * @created   October 01, 2002
 * @version   $Revision: 1.1 $
 */
public final class XDocletModulesSunONEEjbMessages
{
    /**
     * @msg.bundle   msg="Invalid transaction manager type. Valid values are 'local' 
and 'global'."
     */
    public final static String INVALID_TRANSACTION_MANAGER_TYPE = 
"INVALID_TRANSACTION_MANAGER_TYPE";
}

--- NEW FILE: SunONETagsHandler.java ---
/*
 * Copyright (c) 2001, 2002 The XDoclet team
 * All rights reserved.
 */
package xdoclet.modules.sun.sunone.ejb;

import java.net.InetAddress;
import java.security.SecureRandom;
import java.util.*;

import xjavadoc.*;

import xdoclet.XDocletException;
import xdoclet.XDocletMessages;
import xdoclet.tagshandler.AbstractProgramElementTagsHandler;
import xdoclet.tagshandler.MethodTagsHandler;
import xdoclet.util.Translator;

/**
 * @author               <a href="mailto:[EMAIL PROTECTED]">Andrew Stevens</a>
 * @created              23 February, 2003
 * @xdoclet.taghandler   namespace="SunONE"
 * @version              $Revision: 1.1 $
 */
public class SunONETagsHandler extends AbstractProgramElementTagsHandler
{

    // initialise the secure random instance
    private final static SecureRandom seeder = new SecureRandom();

    /**
     * Cached per JVM server IP.
     */
    private static String hexServerIP = null;
    /**
     * For use in extracting method names.
     */
    protected MethodTagsHandler handler = new MethodTagsHandler();

    /**
     * Collection of attributes. XXX: Does this need to be synchronized?
     */
    protected Map   attributes = Collections.synchronizedMap(new HashMap());

    /**
     * For looping through indexed tags.
     */
    protected int   index = 0;

    /**
     * A 32 byte GUID generator (Globally Unique ID). I couldn't find any 
documentation for how Sun's own utilities
     * generate them, so I've copied the method used in the generated Util classes. 
Hopefully that's good enough.
     *
     * @return                      The name of current EJB bean.
     * @exception XDocletException
     * @doc.tag                     type="content"
     */
    public static String generateGUID() throws XDocletException
    {
        return generateGUID(getCurrentClass());
    }

    /**
     * A 32 byte GUID generator (Globally Unique ID). I couldn't find any 
documentation for how Sun's own utilities
     * generate them, so I've copied the method used in the generated Util classes. 
Hopefully that's good enough.
     *
     * @param o
     * @return                      The name of current EJB bean.
     * @exception XDocletException
     */
    public static String generateGUID(Object o) throws XDocletException
    {
        StringBuffer tmpBuffer = new StringBuffer(16);

        if (hexServerIP == null) {
            InetAddress localInetAddress = null;

            try {
                // get the inet address
                localInetAddress = InetAddress.getLocalHost();
            }
            catch (java.net.UnknownHostException uhe) {
                System.err.println("Could not get the local IP address using 
InetAddress.getLocalHost()!");
                // todo: find better way to get around this...
                uhe.printStackTrace();
                return null;
            }

            byte serverIP[] = localInetAddress.getAddress();

            hexServerIP = hexFormat(getInt(serverIP), 8);
        }

        String hashcode = hexFormat(System.identityHashCode(o), 8);

        tmpBuffer.append(hexServerIP);
        tmpBuffer.append(hashcode);

        long timeNow = System.currentTimeMillis();
        int timeLow = (int) timeNow & 0xFFFFFFFF;
        int node = seeder.nextInt();

        StringBuffer guid = new StringBuffer(32);

        guid.append(hexFormat(timeLow, 8));
        guid.append(tmpBuffer.toString());
        guid.append(hexFormat(node, 8));
        return "{" + guid.substring(0, 8) + "-" + guid.substring(8, 12) + "-"
            + guid.substring(12, 16) + "-" + guid.substring(16, 20) + "-"
            + guid.substring(20, 32) + "}";
    }

    private static int getInt(byte bytes[])
    {
        int i = 0;
        int j = 24;

        for (int k = 0; j >= 0; k++) {
            int l = bytes[k] & 0xff;

            i += l << j;
            j -= 8;
        }
        return i;
    }

    private static String hexFormat(int i, int j)
    {
        String s = Integer.toHexString(i);

        return padHex(s, j) + s;
    }

    private static String padHex(String s, int i)
    {
        StringBuffer tmpBuffer = new StringBuffer();

        if (s.length() < i) {
            for (int j = 0; j < i - s.length(); j++) {
                tmpBuffer.append('0');
            }
        }
        return tmpBuffer.toString();
    }

}



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
xdoclet-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-devel

Reply via email to