aoqi@0: /* aoqi@0: * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. Oracle designates this aoqi@0: * particular file as subject to the "Classpath" exception as provided aoqi@0: * by Oracle in the LICENSE file that accompanied this code. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: package com.sun.xml.internal.xsom.util; aoqi@0: aoqi@0: import com.sun.xml.internal.xsom.XSAnnotation; aoqi@0: import com.sun.xml.internal.xsom.XSAttGroupDecl; aoqi@0: import com.sun.xml.internal.xsom.XSAttributeDecl; aoqi@0: import com.sun.xml.internal.xsom.XSAttributeUse; aoqi@0: import com.sun.xml.internal.xsom.XSComplexType; aoqi@0: import com.sun.xml.internal.xsom.XSContentType; aoqi@0: import com.sun.xml.internal.xsom.XSElementDecl; aoqi@0: import com.sun.xml.internal.xsom.XSFacet; aoqi@0: import com.sun.xml.internal.xsom.XSModelGroup; aoqi@0: import com.sun.xml.internal.xsom.XSModelGroupDecl; aoqi@0: import com.sun.xml.internal.xsom.XSNotation; aoqi@0: import com.sun.xml.internal.xsom.XSParticle; aoqi@0: import com.sun.xml.internal.xsom.XSSchema; aoqi@0: import com.sun.xml.internal.xsom.XSSimpleType; aoqi@0: import com.sun.xml.internal.xsom.XSWildcard; aoqi@0: import com.sun.xml.internal.xsom.XSIdentityConstraint; aoqi@0: import com.sun.xml.internal.xsom.XSXPath; aoqi@0: import com.sun.xml.internal.xsom.visitor.XSFunction; aoqi@0: aoqi@0: /** aoqi@0: * Extract the name of the components. aoqi@0: * aoqi@0: * @author aoqi@0: */ aoqi@0: public class ComponentNameFunction implements XSFunction { aoqi@0: aoqi@0: // delegate to this object to get the localized name of the component type aoqi@0: private NameGetter nameGetter = new NameGetter(null); aoqi@0: aoqi@0: /** aoqi@0: * @see com.sun.xml.internal.xsom.visitor.XSFunction#annotation(XSAnnotation) aoqi@0: */ aoqi@0: public String annotation(XSAnnotation ann) { aoqi@0: // unnamed component aoqi@0: return nameGetter.annotation( ann ); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * @see com.sun.xml.internal.xsom.visitor.XSFunction#attGroupDecl(XSAttGroupDecl) aoqi@0: */ aoqi@0: public String attGroupDecl(XSAttGroupDecl decl) { aoqi@0: String name = decl.getName(); aoqi@0: if( name == null ) name = ""; aoqi@0: return name + " " + nameGetter.attGroupDecl( decl ); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * @see com.sun.xml.internal.xsom.visitor.XSFunction#attributeDecl(XSAttributeDecl) aoqi@0: */ aoqi@0: public String attributeDecl(XSAttributeDecl decl) { aoqi@0: String name = decl.getName(); aoqi@0: if( name == null ) name = ""; aoqi@0: return name + " " + nameGetter.attributeDecl( decl ); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * @see com.sun.xml.internal.xsom.visitor.XSFunction#attributeUse(XSAttributeUse) aoqi@0: */ aoqi@0: public String attributeUse(XSAttributeUse use) { aoqi@0: // unnamed component aoqi@0: return nameGetter.attributeUse( use ); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * @see com.sun.xml.internal.xsom.visitor.XSFunction#complexType(XSComplexType) aoqi@0: */ aoqi@0: public String complexType(XSComplexType type) { aoqi@0: String name = type.getName(); aoqi@0: if( name == null ) name = "anonymous"; aoqi@0: return name + " " + nameGetter.complexType( type ); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * @see com.sun.xml.internal.xsom.visitor.XSFunction#schema(XSSchema) aoqi@0: */ aoqi@0: public String schema(XSSchema schema) { aoqi@0: return nameGetter.schema( schema ) + " \"" + schema.getTargetNamespace()+"\""; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * @see com.sun.xml.internal.xsom.visitor.XSFunction#facet(XSFacet) aoqi@0: */ aoqi@0: public String facet(XSFacet facet) { aoqi@0: String name = facet.getName(); aoqi@0: if( name == null ) name = ""; aoqi@0: return name + " " + nameGetter.facet( facet ); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * @see com.sun.xml.internal.xsom.visitor.XSFunction#notation(XSNotation) aoqi@0: */ aoqi@0: public String notation(XSNotation notation) { aoqi@0: String name = notation.getName(); aoqi@0: if( name == null ) name = ""; aoqi@0: return name + " " + nameGetter.notation( notation ); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * @see com.sun.xml.internal.xsom.visitor.XSContentTypeFunction#simpleType(XSSimpleType) aoqi@0: */ aoqi@0: public String simpleType(XSSimpleType simpleType) { aoqi@0: String name = simpleType.getName(); aoqi@0: if( name == null ) name = "anonymous"; aoqi@0: return name + " " + nameGetter.simpleType( simpleType ); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * @see com.sun.xml.internal.xsom.visitor.XSContentTypeFunction#particle(XSParticle) aoqi@0: */ aoqi@0: public String particle(XSParticle particle) { aoqi@0: // unnamed component aoqi@0: return nameGetter.particle( particle ); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * @see com.sun.xml.internal.xsom.visitor.XSContentTypeFunction#empty(XSContentType) aoqi@0: */ aoqi@0: public String empty(XSContentType empty) { aoqi@0: // unnamed component aoqi@0: return nameGetter.empty( empty ); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * @see com.sun.xml.internal.xsom.visitor.XSTermFunction#wildcard(XSWildcard) aoqi@0: */ aoqi@0: public String wildcard(XSWildcard wc) { aoqi@0: // unnamed component aoqi@0: return nameGetter.wildcard( wc ); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * @see com.sun.xml.internal.xsom.visitor.XSTermFunction#modelGroupDecl(XSModelGroupDecl) aoqi@0: */ aoqi@0: public String modelGroupDecl(XSModelGroupDecl decl) { aoqi@0: String name = decl.getName(); aoqi@0: if( name == null ) name = ""; aoqi@0: return name + " " + nameGetter.modelGroupDecl( decl ); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * @see com.sun.xml.internal.xsom.visitor.XSTermFunction#modelGroup(XSModelGroup) aoqi@0: */ aoqi@0: public String modelGroup(XSModelGroup group) { aoqi@0: // unnamed component aoqi@0: return nameGetter.modelGroup( group ); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * @see com.sun.xml.internal.xsom.visitor.XSTermFunction#elementDecl(XSElementDecl) aoqi@0: */ aoqi@0: public String elementDecl(XSElementDecl decl) { aoqi@0: String name = decl.getName(); aoqi@0: if( name == null ) name = ""; aoqi@0: return name + " " + nameGetter.elementDecl( decl ); aoqi@0: } aoqi@0: aoqi@0: public String identityConstraint(XSIdentityConstraint decl) { aoqi@0: return decl.getName()+" "+nameGetter.identityConstraint(decl); aoqi@0: } aoqi@0: aoqi@0: public String xpath(XSXPath xpath) { aoqi@0: return nameGetter.xpath(xpath); aoqi@0: } aoqi@0: }