Update of 
/cvsroot/xdoclet-plugins/xdoclet-plugins/plugin-weblogic/src/main/java/org/xdoclet/plugin/weblogic/ejb
In directory 
sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv12277/plugin-weblogic/src/main/java/org/xdoclet/plugin/weblogic/ejb

Added Files:
        WeblogicEjbUtils.java WeblogicCmpUtils.java 
Log Message:
Initial Revision

--- NEW FILE: WeblogicCmpUtils.java ---
package org.xdoclet.plugin.weblogic.ejb;

import java.util.Collection;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.xdoclet.plugin.ejb.Relation;
import org.xdoclet.plugin.ejb.RelationManager;
import org.xdoclet.plugin.weblogic.qtags.TagLibrary;

import com.thoughtworks.qdox.model.DocletTag;
import com.thoughtworks.qdox.model.JavaClass;
import com.thoughtworks.qdox.model.JavaMethod;

/**
 * Contains some utility methods which simplify working
 * with the Weblogic specific relation related parameters. 
 *
 * @author Ive Hellemans
 * @version $Revision$
 */
public class WeblogicCmpUtils {

    /** The logging object */
    protected static Log log = LogFactory.getLog(WeblogicCmpUtils.class);

    /** The WeblogicEjbUtils used to perfomr standard ejb related stuff. */
    protected WeblogicEjbUtils ejbUtils;
    
    public WeblogicCmpUtils(WeblogicEjbUtils ejbUtils) {
        this.ejbUtils = ejbUtils;
    }
    
    public String getDataSourceJndiName(JavaClass clazz, String def) {
        DocletTag tag = clazz.getTagByName("weblogic.data-source-name");
        return tag == null ? def : tag.getValue();
    }

    public String getColumnFor(JavaMethod method) {
        String result = method.getNamedParameter("ejb.persistence-field", 
"column-name"); 
        return result == null ? 
                "column-name attribute of ejb.persistence-field not set" : 
result;
    }

    public String getTableNameFor(JavaClass clazz) {
        String result = clazz.getNamedParameter("ejb.persistence", 
"table-name"); 
        return result == null ? 
                "table-name attribute of ejb.persistence not set" : result;
    }

    /**
     * Returns a collection of Relation objects.
     */
    public Relation[] getRelationships(Collection metadata) {
        System.out.println( "getRelationships called" );
        long start = System.currentTimeMillis();
        RelationManager relationManager = 
ejbUtils.createRelationManager(metadata);
        System.out.println( " .. got relationMgr (" + 
(System.currentTimeMillis() - start) + ")" );
        
        Relation[] relations = relationManager.getRelations();
        for (int i = 0; i < relations.length; i++) {
            relations[i] = ensureColumnMapTagsRight(relations[i]);
        }
        System.out.println( " .. inversed" );

        return relations;
    }

