01: /*
02: * BEGIN_HEADER - DO NOT EDIT
03: *
04: * The contents of this file are subject to the terms
05: * of the Common Development and Distribution License
06: * (the "License"). You may not use this file except
07: * in compliance with the License.
08: *
09: * You can obtain a copy of the license at
10: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
11: * See the License for the specific language governing
12: * permissions and limitations under the License.
13: *
14: * When distributing Covered Code, include this CDDL
15: * HEADER in each file and include the License file at
16: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
17: * If applicable add the following below this CDDL HEADER,
18: * with the fields enclosed by brackets "[]" replaced with
19: * your own identifying information: Portions Copyright
20: * [year] [name of copyright owner]
21: */
22:
23: /*
24: * @(#)XmlBeansUtil.java
25: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
26: *
27: * END_HEADER - DO NOT EDIT
28: */
29: package com.sun.jbi.wsdl2.impl;
30:
31: import java.util.ArrayList;
32: import java.util.HashMap;
33: import java.util.Iterator;
34: import java.util.List;
35: import java.util.Map;
36:
37: import javax.xml.namespace.QName;
38:
39: import org.apache.xmlbeans.SchemaAttributeModel;
40: import org.apache.xmlbeans.SchemaLocalAttribute;
41: import org.apache.xmlbeans.SchemaType;
42:
43: /**
44: * This class collects a set of XmlBeans utilities.
45: *
46: * @author Sun Microsystems, Inc.
47: */
48: class XmlBeansUtil {
49: /**
50: * Get the qualified names of all attributes given in the attribute model
51: * of the given schema type. This is handy for distinguishing extension
52: * attributes in the empty namespace.
53: *
54: * @param type The schema type to analyze.
55: * @return A possibly empty list of attribute QNames.
56: */
57: static List getAttributes(SchemaType type) {
58: ArrayList result = new ArrayList();
59: SchemaAttributeModel model;
60:
61: if (type != null && (model = type.getAttributeModel()) != null) {
62: SchemaLocalAttribute[] attrs = model.getAttributes();
63: final int nAttrs = attrs != null ? attrs.length : 0;
64:
65: for (int idx = 0; idx < nAttrs; idx++) {
66: result.add(attrs[idx].getName());
67: }
68: }
69:
70: return result;
71: }
72:
73: /**
74: * Get a map of the qualified names of all attributes given in the attribute
75: * model of the given schema type. This is handy for distinguishing extension
76: * attributes in the empty namespace.
77: *
78: * @param type The schema type to analyze.
79: * @return A possibly empty map of attribute QNames, keyed on the QName
80: * canonical name string.
81: */
82: static Map getAttributesMap(SchemaType type) {
83: HashMap result = new HashMap();
84: List attrs = getAttributes(type);
85: Iterator eachAttr = attrs.iterator();
86:
87: while (eachAttr.hasNext()) {
88: QName attrName = (QName) eachAttr.next();
89: result.put(attrName.toString(), attrName);
90: }
91:
92: return result;
93: }
94: }
|