1   package com.trendmicro.grid.acl.ds.dummy;
2   
3   import com.trendmicro.grid.acl.ds.SourceDomainRepository;
4   import com.trendmicro.grid.acl.ds.datatypes.SharedSourceDomain;
5   import com.trendmicro.grid.acl.ds.datatypes.SharedSourceDomainListPage;
6   import com.trendmicro.grid.acl.l0.datatypes.SourceDomain;
7   import net.sf.tinyjee.concurrent.LockingMap;
8   import org.springframework.stereotype.Repository;
9   
10  import java.util.Map;
11  
12  /**
13   * Implements a dummy in-memory repository for sources-domains.
14   *
15   * @author juergen_kellerer, 2010-05-07
16   * @version 1.0
17   */
18  @Repository
19  public class DummySourceDomainRepository implements SourceDomainRepository {
20  
21  	Map<String, SharedSourceDomain> domains = new LockingMap<String, SharedSourceDomain>();
22  
23  	/**
24  	 * {@inheritDoc}
25  	 */
26  	public SharedSourceDomainListPage getAllPaged(int pageNumber) {
27  		return pageNumber > 0 ? null : new SharedSourceDomainListPage(0, true, domains.values());
28  	}
29  
30  	/**
31  	 * {@inheritDoc}
32  	 */
33  	public SharedSourceDomain getByName(String domainName) {
34  		return domains.get(domainName);
35  	}
36  
37  	/**
38  	 * {@inheritDoc}
39  	 */
40  	public SharedSourceDomain getOrCreate(String domainName) {
41  		SharedSourceDomain domain = null;
42  		if (domainName != null && !domainName.isEmpty()) {
43  			domain = getByName(domainName);
44  			if (domain == null)
45  				createOrUpdate(domain = new SharedSourceDomain(domainName, null));
46  		}
47  		return domain;
48  	}
49  
50  	/**
51  	 * {@inheritDoc}
52  	 */
53  	public void createOrUpdate(SourceDomain domain) {
54  		domains.put(domain.getName(), new SharedSourceDomain(domain.getName(), domain.getMetadata()));
55  	}
56  }