FileDocCategorySizeDatePackage
XSAnnotationImpl.javaAPI DocApache Xerces 3.0.16512Fri Sep 14 20:33:52 BST 2007org.apache.xerces.impl.xs

XSAnnotationImpl

public class XSAnnotationImpl extends Object implements org.apache.xerces.xs.XSAnnotation
This is an implementation of the XSAnnotation schema component.
xerces.internal
version
$Id: XSAnnotationImpl.java 446734 2006-09-15 20:51:23Z mrglavas $

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 org.apache.xerces.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();
        parser.dropDocumentReferences();
        Element annotation = aDocument.getDocumentElement();
        Node newElem = null;
        if (futureOwner instanceof CoreDocumentImpl) {
            newElem = futureOwner.adoptNode(annotation);
            // adoptNode will return null when the DOM implementations are not compatible.
            if (newElem == null) {
                newElem = futureOwner.importNode(annotation, true);
            }
        }
        else {
            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
        }