1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 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.getDocumentElementName().getNamespaceURI(); 35 private static final String NAMING_NS = GerPatternType.type.getName().getNamespaceURI(); 36 private static final String CLUSTER_ELEMENT_NAME = "cluster"; 37 private static final String BACKING_STRATEGY_FACTORY_ELEMENT_NAME = "backing-strategy-factory"; 38 39 public void convertElement(XmlCursor cursor, XmlCursor end) { 40 end.toCursor(cursor); 41 end.toEndToken(); 42 43 while (cursor.hasNextToken() && cursor.isLeftOf(end)) { 44 if (cursor.isStart()) { 45 String localPart = cursor.getName().getLocalPart(); 46 cursor.setName(new QName(CLUSTERING_WADI_NS, localPart)); 47 if (localPart.equals(CLUSTER_ELEMENT_NAME) || localPart.equals(BACKING_STRATEGY_FACTORY_ELEMENT_NAME)) { 48 convertChildrenToNamingNS(cursor); 49 cursor.toEndToken(); 50 } 51 } 52 cursor.toNextToken(); 53 } 54 } 55 56 protected void convertChildrenToNamingNS(XmlCursor cursor) { 57 XmlCursor namingCursor = cursor.newCursor(); 58 try { 59 if (namingCursor.toFirstChild()) { 60 XmlCursor endNamingCursor = namingCursor.newCursor(); 61 try { 62 convertToNamingNS(namingCursor, endNamingCursor); 63 } finally { 64 endNamingCursor.dispose(); 65 } 66 } 67 } finally { 68 namingCursor.dispose(); 69 } 70 } 71 72 protected void convertToNamingNS(XmlCursor cursor, XmlCursor end) { 73 end.toCursor(cursor); 74 end.toEndToken(); 75 while (cursor.hasNextToken() && cursor.isLeftOf(end)) { 76 if (cursor.isStart()) { 77 String localPart = cursor.getName().getLocalPart(); 78 cursor.setName(new QName(NAMING_NS, localPart)); 79 } 80 cursor.toNextToken(); 81 } 82 } 83 84 }