1 19 20 21 package org.netbeans.modules.search.types; 22 23 24 import java.io.IOException ; 25 import java.io.ObjectInputStream ; 26 import java.io.ObjectOutputStream ; 27 import java.io.ObjectStreamField ; 28 import java.util.ArrayList ; 29 import java.util.Iterator ; 30 import java.util.List ; 31 32 import org.openide.loaders.DataObject; 33 import org.openide.util.HelpCtx; 34 import org.openide.util.NbBundle; 35 36 37 43 public class ObjectTypeType extends DataObjectType { 44 45 private static final long serialVersionUID = 1L; 46 48 49 private static final String NAMES_FIELD = "classNames"; 51 52 private static final ObjectStreamField [] serialPersistentFields 53 = {new ObjectStreamField (NAMES_FIELD, List .class)}; 54 55 56 private transient Class [] mask = new Class [0]; 57 58 59 61 protected String displayName() { 62 67 68 return NbBundle.getMessage(ObjectTypeType.class, 69 "TEXT_OBJECTTYPE_CRITERION"); } 71 72 73 public boolean testDataObject(DataObject dataObject) { 74 Class ld = dataObject.getLoader().getClass(); 75 76 for (int i = 0; i < mask.length; i++) { 77 if (mask[i].isAssignableFrom(ld)) { 78 return true; 79 } 80 } 81 82 return false; 83 } 84 85 86 public void setMask(Class [] mask) { 87 this.mask = mask; 88 firePropertyChange("mask", null, null); 90 setValid(this.mask.length != 0); 91 } 92 93 94 public Class [] getMask() { 95 return mask; 96 } 97 98 99 public void setMask(int i, Class m) { 100 mask[i] = m; 101 firePropertyChange("mask", null, null); setValid(true); 103 } 104 105 106 public Class getMask(int i) { 107 return mask[i]; 108 } 109 110 112 public HelpCtx getHelpCtx() { 113 return new HelpCtx(ObjectTypeType.class); 114 } 115 116 117 private void writeObject(ObjectOutputStream out) throws IOException { 118 List classNames = new ArrayList (mask == null ? 0 : mask.length); 119 120 if (mask != null) { 121 for (int i = 0; i < mask.length; i++) { 122 if (mask[i] == null) { 123 continue; 124 } 125 126 classNames.add(mask[i].getName()); 127 } 128 } 129 130 out.putFields().put(NAMES_FIELD, classNames); 131 out.writeFields(); 132 } 133 134 135 private void readObject(ObjectInputStream in) 136 throws IOException , ClassNotFoundException { 137 List classNames = (List ) in.readFields().get(NAMES_FIELD, new ArrayList ()); 138 139 List classes = new ArrayList (classNames.size()); 141 ClassLoader classLoader = (ClassLoader ) 142 org.openide.util.Lookup.getDefault() 143 .lookup(ClassLoader .class); 144 145 Iterator it = classNames.iterator(); 146 while (it.hasNext()) { 147 try { 148 classes.add(Class.forName((String ) it.next(), 149 false, 150 classLoader)); 151 } catch (ClassNotFoundException cnfe) { 152 cnfe.printStackTrace(); 153 } 154 } 155 156 mask = new Class [classes.size()]; 157 classes.toArray(mask); 158 159 setValid(false); 160 } 161 162 } 163 | Popular Tags |