001: package com.sun.xml.xsom.util;
002:
003: import com.sun.xml.xsom.XSAnnotation;
004: import com.sun.xml.xsom.XSAttGroupDecl;
005: import com.sun.xml.xsom.XSAttributeDecl;
006: import com.sun.xml.xsom.XSAttributeUse;
007: import com.sun.xml.xsom.XSComplexType;
008: import com.sun.xml.xsom.XSContentType;
009: import com.sun.xml.xsom.XSElementDecl;
010: import com.sun.xml.xsom.XSFacet;
011: import com.sun.xml.xsom.XSModelGroup;
012: import com.sun.xml.xsom.XSModelGroupDecl;
013: import com.sun.xml.xsom.XSNotation;
014: import com.sun.xml.xsom.XSParticle;
015: import com.sun.xml.xsom.XSSchema;
016: import com.sun.xml.xsom.XSSimpleType;
017: import com.sun.xml.xsom.XSWildcard;
018: import com.sun.xml.xsom.XSIdentityConstraint;
019: import com.sun.xml.xsom.XSXPath;
020: import com.sun.xml.xsom.visitor.XSFunction;
021:
022: /**
023: * Extract the name of the components.
024: *
025: * @author <ul><li>Ryan Shoemaker, Sun Microsystems, Inc.</li></ul>
026: * @version $Revision: 1.1 $
027: */
028: public class ComponentNameFunction implements XSFunction<String> {
029:
030: // delegate to this object to get the localized name of the component type
031: private NameGetter nameGetter = new NameGetter(null);
032:
033: /**
034: * @see com.sun.xml.xsom.visitor.XSFunction#annotation(XSAnnotation)
035: */
036: public String annotation(XSAnnotation ann) {
037: // unnamed component
038: return nameGetter.annotation(ann);
039: }
040:
041: /**
042: * @see com.sun.xml.xsom.visitor.XSFunction#attGroupDecl(XSAttGroupDecl)
043: */
044: public String attGroupDecl(XSAttGroupDecl decl) {
045: String name = decl.getName();
046: if (name == null)
047: name = "";
048: return name + " " + nameGetter.attGroupDecl(decl);
049: }
050:
051: /**
052: * @see com.sun.xml.xsom.visitor.XSFunction#attributeDecl(XSAttributeDecl)
053: */
054: public String attributeDecl(XSAttributeDecl decl) {
055: String name = decl.getName();
056: if (name == null)
057: name = "";
058: return name + " " + nameGetter.attributeDecl(decl);
059: }
060:
061: /**
062: * @see com.sun.xml.xsom.visitor.XSFunction#attributeUse(XSAttributeUse)
063: */
064: public String attributeUse(XSAttributeUse use) {
065: // unnamed component
066: return nameGetter.attributeUse(use);
067: }
068:
069: /**
070: * @see com.sun.xml.xsom.visitor.XSFunction#complexType(XSComplexType)
071: */
072: public String complexType(XSComplexType type) {
073: String name = type.getName();
074: if (name == null)
075: name = "anonymous";
076: return name + " " + nameGetter.complexType(type);
077: }
078:
079: /**
080: * @see com.sun.xml.xsom.visitor.XSFunction#schema(XSSchema)
081: */
082: public String schema(XSSchema schema) {
083: return nameGetter.schema(schema) + " \""
084: + schema.getTargetNamespace() + "\"";
085: }
086:
087: /**
088: * @see com.sun.xml.xsom.visitor.XSFunction#facet(XSFacet)
089: */
090: public String facet(XSFacet facet) {
091: String name = facet.getName();
092: if (name == null)
093: name = "";
094: return name + " " + nameGetter.facet(facet);
095: }
096:
097: /**
098: * @see com.sun.xml.xsom.visitor.XSFunction#notation(XSNotation)
099: */
100: public String notation(XSNotation notation) {
101: String name = notation.getName();
102: if (name == null)
103: name = "";
104: return name + " " + nameGetter.notation(notation);
105: }
106:
107: /**
108: * @see com.sun.xml.xsom.visitor.XSContentTypeFunction#simpleType(XSSimpleType)
109: */
110: public String simpleType(XSSimpleType simpleType) {
111: String name = simpleType.getName();
112: if (name == null)
113: name = "anonymous";
114: return name + " " + nameGetter.simpleType(simpleType);
115: }
116:
117: /**
118: * @see com.sun.xml.xsom.visitor.XSContentTypeFunction#particle(XSParticle)
119: */
120: public String particle(XSParticle particle) {
121: // unnamed component
122: return nameGetter.particle(particle);
123: }
124:
125: /**
126: * @see com.sun.xml.xsom.visitor.XSContentTypeFunction#empty(XSContentType)
127: */
128: public String empty(XSContentType empty) {
129: // unnamed component
130: return nameGetter.empty(empty);
131: }
132:
133: /**
134: * @see com.sun.xml.xsom.visitor.XSTermFunction#wildcard(XSWildcard)
135: */
136: public String wildcard(XSWildcard wc) {
137: // unnamed component
138: return nameGetter.wildcard(wc);
139: }
140:
141: /**
142: * @see com.sun.xml.xsom.visitor.XSTermFunction#modelGroupDecl(XSModelGroupDecl)
143: */
144: public String modelGroupDecl(XSModelGroupDecl decl) {
145: String name = decl.getName();
146: if (name == null)
147: name = "";
148: return name + " " + nameGetter.modelGroupDecl(decl);
149: }
150:
151: /**
152: * @see com.sun.xml.xsom.visitor.XSTermFunction#modelGroup(XSModelGroup)
153: */
154: public String modelGroup(XSModelGroup group) {
155: // unnamed component
156: return nameGetter.modelGroup(group);
157: }
158:
159: /**
160: * @see com.sun.xml.xsom.visitor.XSTermFunction#elementDecl(XSElementDecl)
161: */
162: public String elementDecl(XSElementDecl decl) {
163: String name = decl.getName();
164: if (name == null)
165: name = "";
166: return name + " " + nameGetter.elementDecl(decl);
167: }
168:
169: public String identityConstraint(XSIdentityConstraint decl) {
170: return decl.getName() + " "
171: + nameGetter.identityConstraint(decl);
172: }
173:
174: public String xpath(XSXPath xpath) {
175: return nameGetter.xpath(xpath);
176: }
177: }
|