1 package fr.jayasoft.ivy.repository; 2 3 4 public abstract class LazyResource implements Resource { 5 private boolean _init = false; 6 7 private boolean _local; 8 private String _name; 9 private long _lastModified; 10 private long _contentLength; 11 private boolean _exists; 12 13 14 public LazyResource(String name) { 15 _name = name; 16 } 17 18 protected abstract void init(); 19 20 private void checkInit() { 21 if (!_init) { 22 init(); 23 _init = true; 24 } 25 } 26 27 public boolean exists() { 28 checkInit(); 29 return _exists; 30 } 31 32 public long getContentLength() { 33 checkInit(); 34 return _contentLength; 35 } 36 37 public long getLastModified() { 38 checkInit(); 39 return _lastModified; 40 } 41 42 public String getName() { 43 return _name; 44 } 45 46 public boolean isLocal() { 47 checkInit(); 48 return _local; 49 } 50 51 public String toString() { 52 return getName(); 53 } 54 55 protected void setContentLength(long contentLength) { 56 _contentLength = contentLength; 57 } 58 59 protected void setExists(boolean exists) { 60 _exists = exists; 61 } 62 63 protected void setLastModified(long lastModified) { 64 _lastModified = lastModified; 65 } 66 67 protected void setLocal(boolean local) { 68 _local = local; 69 } 70 71 protected void init(Resource r) { 72 setContentLength(r.getContentLength()); 73 setLocal(r.isLocal()); 74 setLastModified(r.getLastModified()); 75 setExists(r.exists()); 76 } 77 78 79 } 80 | Popular Tags |