    /**
     * Returns the name of the join-table-name for a many to many relationship.
     * 
     * @param relation
     * @return
     */
    public String getJoinTableNameFor(Relation relation) {

        String leftJoinTableName = relation.getLeftMethod().getNamedParameter(
                TagLibrary.WEBLOGIC_RELATION, "join-table-name");
        String rightJoinTableName = null;
        String joinTableName = leftJoinTableName;

        // do some sanity checking
        if (leftJoinTableName == null && relation.getRightMethod() != null) {
            rightJoinTableName = relation.getRightMethod().getNamedParameter(
                    TagLibrary.WEBLOGIC_RELATION, "join-table-name");
            joinTableName = rightJoinTableName;
        }
        if (leftJoinTableName != null && rightJoinTableName != null) {
            throw new Error("join-table-name defined on both sides !");
        }
        if (leftJoinTableName == null && rightJoinTableName == null) {
            throw new Error("join-table-name must be defined for many-to-many 
relation [" + relation.getName() + "]");
        }
        return joinTableName;
    }

    /**
     * Returns the left group name for this relationship.
     */
    public String getLeftGroupNameFor(Relation relation) {
        if (relation.getLeftMethod() != null) {
            return relation.getLeftMethod().getNamedParameter(
                    TagLibrary.WEBLOGIC_RELATION, "group-name");
        }
        return null;
    }
    
    /**
     * Returns the right group name for this relationship. When not set,
     * the group name of the left side is returned (to support unidirectional
     * relationships)
     */
    public String getRightGroupNameFor(Relation relation) {
        if (relation.getRightMethod() != null) {
            return relation.getRightMethod().getNamedParameter(
                    TagLibrary.WEBLOGIC_RELATION, "group-name");
        } else {
            return getLeftGroupNameFor(relation);
        }
    }    

//    public String getKeyColumn(Relation relation, WeblogicColumnMapTag tag) {
//        String keyColumn = tag.getKeyColumn();
//        if (keyColumn == null) {
//            throw new Error("Guessing the key column not implemented yet");
//        }
//        return keyColumn;
//    }
//    
//    public String getForeignKeyColumn(Relation relation, WeblogicColumnMapTag 
tag) {
//        String keyColumn = tag.getForeignKeyColumn();
//    }

    /**
     * Returns true if this Relation represents a many-to-many relationship
     * @param relation
     * @return
     */
    public boolean isMany2Many(Relation relation) {
        boolean many2many = relation.isLeftMany() && relation.isRightMany(); 
        log.debug("isMany2Many for relation " + relation.getName() + " returns 
" + many2many);
        return many2many;
    }
    
    protected DocletTag[] getAllColumnMapsFor(Relation relation, boolean left) {
        log.debug("getAllColumnMapsFor " + relation);

        DocletTag[] result; 
        JavaMethod methodA;
        JavaMethod methodB;

        if (left) {
            methodA = relation.getLeftMethod();
            methodB = relation.getRightMethod();
        } else {
            methodA = relation.getRightMethod();
            methodB = relation.getLeftMethod();
        }

        if (methodA != null) {
            // bidirectional
            result = methodA.getTagsByName(
                    TagLibrary.WEBLOGIC_COLUMN_MAP, true);
        } else {
            // unidirectional
            result = methodB.getTagsByName(
                    TagLibrary.WEBLOGIC_TARGET_COLUMN_MAP, true);
        }

        return result;
    }

    public DocletTag[] getLeftColumnMapsFor(Relation relation) {
        return getAllColumnMapsFor(relation, true);
    }

    public DocletTag[] getRightColumnMapsFor(Relation relation) {
        return getAllColumnMapsFor(relation, false);
    }

    /**
     * Makes sure the column-map tags are on the right side and 
     * target-column-map tags left.
     */
    protected Relation ensureColumnMapTagsRight(Relation relation) {
        boolean db = log.isDebugEnabled();
        boolean rightHasTargetColumnMapTags = false;
        boolean leftHasColumnMapTags = false;

        if (relation.getLeftMethod() != null) {
            rightHasTargetColumnMapTags = 
                
relation.getLeftMethod().getTagByName("weblogic.target-column-map") != null;
        }
        if (relation.getRightMethod() != null) {
            leftHasColumnMapTags = 
                relation.getRightMethod().getTagByName(
                        TagLibrary.WEBLOGIC_COLUMN_MAP) != null;
        }
        if (rightHasTargetColumnMapTags || leftHasColumnMapTags) {
            if (db) log.debug("Reversing relationship " + relation.getName());
            return relation.reverse();
        } else {
            if (db) log.debug("Not Reversing relationship " + 
relation.getName());
            return relation;
        }
    }
    
}

--- NEW FILE: WeblogicEjbUtils.java ---
package org.xdoclet.plugin.weblogic.ejb;

import java.util.Collection;

import org.xdoclet.plugin.ejb.EjbConfig;
import org.xdoclet.plugin.ejb.EjbUtils;

import com.thoughtworks.qdox.model.JavaClass;

/**
 * Extension of the EjbUtils class which provides additional support 
 * for Weblogic specific things
 *
 * @author Ive Hellemans
 * @version $Revision$
 */
public class WeblogicEjbUtils extends EjbUtils {
    
    public WeblogicEjbUtils() {
        super();
    }

    public WeblogicEjbUtils(EjbConfig config) {
        super(config);
    }

    /**
     * Returns true if this bean should have a jndi-name.
     */
    public boolean shouldHaveJndiName(JavaClass clazz) {
        return hasFlag(getViewType(clazz), REMOTE) 
                    || isMessageDrivenBean(clazz); 
    }

    /**
     * Returns true if this bean should have a local-jndi-name.
     */
    public boolean shouldHaveLocalJndiName(JavaClass clazz) {
        return hasFlag(getViewType(clazz), LOCAL) 
                    && !isMessageDrivenBean(clazz);
    }

    //TODO: delete all below
    
    public Collection getCMPBeans(Collection metadata) {
        System.out.println("getCMPBeans called");
        Collection collection = super.getCMPBeans(metadata);
        System.out.println("getCMPBeans done");
        return collection;
    }

    public Collection getCMPFields(JavaClass clazz) {
        System.out.print("getCMPFields called for " + clazz.getName());
        Collection collection = super.getCMPFields(clazz);
        System.out.println(" .. done");
        return collection;
    }

    public boolean shouldGenerate(Object metadata) {
        System.out.print("shouldGenerate called for " + 
((JavaClass)metadata).getName());
        boolean result = super.shouldGenerate(metadata);
        if (result)
            System.out.println(" .. done");
        else
            System.out.println("\r\n ****************************** FALSE !!!");
        return result;
    }

    public String getEjbName(JavaClass clazz) {
        System.out.print("getEjbName called for " + clazz.getName());
        String x = super.getEjbName(clazz);
        System.out.println(" .. done");
        return x;
    }

    
    public void sayHello(int i) {
        System.out.println("hello " + i);
    }
}



_______________________________________________
xdoclet-plugins-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/xdoclet-plugins-commits

Reply via email to