KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > spi > ExtensibilityElementConfiguratorFactory


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 package org.netbeans.modules.xml.wsdl.ui.spi;
21
22 import java.util.HashMap JavaDoc;
23 import java.util.Map JavaDoc;
24
25 import javax.xml.namespace.QName JavaDoc;
26
27 import org.netbeans.modules.xml.wsdl.model.ExtensibilityElement;
28 import org.openide.ErrorManager;
29 import org.openide.nodes.Node;
30 import org.openide.util.Lookup;
31
32 public class ExtensibilityElementConfiguratorFactory {
33     private static Map JavaDoc<QName JavaDoc, ExtensibilityElementConfigurator> configurators;
34
35     public ExtensibilityElementConfiguratorFactory() {
36         initialise();
37     }
38
39     private void initialise() {
40         lookupFactories();
41     }
42     
43     public ExtensibilityElementConfigurator getExtensibilityElementConfigurator(QName JavaDoc qname) {
44         if (configurators == null || qname == null) return null;
45         return configurators.get(qname);
46     }
47     
48     public Node.Property getNodeProperty(ExtensibilityElement element, QName JavaDoc qname, String JavaDoc attributeName) {
49         if (configurators == null) return null;
50         
51         ExtensibilityElementConfigurator configurator = configurators.get(qname);
52         if (configurator != null) {
53             return configurator.getProperty(element, qname, attributeName);
54         }
55         return null;
56     }
57     
58     private synchronized void lookupFactories() {
59         if(configurators != null)
60             return;
61         
62         configurators = new HashMap JavaDoc<QName JavaDoc, ExtensibilityElementConfigurator>();
63         
64         Lookup.Result result = Lookup.getDefault().lookup(
65                 new Lookup.Template(ExtensibilityElementConfigurator.class));
66         
67         for(Object JavaDoc obj: result.allInstances()) {
68             ExtensibilityElementConfigurator factory = (ExtensibilityElementConfigurator) obj;
69             
70             for (QName JavaDoc qname : factory.getSupportedQNames()) {
71                 if (configurators.containsKey(qname)) {
72                     ErrorManager.getDefault().notify(new Exception JavaDoc("There is a ExtensibilityConfigurator already present for this " + qname.toString()));
73                 }
74                 configurators.put(qname, factory);
75             }
76         }
77         
78     }
79 }
80
Popular Tags