01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: */package org.apache.geronimo.connector.deployment;
17:
18: import javax.xml.namespace.QName;
19:
20: import org.apache.geronimo.xbeans.geronimo.GerConnectorType;
21: import org.apache.geronimo.xbeans.geronimo.GerResourceadapterType;
22: import org.apache.geronimo.xbeans.geronimo.GerConnectionDefinitionType;
23: import org.apache.geronimo.xbeans.geronimo.GerConnectiondefinitionInstanceType;
24: import org.apache.xmlbeans.XmlCursor;
25: import org.apache.commons.logging.Log;
26: import org.apache.commons.logging.LogFactory;
27:
28: /**
29: * @version $Rev: 476049 $ $Date: 2006-11-16 20:35:17 -0800 (Thu, 16 Nov 2006) $
30: */
31: public class ConnectorPlanRectifier {
32:
33: private static final Log log = LogFactory
34: .getLog(ConnectorPlanRectifier.class);
35:
36: private static final QName VERSION_QNAME = new QName("", "version");
37: private static final QName GLOBAL_JNDI_NAME_QNAME = new QName(
38: ConnectorModuleBuilder.GERCONNECTOR_NAMESPACE,
39: "global-jndi-name");
40: private static final QName CREDENTIAL_INTERFACE_QNAME = new QName(
41: ConnectorModuleBuilder.GERCONNECTOR_NAMESPACE,
42: "credential-interface");
43:
44: static void rectifyPlan(GerConnectorType gerConnector) {
45: boolean updated = false;
46: XmlCursor cursor = gerConnector.newCursor();
47: try {
48: updated = cursor.removeAttribute(VERSION_QNAME);
49: } finally {
50: cursor.dispose();
51: }
52: GerResourceadapterType[] resourceAdapters = gerConnector
53: .getResourceadapterArray();
54: for (int i = 0; i < resourceAdapters.length; i++) {
55: GerResourceadapterType resourceAdapter = resourceAdapters[i];
56: if (resourceAdapter.isSetOutboundResourceadapter()) {
57: GerConnectionDefinitionType[] connectionDefinitions = resourceAdapter
58: .getOutboundResourceadapter()
59: .getConnectionDefinitionArray();
60: for (int j = 0; j < connectionDefinitions.length; j++) {
61: GerConnectionDefinitionType connectionDefinition = connectionDefinitions[j];
62: GerConnectiondefinitionInstanceType[] connectiondefinitionInstances = connectionDefinition
63: .getConnectiondefinitionInstanceArray();
64: for (int k = 0; k < connectiondefinitionInstances.length; k++) {
65: GerConnectiondefinitionInstanceType connectiondefinitionInstance = connectiondefinitionInstances[k];
66: cursor = connectiondefinitionInstance
67: .newCursor();
68: try {
69: if (cursor.toFirstChild()) {
70: if (cursor
71: .toNextSibling(GLOBAL_JNDI_NAME_QNAME)) {
72: cursor.removeXml();
73: updated = true;
74: }
75: if (cursor
76: .toNextSibling(CREDENTIAL_INTERFACE_QNAME)) {
77: cursor.removeXml();
78: updated = true;
79: }
80: }
81: } finally {
82: cursor.dispose();
83: }
84: }
85: }
86: }
87: }
88: if (updated) {
89: log
90: .warn("Your connector plan has obsolete elements or attributes in it. Please remove version attributes, global-jndi-name elements, and credential-interface elements");
91: }
92: }
93:
94: }
|