325N/A/*
325N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
325N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
325N/A *
325N/A * This code is free software; you can redistribute it and/or modify it
325N/A * under the terms of the GNU General Public License version 2 only, as
325N/A * published by the Free Software Foundation. Oracle designates this
325N/A * particular file as subject to the "Classpath" exception as provided
325N/A * by Oracle in the LICENSE file that accompanied this code.
325N/A *
325N/A * This code is distributed in the hope that it will be useful, but WITHOUT
325N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
325N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
325N/A * version 2 for more details (a copy is included in the LICENSE file that
325N/A * accompanied this code).
325N/A *
325N/A * You should have received a copy of the GNU General Public License version
325N/A * 2 along with this work; if not, write to the Free Software Foundation,
325N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
325N/A *
325N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
325N/A * or visit www.oracle.com if you need additional information or have any
325N/A * questions.
325N/A */
325N/A
325N/Apackage com.sun.xml.internal.xsom.util;
325N/A
325N/Aimport java.util.Locale;
325N/Aimport java.util.ResourceBundle;
325N/A
325N/Aimport com.sun.xml.internal.xsom.XSAnnotation;
325N/Aimport com.sun.xml.internal.xsom.XSAttGroupDecl;
325N/Aimport com.sun.xml.internal.xsom.XSAttributeDecl;
325N/Aimport com.sun.xml.internal.xsom.XSAttributeUse;
325N/Aimport com.sun.xml.internal.xsom.XSComplexType;
325N/Aimport com.sun.xml.internal.xsom.XSComponent;
325N/Aimport com.sun.xml.internal.xsom.XSContentType;
325N/Aimport com.sun.xml.internal.xsom.XSElementDecl;
325N/Aimport com.sun.xml.internal.xsom.XSFacet;
325N/Aimport com.sun.xml.internal.xsom.XSModelGroup;
325N/Aimport com.sun.xml.internal.xsom.XSModelGroupDecl;
325N/Aimport com.sun.xml.internal.xsom.XSNotation;
325N/Aimport com.sun.xml.internal.xsom.XSParticle;
325N/Aimport com.sun.xml.internal.xsom.XSSchema;
325N/Aimport com.sun.xml.internal.xsom.XSSimpleType;
325N/Aimport com.sun.xml.internal.xsom.XSWildcard;
325N/Aimport com.sun.xml.internal.xsom.XSIdentityConstraint;
325N/Aimport com.sun.xml.internal.xsom.XSXPath;
325N/Aimport com.sun.xml.internal.xsom.visitor.XSFunction;
325N/A
325N/A/**
325N/A * Gets the human-readable name of a schema component.
325N/A *
325N/A * <p>
325N/A * This is a function object that returns {@link String}.
325N/A *
325N/A * @author
325N/A * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
325N/A */
325N/Apublic class NameGetter implements XSFunction<String> {
325N/A /**
325N/A * Initializes a NameGetter so that it will return
325N/A * messages in the specified locale.
325N/A */
325N/A public NameGetter( Locale _locale ) {
325N/A this.locale = _locale;
325N/A }
325N/A
325N/A private final Locale locale;
325N/A
325N/A /**
325N/A * An instance that gets names in the default locale.
325N/A * This instance is provided just for convenience.
325N/A */
325N/A public final static XSFunction theInstance = new NameGetter(null);
325N/A
325N/A /**
325N/A * Gets the name of the specified component in the default locale.
325N/A * This method is just a wrapper.
325N/A */
325N/A public static String get( XSComponent comp ) {
325N/A return (String)comp.apply(theInstance);
325N/A }
325N/A
325N/A
325N/A public String annotation(XSAnnotation ann) {
325N/A return localize("annotation");
325N/A }
325N/A
325N/A public String attGroupDecl(XSAttGroupDecl decl) {
325N/A return localize("attGroupDecl");
325N/A }
325N/A
325N/A public String attributeUse(XSAttributeUse use) {
325N/A return localize("attributeUse");
325N/A }
325N/A
325N/A public String attributeDecl(XSAttributeDecl decl) {
325N/A return localize("attributeDecl");
325N/A }
325N/A
325N/A public String complexType(XSComplexType type) {
325N/A return localize("complexType");
325N/A }
325N/A
325N/A public String schema(XSSchema schema) {
325N/A return localize("schema");
325N/A }
325N/A
325N/A public String facet(XSFacet facet) {
325N/A return localize("facet");
325N/A }
325N/A
325N/A public String simpleType(XSSimpleType simpleType) {
325N/A return localize("simpleType");
325N/A }
325N/A
325N/A public String particle(XSParticle particle) {
325N/A return localize("particle");
325N/A }
325N/A
325N/A public String empty(XSContentType empty) {
325N/A return localize("empty");
325N/A }
325N/A
325N/A public String wildcard(XSWildcard wc) {
325N/A return localize("wildcard");
325N/A }
325N/A
325N/A public String modelGroupDecl(XSModelGroupDecl decl) {
325N/A return localize("modelGroupDecl");
325N/A }
325N/A
325N/A public String modelGroup(XSModelGroup group) {
325N/A return localize("modelGroup");
325N/A }
325N/A
325N/A public String elementDecl(XSElementDecl decl) {
325N/A return localize("elementDecl");
325N/A }
325N/A
325N/A public String notation( XSNotation n ) {
325N/A return localize("notation");
325N/A }
325N/A
325N/A public String identityConstraint(XSIdentityConstraint decl) {
325N/A return localize("idConstraint");
325N/A }
325N/A
325N/A public String xpath(XSXPath xpath) {
325N/A return localize("xpath");
325N/A }
325N/A
325N/A private String localize( String key ) {
325N/A ResourceBundle rb;
325N/A
325N/A if(locale==null)
325N/A rb = ResourceBundle.getBundle(NameGetter.class.getName());
325N/A else
325N/A rb = ResourceBundle.getBundle(NameGetter.class.getName(),locale);
325N/A
325N/A return rb.getString(key);
325N/A }
325N/A}