1 /*2 * The contents of this file are subject to the terms of the Common Development3 * and Distribution License (the License). You may not use this file except in4 * compliance with the License.5 * 6 * You can obtain a copy of the License at http://www.netbeans.org/cddl.html7 * or http://www.netbeans.org/cddl.txt.8 * 9 * When distributing Covered Code, include this CDDL Header Notice in each file10 * and include the License file at http://www.netbeans.org/cddl.txt.11 * If applicable, add the following below the CDDL Header, with the fields12 * 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 Original16 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun17 * Microsystems, Inc. All Rights Reserved.18 */19 package org.netbeans.modules.xml.axi.impl;20 21 import org.netbeans.modules.xml.schema.model.All;22 import org.netbeans.modules.xml.schema.model.AnyAttribute;23 import org.netbeans.modules.xml.schema.model.AnyElement;24 import org.netbeans.modules.xml.schema.model.AttributeGroupReference;25 import org.netbeans.modules.xml.schema.model.AttributeReference;26 import org.netbeans.modules.xml.schema.model.Choice;27 import org.netbeans.modules.xml.schema.model.ComplexContent;28 import org.netbeans.modules.xml.schema.model.ComplexExtension;29 import org.netbeans.modules.xml.schema.model.ElementReference;30 import org.netbeans.modules.xml.schema.model.GlobalAttribute;31 import org.netbeans.modules.xml.schema.model.GlobalAttributeGroup;32 import org.netbeans.modules.xml.schema.model.GlobalComplexType;33 import org.netbeans.modules.xml.schema.model.GlobalElement;34 import org.netbeans.modules.xml.schema.model.GlobalGroup;35 import org.netbeans.modules.xml.schema.model.GroupReference;36 import org.netbeans.modules.xml.schema.model.LocalAttribute;37 import org.netbeans.modules.xml.schema.model.LocalComplexType;38 import org.netbeans.modules.xml.schema.model.LocalElement;39 import org.netbeans.modules.xml.schema.model.Schema;40 import org.netbeans.modules.xml.schema.model.SchemaComponent;41 import org.netbeans.modules.xml.schema.model.Sequence;42 import org.netbeans.modules.xml.schema.model.SimpleContent;43 import org.netbeans.modules.xml.schema.model.SimpleExtension;44 import org.netbeans.modules.xml.schema.model.visitor.DeepSchemaVisitor;45 46 /**47 * Helper class that exposes query-like APIs. Various queries can be made48 * on schema components such as whether or not the a component has any affect49 * on the AXI model OR whether or not a component can be viewed in the editor.50 *51 * @author Samaresh (Samaresh.Panda@Sun.Com)52 */53 public class AXIModelBuilderQuery extends AbstractModelBuilder {54 55 public AXIModelBuilderQuery(AXIModelImpl model) {56 super(model);57 }58 59 /**60 * Returns true for all schema components that are viewable,61 * false otherwise. Not all schema components have corresponding AXI62 * components and not all AXI components are viewable.63 */64 public boolean canView(SchemaComponent schemaComponent) {65 canView = false;66 schemaComponent.accept(this);67 return canView;68 }69 70 /**71 * Returns true if the schema component has an impact on AXI model,72 * false otherwise. Not all schema components affects AXI model.73 */74 public boolean affectsModel(SchemaComponent schemaComponent) {75 affectsModel = false;76 schemaComponent.accept(this);77 return affectsModel;78 }79 80 public void visit(Schema schema) {81 affectsModel = true;82 canView = true;83 }84 85 public void visit(AnyElement schemaComponent) {86 affectsModel = true;87 canView = true;88 }89 90 public void visit(AnyAttribute schemaComponent) {91 affectsModel = true;92 canView = true;93 }94 95 public void visit(GlobalElement schemaComponent) {96 affectsModel = true;97 canView = true;98 }99 100 public void visit(LocalElement component) {101 affectsModel = true;102 canView = true;103 }104 105 public void visit(ElementReference component) {106 affectsModel = true;107 canView = true;108 }109 110 public void visit(GlobalAttribute schemaComponent) {111 affectsModel = true;112 canView = true;113 }114 115 public void visit(LocalAttribute component) {116 affectsModel = true;117 canView = true;118 }119 120 public void visit(AttributeReference component) {121 affectsModel = true;122 canView = true;123 }124 125 public void visit(Sequence component) {126 affectsModel = true;127 canView = true;128 }129 130 public void visit(Choice component) {131 affectsModel = true;132 canView = true;133 }134 135 public void visit(All component) {136 affectsModel = true;137 canView = true;138 }139 140 public void visit(GlobalGroup schemaComponent) {141 affectsModel = true;142 canView = false;143 }144 145 public void visit(GroupReference component) {146 affectsModel = true;147 canView = false;148 }149 150 public void visit(GlobalAttributeGroup schemaComponent) {151 affectsModel = true;152 canView = false;153 }154 155 public void visit(AttributeGroupReference component) {156 affectsModel = true;157 canView = false;158 }159 160 public void visit(GlobalComplexType schemaComponent) {161 affectsModel = true;162 canView = true;163 }164 165 public void visit(LocalComplexType component) {166 affectsModel = true;167 canView = false;168 }169 170 public void visit(ComplexContent component) {171 affectsModel = true;172 canView = false;173 }174 175 public void visit(SimpleContent component) {176 affectsModel = true;177 canView = false;178 }179 180 public void visit(SimpleExtension component) {181 affectsModel = true;182 canView = false;183 }184 185 public void visit(ComplexExtension component) {186 affectsModel = true;187 canView = false;188 }189 190 ////////////////////////////////////////////////////////////////////191 ////////////////////////// member variables ////////////////////////192 ////////////////////////////////////////////////////////////////////193 private boolean affectsModel;194 private boolean canView;195 }196