01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19:
20: package org.apache.geronimo.openejb.deployment.cluster;
21:
22: import javax.xml.namespace.QName;
23:
24: import org.apache.geronimo.schema.ElementConverter;
25: import org.apache.geronimo.xbeans.geronimo.GerOpenejbClusteringWadiDocument;
26: import org.apache.geronimo.xbeans.geronimo.naming.GerPatternType;
27: import org.apache.xmlbeans.XmlCursor;
28:
29: /**
30: *
31: * @version $Rev:$ $Date:$
32: */
33: public class OpenEJBClusteringWADIConverter implements ElementConverter {
34: private static final String CLUSTERING_WADI_NS = GerOpenejbClusteringWadiDocument.type
35: .getDocumentElementName().getNamespaceURI();
36: private static final String NAMING_NS = GerPatternType.type
37: .getName().getNamespaceURI();
38: private static final String CLUSTER_ELEMENT_NAME = "cluster";
39: private static final String BACKING_STRATEGY_FACTORY_ELEMENT_NAME = "backing-strategy-factory";
40:
41: public void convertElement(XmlCursor cursor, XmlCursor end) {
42: end.toCursor(cursor);
43: end.toEndToken();
44:
45: while (cursor.hasNextToken() && cursor.isLeftOf(end)) {
46: if (cursor.isStart()) {
47: String localPart = cursor.getName().getLocalPart();
48: cursor
49: .setName(new QName(CLUSTERING_WADI_NS,
50: localPart));
51: if (localPart.equals(CLUSTER_ELEMENT_NAME)
52: || localPart
53: .equals(BACKING_STRATEGY_FACTORY_ELEMENT_NAME)) {
54: convertChildrenToNamingNS(cursor);
55: cursor.toEndToken();
56: }
57: }
58: cursor.toNextToken();
59: }
60: }
61:
62: protected void convertChildrenToNamingNS(XmlCursor cursor) {
63: XmlCursor namingCursor = cursor.newCursor();
64: try {
65: if (namingCursor.toFirstChild()) {
66: XmlCursor endNamingCursor = namingCursor.newCursor();
67: try {
68: convertToNamingNS(namingCursor, endNamingCursor);
69: } finally {
70: endNamingCursor.dispose();
71: }
72: }
73: } finally {
74: namingCursor.dispose();
75: }
76: }
77:
78: protected void convertToNamingNS(XmlCursor cursor, XmlCursor end) {
79: end.toCursor(cursor);
80: end.toEndToken();
81: while (cursor.hasNextToken() && cursor.isLeftOf(end)) {
82: if (cursor.isStart()) {
83: String localPart = cursor.getName().getLocalPart();
84: cursor.setName(new QName(NAMING_NS, localPart));
85: }
86: cursor.toNextToken();
87: }
88: }
89:
90: }
|