KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > view > treeeditor > Utils


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
20 /*
21  * Created on Jun 23, 2005
22  *
23  * To change the template for this generated file go to
24  * Window - Preferences - Java - Code Generation - Code and Comments
25  */

26 package org.netbeans.modules.xml.wsdl.ui.view.treeeditor;
27
28 import java.util.Iterator JavaDoc;
29 import java.util.List JavaDoc;
30
31 import org.netbeans.modules.xml.schema.model.AnyAttribute;
32 import org.netbeans.modules.xml.schema.model.Attribute;
33 import org.netbeans.modules.xml.schema.model.Element;
34 import org.netbeans.modules.xml.wsdl.model.WSDLComponent;
35 import org.netbeans.modules.xml.wsdl.ui.cookies.WSDLDefinitionNodeCookie;
36 import org.netbeans.modules.xml.wsdl.ui.schema.visitor.AbstractXSDVisitor;
37 import org.netbeans.modules.xml.wsdl.ui.schema.visitor.SchemaElementAttributeFinderVisitor;
38 import org.netbeans.modules.xml.xam.Nameable;
39 import org.openide.nodes.Node;
40 import org.w3c.dom.NamedNodeMap JavaDoc;
41
42
43
44 /**
45  * @author radval
46  *
47  * To change the template for this generated type comment go to
48  * Window - Preferences - Java - Code Generation - Code and Comments
49  */

50 public class Utils {
51     
52     public static WSDLDefinitionNodeCookie getWSDLDefinitionNodeCookie(Node node) {
53         Node parent = node;
54         if(parent != null) {
55             while(parent != null) {
56                 WSDLDefinitionNodeCookie cookie = (WSDLDefinitionNodeCookie) parent.getCookie(WSDLDefinitionNodeCookie.class);
57                 if(cookie != null) {
58                     return cookie;
59                 } else {
60                     parent = parent.getParentNode();
61                 }
62             }
63         }
64         
65         return null;
66     }
67     
68     public static boolean isMissingAttributes(WSDLComponent element, Element schemaElement) {
69         boolean result = false;
70         
71 // //go through attributes defined in schema element
72
// //and check if they are already available in WSDLElement
73
// //if so, skip them and add if not.
74
NamedNodeMap JavaDoc elementAttrs = element.getPeer().getAttributes();
75         SchemaElementAttributeFinderVisitor seaFinder = new SchemaElementAttributeFinderVisitor(schemaElement);
76         schemaElement.accept(seaFinder);
77         List JavaDoc<Attribute> attrs = seaFinder.getAttributes();
78         Iterator JavaDoc<Attribute> it = attrs.iterator();
79         while(it.hasNext()) {
80             Attribute attr = it.next();
81             Nameable namedAttr = (Nameable) attr;
82             //check if attribute is already added
83
//TODO: need to check namespace as well
84
if(elementAttrs.getNamedItem(namedAttr.getName())== null) {
85                 result = true;
86                 break;
87             }
88         }
89         
90         return result;
91     }
92     
93     public static boolean isExtensionAttributesAllowed(Element element) {
94         AnyAttributesVisitor visitor = new AnyAttributesVisitor();
95         element.accept(visitor);
96         return visitor.isExtensionAttributesAllowed();
97     }
98     
99     
100
101
102 }
103
104 class AnyAttributesVisitor extends AbstractXSDVisitor{
105     private boolean hasAnyAttributes = false;
106     @Override JavaDoc
107     public void visit(AnyAttribute anyAttr) {
108         hasAnyAttributes = true;
109     }
110     public boolean isExtensionAttributesAllowed() {
111         return hasAnyAttributes;
112     }
113 };
114
Popular Tags