1 19 20 package org.netbeans.modules.xml.wsdl.ui.view; 21 22 import java.io.IOException ; 23 import java.util.HashMap ; 24 import java.util.List ; 25 import java.util.Map ; 26 import org.netbeans.modules.xml.schema.model.Import; 27 import org.netbeans.modules.xml.schema.model.Schema; 28 import org.netbeans.modules.xml.schema.model.SchemaModel; 29 import org.netbeans.modules.xml.wsdl.model.WSDLModel; 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 ImportSchemaCustomizer extends ExternalReferenceCreator<Schema> { 46 47 private static final long serialVersionUID = 1L; 48 private ExternalReferenceDecorator decorator; 49 50 private WSDLModel mModel; 51 52 57 public ImportSchemaCustomizer(Schema schema, WSDLModel model) { 58 super(schema, model); 59 } 60 61 @Override 62 protected void init(Schema component, Model model) { 63 mModel = (WSDLModel) model; 65 } 66 67 @Override 68 public void applyChanges() throws IOException { 69 super.applyChanges(); 70 Schema schema = getModelComponent(); 71 List <Node> nodes = getSelectedNodes(); 72 for (Node node : nodes) { 73 Import schemaImport = schema.getModel().getFactory().createImport(); 74 schemaImport.setSchemaLocation(getLocation(node)); 76 77 String namespace = getNamespace(node); 78 if (mustNamespaceDiffer()) { 79 schemaImport.setNamespace(namespace); 81 } 82 83 if (node instanceof ExternalReferenceDataNode) { 85 String prefix = ((ExternalReferenceDataNode) node).getPrefix(); 86 if (prefix.length() > 0) { 87 if (mModel != null) { 88 AbstractDocumentComponent def = 89 (AbstractDocumentComponent) mModel.getDefinitions(); 90 Map prefixes = def.getPrefixes(); 91 if (!prefixes.containsKey(prefix)) { 92 def.addPrefix(prefix, namespace); 93 } 94 95 } 96 } 97 } 98 schema.addExternalReference(schemaImport); 99 } 100 } 101 102 public HelpCtx getHelpCtx() { 103 return new HelpCtx(ImportSchemaCustomizer.class); 104 } 105 106 111 public WSDLModel getModel() { 112 return mModel; 113 } 114 115 protected String getTargetNamespace(Model model) { 116 return ((SchemaModel) model).getSchema().getTargetNamespace(); 117 } 118 119 protected Map <String , String > getPrefixes(Model model) { 120 if (mModel != null) { 121 return ((AbstractDocumentComponent) mModel.getDefinitions()).getPrefixes(); 122 } 123 return new HashMap (); 124 } 125 126 protected ExternalReferenceDecorator getNodeDecorator() { 127 if (decorator == null) { 128 decorator = new SchemaReferenceDecorator(this); 129 } 130 return decorator; 131 } 132 133 public boolean mustNamespaceDiffer() { 134 return true; 135 } 136 137 protected String referenceTypeName() { 138 return NbBundle.getMessage(ImportWSDLCreator.class, 139 "LBL_ImportCreator_Type"); 140 } 141 } 142 | Popular Tags |