1 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 32 public class MDRDescriptor extends Object { 33 34 private static final HashMap repositories = new HashMap(); 35 36 private final String className; 37 private final Map parameters; 38 39 40 public MDRDescriptor(String 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 repClass = Class.forName(className); 51 try { 52 Constructor c = repClass.getConstructor(new Class [] {Map.class}); 53 result = (MDRepository) c.newInstance(new Object [] {parameters}); 54 } catch (NoSuchMethodException e) { 55 result = (MDRepository) repClass.newInstance(); 56 } 57 repositories.put(this, result); 58 } catch (Exception e) { 59 Logger.getDefault().notify(Logger.INFORMATIONAL, e); 61 return null; 62 } 63 } 64 65 return result; 66 } 67 68 public boolean equals(Object 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 |