1 19 20 package org.netbeans.modules.xml.wsdl.ui.view; 21 22 import java.io.IOException ; 23 import java.util.List ; 24 import java.util.Map ; 25 import org.netbeans.modules.xml.wsdl.model.Definitions; 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.netbeans.module.Utility; 30 import org.netbeans.modules.xml.xam.Model; 31 import org.netbeans.modules.xml.xam.dom.AbstractDocumentComponent; 32 import org.netbeans.modules.xml.xam.ui.customizer.ExternalReferenceCreator; 33 import org.netbeans.modules.xml.xam.ui.customizer.ExternalReferenceDataNode; 34 import org.netbeans.modules.xml.xam.ui.customizer.ExternalReferenceDecorator; 35 import org.openide.nodes.Node; 36 import org.openide.util.HelpCtx; 37 import org.openide.util.NbBundle; 38 39 45 public class ImportWSDLCreator extends ExternalReferenceCreator<Definitions> { 46 47 private static final long serialVersionUID = 1L; 48 private ExternalReferenceDecorator decorator; 49 50 55 public ImportWSDLCreator(Definitions defs) { 56 super(defs, null); 57 } 58 59 @Override 60 public void applyChanges() throws IOException { 61 super.applyChanges(); 62 Definitions def = getModelComponent(); 63 WSDLModel model = def.getModel(); 64 List <Node> nodes = getSelectedNodes(); 65 for (Node node : nodes) { 66 Import imp = model.getFactory().createImport(); 67 imp.setLocation(getLocation(node)); 69 70 String namespace = getNamespace(node); 72 if (mustNamespaceDiffer()) { 73 imp.setNamespace(namespace); 74 } 75 76 if (node instanceof ExternalReferenceDataNode) { 78 String prefix = ((ExternalReferenceDataNode) node).getPrefix(); 79 if (prefix.length() > 0) { 80 AbstractDocumentComponent adc = 83 (AbstractDocumentComponent) model.getDefinitions(); 84 Map prefixes = adc.getPrefixes(); 85 if (!prefixes.containsKey(prefix)) { 86 adc.addPrefix(prefix, namespace); 87 } 88 } 89 } 90 def.addImport(imp); 91 92 if (Utility.getNamespacePrefix(imp.getNamespace(), model) == null) { 95 String prefix = NameGenerator.getInstance().generateNamespacePrefix(null, model); 97 ((AbstractDocumentComponent) def).addPrefix(prefix, imp.getNamespace()); 98 } 99 } 100 } 101 102 public HelpCtx getHelpCtx() { 103 return new HelpCtx(ImportWSDLCreator.class); 104 } 105 106 protected String getTargetNamespace(Model model) { 107 return ((WSDLModel) model).getDefinitions().getTargetNamespace(); 108 } 109 110 protected Map <String , String > getPrefixes(Model model) { 111 WSDLModel wm = (WSDLModel) model; 112 AbstractDocumentComponent def = 113 (AbstractDocumentComponent) wm.getDefinitions(); 114 return def.getPrefixes(); 115 } 116 117 protected ExternalReferenceDecorator getNodeDecorator() { 118 if (decorator == null) { 119 decorator = new WSDLReferenceDecorator(this); 120 } 121 return decorator; 122 } 123 124 public boolean mustNamespaceDiffer() { 125 return true; 126 } 127 128 protected String referenceTypeName() { 129 return NbBundle.getMessage(ImportWSDLCreator.class, 130 "LBL_ImportCreator_Type"); 131 } 132 } 133 | Popular Tags |