1: 
  37: 
  38: package ;
  39: 
  40: import ;
  41: 
  42: 
  68: public final class AttributeSetUtilities
  69: {
  70:   
  73:   private AttributeSetUtilities() 
  74:   {
  75:     
  76:   }
  77: 
  78:   private static class UnmodifiableAttributeSet
  79:     implements AttributeSet, Serializable
  80:   {
  81:     private AttributeSet attrset;
  82: 
  83:     public UnmodifiableAttributeSet(AttributeSet attributeSet)
  84:     {
  85:       if (attributeSet == null)
  86:         throw new NullPointerException("attributeSet may not be null");
  87: 
  88:       this.attrset = attributeSet;
  89:     }
  90: 
  91:     public boolean add(Attribute attribute)
  92:     {
  93:       throw new UnmodifiableSetException();
  94:     }
  95: 
  96:     public boolean addAll(AttributeSet attributes)
  97:     {
  98:       throw new UnmodifiableSetException();
  99:     }
 100:     
 101:     public void clear()
 102:     {
 103:       throw new UnmodifiableSetException();
 104:     }
 105: 
 106:     public boolean containsKey(Class category)
 107:     {
 108:       return attrset.containsKey(category);
 109:     }
 110: 
 111:     public boolean containsValue(Attribute attribute)
 112:     {
 113:       return attrset.containsValue(attribute);
 114:     }
 115: 
 116:     public boolean equals(Object obj)
 117:     {
 118:       return attrset.equals(obj);
 119:     }
 120:     
 121:     public Attribute get(Class interfaceName)
 122:     {
 123:       return attrset.get(interfaceName);
 124:     }
 125: 
 126:     public int hashCode()
 127:     {
 128:       return attrset.hashCode();
 129:     }
 130:     
 131:     public boolean isEmpty()
 132:     {
 133:       return attrset.isEmpty();
 134:     }
 135: 
 136:     public boolean remove(Class category)
 137:     {
 138:       throw new UnmodifiableSetException();
 139:     }
 140: 
 141:     public boolean remove(Attribute attribute)
 142:     {
 143:       throw new UnmodifiableSetException();
 144:     }
 145: 
 146:     public int size()
 147:     {
 148:       return attrset.size();
 149:     }
 150: 
 151:     public Attribute[] toArray()
 152:     {
 153:       return attrset.toArray();
 154:     }
 155:   }
 156: 
 157:   private static class UnmodifiableDocAttributeSet
 158:     extends UnmodifiableAttributeSet
 159:     implements DocAttributeSet, Serializable
 160:   {
 161:     public UnmodifiableDocAttributeSet(DocAttributeSet attributeSet)
 162:     {
 163:       super(attributeSet);
 164:     }
 165:   }
 166: 
 167:   private static class UnmodifiablePrintJobAttributeSet
 168:     extends UnmodifiableAttributeSet
 169:     implements PrintJobAttributeSet, Serializable
 170:   {
 171:     public UnmodifiablePrintJobAttributeSet(PrintJobAttributeSet attributeSet)
 172:     {
 173:       super(attributeSet);
 174:     }
 175:   }
 176: 
 177:   private static class UnmodifiablePrintRequestAttributeSet
 178:     extends UnmodifiableAttributeSet
 179:     implements PrintRequestAttributeSet, Serializable
 180:   {
 181:     public UnmodifiablePrintRequestAttributeSet(PrintRequestAttributeSet attributeSet)
 182:     {
 183:       super(attributeSet);
 184:     }
 185:   }
 186: 
 187:   private static class UnmodifiablePrintServiceAttributeSet
 188:     extends UnmodifiableAttributeSet
 189:     implements PrintServiceAttributeSet, Serializable
 190:   {
 191:     public UnmodifiablePrintServiceAttributeSet(PrintServiceAttributeSet attributeSet)
 192:     {
 193:       super(attributeSet);
 194:     }
 195:   }
 196: 
 197:   private static class SynchronizedAttributeSet
 198:     implements AttributeSet, Serializable
 199:   {
 200:     private AttributeSet attrset;
 201: 
 202:     public SynchronizedAttributeSet(AttributeSet attributeSet)
 203:     {
 204:       if (attributeSet == null)
 205:         throw new NullPointerException("attributeSet may not be null");
 206: 
 207:       attrset = attributeSet;
 208:     }
 209: 
 210:     public synchronized boolean add(Attribute attribute)
 211:     {
 212:       return attrset.add(attribute);
 213:     }
 214: 
 215:     public synchronized boolean addAll(AttributeSet attributes)
 216:     {
 217:       return attrset.addAll(attributes);
 218:     }
 219:     
 220:     public synchronized void clear()
 221:     {
 222:       attrset.clear();
 223:     }
 224: 
 225:     public synchronized boolean containsKey(Class category)
 226:     {
 227:       return attrset.containsKey(category);
 228:     }
 229: 
 230:     public synchronized boolean containsValue(Attribute attribute)
 231:     {
 232:       return attrset.containsValue(attribute);
 233:     }
 234: 
 235:     public synchronized boolean equals(Object obj)
 236:     {
 237:       return attrset.equals(obj);
 238:     }
 239:     
 240:     public synchronized Attribute get(Class interfaceName)
 241:     {
 242:       return attrset.get(interfaceName);
 243:     }
 244: 
 245:     public synchronized int hashCode()
 246:     {
 247:       return attrset.hashCode();
 248:     }
 249:     
 250:     public synchronized boolean isEmpty()
 251:     {
 252:       return attrset.isEmpty();
 253:     }
 254: 
 255:     public synchronized boolean remove(Class category)
 256:     {
 257:       return attrset.remove(category);
 258:     }
 259: 
 260:     public synchronized boolean remove(Attribute attribute)
 261:     {
 262:       return attrset.remove(attribute);
 263:     }
 264: 
 265:     public synchronized int size()
 266:     {
 267:       return attrset.size();
 268:     }
 269: 
 270:     public synchronized Attribute[] toArray()
 271:     {
 272:       return attrset.toArray();
 273:     }
 274:   }
 275: 
 276:   private static class SynchronizedDocAttributeSet
 277:     extends SynchronizedAttributeSet
 278:     implements DocAttributeSet, Serializable
 279:   {
 280:     public SynchronizedDocAttributeSet(DocAttributeSet attributeSet)
 281:     {
 282:       super(attributeSet);
 283:     }
 284:   }
 285: 
 286:   private static class SynchronizedPrintJobAttributeSet
 287:     extends SynchronizedAttributeSet
 288:     implements PrintJobAttributeSet, Serializable
 289:   {
 290:     public SynchronizedPrintJobAttributeSet(PrintJobAttributeSet attributeSet)
 291:     {
 292:       super(attributeSet);
 293:     }
 294:   }
 295: 
 296:   private static class SynchronizedPrintRequestAttributeSet
 297:     extends SynchronizedAttributeSet
 298:     implements PrintRequestAttributeSet, Serializable
 299:   {
 300:     public SynchronizedPrintRequestAttributeSet(PrintRequestAttributeSet attributeSet)
 301:     {
 302:       super(attributeSet);
 303:     }
 304:   }
 305: 
 306:   private static class SynchronizedPrintServiceAttributeSet
 307:     extends SynchronizedAttributeSet
 308:     implements PrintServiceAttributeSet, Serializable
 309:   {
 310:     public SynchronizedPrintServiceAttributeSet(PrintServiceAttributeSet attributeSet)
 311:     {
 312:       super(attributeSet);
 313:     }
 314:   }
 315: 
 316:   
 322:   public static AttributeSet synchronizedView(AttributeSet attributeSet)
 323:   {
 324:     return new SynchronizedAttributeSet(attributeSet);
 325:   }
 326: 
 327:   
 333:   public static DocAttributeSet synchronizedView(DocAttributeSet attributeSet)
 334:   {
 335:     return new SynchronizedDocAttributeSet(attributeSet);
 336:   }
 337:   
 338:   
 344:   public static PrintJobAttributeSet synchronizedView(PrintJobAttributeSet attributeSet)
 345:   {
 346:     return new SynchronizedPrintJobAttributeSet(attributeSet);
 347:   }
 348:   
 349:   
 355:   public static PrintRequestAttributeSet synchronizedView(PrintRequestAttributeSet attributeSet)
 356:   {
 357:     return new SynchronizedPrintRequestAttributeSet(attributeSet);
 358:   }
 359:   
 360:   
 366:   public static PrintServiceAttributeSet synchronizedView(PrintServiceAttributeSet attributeSet)
 367:   {
 368:     return new SynchronizedPrintServiceAttributeSet(attributeSet);
 369:   }
 370:   
 371:   
 377:   public static AttributeSet unmodifiableView(AttributeSet attributeSet)
 378:   {
 379:     return new UnmodifiableAttributeSet(attributeSet);
 380:   }
 381:   
 382:   
 388:   public static DocAttributeSet unmodifiableView(DocAttributeSet attributeSet)
 389:   {
 390:     return new UnmodifiableDocAttributeSet(attributeSet);
 391:   }
 392:   
 393:   
 399:   public static PrintJobAttributeSet unmodifiableView(PrintJobAttributeSet attributeSet)
 400:   {
 401:     return new UnmodifiablePrintJobAttributeSet(attributeSet);
 402:   }
 403:   
 404:   
 410:   public static PrintRequestAttributeSet unmodifiableView(PrintRequestAttributeSet attributeSet)
 411:   {
 412:     return new UnmodifiablePrintRequestAttributeSet(attributeSet);
 413:   }
 414:   
 415:   
 421:   public static PrintServiceAttributeSet unmodifiableView(PrintServiceAttributeSet attributeSet)
 422:   {
 423:     return new UnmodifiablePrintServiceAttributeSet(attributeSet);
 424:   }
 425: 
 426:   
 438:   public static Class<?> verifyAttributeCategory(Object object,
 439:                                                  Class<?> interfaceName)
 440:   {
 441:     if (object == null)
 442:       throw new NullPointerException("object may not be null");
 443: 
 444:     Class clazz = (Class) object;
 445: 
 446:     if (interfaceName.isAssignableFrom(clazz))
 447:       return clazz;
 448: 
 449:     throw new ClassCastException();
 450:   }
 451:   
 452:   
 463:   public static Attribute verifyAttributeValue(Object object,
 464:                                                Class<?> interfaceName)
 465:   {
 466:     if (object == null)
 467:       throw new NullPointerException("object may not be null");
 468: 
 469:     if (interfaceName.isInstance(object))
 470:       return (Attribute) object;
 471: 
 472:     throw new ClassCastException();
 473:   }
 474: 
 475:   
 485:   public static void verifyCategoryForValue(Class<?> category,
 486:                                             Attribute attribute)
 487:   {
 488:     if (category == null || attribute == null)
 489:       throw new NullPointerException("category or attribute may not be null");
 490: 
 491:     if (!category.equals(attribute.getCategory()))
 492:       throw new IllegalArgumentException
 493:         ("category of attribute not equal to category");
 494:   }
 495: }