Update of /cvsroot/xdoclet/xdoclet/modules/borland/src/xdoclet/modules/borland/bes/ejb
In directory 
sc8-pr-cvs1:/tmp/cvs-serv11109/xdoclet-all/xdoclet/modules/borland/src/xdoclet/modules/borland/bes/ejb

Added Files:
        BorlandSubTask.java BorlandRelationTagsHandler.java 
Log Message:


Added Borland Enterprise Server module submitted by Michal Maczka.

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

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

/**
 * @author        Michal Maczka
 * @created       December 5, 2002
 * @ant.element   display-name="Borland" name="borland" 
parent="xdoclet.modules.ejb.EjbDocletTask"
 */
public class BorlandSubTask extends AbstractEjbDeploymentDescriptorSubTask
{
    private final static String BORLAND_DD_FILE_NAME = "ejb-borland.xml";

    private final static String BORLAND_DD_PUBLICID =
        "-//Borland Software Corporation//DTD Enterprise JavaBeans 2.0//EN";

    private final static String BORLAND_DD_SYSTEMID =
        "http://www.borland.com/devsupport/appserver/dtds/ejb-jar_2_0-borland.dtd";;

    private final static String BORLAND_DTD_FILE_NAME =
        "resources/ejb-borland_2_0.dtd";

    private static String DEFAULT_TEMPLATE_FILE =
        "resources/ejb-borland_2_0.xdt";

    private String  _version = "5.1";

    private String  _datasource = "NO DATA SOURCE!";

    private String  _datasourceMapping = "NO DATASOURCE MAPPING!";

    private boolean _createTables = false;

    /**
     * Gets the Version attribute of the BorlandSubTask object
     *
     * @return   The Version value
     */
    public String getVersion()
    {
        return _version;
    }

    /**
     * Gets the Createtables attribute of the BorlandSubTask object
     *
     * @return   The Createtables value
     */
    public String getCreatetables()
    {
        return _createTables ? "True" : "False";
    }

    /**
     * Gets the Createtables attribute of the BorlandSubTask object
     *
     * @return   The Createtables value
     */
    public String getDatasource()
    {
        return _datasource;
    }


    public String getDatasourceMapping()
    {
        return _datasourceMapping;
    }

    /**
     * Sets the Version attribute of the BorlandSubTask object
     *
     * @param version  The new Version value
     */
    public void setVersion(String version)
    {
        _version = version;
    }

    /**
     * Sets the Createtables attribute of the BorlandSubTask object
     *
     * @param flag  The new Createtables value
     */
    public void setCreatetables(boolean flag)
    {
        _createTables = flag;
    }

    /**
     * Sets the Datasource attribute of the JBossSubTask object
     *
     * @param datasource
     */
    public void setDatasource(String datasource)
    {
        _datasource = datasource;
    }

    /**
     * @param datasourceMapping
     */
    public void setDatasourceMapping(String datasourceMapping)
    {
        _datasourceMapping = datasourceMapping;
    }

    /**
     * Called to validate configuration parameters.
     *
     * @exception XDocletException  Description of Exception
     */
    public void validateOptions() throws XDocletException
    {
        //
        //super.validateOptions();
    }

    /**
     * Describe what the method does
     *
     * @exception XDocletException  Describe the exception
     */
    public void execute() throws XDocletException
    {
        setTemplateURL(getClass().getResource(DEFAULT_TEMPLATE_FILE));
        setDestinationFile(BORLAND_DD_FILE_NAME);
        setPublicId(BORLAND_DD_PUBLICID);
        setSystemId(BORLAND_DD_SYSTEMID);
        setDtdURL(getClass().getResource(BORLAND_DTD_FILE_NAME));
        startProcess();
    }

    /**
     * Describe what the method does
     *
     * @exception XDocletException  Describe the exception
     */
    protected void engineStarted() throws XDocletException
    {
        if (getDestinationFile().equals(BORLAND_DD_FILE_NAME)) {
            System.out.println(
                Translator.getString(
                XDocletMessages.class,
                XDocletMessages.GENERATING_SOMETHING,
                new String[]{BORLAND_DD_FILE_NAME}));
        }
    }

    private boolean hasDatasource()
    {
        return getDatasource() != null && getDatasource().trim().length() > 0;
    }

    private boolean hasDatasourceMapping()
    {
        return getDatasourceMapping() != null
            && getDatasourceMapping().trim().length() > 0;
    }

}

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

