KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > mdr > MDRDescriptor


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 package org.netbeans.modules.mdr;
20
21 import java.lang.reflect.*;
22 import java.util.*;
23
24 import org.netbeans.api.mdr.*;
25 import org.netbeans.mdr.util.Logger;
26
27 /**
28  *
29  * @author mmatula
30  * @version
31  */

32 public class MDRDescriptor extends Object JavaDoc {
33
34     private static final HashMap repositories = new HashMap();
35
36     private final String JavaDoc className;
37     private final Map parameters;
38
39     /** Creates new MDRDescriptor */
40     public MDRDescriptor(String JavaDoc className, Map parameters) {
41         this.className = className;
42         this.parameters = parameters;
43     }
44     
45     public synchronized MDRepository getMDRInstance() {
46         MDRepository result = (MDRepository) repositories.get(this);
47         
48         if (result == null) {
49             try {
50                 Class JavaDoc repClass = Class.forName(className);
51                 try {
52                     Constructor c = repClass.getConstructor(new Class JavaDoc[] {Map.class});
53                     result = (MDRepository) c.newInstance(new Object JavaDoc[] {parameters});
54                 } catch (NoSuchMethodException JavaDoc e) {
55                     result = (MDRepository) repClass.newInstance();
56                 }
57                 repositories.put(this, result);
58             } catch (Exception JavaDoc e) {
59                 // [PENDING] exception should be trown here
60
Logger.getDefault().notify(Logger.INFORMATIONAL, e);
61                 return null;
62             }
63         }
64         
65         return result;
66     }
67     
68     public boolean equals(Object JavaDoc o) {
69         return (o instanceof MDRDescriptor) && parameters.equals(((MDRDescriptor) o).parameters) && className.equals(((MDRDescriptor) o).className);
70     }
71     
72     public int hashCode() {
73         return parameters.hashCode();
74     }
75 }
76
Popular Tags