KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > model > impl > EmbeddedSchemaModelImpl


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.schema.model.impl;
21
22 import java.beans.PropertyChangeEvent JavaDoc;
23 import java.beans.PropertyChangeListener JavaDoc;
24 import java.io.IOException JavaDoc;
25 import javax.swing.event.UndoableEditListener JavaDoc;
26 import org.netbeans.modules.xml.xam.ModelSource;
27 import org.netbeans.modules.xml.schema.model.SchemaComponent;
28 import org.netbeans.modules.xml.xam.dom.AbstractDocumentModel;
29 import org.netbeans.modules.xml.xam.ComponentListener;
30 import org.netbeans.modules.xml.xam.ComponentEvent;
31 import org.netbeans.modules.xml.xam.dom.DocumentModel;
32 import org.netbeans.modules.xml.xam.Model.State;
33 import org.netbeans.modules.xml.xam.dom.DocumentModelAccess;
34 import org.w3c.dom.Document JavaDoc;
35 import org.w3c.dom.Element JavaDoc;
36
37 /**
38  *
39  * @author rico
40  */

41 public class EmbeddedSchemaModelImpl extends SchemaModelImpl {
42     
43     private DocumentModel delegate;
44     private Element JavaDoc element;
45     private SchemaImpl schema;
46     
47     public EmbeddedSchemaModelImpl(DocumentModel delegate, Element JavaDoc element) {
48         super(delegate.getModelSource());
49         if (! (delegate instanceof AbstractDocumentModel)) {
50             throw new IllegalArgumentException JavaDoc("Expect instance of AbstractComponent");
51         }
52         this.delegate = delegate;
53         this.element = element;
54     }
55     
56     //reimplementation of Model APIs to account for delegate model
57
public void addComponentListener(ComponentListener cl){
58         delegate.addComponentListener(cl);
59     }
60     
61     public void removeComponentListener(ComponentListener cl){
62         delegate.removeComponentListener(cl);
63     }
64     
65     public void removePropertyChangeListener(PropertyChangeListener JavaDoc pcl){
66         delegate.removePropertyChangeListener(pcl);
67     }
68     
69     public void addPropertyChangeListener(PropertyChangeListener JavaDoc pcl){
70         delegate.addPropertyChangeListener(pcl);
71     }
72     
73     public void removeUndoableEditListener(UndoableEditListener JavaDoc uel){
74         delegate.removeUndoableEditListener(uel);
75     }
76     
77     public void addUndoableEditListener(UndoableEditListener JavaDoc uel){
78         delegate.addUndoableEditListener(uel);
79     }
80     
81     public ModelSource getModelSource() {
82         return delegate.getModelSource();
83     }
84     
85     public void sync() throws java.io.IOException JavaDoc{
86         delegate.sync();
87     }
88     
89     public boolean inSync(){
90         return delegate.inSync();
91     }
92     
93     public State getState(){
94         return delegate.getState();
95     }
96     
97     public boolean isIntransaction(){
98         return delegate.isIntransaction();
99     }
100     
101     public boolean startTransaction(){
102         return delegate.startTransaction();
103     }
104     
105     public void endTransaction() {
106         delegate.endTransaction();
107     }
108     
109     public SchemaImpl getSchema() {
110         if(schema == null){
111             schema = (SchemaImpl)this.getFactory().create(element, null);
112         }
113         return schema;
114     }
115     
116     //from AbstractModel
117
public Document JavaDoc getDocument(){
118         return delegate.getDocument();
119     }
120     
121     public synchronized void validateWrite() {
122         getDelegate().validateWrite();
123     }
124     
125     public DocumentModelAccess getAccess(){
126         return getDelegate().getAccess();
127     }
128     
129     public void firePropertyChangeEvent(PropertyChangeEvent JavaDoc event) {
130         getDelegate().firePropertyChangeEvent(event);
131     }
132     
133     public void fireComponentChangedEvent(ComponentEvent evt) {
134         getDelegate().fireComponentChangedEvent(evt);
135     }
136
137     public SchemaComponent getRootComponent() {
138         return getSchema();
139     }
140     
141     private AbstractDocumentModel getDelegate() {
142         return (AbstractDocumentModel) delegate;
143     }
144 }
145
Popular Tags