KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > axi > AXIModel


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.xml.axi;
20
21 import java.util.List JavaDoc;
22 import org.netbeans.modules.xml.axi.impl.AXIDocumentImpl;
23 import org.netbeans.modules.xml.axi.impl.AXIModelImpl;
24 import org.netbeans.modules.xml.axi.impl.AXIModelBuilderQuery;
25 import org.netbeans.modules.xml.axi.impl.ModelAccessImpl;
26 import org.netbeans.modules.xml.schema.model.SchemaComponent;
27 import org.netbeans.modules.xml.schema.model.SchemaModel;
28 import org.netbeans.modules.xml.xam.AbstractModel;
29 import org.netbeans.modules.xml.xam.ModelAccess;
30 import org.netbeans.modules.xml.xam.ModelSource;
31 import org.netbeans.modules.xml.xam.Component;
32 import org.openide.filesystems.FileObject;
33
34 /**
35  * Represents an AXI model for a schema.
36  *
37  * @author Samaresh (Samaresh.Panda@Sun.Com)
38  */

39 public abstract class AXIModel extends AbstractModel<AXIComponent> {
40
41     /**
42      * Creates a new instance AXIModel.
43      */

44     public AXIModel(ModelSource modelSource) {
45         super(modelSource);
46         this.factory = new AXIComponentFactory(this);
47         this.root = new AXIDocumentImpl(this, getSchemaModel().getSchema());
48         this.modelAccess = new ModelAccessImpl(this);
49     }
50     
51     /**
52      * Returns other AXIModels this model refers to.
53      */

54     public abstract List JavaDoc<AXIModel> getReferencedModels();
55             
56     /**
57      * Returns the schema design pattern property.
58      */

59     public abstract SchemaGenerator.Pattern getSchemaDesignPattern();
60     
61     /**
62      * Sets the schema design pattern property.
63      */

64     public abstract void setSchemaDesignPattern(SchemaGenerator.Pattern p);
65     
66     /**
67      * Returns the corresponding SchemaModel.
68      * @return Returns the corresponding SchemaModel.
69      */

70     public SchemaModel getSchemaModel() {
71         return (SchemaModel)getModelSource().getLookup().
72                 lookup(SchemaModel.class);
73     }
74         
75     /**
76      * Returns the root of the AXI model.
77      */

78     public AXIDocument getRoot() {
79         return root;
80     }
81     
82     /**
83      * Returns the component factory.
84      */

85     public AXIComponentFactory getComponentFactory() {
86         return factory;
87     }
88     
89     /**
90      * Returns true if the underlying document is read-only, false otherwise.
91      */

92     public boolean isReadOnly() {
93         ModelSource ms = getModelSource();
94         assert(ms != null);
95         if (ms.isEditable()) {
96             FileObject fo = (FileObject) ms.getLookup().lookup(FileObject.class);
97             assert(fo != null);
98             return !fo.canWrite();
99         }
100         return true;
101     }
102     
103     /**
104      * Returns true if there exists a corresponding visible AXIComponent.
105      */

106     public boolean canView(SchemaComponent component) {
107         AXIModelBuilderQuery factory = new AXIModelBuilderQuery((AXIModelImpl)this);
108         return factory.canView(component);
109     }
110
111     /////////////////////////////////////////////////////////////////////
112
///////////////////////////// XAM methods ///////////////////////////
113
/////////////////////////////////////////////////////////////////////
114
public ModelAccess getAccess() {
115         return modelAccess;
116     }
117     
118     public void addChildComponent(Component parent, Component child, int index) {
119         AXIComponent axiParent = (AXIComponent)parent;
120         AXIComponent axiChild = (AXIComponent)child;
121         axiParent.addChildAtIndex(axiChild, index);
122     }
123
124     public void removeChildComponent(Component child) {
125         AXIComponent axiChild = (AXIComponent)child;
126         AXIComponent axiParent = axiChild.getParent();
127         axiParent.removeChild(axiChild);
128     }
129     
130     /////////////////////////////////////////////////////////////////////
131
////////////////////////// member variables ////////////////////////
132
/////////////////////////////////////////////////////////////////////
133
/**
134      * Keeps a component factory.
135      */

136     private AXIComponentFactory factory;
137     
138     /**
139      * ModelAccess
140      */

141     private ModelAccess modelAccess;
142     
143     /**
144      * Root of the AXI tree.
145      */

146     private AXIDocument root;
147 }
148
Popular Tags