1 19 20 package org.netbeans.modules.xml.wsdl.ui.view; 21 22 import java.util.Collection ; 23 import org.netbeans.modules.xml.retriever.catalog.Utilities; 24 import org.netbeans.modules.xml.schema.model.SchemaModel; 25 import org.netbeans.modules.xml.schema.model.SchemaModelReference; 26 import org.netbeans.modules.xml.wsdl.model.WSDLModel; 27 import org.netbeans.modules.xml.wsdl.ui.actions.NameGenerator; 28 import org.netbeans.modules.xml.xam.Model; 29 import org.netbeans.modules.xml.xam.locator.CatalogModelException; 30 import org.netbeans.modules.xml.xam.ui.customizer.AbstractReferenceDecorator; 31 import org.netbeans.modules.xml.xam.ui.customizer.ExternalReferenceDataNode; 32 import org.netbeans.modules.xml.xam.ui.customizer.ExternalReferenceNode; 33 import org.openide.nodes.Node; 34 import org.openide.util.NbBundle; 35 36 41 public class SchemaReferenceDecorator extends AbstractReferenceDecorator { 42 43 private ImportSchemaCustomizer customizer; 44 45 private int prefixCounter; 46 47 52 public SchemaReferenceDecorator(ImportSchemaCustomizer customizer) { 53 this.customizer = customizer; 54 } 55 56 public String validate(ExternalReferenceNode node) { 57 if (node.hasModel()) { 58 Model model = node.getModel(); 59 if (model == null) { 60 return NbBundle.getMessage(SchemaReferenceDecorator.class, 62 "LBL_ReferenceDecorator_NoModel"); 63 } 64 Model componentModel = customizer.getComponentModel(); 65 if (model.equals(componentModel)) { 66 return NbBundle.getMessage(SchemaReferenceDecorator.class, 67 "LBL_ReferenceDecorator_SameModel"); 68 } 69 if (componentModel instanceof SchemaModel) { 71 SchemaModel sm = (SchemaModel) componentModel; 72 Collection <SchemaModelReference> references = 73 sm.getSchema().getSchemaReferences(); 74 for (SchemaModelReference ref : references) { 77 try { 78 SchemaModel otherModel = ref.resolveReferencedModel(); 79 if (model.equals(otherModel)) { 80 return NbBundle.getMessage(SchemaReferenceDecorator.class, 81 "LBL_ReferenceDecorator_AlreadyRefd"); 82 } 83 } catch (CatalogModelException cme) { 84 } 86 } 87 } 88 } 89 String ns = node.getNamespace(); 90 String namespace = customizer.getTargetNamespace(); 91 if (customizer.mustNamespaceDiffer()) { 92 if (ns != null && !Utilities.NO_NAME_SPACE.equals(ns) && 95 namespace.equals(ns)) { 96 return NbBundle.getMessage(SchemaReferenceDecorator.class, 97 "LBL_ReferenceDecorator_SameNamespace"); 98 } 99 } else { 100 if (ns != null && !Utilities.NO_NAME_SPACE.equals(ns) && 103 !namespace.equals(ns)) { 104 return NbBundle.getMessage(SchemaReferenceDecorator.class, 105 "LBL_ReferenceDecorator_DifferentNamespace"); 106 } 107 } 108 return null; 109 } 110 111 public ExternalReferenceDataNode createExternalReferenceNode(Node original) { 112 return customizer.createExternalReferenceNode(original); 113 } 114 115 protected String generatePrefix(Model model) { 116 WSDLModel wModel = customizer.getModel(); 117 if (wModel != null) { 118 return NameGenerator.getInstance().generateNamespacePrefix( 119 null, wModel, prefixCounter++); 120 } 121 return ""; 122 } 123 124 public Utilities.DocumentTypesEnum getDocumentType() { 125 return Utilities.DocumentTypesEnum.schema; 126 } 127 128 public String getHtmlDisplayName(String name, ExternalReferenceNode node) { 129 if (validate(node) != null) { 130 return "<s>" + name + "</s>"; 131 } 132 return name; 133 } 134 135 public String getNamespace(Model model) { 136 if (model instanceof SchemaModel) { 137 SchemaModel sm = (SchemaModel) model; 138 return sm.getSchema().getTargetNamespace(); 139 } 140 return null; 141 } 142 } 143 | Popular Tags |