001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)CustomConfig.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package java4ant;
030:
031: import java.io.File;
032:
033: import javax.management.MBeanException;
034: import javax.management.openmbean.ArrayType;
035: import javax.management.openmbean.CompositeData;
036: import javax.management.openmbean.CompositeDataSupport;
037: import javax.management.openmbean.CompositeType;
038: import javax.management.openmbean.TabularData;
039: import javax.management.openmbean.TabularDataSupport;
040: import javax.management.openmbean.TabularType;
041: import javax.management.openmbean.OpenType;
042: import javax.management.openmbean.SimpleType;
043:
044: import javax.jbi.component.ComponentContext;
045:
046: public class CustomConfiguration implements CustomConfigurationMBean {
047: private String mInfo;
048: private String mA, mB, mC;
049: /** The application variables TabularData */
050: private TabularDataSupport mAppVars;
051: private ComponentContext mContext;
052:
053: /** Application Variable Composite Type */
054: private static CompositeType sAppVarComposite;
055:
056: /** Application Variable Tabular Type */
057: private static TabularType sAppVarTable;
058:
059: /** Application Variable Composite Item Names */
060: private static String[] sAppVarItemNames;
061:
062: /** The index of the Application Variables **/
063: private static String[] sappVarRowIndex;
064:
065: /** The application configuration TabularData */
066: private TabularDataSupport mAppConfigs;
067:
068: /** Application Configuration Composite Type */
069: private static CompositeType sAppConfigComposite;
070:
071: /** Application Configuration Tabular Type */
072: private static TabularType sAppConfigTable;
073:
074: /** Application Configuration Composite Item Names */
075: private static String[] sAppConfigItemNames;
076:
077: /** The index of the Application Configurations **/
078: private static String[] sAppConfigRowIndex;
079:
080: private void initOpenTypes()
081: throws javax.management.openmbean.OpenDataException {
082: // Define the Application Variables CompositeType
083: sAppVarItemNames = new String[] { "name", "value", "type" };
084:
085: String[] appVarItemDesc = { "Application variable name",
086: "Application variable value",
087: "Application variable type" };
088:
089: OpenType[] appVarRowAttrTypes = { SimpleType.STRING,
090: SimpleType.STRING, SimpleType.STRING };
091:
092: sappVarRowIndex = new String[] { "name" };
093:
094: sAppVarComposite = new CompositeType(
095: "ApplicationVariableComposite",
096: "Application variable name and value pair",
097: sAppVarItemNames, appVarItemDesc, appVarRowAttrTypes);
098:
099: sAppVarTable = new TabularType("ApplicationVariableList",
100: "List of application variables", sAppVarComposite,
101: sappVarRowIndex);
102:
103: // Define the Application Configuration OpenType
104: sAppConfigItemNames = new String[] { "configurationName",
105: "connectionURL", "securityPrincipal",
106: "securityCredential", "jndienv" };
107:
108: String[] appConfigItemDesc = {
109: "Application configuration name", "Connection URL",
110: "Security Principal", "Security Credential",
111: "JNDI Properties" };
112:
113: ArrayType jndiEnvArrayType = new ArrayType(1, SimpleType.STRING);
114: OpenType[] appConfigRowAttrTypes = { SimpleType.STRING,
115: SimpleType.STRING, SimpleType.STRING,
116: SimpleType.STRING, jndiEnvArrayType };
117:
118: sAppConfigRowIndex = new String[] { "configurationName" };
119:
120: sAppConfigComposite = new CompositeType(
121: "ApplicationConfigurationComposite",
122: "Application Configuration Composite",
123: sAppConfigItemNames, appConfigItemDesc,
124: appConfigRowAttrTypes);
125:
126: sAppConfigTable = new TabularType(
127: "ApplicationConfigurationList",
128: "List of application configurations",
129: sAppConfigComposite, sAppConfigRowIndex);
130: }
131:
132: public CustomConfiguration(String info, ComponentContext context) {
133: mContext = context;
134: mInfo = info;
135: try {
136: initOpenTypes();
137: mAppVars = new TabularDataSupport(sAppVarTable);
138: mAppConfigs = new TabularDataSupport(sAppConfigTable);
139:
140: // Add a default app var
141: CompositeDataSupport cd = new CompositeDataSupport(
142: sAppVarComposite, sAppVarItemNames, new String[] {
143: "default", "defValue", "STRING" });
144: mAppVars.put(cd);
145:
146: // Add a default app config
147: CompositeDataSupport appCfgCD = new CompositeDataSupport(
148: sAppConfigComposite,
149: sAppConfigItemNames,
150: new Object[] {
151: "defaultConfig",
152: "http://www.sun.com",
153: "administrator",
154: "abc",
155: new String[] { "env1=value1", "env2=value2" } });
156: mAppConfigs.put(appCfgCD);
157:
158: } catch (Exception ex) {
159: System.out
160: .println("Error in populating the Application Variables");
161: System.out.println(ex.getMessage());
162: }
163:
164: mA = System.getProperty("A", "");
165: mB = System.getProperty("B", "");
166: }
167:
168: /**
169: * Test method.
170: */
171: public String getComponentCustomInfo() {
172: return mInfo;
173: }
174:
175: /**
176: * Attribute getters/setters
177: */
178: public String getA() {
179: return mA;
180: }
181:
182: public void setA(String a) {
183: mA = a;
184: }
185:
186: public String getB() {
187: return mB;
188: }
189:
190: public void setB(String b) {
191: mB = b;
192: }
193:
194: public String getC() {
195: return mC;
196: }
197:
198: public void setC(String c) {
199: mC = c;
200: }
201:
202: /**
203: * This operation adds a new application variable. If a variable already exists with
204: * the same name as that specified then the operation fails.
205: *
206: * @param name - name of the application variable
207: * @param appVar - this is the application variable compoiste
208: * @throws MBeanException if an error occurs in adding the application variables to the
209: * component.
210: * @return management message string which gives the status of the operation. For
211: * target=cluster, instance specific details are included.
212: */
213: public void addApplicationVariable(String name, CompositeData appVar)
214: throws MBeanException {
215: mAppVars.put(appVar);
216: }
217:
218: /**
219: * This operation sets an application variable. If a variable does not exist with
220: * the same name, its an error.
221: *
222: * @param name - name of the application variable
223: * @param appVar - this is the application variable compoiste to be updated.
224: * @throws MBeanException if one or more application variables cannot be deleted
225: * @return management message string which gives the status of the operation. For
226: * target=cluster, instance specific details are included.
227: */
228: public void setApplicationVariable(String name, CompositeData appVar)
229: throws MBeanException {
230: CompositeData cd = (CompositeData) mAppVars
231: .get(new String[] { name });
232:
233: if (cd != null) {
234: mAppVars.remove(new String[] { name });
235: mAppVars.put(appVar);
236: }
237: }
238:
239: /**
240: * This operation deletes an application variable, if a variable with the specified name does
241: * not exist, it's an error.
242: *
243: * @param name - name of the application variable
244: * @throws MBeanException on errors.
245: * @return management message string which gives the status of the operation. For
246: * target=cluster, instance specific details are included.
247: */
248: public void deleteApplicationVariable(String name)
249: throws MBeanException {
250: mAppVars.remove(new String[] { name });
251: }
252:
253: /**
254: * Get the Application Variable set for a component.
255: *
256: * @return a TabularData which has all the applicationvariables set on the component.
257: */
258: public TabularData getApplicationVariables() {
259: return mAppVars;
260: }
261:
262: /**
263: * Get the CompositeType definition for the components application configuration
264: *
265: * @return the CompositeType for the components application configuration.
266: */
267: public CompositeType queryApplicationConfigurationType() {
268: return sAppConfigComposite;
269: }
270:
271: /**
272: * Add an application configuration. The configuration name is a part of the CompositeData.
273: * The itemName for the configuration name is "configurationName" and the type is SimpleType.STRING
274: *
275: * @param name - configuration name, must match the value of the field "name" in the namedConfig
276: * @param appConfig - application configuration composite
277: * @throws MBeanException if the application configuration cannot be added.
278: * @return management message string which gives the status of the operation. For
279: * target=cluster, instance specific details are included.
280: */
281: public void addApplicationConfiguration(String name,
282: CompositeData appConfig) throws MBeanException {
283: mAppConfigs.put(appConfig);
284: }
285:
286: /**
287: * Delete an application configuration.
288: *
289: * @param name - identification of the application configuration to be deleted
290: * @throws MBeanException if the configuration cannot be deleted.
291: * @return management message string which gives the status of the operation. For
292: * target=cluster, instance specific details are included.
293: */
294: public void deleteApplicationConfiguration(String name)
295: throws MBeanException {
296: CompositeData cd = (CompositeData) mAppConfigs
297: .get(new String[] { name });
298:
299: if (cd != null) {
300: mAppConfigs.remove(new String[] { name });
301: }
302: }
303:
304: /**
305: * Update a application configuration. The configuration name is a part of the CompositeData.
306: * The itemName for the configuration name is "configurationName" and the type is SimpleType.STRING
307: *
308: * @param name - configuration name, must match the value of the field "configurationName" in the appConfig
309: * @param appConfig - application configuration composite
310: * @throws MBeanException if there are errors encountered when updating the configuration.
311: * @return management message string which gives the status of the operation. For
312: * target=cluster, instance specific details are included.
313: */
314: public void setApplicationConfiguration(String name,
315: CompositeData appConfig) throws MBeanException {
316: CompositeData cd = (CompositeData) mAppConfigs
317: .get(new String[] { name });
318:
319: if (cd != null) {
320: mAppConfigs.remove(new String[] { name });
321: mAppConfigs.put(appConfig);
322: }
323: }
324:
325: /**
326: * Get a Map of all application configurations for the component.
327: *
328: * @return a TabularData of all the application configurations for a
329: * component keyed by the configuration name.
330: */
331: public TabularData getApplicationConfigurations() {
332: return mAppConfigs;
333: }
334: }
|