View Javadoc

1   /*
2    * Copyright 2004-2006 the Seasar Foundation and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.seasar.tuigwaa.util.ajax;
17  
18  import java.util.HashSet;
19  import java.util.Iterator;
20  import java.util.Set;
21  
22  public class SharedObjects {
23  
24  	private Set objects = new HashSet();
25  
26  	public int size(){
27  		synchronized (objects) {	
28  			return objects.size();
29  		}
30  	}
31  	
32  	public void addObject(Ajaxlizable obj) {
33  		synchronized (objects) {
34  			objects.add(obj);
35  			obj.setSharedObject(this);
36  		}
37  	}
38  
39  	public void removeObject(Ajaxlizable obj) {
40  		synchronized (objects) {
41  			objects.remove(obj);
42  		}
43  	}
44  
45  	public void addEvent(AjaxEvent event, Object fromObj) {
46  		synchronized (objects) {
47  			Iterator itr = objects.iterator();
48  			while (itr.hasNext()) {
49  				Ajaxlizable obj = (Ajaxlizable) itr.next();
50  				if (!obj.equals(fromObj)) {
51  					obj.addEvent(event);
52  				}
53  			}
54  		}
55  	}
56  }