KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > api > jaxws > wsdlmodel > WsdlModelerFactory


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-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.websvc.api.jaxws.wsdlmodel;
21
22 import java.lang.ref.WeakReference JavaDoc;
23 import java.net.URL JavaDoc;
24 import java.util.WeakHashMap JavaDoc;
25
26 /**
27  *
28  * @author mkuchtiak
29  */

30 public class WsdlModelerFactory {
31     
32     private static WsdlModelerFactory factory;
33     WeakHashMap JavaDoc<URL JavaDoc, WeakReference JavaDoc<WsdlModeler>> modelers;
34     
35     /** Creates a new instance of WsdlModelerFactory */
36     private WsdlModelerFactory() {
37         modelers = new WeakHashMap JavaDoc<URL JavaDoc, WeakReference JavaDoc<WsdlModeler>>(5);
38     }
39     
40     /**
41     * Accessor method for WsdlModelerFactory singleton
42     * @return WsdlModelerFactory object
43     */

44     public static synchronized WsdlModelerFactory getDefault() {
45         if (factory==null) factory = new WsdlModelerFactory();
46         return factory;
47     }
48     
49     /** Get WsdlModeler for particular WSDL
50      */

51     public WsdlModeler getWsdlModeler(URL JavaDoc wsdlUrl) {
52         WsdlModeler modeler = null;
53         synchronized (modelers) {
54             modeler = getFromCache(wsdlUrl);
55             if (modeler!=null) {
56                 return modeler;
57             }
58             modeler = new WsdlModeler(wsdlUrl);
59             modelers.put(wsdlUrl, new WeakReference JavaDoc<WsdlModeler>(modeler));
60         }
61         return modeler;
62     }
63     
64     private WsdlModeler getFromCache (URL JavaDoc url) {
65         if (url == null) {
66             return null;
67         }
68         WeakReference JavaDoc wr = modelers.get(url);
69         if (wr == null) {
70             return null;
71         }
72         WsdlModeler modeler = (WsdlModeler) wr.get();
73         if (modeler == null) {
74             modelers.remove(url);
75         }
76         return modeler;
77     }
78     
79     int mapLength() {
80         return modelers.size();
81     }
82     
83     
84 }
85
Popular Tags