1 19 20 package org.netbeans.modules.xml.wsdl.ui.view; 21 22 import java.util.Collection ; 23 import org.netbeans.api.project.Project; 24 import org.netbeans.api.project.ProjectUtils; 25 import org.netbeans.modules.xml.retriever.catalog.Utilities; 26 import org.netbeans.modules.xml.wsdl.model.Import; 27 import org.netbeans.modules.xml.wsdl.model.WSDLModel; 28 import org.netbeans.modules.xml.wsdl.ui.actions.NameGenerator; 29 import org.netbeans.modules.xml.wsdl.ui.wsdl.nodes.ImportViewNodes; 30 import org.netbeans.modules.xml.xam.Model; 31 import org.netbeans.modules.xml.xam.locator.CatalogModelException; 32 import org.netbeans.modules.xml.xam.ui.customizer.AbstractReferenceCustomizer; 33 import org.netbeans.modules.xml.xam.ui.customizer.AbstractReferenceDecorator; 34 import org.netbeans.modules.xml.xam.ui.customizer.ExternalReferenceDataNode; 35 import org.netbeans.modules.xml.xam.ui.customizer.ExternalReferenceNode; 36 import org.openide.nodes.Node; 37 import org.openide.util.NbBundle; 38 39 44 public class WSDLReferenceDecorator extends AbstractReferenceDecorator { 45 46 private AbstractReferenceCustomizer customizer; 47 48 private int prefixCounter; 49 50 55 public WSDLReferenceDecorator(AbstractReferenceCustomizer customizer) { 56 this.customizer = customizer; 57 } 58 59 public String validate(ExternalReferenceNode node) { 60 if (node.hasModel()) { 61 Model model = node.getModel(); 62 if (model == null) { 63 return NbBundle.getMessage(WSDLReferenceDecorator.class, 65 "LBL_ReferenceDecorator_NoModel"); 66 } 67 Model componentModel = customizer.getComponentModel(); 68 if (model.equals(componentModel)) { 69 return NbBundle.getMessage(WSDLReferenceDecorator.class, 70 "LBL_ReferenceDecorator_SameModel"); 71 } 72 if (componentModel instanceof WSDLModel) { 74 WSDLModel sm = (WSDLModel) componentModel; 75 Collection <Import> references = 76 sm.getDefinitions().getImports(); 77 for (Import ref : references) { 80 try { 81 WSDLModel otherModel = ref.getImportedWSDLModel(); 82 if (model.equals(otherModel)) { 83 return NbBundle.getMessage(WSDLReferenceDecorator.class, 84 "LBL_ReferenceDecorator_AlreadyRefd"); 85 } 86 } catch (CatalogModelException cme) { 87 } 89 } 90 } 91 } 92 String ns = node.getNamespace(); 93 String namespace = customizer.getTargetNamespace(); 94 if (customizer.mustNamespaceDiffer()) { 95 if (ns != null && !Utilities.NO_NAME_SPACE.equals(ns) && 98 namespace.equals(ns)) { 99 return NbBundle.getMessage(WSDLReferenceDecorator.class, 100 "LBL_ReferenceDecorator_SameNamespace"); 101 } 102 } else { 103 if (ns != null && !Utilities.NO_NAME_SPACE.equals(ns) && 106 !namespace.equals(ns)) { 107 return NbBundle.getMessage(WSDLReferenceDecorator.class, 108 "LBL_ReferenceDecorator_DifferentNamespace"); 109 } 110 } 111 ImportViewNodes.DuplicateFileCookie cookie = 112 (ImportViewNodes.DuplicateFileCookie) node.getCookie( 113 ImportViewNodes.DuplicateFileCookie.class); 114 if (cookie != null) { 115 Project ownerProject = cookie.getPrecedingOwnerProject(); 116 String projectName = ""; 117 if (ownerProject != null) { 118 projectName = ProjectUtils.getInformation(ownerProject).getDisplayName(); 119 } 120 String fileName = cookie.getFileName(); 121 return NbBundle.getMessage(WSDLReferenceDecorator.class, 122 "LBL_ReferenceDecorator_DupeInDependentProject", 123 fileName, projectName); 124 } 125 return null; 126 } 127 128 public ExternalReferenceDataNode createExternalReferenceNode(Node original) { 129 return customizer.createExternalReferenceNode(original); 130 } 131 132 protected String generatePrefix(Model model) { 133 Model ourModel = customizer.getComponentModel(); 134 if (ourModel instanceof WSDLModel) { 135 return NameGenerator.getInstance().generateNamespacePrefix( 136 null, (WSDLModel) ourModel, prefixCounter++); 137 } 138 return ""; 139 } 140 141 public Utilities.DocumentTypesEnum getDocumentType() { 142 return Utilities.DocumentTypesEnum.wsdl; 143 } 144 145 public String getHtmlDisplayName(String name, ExternalReferenceNode node) { 146 if (validate(node) != null) { 147 return "<s>" + name + "</s>"; 148 } 149 return name; 150 } 151 152 public String getNamespace(Model model) { 153 if (model instanceof WSDLModel) { 154 WSDLModel wm = (WSDLModel) model; 155 return wm.getDefinitions().getTargetNamespace(); 156 } 157 return null; 158 } 159 } 160 | Popular Tags |