001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.xml.axi;
042:
043: import java.util.List;
044: import org.netbeans.modules.xml.axi.impl.AXIDocumentImpl;
045: import org.netbeans.modules.xml.axi.impl.AXIModelImpl;
046: import org.netbeans.modules.xml.axi.impl.AXIModelBuilderQuery;
047: import org.netbeans.modules.xml.axi.impl.ModelAccessImpl;
048: import org.netbeans.modules.xml.schema.model.SchemaComponent;
049: import org.netbeans.modules.xml.schema.model.SchemaModel;
050: import org.netbeans.modules.xml.xam.AbstractModel;
051: import org.netbeans.modules.xml.xam.ModelAccess;
052: import org.netbeans.modules.xml.xam.ModelSource;
053: import org.netbeans.modules.xml.xam.Component;
054: import org.openide.filesystems.FileObject;
055:
056: /**
057: * Represents an AXI model for a schema.
058: *
059: * @author Samaresh (Samaresh.Panda@Sun.Com)
060: */
061: public abstract class AXIModel extends AbstractModel<AXIComponent> {
062:
063: /**
064: * Creates a new instance AXIModel.
065: */
066: public AXIModel(ModelSource modelSource) {
067: super (modelSource);
068: this .factory = new AXIComponentFactory(this );
069: this .root = new AXIDocumentImpl(this , getSchemaModel()
070: .getSchema());
071: this .modelAccess = new ModelAccessImpl(this );
072: }
073:
074: /**
075: * Returns other AXIModels this model refers to.
076: */
077: public abstract List<AXIModel> getReferencedModels();
078:
079: /**
080: * Returns the schema design pattern property.
081: */
082: public abstract SchemaGenerator.Pattern getSchemaDesignPattern();
083:
084: /**
085: * Sets the schema design pattern property.
086: */
087: public abstract void setSchemaDesignPattern(
088: SchemaGenerator.Pattern p);
089:
090: /**
091: * Returns the corresponding SchemaModel.
092: * @return Returns the corresponding SchemaModel.
093: */
094: public SchemaModel getSchemaModel() {
095: return (SchemaModel) getModelSource().getLookup().lookup(
096: SchemaModel.class);
097: }
098:
099: /**
100: * Returns the root of the AXI model.
101: */
102: public AXIDocument getRoot() {
103: return root;
104: }
105:
106: /**
107: * Returns the component factory.
108: */
109: public AXIComponentFactory getComponentFactory() {
110: return factory;
111: }
112:
113: /**
114: * Returns true if the underlying document is read-only, false otherwise.
115: */
116: public boolean isReadOnly() {
117: ModelSource ms = getModelSource();
118: assert (ms != null);
119: if (ms.isEditable()) {
120: FileObject fo = (FileObject) ms.getLookup().lookup(
121: FileObject.class);
122: assert (fo != null);
123: return !fo.canWrite();
124: }
125: return true;
126: }
127:
128: /**
129: * Returns true if there exists a corresponding visible AXIComponent.
130: */
131: public boolean canView(SchemaComponent component) {
132: AXIModelBuilderQuery factory = new AXIModelBuilderQuery(
133: (AXIModelImpl) this );
134: return factory.canView(component);
135: }
136:
137: /////////////////////////////////////////////////////////////////////
138: ///////////////////////////// XAM methods ///////////////////////////
139: /////////////////////////////////////////////////////////////////////
140: public ModelAccess getAccess() {
141: return modelAccess;
142: }
143:
144: public void addChildComponent(Component parent, Component child,
145: int index) {
146: AXIComponent axiParent = (AXIComponent) parent;
147: AXIComponent axiChild = (AXIComponent) child;
148: axiParent.addChildAtIndex(axiChild, index);
149: }
150:
151: public void removeChildComponent(Component child) {
152: AXIComponent axiChild = (AXIComponent) child;
153: AXIComponent axiParent = axiChild.getParent();
154: axiParent.removeChild(axiChild);
155: }
156:
157: /////////////////////////////////////////////////////////////////////
158: ////////////////////////// member variables ////////////////////////
159: /////////////////////////////////////////////////////////////////////
160: /**
161: * Keeps a component factory.
162: */
163: private AXIComponentFactory factory;
164:
165: /**
166: * ModelAccess
167: */
168: private ModelAccess modelAccess;
169:
170: /**
171: * Root of the AXI tree.
172: */
173: private AXIDocument root;
174: }
|