1   package com.trendmicro.grid.acl.ds.dummy;
2   
3   import com.trendmicro.grid.acl.ds.VendorRepository;
4   import com.trendmicro.grid.acl.ds.datatypes.SharedVendor;
5   import com.trendmicro.grid.acl.l0.datatypes.NameListPage;
6   import com.trendmicro.grid.acl.l0.datatypes.Vendor;
7   import com.trendmicro.grid.acl.metadata.Metadata;
8   import net.sf.tinyjee.concurrent.LockingMap;
9   import org.springframework.stereotype.Repository;
10  
11  import java.util.Date;
12  import java.util.Map;
13  
14  /**
15   * Implements a dummy in-memory provider for vendors.
16   *
17   * @author juergen_kellerer, 2010-05-07
18   * @version 1.0
19   */
20  @Repository
21  public class DummyVendorRepository implements VendorRepository {
22  
23  	Map<String, SharedVendor> vendorMap = new LockingMap<String, SharedVendor>();
24  
25  	@Override
26  	public SharedVendor create(String name, String displayName, Metadata metadata) {
27  		SharedVendor v = new SharedVendor(name, displayName, new Date(), metadata);
28  		update(v);
29  		return v;
30  	}
31  
32  	@Override
33  	public void update(Vendor vendor) {
34  		final SharedVendor sharedVendor;
35  		if (vendor instanceof SharedVendor)
36  			sharedVendor = (SharedVendor) vendor;
37  		else
38  			sharedVendor = new SharedVendor(vendor.getName(), vendor.getDisplayName(), vendor.getFirstSeen(), vendor.getMetadata());
39  
40  		vendorMap.put(vendor.getName(), sharedVendor);
41  	}
42  
43  	@Override
44  	public SharedVendor getByName(String name) {
45  		return vendorMap.get(name);
46  	}
47  
48  	@Override
49  	public NameListPage listNames(int pageNumber) {
50  		return pageNumber > 0 ? null : new NameListPage(0, true, vendorMap.keySet());
51  	}
52  }