KickJava   Java API By Example, From Geeks To Geeks.

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


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  * PropertyElements.java
26  *
27  * Created on March 13, 2002, 2:00 PM
28  */

29
30 package com.sun.enterprise.tools.common.properties;
31
32 import com.sun.enterprise.tools.common.dd.connector.ResourceAdapter;
33 import com.sun.enterprise.tools.common.dd.connector.SunConnector;
34 import java.io.FileInputStream JavaDoc;
35 /**
36  *
37  * @author vkraemer
38  * @version
39  */

40 public class PropertyElements {
41
42     private ResourceAdapter ra;
43
44     /** Creates new PropertyElements */
45     public PropertyElements(ResourceAdapter ra) {
46         this.ra = ra;
47     }
48     
49     public PropertyElements(PropertyElements source) {
50         this.ra = (ResourceAdapter) source.ra.clone();
51     }
52     
53     public ResourceAdapter getResourceAdapter() {
54         return ra;
55     }
56     
57     public Object JavaDoc getAttributeDetail(int row, int col) {
58         return ra.getAttributeValue(ResourceAdapter.PROPERTY, row, intToAttribute(col)); //NOI18N
59
}
60     
61     public void setAttributeDetail(Object JavaDoc v, int r, int c) {
62         String JavaDoc input = (String JavaDoc) v;
63         if (null == input || 0 == input.trim().length()) {
64             // test for need to delete
65
if (r >= getLength())
66                 return;
67             int otherDex = c - 1;
68             if (otherDex < 0)
69                 otherDex = -otherDex;
70             String JavaDoc otherVal = ra.getAttributeValue(ResourceAdapter.PROPERTY, r,
71                 intToAttribute(otherDex));
72             if (null == otherVal || 0 == otherVal.trim().length()) {
73                 ra.removePropertyElement(r);
74                 return;
75             }
76             input = " "; // NOI18N
77
}
78         while (r >= getLength())
79             ra.addPropertyElement(true);
80         ra.setAttributeValue(ResourceAdapter.PROPERTY, r, intToAttribute(c), input); //NOI18N
81
}
82
83     public int getLength() {
84         return ra.sizePropertyElement();
85     }
86     
87     public int getWidth() {
88         return 2;
89     }
90     
91     private String JavaDoc intToAttribute(int col) {
92         if (col == 0)
93             return "name"; // NOI18N
94
if (col == 1)
95             return "value"; // NOI18N
96
return "error"; // NOI18N
97
}
98
99     // this is used for debugging the PropertyElementsTableModel DO NOT EXPOSE
100
//
101
PropertyElements(String JavaDoc args[]) {
102         int rowCount = 0;
103         if (null != args && args.length > 0) {
104             try {
105                 rowCount = Integer.parseInt(args[0]);
106             }
107             catch (Throwable JavaDoc t) {
108                 t.printStackTrace();
109             }
110         }
111         ra = new ResourceAdapter();
112         for (int i = 0; i < rowCount; i++) {
113             ra.addPropertyElement(true);
114             ra.setAttributeValue(ResourceAdapter.PROPERTY,i,"name",""+i); //NOI18N
115
ra.setAttributeValue(ResourceAdapter.PROPERTY,i,"value",""+(rowCount - i)); //NOI18N
116
}
117         //
118
// Note: the ResourceAdapter MUST be part of a SunConnector or the
119
// PropertyElementsTableModel is BROKEN.
120
SunConnector connectorDD = SunConnector.createGraph();
121         connectorDD.setResourceAdapter(ra);
122     }
123     
124     //ResourceAdapter getRA() {
125
//return ra;
126
//}
127

128     String JavaDoc dumpIt() {
129         return ra.dumpBeanNode();
130     }
131
132     public String JavaDoc toString() {
133         return ra.dumpBeanNode();
134     }
135 }
136
Popular Tags