KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > api > property > DefaultElementOrTypeProvider


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.api.property;
20
21 import javax.xml.namespace.QName JavaDoc;
22
23 import org.netbeans.modules.xml.wsdl.model.ExtensibilityElement;
24 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
25 import org.netbeans.modules.xml.wsdl.ui.actions.ActionHelper;
26 import org.netbeans.modules.xml.wsdl.ui.netbeans.module.Utility;
27
28 public class DefaultElementOrTypeProvider implements ElementOrTypeProvider {
29
30     private final ExtensibilityElement extensibilityElement;
31     private final String JavaDoc typeAttributeName;
32     private final String JavaDoc elementAttributeName;
33
34     public DefaultElementOrTypeProvider(ExtensibilityElement extensibilityElement, String JavaDoc elementAttributeName, String JavaDoc typeAttributeName) {
35         this.extensibilityElement = extensibilityElement;
36         this.elementAttributeName = elementAttributeName;
37         this.typeAttributeName = typeAttributeName;
38     }
39
40     public void setElementOrType(ElementOrType o) {
41         if (o == null) {
42             return;
43         }
44         getModel().startTransaction();
45         if (o.isElement()) {
46             Utility.addSchemaImport(o.getElement(), getModel());
47             Utility.addNamespacePrefix(o.getElement().getModel().getSchema(), extensibilityElement.getModel(), null);
48             extensibilityElement.setAttribute(elementAttributeName, o.toString());
49             extensibilityElement.setAttribute(typeAttributeName, null);
50         } else {
51             Utility.addSchemaImport(o.getType(), getModel());
52             Utility.addNamespacePrefix(o.getType().getModel().getSchema(), extensibilityElement.getModel(), null);
53             extensibilityElement.setAttribute(typeAttributeName, o.toString());
54             extensibilityElement.setAttribute(elementAttributeName, null);
55         }
56         getModel().endTransaction();
57         ActionHelper.selectNode(extensibilityElement);
58     }
59
60     public ElementOrType getElementOrType() {
61         boolean isElement = false;
62         String JavaDoc value = extensibilityElement.getAttribute(typeAttributeName);
63         if (value == null) {
64             value = extensibilityElement.getAttribute(elementAttributeName);
65         } else {
66             isElement = false;
67         }
68         if (value != null) {
69             isElement = true;
70         }
71         
72         if (extensibilityElement.getModel() == null) { //this seems to happen during deletion.
73
return null;
74         }
75         
76         if (value != null && value.trim().length() > 0) {
77             String JavaDoc[] parts = value.split(":");
78             if (parts != null && parts.length == 2) {
79                 String JavaDoc prefix = parts[0];
80                 String JavaDoc localPart = parts[1];
81                 String JavaDoc namespace = Utility.getNamespaceURI(prefix, extensibilityElement);
82                 return new ElementOrType(new QName JavaDoc(namespace, localPart, prefix), extensibilityElement.getModel(), isElement);
83             }
84             return new ElementOrType(new QName JavaDoc(value), extensibilityElement.getModel(), false);
85         }
86         
87         return new ElementOrType(new QName JavaDoc(""), extensibilityElement.getModel(), false);
88     }
89
90     public WSDLModel getModel() {
91         return extensibilityElement.getModel();
92     }
93
94 }
95
Popular Tags