import java.util.*;

import xjavadoc.*;
import xdoclet.XDocletException;
import xdoclet.modules.ejb.EjbTagsHandler;
import xdoclet.modules.ejb.dd.RelationTagsHandler;

import xdoclet.util.Translator;

/**
 * This tag handler handles tags needed for Web
 *
 * @author               <a href="mailto:[EMAIL PROTECTED]";>Michal Maczka</a>
 * @created              12 mei 2002
 * @xdoclet.taghandler   namespace="BesEjbRel"
 * @version              $Revision: 1.1 $
 */
public class BorlandRelationTagsHandler extends RelationTagsHandler
{

    private final static String BES_RELATION = "bes.relation";

    /**
     * Describe what the method does
     *
     * @return                      Describe the return value
     * @exception XDocletException  Describe the exception
     */
    public String leftTableName() throws XDocletException
    {
        // We say mandatory is false (last parameter), so we can provide a more 
detailed error message.
        String leftTableName =
            currentRelation.getLeftMethod().getDoc().getTagAttributeValue(
            BES_RELATION,
            "left-table-name",
            false);

        return leftTableName;
    }

    /**
     * Describe what the method does
     *
     * @return                      Describe the return value
     * @exception XDocletException  Describe the exception
     */
    public String defaultLeftTableName() throws XDocletException
    {
        ;

        XClass clazz = currentRelation.getLeft();
        XTag persistenceTag = clazz.getDoc().getTag("ejb.persistence");

        if (persistenceTag != null) {
            String tableName = persistenceTag.getAttributeValue("table-name");

            return tableName;
        }
        return "??";
    }

    /**
     * Describe what the method does
     *
     * @param template              Describe what the parameter does
     * @exception XDocletException  Describe the exception
     * @doc.tag                     type="block"
     */
    public void ifHasLeftTableName(String template) throws XDocletException
    {
        if (leftTableName() != null) {
            generate(template);
        }
    }

    /**
     * Describe what the method does
     *
     * @param template              Describe what the parameter does
     * @exception XDocletException  Describe the exception
     * @doc.tag                     type="block"
     */
    public void ifDoesntHaveLeftTableName(String template)
         throws XDocletException
    {
        if (leftTableName() == null) {
            generate(template);
        }
    }

    /**
     * Describe what the method does
     *
     * @return                      Describe the return value
     * @exception XDocletException  Describe the exception
     */
    public String leftColumnName() throws XDocletException
    {

        String leftColumnName =
            currentRelation.getLeftMethod().getDoc().getTagAttributeValue(
            BES_RELATION,
            "left-column-name",
            false);

        return leftColumnName;
    }

    /**
     * Describe what the method does
     *
     * @param template              Describe what the parameter does
     * @exception XDocletException  Describe the exception
     * @doc.tag                     type="block"
     */
    public void ifHasLeftColumnName(String template) throws XDocletException
    {
        if (leftColumnName() != null) {
            generate(template);
        }
    }

    /**
     * Describe what the method does
     *
     * @param template              Describe what the parameter does
     * @exception XDocletException  Describe the exception
     * @doc.tag                     type="block"
     */
    public void ifDoesntHaveLeftColumnName(String template)
         throws XDocletException
    {
        if (leftColumnName() == null) {
            generate(template);
        }
    }

    /**
     * Describe what the method does
     *
     * @return                      Describe the return value
     * @exception XDocletException  Describe the exception
     */
    public String defaultLeftColumnName() throws XDocletException
    {
        // We say mandatory is false (last parameter), so we can provide a more 
detailed error message.
        String defaultLeftColumnName =
            currentRelation.getLeftMethod().getDoc().getTagAttributeValue(
            "ejb.persistence",
            "column-name",
            false);

        return defaultLeftColumnName;
    }

    /**
     * Describe what the method does
     *
     * @return                      Describe the return value
     * @exception XDocletException  Describe the exception
     */
    public String rightTableName() throws XDocletException
    {

        String rightTableName =
            currentRelation.getLeftMethod().getDoc().getTagAttributeValue(
            BES_RELATION,
            "right-table-name",
            false);

        return rightTableName;
    }

    /**
     * Describe what the method does
     *
     * @return                      Describe the return value
     * @exception XDocletException  Describe the exception
     */

