View Javadoc
1   /******************************************************************************
2    * MetaSetChangeAuditor - Listen for changes to sets in case a MetaSet has changed.
3    * 
4    * PicMan - The BuckoSoft Picture Manager in Java
5    * Copyright(c) 2011 - Dick Balaska
6    * 
7    */
8   package com.buckosoft.PicMan.business;
9   
10  import java.util.List;
11  
12  import org.apache.commons.logging.Log;
13  import org.apache.commons.logging.LogFactory;
14  
15  import com.buckosoft.PicMan.domain.MetaSet;
16  import com.buckosoft.PicMan.domain.MetaSetRule;
17  import com.buckosoft.PicMan.domain.Set;
18  import com.buckosoft.PicMan.domain.SetSize;
19  
20  /** Listen for changes to sets in case a MetaSet has changed.
21   * @author Dick Balaska
22   * @since 2011/12/30
23   * @version $Revision: 1.1 $ <br> $Date: 2013/12/26 01:26:08 $
24   * @see <a href="http://cvs.buckosoft.com/Projects/java/PicMan/PicMan/src/com/buckosoft/PicMan/business/MetaSetChangeAuditor.java">MetaSetChangeAuditor.java</a>
25   */
26  public class MetaSetChangeAuditor implements SetChangedListener {
27  
28  	protected final Log logger = LogFactory.getLog(getClass());
29  
30  	private	PicManFacade	pmf;
31  
32  	/** Set the reference to the PicMan API.
33  	 * @param pmf The PicManFacade
34  	 */
35  	public	void setPicMan(PicManFacade pmf) {
36  		this.pmf = pmf;
37  		this.pmf.addSetChangedListener(this);
38  	}
39  
40  	/** If a set has changed, perhaps any MetaSets that reference this set have also changed.
41  	 * @param ss The SetSize that is changing.
42  	 */
43  	@Override
44  	public void onSetChanged(SetSize ss) {
45  		List<Set> list = this.pmf.getDB().getSets();
46  		for (Set set : list) {
47  			if (set.isMetaSet()) {
48  				MetaSet ms = pmf.getDB().getMetaSet(set.getSid());
49  				for (MetaSetRule msr : ms.getRules()) {
50  					if (msr.getType() == MetaSet.NAME) {
51  						if (msr.getValue().equals(ss.getSetName())) {
52  							logger.info("MetaSet changed: " + set.getName());
53  							SetSize mss = new SetSize(set.getName(), ss.getSize());
54  							pmf.fireSetSizeChanged(mss);
55  							break;
56  						}
57  					}
58  				}
59  			}
60  		}
61  	}
62  
63  }