1 5 package net.nutch.plugin; 6 import java.util.HashMap ; 7 14 public class Extension { 15 private PluginDescriptor fDescriptor; 16 private String fId; 17 private String fTargetPoint; 18 private String fClazz; 19 private HashMap fAttributes; 20 28 public Extension(PluginDescriptor pDescriptor, String pExtensionPoint, 29 String pId, String pExtensionClass) { 30 fAttributes = new HashMap (); 31 setDiscriptor(pDescriptor); 32 setExtensionPoint(pExtensionPoint); 33 setId(pId); 34 setClazz(pExtensionClass); 35 } 36 39 private void setExtensionPoint(String point) { 40 fTargetPoint = point; 41 } 42 50 public String getAttribute(String pKey) { 51 return (String ) fAttributes.get(pKey); 52 } 53 58 public String getClazz() { 59 return fClazz; 60 } 61 66 public String getId() { 67 return fId; 68 } 69 78 public void addAttribute(String pKey, String pValue) { 79 fAttributes.put(pKey, pValue); 80 } 81 88 public void setClazz(String extensionClazz) { 89 fClazz = extensionClazz; 90 } 91 98 public void setId(String extensionID) { 99 fId = extensionID; 100 } 101 105 public String getTargetPoint() { 106 return fTargetPoint; 107 } 108 119 public Object getExtensionInstance() throws PluginRuntimeException { 120 synchronized (getId()) { 126 try { 127 PluginClassLoader loader = fDescriptor.getClassLoader(); 128 Class extensionClazz = loader.loadClass(getClazz()); 129 PluginRepository.getInstance().getPluginInstance(getDiscriptor()); 132 Object object = extensionClazz.newInstance(); 133 return object; 134 } catch (ClassNotFoundException e) { 135 throw new PluginRuntimeException(e); 136 } catch (InstantiationException e) { 137 throw new PluginRuntimeException(e); 138 } catch (IllegalAccessException e) { 139 throw new PluginRuntimeException(e); 140 } 141 } 142 } 143 148 public PluginDescriptor getDiscriptor() { 149 return fDescriptor; 150 } 151 157 public void setDiscriptor(PluginDescriptor pDescriptor) { 158 fDescriptor = pDescriptor; 159 } 160 } 161 | Popular Tags |