1 19 20 21 package org.netbeans.modules.i18n; 22 23 24 import java.io.IOException ; 25 import java.util.Arrays ; 26 27 import org.openide.loaders.DataObject; 28 29 38 public abstract class ResourceHolder { 39 40 41 protected DataObject resource; 42 43 44 protected final Class [] resourceClasses; 45 46 47 48 public ResourceHolder(Class [] resourceClasses) { 49 if(resourceClasses == null || resourceClasses.length == 0) 50 throw new IllegalArgumentException (); 51 52 this.resourceClasses = resourceClasses; 53 } 54 55 56 57 public void setResource(DataObject resource) { 58 if (resource == null) { 59 this.resource = null; 60 return; 61 } 62 63 Class clazz = resource.getClass(); 64 65 if(!Arrays.asList(resourceClasses).contains(clazz)) 67 throw new IllegalArgumentException (); 68 69 if(!resource.equals(this.resource)) 70 this.resource = resource; 71 } 72 73 74 public DataObject getResource() { 75 return resource; 76 } 77 78 79 public Class [] getResourceClasses() { 80 return resourceClasses; 81 } 82 83 84 public abstract String [] getAllKeys(); 85 86 88 public abstract String getValueForKey(String key); 89 90 92 public abstract String getCommentForKey(String key); 93 94 98 public void addProperty(Object key, Object value, String comment) { 99 boolean overwriteValues = I18nUtil.getOptions().isReplaceResourceValue(); 100 addProperty(key, value, comment, overwriteValues); 101 } 102 103 105 public abstract void addProperty(Object key, Object value, String comment, boolean forceNewValue); 106 107 109 public final DataObject getTemplate(Class clazz) throws IOException { 110 if(!Arrays.asList(resourceClasses).contains(clazz)) 111 throw new IllegalArgumentException (); 112 113 return createTemplate(clazz); 114 } 115 116 117 protected abstract DataObject createTemplate(Class clazz) throws IOException ; 118 119 } 120 121 | Popular Tags |