KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > common > beans > IasConnectorOneZero


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  * IasResourceAdapterConfigBean.java
26  *
27  * Created on March 12, 2002, 10:02 AM
28  */

29
30 package com.sun.enterprise.tools.common.beans;
31
32 import java.util.ResourceBundle JavaDoc;
33
34 import java.beans.PropertyVetoException JavaDoc;
35 import java.beans.VetoableChangeListener JavaDoc;
36 import java.beans.PropertyChangeEvent JavaDoc;
37
38 import com.sun.enterprise.tools.common.properties.RoleMapElement;
39 import com.sun.enterprise.tools.common.properties.PropertyElements;
40
41 import com.sun.enterprise.tools.common.dd.connector.*;
42 import org.netbeans.modules.schema2beans.BaseBean;
43 /**
44  *
45  * @author vkraemer
46  * @version
47  */

48 public class IasConnectorOneZero extends BasicIasBean { // implements ConfigBean {
49

50     private static String JavaDoc PROPNAME_MAXPOOLSIZE = "maxPoolSize";//NOI18N
51
private static String JavaDoc PROPNAME_STEADYPOOLSIZE = "steadyPoolSize";//NOI18N
52
private static String JavaDoc PROPNAME_MAXWAITTIMEINMILLIS= "maxWaitTimeInMilis";//NOI18N
53
private static String JavaDoc PROPNAME_IDLETIMEOUTINSECONDS = "idleTimeoutInSeconds";//NOI18N
54
private static String JavaDoc PROPNAME_JNDINAME = "jndiName"; ///NOI18N
55
private static String JavaDoc PROPNAME_DESCRIPTION = "description";//NOI18N
56

57     protected SunConnector fileBean = null;
58     protected ResourceAdapter ra = null;
59     protected RoleMapElement roleMap = null;
60     protected PropertyElements propertyElements = null;
61     public static String JavaDoc DEFAULT_MAP_ID = "1"; //any number will do since there is only one role-map
62

63     //private static ResourceBundle bundle =
64
//ResourceBundle.getBundle("com.sun.enterprise.tools.common.beans.Bundle"); //NOI18N
65

66     protected IasConnectorOneZero() {
67         initListeners();
68     }
69     
70     public IasConnectorOneZero(java.io.InputStream JavaDoc is) {
71         try {
72             fileBean = SunConnector.createGraph(is);
73         }
74         catch (Throwable JavaDoc t) {
75             // If there is ANY problem with the file on the input stream,
76
// we will create a new EMPTY bean.
77
fileBean = SunConnector.createGraph();
78             ra = new ResourceAdapter();
79             ra.setAttributeValue("jndi-name","default"); //NOI18N
80
fileBean.setResourceAdapter(ra);
81         }
82         ra = fileBean.getResourceAdapter();
83         RoleMap rm = fileBean.getRoleMap();
84         if (null == rm) {
85             rm = new RoleMap();
86             rm.setAttributeValue("map-id", DEFAULT_MAP_ID);
87             // if setRoleMap was called, this is the strategy I would use to allow the user
88
// to edit values when the original SunConnector doesn't have a role-map
89
// sub-element.
90
// BUT, setRoleMap is not called....
91
//
92
//SunConnector tmp = SunConnector.createGraph();
93
//tmp.setRoleMap(rm);
94
fileBean.setRoleMap(rm);
95         }
96         roleMap = new RoleMapElement(rm);
97         propertyElements = new PropertyElements(ra);
98         initListeners();
99     }
100     
101     private void initListeners() {
102         getVCS().addVetoableChangeListener(PROPNAME_MAXPOOLSIZE, greaterThanNegOne);
103         getVCS().addVetoableChangeListener(PROPNAME_STEADYPOOLSIZE, greaterThanNegOne);
104         getVCS().addVetoableChangeListener(PROPNAME_MAXWAITTIMEINMILLIS, greaterThanNegOne);
105         getVCS().addVetoableChangeListener(PROPNAME_IDLETIMEOUTINSECONDS, greaterThanNegOne);
106         getVCS().addVetoableChangeListener(PROPNAME_JNDINAME, notNull);
107     }
108     
109         
110     public void setDescription(String JavaDoc newDesc) throws PropertyVetoException JavaDoc {
111          String JavaDoc elementName = "description"; // NOI18N
112
String JavaDoc propName = PROPNAME_DESCRIPTION;
113          doElementSetProcessing(ra, newDesc, elementName, propName);
114     }
115     
116     public String JavaDoc getDescription() {
117         return ra.getDescription();
118     }
119     
120      public void setJndiName(String JavaDoc newName) throws PropertyVetoException JavaDoc {
121          String JavaDoc attrName = "jndi-name"; // NOI18N
122
String JavaDoc propName = PROPNAME_JNDINAME;
123          doAttrSetProcessing(ra, newName, attrName, propName);
124      }
125      
126     
127     public String JavaDoc getJndiName() {
128         return ra.getAttributeValue("jndi-name"); //NOI18N
129
}
130     
131     public void setMaxPoolSize(int newVal) throws PropertyVetoException JavaDoc {
132         String JavaDoc attrName = "max-pool-size"; // NOI18N
133
String JavaDoc propName = PROPNAME_MAXPOOLSIZE;
134         doAttrSetProcessing(ra, newVal,attrName, propName);
135     }
136     
137     
138     public int getMaxPoolSize() {
139         return Integer.parseInt(ra.getAttributeValue("max-pool-size")); //NOI18N
140
}
141     
142     public void setSteadyPoolSize(int newVal) throws PropertyVetoException JavaDoc {
143         String JavaDoc attrName = "steady-pool-size"; // NOI18N
144
String JavaDoc propName = PROPNAME_STEADYPOOLSIZE;
145         doAttrSetProcessing(ra, newVal,attrName, propName);
146     }
147     
148     public int getSteadyPoolSize() {
149         return Integer.parseInt(ra.getAttributeValue("steady-pool-size")); //NOI18N
150
}
151     
152     public void setMaxWaitTimeInMillis(int newVal) throws PropertyVetoException JavaDoc {
153         String JavaDoc attrName = "max-wait-time-in-millis"; // NOI18N
154
String JavaDoc propName = PROPNAME_MAXWAITTIMEINMILLIS;
155         doAttrSetProcessing(ra, newVal,attrName, propName);
156     }
157     
158     public int getMaxWaitTimeInMillis() {
159         return Integer.parseInt(ra.getAttributeValue("max-wait-time-in-millis")); //NOI18N
160
}
161     
162     public void setIdleTimeoutInSeconds(int newVal) throws PropertyVetoException JavaDoc {
163         String JavaDoc attrName = "idle-timeout-in-seconds"; // NOI18N
164
String JavaDoc propName = PROPNAME_IDLETIMEOUTINSECONDS;
165         doAttrSetProcessing(ra, newVal,attrName, propName);
166     }
167     
168     public int getIdleTimeoutInSeconds() {
169         return Integer.parseInt(ra.getAttributeValue("idle-timeout-in-seconds")); //NOI18N
170
}
171     
172     public void setRoleMap(RoleMapElement newVal) throws PropertyVetoException JavaDoc {
173         // why doesn't this get called
174
//
175
RoleMapElement oldVal = roleMap;
176         fireMyVetoableChange("roleMap", oldVal, newVal); // NOI18N
177
roleMap = newVal;
178         fileBean.setRoleMap(newVal.getRoleMap());
179         fireMyPropertyChange("roleMap", oldVal, newVal); // NOI18N
180
}
181     
182     public RoleMapElement getRoleMap() {
183         return roleMap;
184     }
185     
186     public void setPropertyElements(PropertyElements newVal) throws PropertyVetoException JavaDoc {
187         // why doesn't this get called
188
//
189
//System.out.println("in set property elements: " + newVal); //NOI18N
190
PropertyElements oldVal = propertyElements;
191         fireMyVetoableChange("propertyElements", oldVal, newVal); // NOI18N
192
propertyElements = newVal;
193         ra = newVal.getResourceAdapter();
194         fileBean.setResourceAdapter(ra);
195         fireMyPropertyChange("propertyElements", oldVal, newVal); // NOI18N
196
}
197     
198     public PropertyElements getPropertyElements() {
199         //System.out.println("in get property elements: " + propertyElements.hashCode()); //NOI18N
200
return propertyElements;
201     }
202     
203    public void outTo(java.io.OutputStream JavaDoc os) throws java.io.IOException JavaDoc {
204        fileBean.write(os);
205    }
206    
207    static public void main (String JavaDoc[] args) {
208        try {
209        IasConnectorOneZero bean = new IasConnectorOneZero(null);
210        bean.outTo(System.out); //NOI18N
211
bean.setDescription("test setDescription"); // NOI18N
212
bean.setIdleTimeoutInSeconds(1);
213        bean.setJndiName("testSetJndiName"); // NOI18N
214
bean.setMaxPoolSize(2);
215        bean.setMaxWaitTimeInMillis(-3);
216        bean.setSteadyPoolSize(4);
217        bean.outTo(System.out); //NOI18N
218
}
219        catch (Throwable JavaDoc t) {
220            t.printStackTrace();
221        }
222    }
223    
224    public SunConnector getSunConnector(){
225        return fileBean;
226    }
227 }
228
Popular Tags