FileDocCategorySizeDatePackage
XSAnnotationImpl.javaAPI DocJava SE 5 API7705Fri Aug 26 14:55:50 BST 2005com.sun.org.apache.xerces.internal.impl.xs

XSAnnotationImpl

public class XSAnnotationImpl extends Object implements XSAnnotation
This is an implementation of the XSAnnotation schema component.

Fields Summary
private String
fData
private SchemaGrammar
fGrammar
Constructors Summary
public XSAnnotationImpl(String contents, SchemaGrammar grammar)


    // constructors
         
        fData = contents;
        fGrammar = grammar;
    
Methods Summary
public java.lang.StringgetAnnotationString()
A text representation of annotation.

        return fData;
    
public java.lang.StringgetName()
The name of type NCName of this declaration as defined in XML Namespaces.

        return null;
    
public java.lang.StringgetNamespace()
The [target namespace] of this object, or null if it is unspecified.

        return null;
    
public com.sun.org.apache.xerces.internal.xs.XSNamespaceItemgetNamespaceItem()
A namespace schema information item corresponding to the target namespace of the component, if it's globally declared; or null otherwise.

        return null;
    
public shortgetType()
The type of this object, i.e. ELEMENT_DECLARATION.

        return XSConstants.ANNOTATION;
    
public booleanwriteAnnotation(java.lang.Object target, short targetType)
Write contents of the annotation to the specified DOM object. If the specified target object is a DOM in-scope namespace declarations for annotation element are added as attributes nodes of the serialized annotation, otherwise the corresponding events for all in-scope namespace declaration are sent via specified document handler.

param
target A target pointer to the annotation target object, i.e. org.w3c.dom.Document, org.xml.sax.ContentHandler.
param
targetType A target type.
return
If the target is recognized type and supported by this implementation return true, otherwise return false.

        if(targetType == XSAnnotation.W3C_DOM_ELEMENT || targetType == XSAnnotation.W3C_DOM_DOCUMENT) {
            writeToDOM((Node)target, targetType);
            return true;
        } else if (targetType == SAX_CONTENTHANDLER) {
            writeToSAX((ContentHandler)target);
            return true;
        }
        return false;
    
private synchronized voidwriteToDOM(org.w3c.dom.Node target, short type)

        Document futureOwner = (type == XSAnnotation.W3C_DOM_ELEMENT)?target.getOwnerDocument():(Document)target;
        DOMParser parser = fGrammar.getDOMParser();
        StringReader aReader = new StringReader(fData);
        InputSource aSource = new InputSource(aReader);
        try {
            parser.parse(aSource);
        } catch (SAXException e) {
            // this should never happen!
            // REVISIT:  what to do with this?; should really not
            // eat it...
        } catch (IOException i) {
            // ditto with above
        }
        Document aDocument = parser.getDocument();
        Element annotation = aDocument.getDocumentElement();
        Node newElem = futureOwner.importNode(annotation, true);
        target.insertBefore(newElem, target.getFirstChild());
    
private synchronized voidwriteToSAX(org.xml.sax.ContentHandler handler)

        // nothing must go wrong with this parse...
        SAXParser parser = fGrammar.getSAXParser();
        StringReader aReader = new StringReader(fData);
        InputSource aSource = new InputSource(aReader);
        parser.setContentHandler(handler);
        try {
            parser.parse(aSource);
        } catch (SAXException e) {
            // this should never happen!
            // REVISIT:  what to do with this?; should really not
            // eat it...
        } catch (IOException i) {
            // ditto with above
        }