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.schema;
17:
18: import javax.xml.namespace.QName;
19:
20: import org.apache.xmlbeans.XmlCursor;
21: import org.apache.xmlbeans.XmlObject;
22:
23: /**
24: * @version $Rev: 476049 $ $Date: 2006-11-16 20:35:17 -0800 (Thu, 16 Nov 2006) $
25: */
26: public class NamespaceElementConverter implements ElementConverter {
27:
28: private final String namespace;
29:
30: public NamespaceElementConverter(String namespace) {
31: this .namespace = namespace;
32: }
33:
34: public XmlObject convertElement(XmlObject element) {
35: XmlCursor cursor = element.newCursor();
36: try {
37: XmlCursor end = cursor.newCursor();
38: try {
39: convertElement(cursor, end);
40: } finally {
41: end.dispose();
42: }
43: } finally {
44: cursor.dispose();
45: }
46: return element;
47: }
48:
49: public void convertElement(XmlCursor cursor, XmlCursor end) {
50: end.toCursor(cursor);
51: end.toEndToken();
52: while (cursor.hasNextToken() && cursor.isLeftOf(end)) {
53: if (cursor.isStart()) {
54: if (!namespace.equals(cursor.getName()
55: .getNamespaceURI())) {
56: cursor.setName(new QName(namespace, cursor
57: .getName().getLocalPart()));
58: }
59: }
60: cursor.toNextToken();
61: }
62: }
63: }
|