1 23 24 29 30 package com.sun.enterprise.tools.common.properties; 31 32 import java.util.Vector ; 33 import com.sun.enterprise.tools.common.dd.connector.RoleMap; 34 import com.sun.enterprise.tools.common.dd.connector.SunConnector; 35 import com.sun.enterprise.tools.common.dd.connector.MapElement; 36 import com.sun.enterprise.tools.common.dd.connector.Principal; 37 import com.sun.enterprise.tools.common.util.diagnostics.Reporter; 38 39 44 public class RoleMapElement { 45 46 private RoleMap rm; 47 48 50 51 public RoleMapElement(RoleMap rm) { 52 this.rm = rm; 53 } 55 56 public RoleMapElement(RoleMapElement rme) { 57 this.rm = (RoleMap) rme.rm.clone(); 58 } 60 61 public RoleMap getRoleMap() { 62 return rm; 63 } 64 65 public int getLength() { 66 return rm.sizeMapElement(); 67 } 68 69 public int getWidth() { 70 return 4; 71 } 72 73 public Object getAttributeDetail(int row, int col) { 74 MapElement me = rm.getMapElement(row); 75 if (col == 0) 76 return me.getAttributeValue(MapElement.BACKEND_PRINCIPAL, 0, "user-name"); if (col == 1) 78 return me.getAttributeValue(MapElement.BACKEND_PRINCIPAL, 0, "password"); if (col == 2) 80 return me.getAttributeValue(MapElement.BACKEND_PRINCIPAL, 0, "credential"); if (col == 3) { 82 95 Vector vec = new Vector (); 96 for (int i = 0; i < me.sizePrincipal(); i++) { 97 Principal prin = me.getPrincipal(i); 98 String [] element = new String [2]; 99 element[0] = prin.getAttributeValue("user-name"); element[1] = prin.getDescription(); 101 vec.add(element); 102 } 103 Reporter.info(new Integer (vec.size())); 104 return vec; 105 } 106 return null; 107 } 108 109 public void setAttributeDetail(Object v, int r, int c) { 110 String input = null; 111 if (c != 3) 112 input = (String ) v; 113 while (r >= getLength()) { 114 MapElement nme = new MapElement(); 115 nme.setBackendPrincipal(true); 116 rm.addMapElement(nme); 117 Reporter.info("add a MapElement"); } 119 MapElement me = rm.getMapElement(r); 120 if ((c != 3 &&(null == input || 0 == input.trim().length())) || (c == 3 && ((Vector )v).size() == 0)) { 121 if (r >= getLength()) 123 return; 124 125 boolean rowHasValue = false; 126 String value = null; 127 if (c != 0) { 128 value = me.getAttributeValue(MapElement.BACKEND_PRINCIPAL, 0, "user-name"); if (null != value && value.trim().length() > 0) 130 rowHasValue = true; 131 } 132 if (c != 1) { 133 value = me.getAttributeValue(MapElement.BACKEND_PRINCIPAL, 0, "password"); if (null != value && value.trim().length() > 0) 135 rowHasValue = true; 136 } 137 if (c != 2) { 138 value = me.getAttributeValue(MapElement.BACKEND_PRINCIPAL, 0, "credential"); if (null != value && value.trim().length() > 0) 140 rowHasValue = true; 141 } 142 if (c != 3) { 143 if (0 != me.sizePrincipal()) 144 rowHasValue = true; 145 } 146 147 if (!rowHasValue) { 155 Reporter.info("remove a MapElement"); rm.removeMapElement(me); 157 return; 158 } 159 } 164 while (r >= getLength()) { 165 Reporter.info("add a MapElement"); me = new MapElement(); 167 me.setBackendPrincipal(true); 168 rm.addMapElement(me); 169 } 170 if (0 == c) 171 me.setAttributeValue(MapElement.BACKEND_PRINCIPAL, 0, "user-name", (String ) v); if (1 == c) 173 me.setAttributeValue(MapElement.BACKEND_PRINCIPAL, 0, "password", (String ) v); if (2 == c) 175 me.setAttributeValue(MapElement.BACKEND_PRINCIPAL, 0, "credential",(String ) v); if (3 == c) { 177 191 Vector vec = (Vector )v; 192 Reporter.info(new Integer (vec.size())); 193 Principal[] principals = new Principal[vec.size()]; 194 for (int i = 0; i < vec.size(); i++) { 195 Principal prin = new Principal(); 196 String [] principal = (String [])vec.elementAt(i); 197 prin.setAttributeValue("user-name", principal[0]); prin.setDescription(principal[1]); 200 principals[i] = prin; 201 } 202 me.setPrincipal(principals); 203 } 205 } 211 212 public String getRoleMapDescription() { 213 return rm.getDescription(); 214 } 215 216 public void setRoleMapDescription(String desc) { 217 rm.setDescription(desc); 218 } 219 220 RoleMapElement(String args[]) { 222 int rowCount = 0; 223 if (null != args && args.length > 0) { 224 try { 225 rowCount = Integer.parseInt(args[0]); 226 } 227 catch (Throwable t) { 228 t.printStackTrace(); 229 } 230 } 231 rm = new RoleMap(); 232 int unameVal = 100; 233 for (int i = 0; i < rowCount; i++) { 234 MapElement me = new MapElement(); 235 me.setBackendPrincipal(true); 236 me.setAttributeValue(MapElement.BACKEND_PRINCIPAL, 0, "user-name", ""+i); me.setAttributeValue(MapElement.BACKEND_PRINCIPAL, 0, "password", ""+i); me.setAttributeValue(MapElement.BACKEND_PRINCIPAL, 0, "credential", ""+i); for (int j = 0; j < rowCount; j++) { 240 Principal p = new Principal(); 241 p.setAttributeValue("user-name", ""+unameVal); unameVal++; 243 me.addPrincipal(p); 244 } 245 rm.addMapElement(me); 246 247 } 251 SunConnector connectorDD = SunConnector.createGraph(); 254 connectorDD.setRoleMap(rm); 255 256 } 257 258 String dumpIt() { 260 return rm.dumpBeanNode(); 261 } 262 } 263 | Popular Tags |