• R/O
  • SSH
  • HTTPS

maskat: Commit


Commit MetaInfo

Révision108 (tree)
l'heure2009-03-03 11:45:45
Auteurkazatoh

Message de Log

マスカットIDE 2.0.0 のソースフォルダに合わせてリソースを移動

Change Summary

Modification

--- maskat-ide/trunk/org.maskat.core/src/org/maskat/core/event/EventDef.java (nonexistent)
+++ maskat-ide/trunk/org.maskat.core/src/org/maskat/core/event/EventDef.java (revision 108)
@@ -0,0 +1,330 @@
1+/*
2+ * Copyright 2006 Maskat Project.
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, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+package org.maskat.core.event;
17+
18+import java.util.ArrayList;
19+import java.util.HashMap;
20+import java.util.HashSet;
21+import java.util.Iterator;
22+import java.util.List;
23+import java.util.Map;
24+import java.util.Set;
25+
26+import org.maskat.core.AbstractMaskatElement;
27+import org.maskat.core.DefChildIterator;
28+
29+/**
30+ * The instance of this class represents the "eventDef" node of the event
31+ * definition file.
32+ *
33+ * @author shengshen
34+ *
35+ */
36+public class EventDef extends AbstractMaskatElement {
37+ private String id;
38+
39+ private RemoteUrl remoteUrl;
40+
41+ private Map headers;
42+
43+ private Map events;
44+
45+ private Map eventRefs;
46+
47+ private Map components;
48+
49+ /**
50+ * Check if there are "equal" events, put them into eventRef
51+ *
52+ */
53+ public void shrinkEvent() {
54+ List eventList = new ArrayList();
55+ int refId = 1;// Increasing refId
56+ // Loop all the events
57+ if (this.getUnmodifiableChildren() == null)
58+ return;
59+
60+ Iterator childrenIt = this.getUnmodifiableChildren().iterator();
61+ while (childrenIt.hasNext()) {
62+ Object child = childrenIt.next();
63+ if (child instanceof Component) {
64+ Component comp = (Component) child;
65+ Iterator it = comp.getUnmodifiableChildren().iterator();
66+ while (it.hasNext()) {
67+ Object compChild = it.next();
68+ if (compChild instanceof Event) {
69+ refId = processOneEvent(eventList, refId, (Event) compChild);
70+ }
71+ }
72+ }
73+ }
74+ }
75+
76+ private int processOneEvent(List eventList, int refId, Event temp) {
77+ // put the event into a list
78+ int idx = eventList.indexOf(temp);
79+ if (idx != -1) {
80+ Event existed = (Event) eventList.get(idx);
81+ existed.removeAllChildren();
82+ if (existed.getRef() != null) {
83+ // There is already one eventRef.
84+ temp.setRef(existed.getRef());
85+ } else {
86+ String ref = "ref" + (refId++);
87+ existed.setRef(ref);
88+ temp.setRef(ref);
89+ EventRef eventRef = new EventRef();
90+ eventRef.setRefid(ref);
91+ Iterator childrenIt = temp.getUnmodifiableChildren().iterator();
92+ while (childrenIt.hasNext()) {
93+ eventRef.addChild(childrenIt.next());
94+ }
95+ // Add a eventRef to the Layout
96+ this.addChild(eventRef);
97+ }
98+ temp.removeAllChildren();
99+ } else {
100+ eventList.add(temp);
101+ temp.setRef(null);
102+ if (eventRefs != null && eventRefs.values() != null) {
103+ Iterator it = this.eventRefs.values().iterator();
104+ while (it.hasNext()) {
105+ EventRef eventRef = (EventRef) it.next();
106+ if (eventRef.contentEquals(temp)) {
107+ temp.setRef(eventRef.getRefid());
108+ temp.removeAllChildren();
109+ }
110+ }
111+ }
112+ }
113+ return refId;
114+ }
115+
116+ /**
117+ * �C�x���g��`XML�ɎQ�Ƃ�����ʃI�u�W�F�N�g���̏W�����擾<br>
118+ */
119+ public Set getAllObjNames() {
120+ Set result = new HashSet();
121+ if (events != null) {
122+ for (Iterator it = events.values().iterator(); it != null && it.hasNext();) {
123+ Event event = (Event) it.next();
124+ event.getRelatedObjNames(result);
125+ }
126+ }
127+ if (eventRefs != null) {
128+ for (Iterator it = eventRefs.values().iterator(); it != null && it.hasNext();) {
129+ EventRef event = (EventRef) it.next();
130+ event.getRelatedObjNames(result);
131+ }
132+ }
133+ if (components != null) {
134+ for (Iterator it = components.values().iterator(); it != null && it.hasNext();) {
135+ Component component = (Component) it.next();
136+ for (Iterator it2 = component.getAllEvents(); it2 != null
137+ && it2.hasNext();) {
138+ Event event = (Event) it2.next();
139+ event.getRelatedObjNames(result);
140+ }
141+ }
142+ }
143+
144+ return result;
145+ }
146+
147+ public void addChild(Object child) {
148+ super.addChild(child);
149+ if (child instanceof Component) {
150+ addComponent((Component) child);
151+ }
152+ if (child instanceof Header) {
153+ addHeader((Header) child);
154+ }
155+ if (child instanceof Event) {
156+ addEvent((Event) child);
157+ }
158+ if (child instanceof RemoteUrl) {
159+ remoteUrl = (RemoteUrl) child;
160+ }
161+ }
162+
163+ private void addComponent(Component comp) {
164+ if (comp == null || comp.getId() == null) {
165+ throw new IllegalArgumentException();
166+ }
167+ if (components == null)
168+ components = new HashMap();
169+ components.put(comp.getId(), comp);
170+ }
171+
172+ private void addHeader(Header header) {
173+ if (header == null || header.getName() == null) {
174+ throw new IllegalArgumentException();
175+ }
176+ if (headers == null)
177+ headers = new HashMap();
178+ headers.put(header.getName(), header);
179+ }
180+
181+ public String getId() {
182+ return id;
183+ }
184+
185+ public void setId(String id) {
186+ this.id = id;
187+ }
188+
189+ public String getRemoteUrl() {
190+ if (remoteUrl == null)
191+ return null;
192+ return remoteUrl.getUrl();
193+ }
194+
195+ public void setRemoteUrl(String remoteUrl) {
196+ if (this.remoteUrl == null)
197+ addChild(new RemoteUrl());
198+ this.remoteUrl.setUrl(remoteUrl);
199+ }
200+
201+ public Component findComponent(String id) {
202+ if (components == null) {
203+ return null;
204+ }
205+ return (Component) components.get(id);
206+ }
207+
208+ public Iterator getAllComponents() {
209+ if (components == null) {
210+ return null;
211+ }
212+ return new DefChildIterator(this, components.values().iterator());
213+ }
214+
215+ public boolean hasComponents() {
216+ if (components == null || components.size() == 0) {
217+ return false;
218+ }
219+ return true;
220+ }
221+
222+ public Header findHeader(String name) {
223+ if (headers == null) {
224+ return null;
225+ }
226+ return (Header) headers.get(name);
227+ }
228+
229+ public Iterator getAllHeaders() {
230+ if (headers == null) {
231+ return null;
232+ }
233+ return new DefChildIterator(this, headers.values().iterator());
234+ }
235+
236+ public boolean hasHeaders() {
237+ if (headers == null || headers.size() == 0) {
238+ return false;
239+ }
240+ return true;
241+ }
242+
243+ private void addEvent(Event event) {
244+ if (event instanceof EventRef) {
245+ EventRef er = (EventRef) event;
246+ if (eventRefs == null) {
247+ eventRefs = new HashMap();
248+ }
249+ eventRefs.put(er.getRefid(), er);
250+ return;
251+ }
252+ // event��`
253+ if (this.events == null) {
254+ events = new HashMap();
255+ }
256+ events.put(event.getId(), event);
257+
258+ }
259+
260+ public Event findEvent(String id) {
261+ if (events == null) {
262+ return null;
263+ }
264+ return (Event) events.get(id);
265+ }
266+
267+ public void removeEvent(String id) {
268+ if (events == null) {
269+ return;
270+ }
271+ events.remove(id);
272+ }
273+
274+ public Iterator getAllEvents() {
275+ if (events == null) {
276+ return null;
277+ }
278+ return new DefChildIterator(this, events.values().iterator());
279+ }
280+
281+ // public void addEventEntity(EventEntity eventEntity) {
282+ // if (eventRefs == null)
283+ // eventRefs = new HashMap();
284+ // eventRefs.put(eventEntity.getRefid(), eventEntity);
285+ // }
286+
287+ public Event findEventRef(String id) {
288+ if (eventRefs == null) {
289+ return null;
290+ }
291+ return (Event) eventRefs.get(id);
292+ }
293+
294+ public Iterator getAllEventRefs() {
295+ if (eventRefs == null) {
296+ return null;
297+ }
298+ return new DefChildIterator(this, eventRefs.values().iterator());
299+ }
300+
301+ /**
302+ * Set the children of eventRef to the event that refers to it. For all
303+ * event that have no param, add one param to it with enabled=false. For all
304+ * event that have no result, add one result to it with enabled=false.
305+ */
306+ public void prepareEvent() {
307+ // result�ɂ���component/event��eventEntity�̕]��(ref������event)
308+ Iterator compIt = getAllComponents();
309+ while (compIt != null && compIt.hasNext()) {
310+ Component comp = (Component) compIt.next();
311+ Iterator eventIt = comp.getAllEvents();
312+ while (eventIt != null && eventIt.hasNext()) {
313+ Event event = (Event) eventIt.next();
314+ if (event.getRef() != null) {
315+ Event evtRef = findEventRef(event.getRef());
316+ if (evtRef != null) {
317+ // ref�Q�Ƃ���ꍇ�A�q�v�f�𖳎�
318+ event.removeAllChildren();
319+ // evtRef�̎q�v�f��event�ɃR�s�[
320+ for (Iterator it = evtRef.getAllChildren(); it != null
321+ && it.hasNext();) {
322+ event.addChild(it.next());
323+ }
324+ }
325+ }
326+ }
327+ }
328+ }
329+
330+}
Afficher sur ancien navigateur de dépôt.