001    package org.mesopotamia.lang.java;
002    
003    import java.util.List;
004    
005    import org.mesopotamia.MesopotamiaException;
006    import org.mesopotamia.NodeData;
007    import org.mesopotamia.RepositoryLanguage;
008    import org.mesopotamia.Scan;
009    import org.w3c.dom.Element;
010    
011    import biz.hammurapi.util.CollectionVisitable;
012    import biz.hammurapi.util.Visitable;
013    import biz.hammurapi.util.Visitor;
014    
015    public class TryBlock extends JavaLanguageElement implements Statement {
016    
017            public TryBlock(NodeData xData, Class<?> context, Scan scan,
018                            RepositoryLanguage language, Object environment) throws MesopotamiaException {
019                    super(xData, context, scan, language, environment);
020    
021                    // Select attributes
022                    CompoundStatement = selectSingleElement(CompoundStatement.class, "SLIST");
023                    Handlers = select(Handler.class, "LITERAL_catch");
024                    FinallyClause = selectSingleElement(CompoundStatement.class,
025                                    "LITERAL_finally/SLIST");
026    
027            }
028    
029            public void toDom(Element holder) {
030                    super.toDom(holder);
031    
032                    // Serialize attributes
033                    setElement(holder, "CompoundStatement", CompoundStatement);
034                    setElement(holder, "Handlers", Handlers);
035                    setElement(holder, "FinallyClause", FinallyClause);
036            }
037    
038            // Attributes
039            private CompoundStatement CompoundStatement;
040    
041            private List<Handler> Handlers;
042    
043            private CompoundStatement FinallyClause;
044    
045            // Accessors
046            public CompoundStatement getCompoundStatement() {
047                    return CompoundStatement;
048            }
049    
050            public List<Handler> getHandlers() {
051                    return Handlers;
052            }
053    
054            public CompoundStatement getFinallyClause() {
055                    return FinallyClause;
056            }
057    
058            protected void acceptChildren(Visitor visitor) {
059                    super.acceptChildren(visitor);
060                    // Visiting non-text attributes
061                    if (CompoundStatement instanceof Visitable) {
062                            ((Visitable) CompoundStatement).accept(visitor);
063                    }
064                    new CollectionVisitable(Handlers, false).accept(visitor);
065                    if (FinallyClause instanceof Visitable) {
066                            ((Visitable) FinallyClause).accept(visitor);
067                    }
068            }
069    
070    }