View Javadoc

1   package fr.in2p3.jsaga.impl.url;
2   
3   import fr.in2p3.jsaga.EngineProperties;
4   import fr.in2p3.jsaga.adaptor.data.read.FileAttributes;
5   import fr.in2p3.jsaga.impl.AbstractSagaObjectImpl;
6   import org.ogf.saga.SagaObject;
7   import org.ogf.saga.error.BadParameterException;
8   import org.ogf.saga.error.NoSuccessException;
9   import org.ogf.saga.session.Session;
10  import org.ogf.saga.url.URL;
11  
12  /* ***************************************************
13  * *** Centre de Calcul de l'IN2P3 - Lyon (France) ***
14  * ***             http://cc.in2p3.fr/             ***
15  * ***************************************************
16  * File:   RelativeURLImpl
17  * Author: Lionel Schwarz (lionel.schwarz@in2p3.fr)
18  * Date:   4 fév 2011
19  * ***************************************************
20  * Description:                                      */
21  /**
22   *
23   */
24  public abstract class AbstractURLImpl extends AbstractSagaObjectImpl implements URL {
25  
26      protected FileAttributes m_cache;
27      protected long m_cache_creation_time;
28  	
29  	AbstractURLImpl() throws BadParameterException {
30  	}
31  
32      public SagaObject clone() throws CloneNotSupportedException {
33      	AbstractURLImpl clone = (AbstractURLImpl) super.clone();
34          clone.m_cache = m_cache;
35          clone.m_cache_creation_time = m_cache_creation_time;
36          return clone;
37      }
38  
39      /** Encode the relative path + set the cache */
40  	/*AbstractURLImpl(FileAttributes cache) throws BadParameterException {
41          this(cache.getRelativePath());
42          m_cache = cache;
43      }*/
44  
45      public abstract URL resolve(URL url) throws NoSuccessException ;
46  
47  	public abstract void setString(String url) throws BadParameterException;
48  
49  	public void setString() throws BadParameterException {
50  		this.setString(null);
51  	}
52  
53  	public abstract String getString() ;
54  
55  	public abstract String getEscaped() ;
56  
57  	public abstract String getFragment() ;
58  
59  	public abstract void setFragment(String fragment) throws BadParameterException ;
60  
61  	public void setFragment() throws BadParameterException {
62  		this.setFragment(null);
63  	}
64  
65  	public abstract String getHost() ;
66  
67  	public abstract void setHost(String host) throws BadParameterException ;
68  
69  	public void setHost() throws BadParameterException {
70  		this.setHost(null);
71  	}
72  
73  	public abstract String getPath() ;
74  
75  	public abstract void setPath(String path) throws BadParameterException ;
76  
77  	public void setPath() throws BadParameterException {
78  		this.setPath(null);
79  	}
80  
81  	public abstract int getPort() ;
82  
83  	public abstract void setPort(int port) throws BadParameterException ;
84  
85  	public void setPort() throws BadParameterException {
86  		this.setPort(-1);
87  	}
88  
89  	public abstract String getQuery() ;
90  
91  	public abstract void setQuery(String query) throws BadParameterException ;
92  
93  	public void setQuery() throws BadParameterException {
94  		this.setQuery(null);
95  	}
96  
97  	public abstract String getScheme();
98  
99  	public abstract void setScheme(String scheme) throws BadParameterException ;
100 
101 	public void setScheme() throws BadParameterException {
102 		this.setScheme(null);
103 	}
104 
105 	public abstract String getUserInfo() ;
106 
107 	public abstract void setUserInfo(String userInfo) throws BadParameterException ;
108 
109 	public void setUserInfo() throws BadParameterException {
110 		this.setUserInfo(null);
111 	}
112 
113 	public abstract URL translate(String scheme) throws BadParameterException,	NoSuccessException ;
114 
115 	public URL translate(Session session, String scheme) throws BadParameterException, NoSuccessException {
116 		return this.translate(scheme);
117 	}
118 
119 	public abstract boolean isAbsolute() ;
120 
121 	public abstract URL normalize() ;
122 	
123     ////////////////////////////////////////// cache methods //////////////////////////////////////////
124 
125     public void setCache(FileAttributes cache) {
126         m_cache = cache;
127         this.m_cache_creation_time = System.currentTimeMillis();
128     }
129 
130     public FileAttributes getCache() {
131         return m_cache;
132     }
133 
134     public boolean hasCache() {
135     	if (this.m_cache == null) return false;
136     	return (System.currentTimeMillis() - this.m_cache_creation_time
137     			< EngineProperties.getInteger(EngineProperties.DATA_ATTRIBUTES_CACHE_LIFETIME).longValue());
138     }
139 
140 
141 }