FileDocCategorySizeDatePackage
RoleMapElement.javaAPI DocGlassfish v2 API10866Fri May 04 22:34:56 BST 2007com.sun.enterprise.tools.common.properties

RoleMapElement

public class RoleMapElement extends Object
author
vkraemer
version

Fields Summary
private com.sun.enterprise.tools.common.dd.connector.RoleMap
rm
Constructors Summary
public RoleMapElement(com.sun.enterprise.tools.common.dd.connector.RoleMap rm)
Creates new IasConnectorRoleMap

        this.rm = rm;
        //connectorDD.setRoleMap(rm);
    
RoleMapElement(String[] args)

        int rowCount = 0;
        if (null != args && args.length > 0) {
            try {
                rowCount = Integer.parseInt(args[0]);
            }
            catch (Throwable t) {
                t.printStackTrace();
            }
        }
        rm = new RoleMap();
        int unameVal = 100;
        for (int i = 0; i < rowCount; i++) {
            MapElement me = new MapElement();
            me.setBackendPrincipal(true);
            me.setAttributeValue(MapElement.BACKEND_PRINCIPAL, 0, "user-name", ""+i); //NOI18N
            me.setAttributeValue(MapElement.BACKEND_PRINCIPAL, 0, "password", ""+i); //NOI18N
            me.setAttributeValue(MapElement.BACKEND_PRINCIPAL, 0, "credential", ""+i); //NOI18N
            for (int j = 0; j < rowCount; j++) {
                Principal p = new Principal();
                p.setAttributeValue("user-name", ""+unameVal); //NOI18N
                unameVal++;
                me.addPrincipal(p);
            }
            rm.addMapElement(me);
            
            //ra.addPropertyElement(true);
            //ra.setAttributeValue(ResourceAdapter.PROPERTY,i,"name",""+i); //NOI18N
            //ra.setAttributeValue(ResourceAdapter.PROPERTY,i,"value",""+(rowCount - i)); //NOI18N
        }
        //connectorDD.setResourceAdapter(ra);
        //ra = (ResourceAdapter) ra.clone();
        SunConnector connectorDD = SunConnector.createGraph();
        connectorDD.setRoleMap(rm);
       
   
public RoleMapElement(RoleMapElement rme)

        this.rm = (RoleMap) rme.rm.clone();
        //connectorDD.setRoleMap(rm);
    
Methods Summary
java.lang.StringdumpIt()

       return rm.dumpBeanNode();
   
public java.lang.ObjectgetAttributeDetail(int row, int col)

 
       MapElement me = rm.getMapElement(row);
       if (col == 0)
           return me.getAttributeValue(MapElement.BACKEND_PRINCIPAL, 0, "user-name"); // , col); //NOI18N
       if (col == 1)
           return me.getAttributeValue(MapElement.BACKEND_PRINCIPAL, 0, "password");//, col); //NOI18N
       if (col == 2)
           return me.getAttributeValue(MapElement.BACKEND_PRINCIPAL, 0, "credential");//, col); //NOI18N
       if (col == 3) {
/*           
           String allPrincipals = ""; // NOI18N
           int rowCount = me.sizePrincipal();
           for (int i = 0; i < rowCount; i++) {
               Principal p = me.getPrincipal(i);
               allPrincipals += (String) p.getAttributeValue("user-name"); //NOI18N
               allPrincipals += ", "; // NOI18N
           }
           int len = allPrincipals.length();
           if (1 < len)
               allPrincipals = allPrincipals.substring(0,len-2);
           return allPrincipals;
 */
           Vector vec = new Vector();
           for (int i = 0; i < me.sizePrincipal(); i++) {
               Principal prin = me.getPrincipal(i);
               String[] element = new String[2];
               element[0] = prin.getAttributeValue("user-name");   //NOI18N
               element[1] = prin.getDescription();
               vec.add(element);
           }
           Reporter.info(new Integer(vec.size()));
           return vec;
       }
       return null;
   
public intgetLength()

       return rm.sizeMapElement();
   
public com.sun.enterprise.tools.common.dd.connector.RoleMapgetRoleMap()

       return rm;
   
public java.lang.StringgetRoleMapDescription()

        return rm.getDescription();
    
public intgetWidth()

       return 4;
   
