KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > completion > WSDLCompletionModel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * 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 Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.xml.wsdl.ui.completion;
20
21 import javax.xml.XMLConstants JavaDoc;
22
23 import org.netbeans.modules.xml.schema.completion.spi.CompletionContext;
24 import org.netbeans.modules.xml.schema.completion.spi.CompletionModelProvider;
25 import org.netbeans.modules.xml.schema.model.SchemaModel;
26
27
28 public class WSDLCompletionModel extends CompletionModelProvider.CompletionModel {
29
30     private final CompletionContext context;
31     private final SchemaModel schemaModel;
32     private String JavaDoc suggestedPrefix;
33
34     public WSDLCompletionModel(CompletionContext context, SchemaModel schemaModel, String JavaDoc suggestedPrefix) {
35         this.context = context;
36         this.schemaModel = schemaModel;
37         this.suggestedPrefix = suggestedPrefix;
38         
39     }
40     
41     @Override JavaDoc
42     public String JavaDoc getSuggestedPrefix() {
43         if(suggestedPrefix == null) {
44             //Generate a new prefix by looking at the document.
45
this.suggestedPrefix = getSuggestedPrefix("ns", getTargetNamespace()); //NOI18N
46
}
47         return suggestedPrefix;
48     }
49     
50     @Override JavaDoc
51     public SchemaModel getSchemaModel() {
52         return schemaModel;
53     }
54     
55     @Override JavaDoc
56     public String JavaDoc getTargetNamespace() {
57         return schemaModel.getSchema().getTargetNamespace();
58     }
59     
60     private String JavaDoc getSuggestedPrefix(String JavaDoc prefix, String JavaDoc tns) {
61         String JavaDoc newPrefix = prefix;
62         String JavaDoc nsDecl = XMLConstants.XMLNS_ATTRIBUTE+":"+newPrefix;
63         int i = 0;
64         while(context.getDeclaredNamespaces().get(nsDecl) != null) {
65             String JavaDoc ns = context.getDeclaredNamespaces().get(nsDecl);
66             if(ns.equals(tns))
67                 return null;
68             newPrefix = newPrefix + i; //NOI18N
69
nsDecl = XMLConstants.XMLNS_ATTRIBUTE+":"+newPrefix;
70             i++;
71         }
72         return newPrefix;
73     }
74
75 }
76
Popular Tags