    public String defaultRightTableName() throws XDocletException
    {

        Collection classes = XJavaDoc.getInstance().getSourceClasses();

        for (ClassIterator i = XCollections.classIterator(classes); i.hasNext(); ) {
            XClass clazz = i.next();

            XTag ejbBeanTag = clazz.getDoc().getTag("ejb.bean");

            if (ejbBeanTag != null) {
                String name = ejbBeanTag.getAttributeValue("name");

                if (
                    name != null
                    &&
                    name.equals(rightEJBName())
                    ) {
                    XTag persistenceTag = clazz.getDoc().getTag("ejb.persistence");

                    if (persistenceTag != null) {
                        String tableName = 
persistenceTag.getAttributeValue("table-name");

                        return tableName;
                    }
                    else {
                        throw new XDocletException("Bean found, but it it's not having 
'@ejb.persistance table-name' tag");
                    }

                }

            }
        }
        throw new XDocletException("Cannot resolve deafultRightTableNam. Probably 
'@ejb.persistance table-name' tag is not existing in right size bean");
    }


    /**
     * Describe what the method does
     *
     * @param template              Describe what the parameter does
     * @exception XDocletException  Describe the exception
     */
    public void ifHasRightTableName(String template)
         throws XDocletException
    {
        if (rightTableName() != null) {
            generate(template);
        }
    }

    /**
     * Describe what the method does
     *
     * @param template              Describe what the parameter does
     * @exception XDocletException  Describe the exception
     * @doc.tag                     type="block"
     */
    public void ifDoesntHaveRightTableName(String template)
         throws XDocletException
    {
        if (rightTableName() == null) {
            generate(template);
        }
    }

    /**
     * Describe what the method does
     *
     * @return                      Describe the return value
     * @exception XDocletException  Describe the exception
     */
    public String rightColumnName() throws XDocletException
    {
        // We say mandatory is false (last parameter), so we can provide a more 
detailed error message.
        String rightColumnName =
            currentRelation.getLeftMethod()
            .getDoc()
            .getTagAttributeValue(
            BES_RELATION,
            "right-column-name",
            false);

        return rightColumnName;
    }

    /**
     * Default right colum name is pk field of the right side bean..
     *
     * @return                      Describe the return value
     * @exception XDocletException  Describe the exception
     */
    public String defaultRightColumnName() throws XDocletException
    {
        Collection classes = XJavaDoc.getInstance().getSourceClasses();

        for (ClassIterator i = XCollections.classIterator(classes); i.hasNext(); ) {
            XClass clazz = i.next();

            XTag ejbBeanTag = clazz.getDoc().getTag("ejb.bean");

            if (ejbBeanTag != null) {
                String name = ejbBeanTag.getAttributeValue("name");

                if (
                    name != null
                    &&
                    name.equals(rightEJBName())
                    ) {
                    XTag persistenceTag = clazz.getDoc().getTag("ejb.bean");

                    if (persistenceTag != null) {
                        String tableName = 
persistenceTag.getAttributeValue("primkey-field");

                        return tableName;
                    }
                    else {
                        throw new XDocletException("Bean found, but does not have 
'@ejb.bean primkey-field' tag");
                    }

                }

            }
        }
        throw new XDocletException("Cannot resolve deafultRightColumnNam. Probably 
'@ejb.bean primkey-field' tag is not existing in right size bean");
    }

    /**
     * Describe what the method does
     *
     * @param template              Describe what the parameter does
     * @exception XDocletException  Describe the exception
     * @doc.tag                     type="block"
     */
    public void ifHasRightColumnName(String template)
         throws XDocletException
    {
        if (rightColumnName() != null) {
            generate(template);
        }
    }

    /**
     * Describe what the method does
     *
     * @param template              Describe what the parameter does
     * @exception XDocletException  Describe the exception
     * @doc.tag                     type="block"
     */
    public void ifDoesntHaveRightColumnName(String template)
         throws XDocletException
    {
        if (rightColumnName() == null) {
            generate(template);
        }
    }

}



-------------------------------------------------------
This SF.NET email is sponsored by: Order your Holiday Geek Presents Now!
Green Lasers, Hip Geek T-Shirts, Remote Control Tanks, Caffeinated Soap,
MP3 Players,  XBox Games,  Flying Saucers,  WebCams,  Smart Putty.
T H I N K G E E K . C O M       http://www.thinkgeek.com/sf/
_______________________________________________
Xdoclet-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-devel

Reply via email to