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.tomcat.cluster.wadi.builder;
21:
22: import javax.xml.namespace.QName;
23:
24: import org.apache.geronimo.schema.ElementConverter;
25: import org.apache.geronimo.xbeans.geronimo.GerTomcatClusteringWadiDocument;
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 TomcatClusteringWADIConverter implements ElementConverter {
34: private static final String TOMCAT_CLUSTERING_WADI_NS = GerTomcatClusteringWadiDocument.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.setName(new QName(TOMCAT_CLUSTERING_WADI_NS,
49: localPart));
50: if (localPart.equals(CLUSTER_ELEMENT_NAME)
51: || localPart
52: .equals(BACKING_STRATEGY_FACTORY_ELEMENT_NAME)) {
53: convertChildrenToNamingNS(cursor);
54: cursor.toEndToken();
55: }
56: }
57: cursor.toNextToken();
58: }
59: }
60:
61: protected void convertChildrenToNamingNS(XmlCursor cursor) {
62: XmlCursor namingCursor = cursor.newCursor();
63: try {
64: if (namingCursor.toFirstChild()) {
65: XmlCursor endNamingCursor = namingCursor.newCursor();
66: try {
67: convertToNamingNS(namingCursor, endNamingCursor);
68: } finally {
69: endNamingCursor.dispose();
70: }
71: }
72: } finally {
73: namingCursor.dispose();
74: }
75: }
76:
77: protected void convertToNamingNS(XmlCursor cursor, XmlCursor end) {
78: end.toCursor(cursor);
79: end.toEndToken();
80: while (cursor.hasNextToken() && cursor.isLeftOf(end)) {
81: if (cursor.isStart()) {
82: String localPart = cursor.getName().getLocalPart();
83: cursor.setName(new QName(NAMING_NS, localPart));
84: }
85: cursor.toNextToken();
86: }
87: }
88:
89: }
|