ReadOnlyLocation.java 720 B

12345678910111213141516171819202122232425262728293031323334
  1. // Copyright (c) 2005 Per M.A. Bothner.
  2. // This is free software; for terms and warranty disclaimer see ./COPYING.
  3. package gnu.mapping;
  4. public class ReadOnlyLocation extends ConstrainedLocation
  5. {
  6. public static ReadOnlyLocation make (Location base)
  7. {
  8. ReadOnlyLocation rloc = new ReadOnlyLocation();
  9. rloc.base = base;
  10. return rloc;
  11. }
  12. public boolean isConstant ()
  13. {
  14. return true;
  15. }
  16. protected Object coerce (Object newValue)
  17. {
  18. StringBuffer sbuf
  19. = new StringBuffer("attempt to modify read-only location");
  20. Symbol name = getKeySymbol();
  21. if (name != null)
  22. {
  23. sbuf.append(": ");
  24. sbuf.append(name);
  25. }
  26. throw new IllegalStateException(sbuf.toString());
  27. }
  28. }