KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > common > properties > RoleMapElement


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * IasConnectorRoleMap.java
26  *
27  * Created on March 13, 2002, 1:56 PM
28  */

29
30 package com.sun.enterprise.tools.common.properties;
31
32 import java.util.Vector JavaDoc;
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 /**
40  *
41  * @author vkraemer
42  * @version
43  */

44 public class RoleMapElement {
45
46     private RoleMap rm;
47     
48     //private SunConnector connectorDD = SunConnector.createGraph();
49

50     /** Creates new IasConnectorRoleMap */
51     public RoleMapElement(RoleMap rm) {
52         this.rm = rm;
53         //connectorDD.setRoleMap(rm);
54
}
55
56    public RoleMapElement(RoleMapElement rme) {
57         this.rm = (RoleMap) rme.rm.clone();
58         //connectorDD.setRoleMap(rm);
59
}
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 JavaDoc 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"); // , col); //NOI18N
77
if (col == 1)
78            return me.getAttributeValue(MapElement.BACKEND_PRINCIPAL, 0, "password");//, col); //NOI18N
79
if (col == 2)
80            return me.getAttributeValue(MapElement.BACKEND_PRINCIPAL, 0, "credential");//, col); //NOI18N
81
if (col == 3) {
82 /*
83            String allPrincipals = ""; // NOI18N
84            int rowCount = me.sizePrincipal();
85            for (int i = 0; i < rowCount; i++) {
86                Principal p = me.getPrincipal(i);
87                allPrincipals += (String) p.getAttributeValue("user-name"); //NOI18N
88                allPrincipals += ", "; // NOI18N
89            }
90            int len = allPrincipals.length();
91            if (1 < len)
92                allPrincipals = allPrincipals.substring(0,len-2);
93            return allPrincipals;
94  */

95            Vector JavaDoc vec = new Vector JavaDoc();
96            for (int i = 0; i < me.sizePrincipal(); i++) {
97                Principal prin = me.getPrincipal(i);
98                String JavaDoc[] element = new String JavaDoc[2];
99                element[0] = prin.getAttributeValue("user-name"); //NOI18N
100
element[1] = prin.getDescription();
101                vec.add(element);
102            }
103            Reporter.info(new Integer JavaDoc(vec.size()));
104            return vec;
105        }
106        return null;
107    }
108        
109     public void setAttributeDetail(Object JavaDoc v, int r, int c) {
110         String JavaDoc input = null;
111         if (c != 3)
112             input = (String JavaDoc) v;
113         while (r >= getLength()) {
114             MapElement nme = new MapElement();
115             nme.setBackendPrincipal(true);
116             rm.addMapElement(nme);
117             Reporter.info("add a MapElement"); //NOI18N
118
}
119         MapElement me = rm.getMapElement(r);
120         if ((c != 3 &&(null == input || 0 == input.trim().length())) || (c == 3 && ((Vector JavaDoc)v).size() == 0)) {
121             // test for need to delete
122
if (r >= getLength())
123                 return;
124             
125             boolean rowHasValue = false;
126             String JavaDoc value = null;
127             if (c != 0) {
128                 value = me.getAttributeValue(MapElement.BACKEND_PRINCIPAL, 0, "user-name"); //NOI18N
129
if (null != value && value.trim().length() > 0)
130                     rowHasValue = true;
131             }
132             if (c != 1) {
133                 value = me.getAttributeValue(MapElement.BACKEND_PRINCIPAL, 0, "password"); //NOI18N
134
if (null != value && value.trim().length() > 0)
135                     rowHasValue = true;
136             }
137             if (c != 2) {
138                 value = me.getAttributeValue(MapElement.BACKEND_PRINCIPAL, 0, "credential"); //NOI18N
139
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 // int otherDex = c - 1;
148
// if (otherDex < 0)
149
// otherDex = -otherDex;
150
// String otherVal = ra.getAttributeValue(ResourceAdapter.PROPERTY, r, //NOI18N
151
// intToAttribute(otherDex));
152
// String otherVal = ra.getAttributeValue(ResourceAdapter.PROPERTY, r, //NOI18N
153
// intToAttribute(otherDex));
154
if (!rowHasValue) {
155                 Reporter.info("remove a MapElement"); //NOI18N
156
rm.removeMapElement(me);
157                 return;
158             }
159 // ra.removePropertyElement(r);
160
// return;
161
// }
162
// input = " ";
163
}
164         while (r >= getLength()) {
165             Reporter.info("add a MapElement"); //NOI18N
166
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 JavaDoc) v); //NOI18N
172
if (1 == c)
173            me.setAttributeValue(MapElement.BACKEND_PRINCIPAL, 0, "password", (String JavaDoc) v); //NOI18N
174
if (2 == c)
175            me.setAttributeValue(MapElement.BACKEND_PRINCIPAL, 0, "credential",(String JavaDoc) v); //NOI18N
176
if (3 == c) {
177 /*
178             java.util.StringTokenizer toker =
179                 new java.util.StringTokenizer((String)v,","); // NOI18N
180             Principal[] ps = new Principal[toker.countTokens()];
181             int i = 0;
182             while (toker.hasMoreTokens()) {
183                 String tok = toker.nextToken();
184                 Principal p = new Principal();
185                 p.setAttributeValue("user-name",tok); //NOI18N
186                 ps[i] = p;
187                 i++;
188             }
189             me.setPrincipal(ps);
190  */

191             Vector JavaDoc vec = (Vector JavaDoc)v;
192             Reporter.info(new Integer JavaDoc(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 JavaDoc[] principal = (String JavaDoc[])vec.elementAt(i);
197 // Reporter.info("(" + principal[0] + ") (" + principal[1] + ")"); //NOI18N
198
prin.setAttributeValue("user-name", principal[0]); //NOI18N
199
prin.setDescription(principal[1]);
200                 principals[i] = prin;
201             }
202             me.setPrincipal(principals);
203 // Reporter.info(new Integer(me.sizePrincipal()));
204
}
205             //ra.addPropertyElement(true);
206
//System.out.println("SETAttributeDetail on " + ra.hashCode()); //NOI18N
207
//ra.setPropertyElement(r,true);
208
//ra.setAttributeValue(ResourceAdapter.PROPERTY, r, intToAttribute(otherDex), otherVal); //NOI18N
209
//ra.setAttributeValue(ResourceAdapter.PROPERTY, r, intToAttribute(c), input); //NOI18N
210
}
211     
212     public String JavaDoc getRoleMapDescription() {
213         return rm.getDescription();
214     }
215         
216     public void setRoleMapDescription(String JavaDoc desc) {
217         rm.setDescription(desc);
218     }
219
220     // For testing Do not expose.
221
RoleMapElement(String JavaDoc args[]) {
222         int rowCount = 0;
223         if (null != args && args.length > 0) {
224             try {
225                 rowCount = Integer.parseInt(args[0]);
226             }
227             catch (Throwable JavaDoc 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); //NOI18N
237
me.setAttributeValue(MapElement.BACKEND_PRINCIPAL, 0, "password", ""+i); //NOI18N
238
me.setAttributeValue(MapElement.BACKEND_PRINCIPAL, 0, "credential", ""+i); //NOI18N
239
for (int j = 0; j < rowCount; j++) {
240                 Principal p = new Principal();
241                 p.setAttributeValue("user-name", ""+unameVal); //NOI18N
242
unameVal++;
243                 me.addPrincipal(p);
244             }
245             rm.addMapElement(me);
246             
247             //ra.addPropertyElement(true);
248
//ra.setAttributeValue(ResourceAdapter.PROPERTY,i,"name",""+i); //NOI18N
249
//ra.setAttributeValue(ResourceAdapter.PROPERTY,i,"value",""+(rowCount - i)); //NOI18N
250
}
251         //connectorDD.setResourceAdapter(ra);
252
//ra = (ResourceAdapter) ra.clone();
253
SunConnector connectorDD = SunConnector.createGraph();
254         connectorDD.setRoleMap(rm);
255        
256    }
257    
258     // For testing Do not expose.
259
String JavaDoc dumpIt() {
260        return rm.dumpBeanNode();
261    }
262 }
263
Popular Tags