View Javadoc

1   /*
2    wsmo4j - a WSMO API and Reference Implementation
3    
4    Copyright (c) 2004-2005, OntoText Lab. / SIRMA
5    
6    This library is free software; you can redistribute it and/or modify it under
7    the terms of the GNU Lesser General Public License as published by the Free
8    Software Foundation; either version 2.1 of the License, or (at your option)
9    any later version.
10   This library is distributed in the hope that it will be useful, but WITHOUT
11   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12   FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13   details.
14   You should have received a copy of the GNU Lesser General Public License along
15   with this library; if not, write to the Free Software Foundation, Inc.,
16   59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17   */
18  
19  package com.ontotext.wsmo4j.serializer.wsml;
20  
21  /**
22   * <p>Title: WSMO4J</p>
23   * <p>Description: WSMO API and a Reference Implementation</p>
24   * <p>Copyright:  Copyright (c) 2004-2005</p>
25   * <p>Company: OntoText Lab. / SIRMA </p>
26   * @author not attributable
27   * @version 1.0
28   *
29   */
30  import org.wsmo.common.Entity;
31  import java.lang.ref.WeakReference;
32  import java.lang.reflect.*;
33  
34  
35  public class WSMLItem extends WeakReference implements Item2Visit {
36      public WSMLItem(Entity o) { super(o); }
37  
38      public void apply(Visitor visitor) {
39          Class[] oC = super.get().getClass().getInterfaces();
40          try {
41              for (int i = 0; i < oC.length; i++) {
42                  Method m = null;
43                  try {
44                      m = visitor.getClass().getMethod("visit", new Class[]{oC[i]});
45                  }
46                  catch (NoSuchMethodException nse) {
47                      continue;
48                  }
49                  if (m != null) {
50                      m.invoke(visitor, new Object[]{get()});
51                  }
52                  break;
53              }
54          }
55          catch (InvocationTargetException e) {
56              Throwable t = e.getCause();
57              if (t != null)
58                  throw new RuntimeException(t.getMessage(), t);
59              throw new RuntimeException(e);
60          }
61          catch (Exception e) {
62              throw new RuntimeException("in apply", e);
63          }
64  
65      }
66  }
67  
68  /*
69   * $Log$
70   * Revision 1.3  2006/03/24 15:31:19  vassil_momtchev
71   * message friendly handling of invocation exceptions added
72   *
73   * Revision 1.2  2005/11/28 14:51:37  vassil_momtchev
74   * moved from com.ontotext.wsmo4j.parser
75   *
76   * Revision 1.1.2.1  2005/11/28 13:59:35  vassil_momtchev
77   * package refactored from com.ontotext.wsmo4j.parser to com.ontotext.wsmo4j.serializer.wsml
78   *
79   * Revision 1.1  2005/06/27 08:32:00  alex_simov
80   * refactoring: *.io.parser -> *.parser
81   *
82   * Revision 1.4  2005/06/22 14:49:27  alex_simov
83   * Copyright header added/updated
84   *
85   * Revision 1.3  2005/06/02 14:19:19  alex_simov
86   * v0.4.0
87   *
88   * Revision 1.2  2005/06/02 12:33:09  damian
89   * fixes
90   *
91   * Revision 1.1  2005/05/26 09:36:03  damian
92   * io package
93   *
94   * Revision 1.2  2005/01/12 15:20:18  alex_simov
95   * checkstyle formatting
96   *
97   */