1/*
2 * reserved comment block
3 * DO NOT REMOVE OR ALTER!
4 */
5/*
6 * Licensed to the Apache Software Foundation (ASF) under one or more
7 * contributor license agreements.  See the NOTICE file distributed with
8 * this work for additional information regarding copyright ownership.
9 * The ASF licenses this file to You under the Apache License, Version 2.0
10 * (the "License"); you may not use this file except in compliance with
11 * the License.  You may obtain a copy of the License at
12 *
13 *      http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 */
21
22package com.sun.org.apache.xerces.internal.dom;
23
24import java.io.IOException;
25import java.io.NotSerializableException;
26import java.io.ObjectInputStream;
27import java.io.ObjectOutputStream;
28import org.w3c.dom.DOMConfiguration;
29import org.w3c.dom.UserDataHandler;
30import org.w3c.dom.*;
31
32/**
33 * Our own document implementation, which knows how to create an element
34 * with PSVI information.
35 *
36 * @xerces.internal
37 *
38 * @author Sandy Gao, IBM
39 *
40 */
41public class PSVIDocumentImpl extends DocumentImpl {
42
43    /** Serialization version. */
44    static final long serialVersionUID = -8822220250676434522L;
45
46    /**
47     * Create a document.
48     */
49    public PSVIDocumentImpl() {
50        super();
51    }
52
53    /**
54     * For DOM2 support.
55     * The createDocument factory method is in DOMImplementation.
56     */
57    public PSVIDocumentImpl(DocumentType doctype) {
58        super(doctype);
59    }
60
61    /**
62     * Deep-clone a document, including fixing ownerDoc for the cloned
63     * children. Note that this requires bypassing the WRONG_DOCUMENT_ERR
64     * protection. I've chosen to implement it by calling importNode
65     * which is DOM Level 2.
66     *
67     * @return org.w3c.dom.Node
68     * @param deep boolean, iff true replicate children
69     */
70    public Node cloneNode(boolean deep) {
71
72        PSVIDocumentImpl newdoc = new PSVIDocumentImpl();
73        callUserDataHandlers(this, newdoc, UserDataHandler.NODE_CLONED);
74        cloneNode(newdoc, deep);
75
76        // experimental
77        newdoc.mutationEvents = mutationEvents;
78
79        return newdoc;
80
81    } // cloneNode(boolean):Node
82
83    /**
84     * Retrieve information describing the abilities of this particular
85     * DOM implementation. Intended to support applications that may be
86     * using DOMs retrieved from several different sources, potentially
87     * with different underlying representations.
88     */
89    public DOMImplementation getImplementation() {
90        // Currently implemented as a singleton, since it's hardcoded
91        // information anyway.
92        return PSVIDOMImplementationImpl.getDOMImplementation();
93    }
94
95    /**
96     * Create an element with PSVI information
97     */
98    public Element createElementNS(String namespaceURI, String qualifiedName)
99        throws DOMException {
100        return new PSVIElementNSImpl(this, namespaceURI, qualifiedName);
101    }
102
103    /**
104     * Create an element with PSVI information
105     */
106    public Element createElementNS(String namespaceURI, String qualifiedName,
107                                   String localpart) throws DOMException {
108        return new PSVIElementNSImpl(this, namespaceURI, qualifiedName, localpart);
109    }
110
111    /**
112     * Create an attribute with PSVI information
113     */
114    public Attr createAttributeNS(String namespaceURI, String qualifiedName)
115        throws DOMException {
116        return new PSVIAttrNSImpl(this, namespaceURI, qualifiedName);
117    }
118
119    /**
120     * Create an attribute with PSVI information
121     */
122    public Attr createAttributeNS(String namespaceURI, String qualifiedName,
123                                  String localName) throws DOMException {
124        return new PSVIAttrNSImpl(this, namespaceURI, qualifiedName, localName);
125    }
126
127    /**
128     *
129     * The configuration used when <code>Document.normalizeDocument</code> is
130     * invoked.
131     * @since DOM Level 3
132     */
133    public DOMConfiguration getDomConfig(){
134        super.getDomConfig();
135        return fConfiguration;
136    }
137
138    // REVISIT: Forbid serialization of PSVI DOM until
139    // we support object serialization of grammars -- mrglavas
140
141    private void writeObject(ObjectOutputStream out)
142        throws IOException {
143        throw new NotSerializableException(getClass().getName());
144        }
145
146    private void readObject(ObjectInputStream in)
147        throws IOException, ClassNotFoundException {
148        throw new NotSerializableException(getClass().getName());
149    }
150
151} // class PSVIDocumentImpl
152