public voidsetAttributeDetail(java.lang.Object v, int r, int c)

 
        String input = null;
        if (c != 3)
            input = (String) v;
        while (r >= getLength()) {
            MapElement nme = new MapElement();
            nme.setBackendPrincipal(true);
            rm.addMapElement(nme);
            Reporter.info("add a MapElement");  //NOI18N
        }
        MapElement me = rm.getMapElement(r);
        if ((c != 3 &&(null == input || 0 == input.trim().length())) || (c == 3 && ((Vector)v).size() == 0)) {
            // test for need to delete
            if (r >= getLength())
                return;
            
            boolean rowHasValue = false;
            String value = null;
            if (c != 0) {
                value = me.getAttributeValue(MapElement.BACKEND_PRINCIPAL, 0, "user-name"); //NOI18N
                if (null != value && value.trim().length() > 0)
                    rowHasValue = true;
            }
            if (c != 1) {
                value = me.getAttributeValue(MapElement.BACKEND_PRINCIPAL, 0, "password"); //NOI18N
                if (null != value && value.trim().length() > 0)
                    rowHasValue = true;
            }
            if (c != 2) {
                value = me.getAttributeValue(MapElement.BACKEND_PRINCIPAL, 0, "credential"); //NOI18N
                if (null != value && value.trim().length() > 0)
                    rowHasValue = true;
            }
            if (c != 3) {
                if (0 != me.sizePrincipal())
                    rowHasValue = true;
            }
            
//            int otherDex = c - 1;
//            if (otherDex < 0)
//                otherDex = -otherDex;
//            String otherVal = ra.getAttributeValue(ResourceAdapter.PROPERTY, r, //NOI18N
//                intToAttribute(otherDex));
//            String otherVal = ra.getAttributeValue(ResourceAdapter.PROPERTY, r, //NOI18N
//                intToAttribute(otherDex));
            if (!rowHasValue) {
                Reporter.info("remove a MapElement");   //NOI18N
                rm.removeMapElement(me);
                return;
            }
//                ra.removePropertyElement(r);
//                return;
//            }
//            input = " ";
        }
        while (r >= getLength()) {
            Reporter.info("add a MapElement");   //NOI18N
            me = new MapElement();
            me.setBackendPrincipal(true);
            rm.addMapElement(me);
        }
       if (0 == c)
           me.setAttributeValue(MapElement.BACKEND_PRINCIPAL, 0, "user-name", (String) v); //NOI18N
       if (1 == c)
           me.setAttributeValue(MapElement.BACKEND_PRINCIPAL, 0, "password", (String) v); //NOI18N
       if (2 == c)
           me.setAttributeValue(MapElement.BACKEND_PRINCIPAL, 0, "credential",(String) v); //NOI18N
        if (3 == c) {
/*            
            java.util.StringTokenizer toker = 
                new java.util.StringTokenizer((String)v,","); // NOI18N
            Principal[] ps = new Principal[toker.countTokens()];
            int i = 0;
            while (toker.hasMoreTokens()) {
                String tok = toker.nextToken();
                Principal p = new Principal();
                p.setAttributeValue("user-name",tok); //NOI18N
                ps[i] = p;
                i++;
            }
            me.setPrincipal(ps);
 */
            Vector vec = (Vector)v;
            Reporter.info(new Integer(vec.size()));
            Principal[] principals = new Principal[vec.size()];
            for (int i = 0; i < vec.size(); i++) {
                Principal prin = new Principal();
                String[] principal = (String[])vec.elementAt(i);
//                Reporter.info("(" + principal[0] + ")   (" + principal[1] + ")");   //NOI18N
                prin.setAttributeValue("user-name", principal[0]);  //NOI18N
                prin.setDescription(principal[1]);
                principals[i] = prin;
            }
            me.setPrincipal(principals);
//            Reporter.info(new Integer(me.sizePrincipal()));
        }
            //ra.addPropertyElement(true);
        //System.out.println("SETAttributeDetail on " + ra.hashCode()); //NOI18N
        //ra.setPropertyElement(r,true);
        //ra.setAttributeValue(ResourceAdapter.PROPERTY, r, intToAttribute(otherDex), otherVal); //NOI18N
        //ra.setAttributeValue(ResourceAdapter.PROPERTY, r, intToAttribute(c), input); //NOI18N
    
public voidsetRoleMapDescription(java.lang.String desc)

        rm.setDescription(desc);