KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > connector > deployment > ConnectorPlanRectifier


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.geronimo.connector.deployment;
18
19 import javax.xml.namespace.QName JavaDoc;
20
21 import org.apache.geronimo.xbeans.geronimo.GerConnectorType;
22 import org.apache.geronimo.xbeans.geronimo.GerResourceadapterType;
23 import org.apache.geronimo.xbeans.geronimo.GerConnectionDefinitionType;
24 import org.apache.geronimo.xbeans.geronimo.GerConnectiondefinitionInstanceType;
25 import org.apache.xmlbeans.XmlCursor;
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28
29 /**
30  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
31  */

32 public class ConnectorPlanRectifier {
33
34     private static final Log log = LogFactory.getLog(ConnectorPlanRectifier.class);
35
36     private static final QName JavaDoc VERSION_QNAME = new QName JavaDoc("", "version");
37     private static final QName JavaDoc GLOBAL_JNDI_NAME_QNAME = new QName JavaDoc(ConnectorModuleBuilder.GERCONNECTOR_NAMESPACE, "global-jndi-name");
38     private static final QName JavaDoc CREDENTIAL_INTERFACE_QNAME = new QName JavaDoc(ConnectorModuleBuilder.GERCONNECTOR_NAMESPACE, "credential-interface");
39
40
41     static void rectifyPlan(GerConnectorType gerConnector) {
42         boolean updated = false;
43         XmlCursor cursor = gerConnector.newCursor();
44         try {
45             updated = cursor.removeAttribute(VERSION_QNAME);
46         } finally {
47             cursor.dispose();
48         }
49         GerResourceadapterType[] resourceAdapters = gerConnector.getResourceadapterArray();
50         for (int i = 0; i < resourceAdapters.length; i++) {
51             GerResourceadapterType resourceAdapter = resourceAdapters[i];
52             if (resourceAdapter.isSetOutboundResourceadapter()) {
53             GerConnectionDefinitionType[] connectionDefinitions = resourceAdapter.getOutboundResourceadapter().getConnectionDefinitionArray();
54                 for (int j = 0; j < connectionDefinitions.length; j++) {
55                     GerConnectionDefinitionType connectionDefinition = connectionDefinitions[j];
56                     GerConnectiondefinitionInstanceType[] connectiondefinitionInstances = connectionDefinition.getConnectiondefinitionInstanceArray();
57                     for (int k = 0; k < connectiondefinitionInstances.length; k++) {
58                         GerConnectiondefinitionInstanceType connectiondefinitionInstance = connectiondefinitionInstances[k];
59                         cursor = connectiondefinitionInstance.newCursor();
60                         try {
61                             if (cursor.toFirstChild()) {
62                                 if (cursor.toNextSibling(GLOBAL_JNDI_NAME_QNAME)) {
63                                     cursor.removeXml();
64                                     updated = true;
65                                 }
66                                 if (cursor.toNextSibling(CREDENTIAL_INTERFACE_QNAME)) {
67                                     cursor.removeXml();
68                                     updated = true;
69                                 }
70                             }
71                         } finally {
72                             cursor.dispose();
73                         }
74                     }
75                 }
76             }
77         }
78         if (updated) {
79             log.warn("Your connector plan has obsolete elements or attributes in it. Please remove version attributes, global-jndi-name elements, and credential-interface elements");
80         }
81     }
82
83 }
84
Popular Tags