Thu, 31 Aug 2017 15:18:52 +0800
merge
1 /*
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
26 package com.sun.xml.internal.xsom.util;
28 import java.util.Locale;
29 import java.util.ResourceBundle;
31 import com.sun.xml.internal.xsom.XSAnnotation;
32 import com.sun.xml.internal.xsom.XSAttGroupDecl;
33 import com.sun.xml.internal.xsom.XSAttributeDecl;
34 import com.sun.xml.internal.xsom.XSAttributeUse;
35 import com.sun.xml.internal.xsom.XSComplexType;
36 import com.sun.xml.internal.xsom.XSComponent;
37 import com.sun.xml.internal.xsom.XSContentType;
38 import com.sun.xml.internal.xsom.XSElementDecl;
39 import com.sun.xml.internal.xsom.XSFacet;
40 import com.sun.xml.internal.xsom.XSModelGroup;
41 import com.sun.xml.internal.xsom.XSModelGroupDecl;
42 import com.sun.xml.internal.xsom.XSNotation;
43 import com.sun.xml.internal.xsom.XSParticle;
44 import com.sun.xml.internal.xsom.XSSchema;
45 import com.sun.xml.internal.xsom.XSSimpleType;
46 import com.sun.xml.internal.xsom.XSWildcard;
47 import com.sun.xml.internal.xsom.XSIdentityConstraint;
48 import com.sun.xml.internal.xsom.XSXPath;
49 import com.sun.xml.internal.xsom.visitor.XSFunction;
51 /**
52 * Gets the human-readable name of a schema component.
53 *
54 * <p>
55 * This is a function object that returns {@link String}.
56 *
57 * @author
58 * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
59 */
60 public class NameGetter implements XSFunction<String> {
61 /**
62 * Initializes a NameGetter so that it will return
63 * messages in the specified locale.
64 */
65 public NameGetter( Locale _locale ) {
66 this.locale = _locale;
67 }
69 private final Locale locale;
71 /**
72 * An instance that gets names in the default locale.
73 * This instance is provided just for convenience.
74 */
75 public final static XSFunction theInstance = new NameGetter(null);
77 /**
78 * Gets the name of the specified component in the default locale.
79 * This method is just a wrapper.
80 */
81 public static String get( XSComponent comp ) {
82 return (String)comp.apply(theInstance);
83 }
86 public String annotation(XSAnnotation ann) {
87 return localize("annotation");
88 }
90 public String attGroupDecl(XSAttGroupDecl decl) {
91 return localize("attGroupDecl");
92 }
94 public String attributeUse(XSAttributeUse use) {
95 return localize("attributeUse");
96 }
98 public String attributeDecl(XSAttributeDecl decl) {
99 return localize("attributeDecl");
100 }
102 public String complexType(XSComplexType type) {
103 return localize("complexType");
104 }
106 public String schema(XSSchema schema) {
107 return localize("schema");
108 }
110 public String facet(XSFacet facet) {
111 return localize("facet");
112 }
114 public String simpleType(XSSimpleType simpleType) {
115 return localize("simpleType");
116 }
118 public String particle(XSParticle particle) {
119 return localize("particle");
120 }
122 public String empty(XSContentType empty) {
123 return localize("empty");
124 }
126 public String wildcard(XSWildcard wc) {
127 return localize("wildcard");
128 }
130 public String modelGroupDecl(XSModelGroupDecl decl) {
131 return localize("modelGroupDecl");
132 }
134 public String modelGroup(XSModelGroup group) {
135 return localize("modelGroup");
136 }
138 public String elementDecl(XSElementDecl decl) {
139 return localize("elementDecl");
140 }
142 public String notation( XSNotation n ) {
143 return localize("notation");
144 }
146 public String identityConstraint(XSIdentityConstraint decl) {
147 return localize("idConstraint");
148 }
150 public String xpath(XSXPath xpath) {
151 return localize("xpath");
152 }
154 private String localize( String key ) {
155 ResourceBundle rb;
157 if(locale==null)
158 rb = ResourceBundle.getBundle(NameGetter.class.getName());
159 else
160 rb = ResourceBundle.getBundle(NameGetter.class.getName(),locale);
162 return rb.getString(key);
163 }
164 }