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:
22: /**
23: * @version $Rev: 545781 $ $Date: 2007-06-09 10:44:02 -0700 (Sat, 09 Jun 2007) $
24: */
25: public class SecurityElementConverter implements ElementConverter {
26:
27: public static final String GERONIMO_SECURITY_NAMESPACE = "http://geronimo.apache.org/xml/ns/security-2.0";
28: private static final QName PRINCIPAL_QNAME = new QName(
29: GERONIMO_SECURITY_NAMESPACE, "principal");
30: private static final QName REALM_NAME_QNAME = new QName(
31: "realm-name");
32: private static final QName DESIGNATED_RUN_AS = new QName(
33: "designated-run-as");
34:
35: public void convertElement(XmlCursor cursor, XmlCursor end) {
36: cursor.push();
37: end.toCursor(cursor);
38: end.toEndToken();
39: while (cursor.hasNextToken() && cursor.isLeftOf(end)) {
40: if (cursor.isStart()) {
41: if (GERONIMO_SECURITY_NAMESPACE.equals(cursor.getName()
42: .getNamespaceURI())) {
43: break;
44: }
45: cursor.setName(new QName(GERONIMO_SECURITY_NAMESPACE,
46: cursor.getName().getLocalPart()));
47:
48: }
49: cursor.toNextToken();
50: }
51: cursor.pop();
52: XmlCursor source = null;
53: try {
54: while (cursor.hasNextToken() && cursor.isLeftOf(end)) {
55: if (cursor.isStart()) {
56: String localPart = cursor.getName().getLocalPart();
57: if (localPart.equals("realm")) {
58: if (source == null) {
59: source = cursor.newCursor();
60: } else {
61: source.toCursor(cursor);
62: }
63: cursor.push();
64: cursor.toEndToken();
65: cursor.toNextToken();
66: if (source.toChild(PRINCIPAL_QNAME)) {
67: do {
68: source
69: .removeAttribute(DESIGNATED_RUN_AS);
70: source.copyXml(cursor);
71: } while (source
72: .toNextSibling(PRINCIPAL_QNAME));
73: }
74:
75: cursor.pop();
76: cursor.removeXml();
77: } else if (localPart.equals("default-subject")) {
78: // cursor.removeAttribute(REALM_NAME_QNAME);
79: cursor.toEndToken();
80: } else if (localPart.equals("default-principal")) {
81: cursor.removeXml();
82: } else if (localPart.equals("principal")) {
83: cursor.removeAttribute(DESIGNATED_RUN_AS);
84: } else if (localPart.equals("run-as-subject")) {
85: cursor.toEndToken();
86: }
87: }
88: cursor.toNextToken();
89: }
90: } finally {
91: if (source != null) {
92: source.dispose();
93: }
94: }
95: }
96: }
|