home *** CD-ROM | disk | FTP | other *** search
/ ftp.disi.unige.it / 2015-02-11.ftp.disi.unige.it.tar / ftp.disi.unige.it / pub / .person / CataniaB / sample.txt < prev    next >
Text File  |  1999-09-07  |  8KB  |  190 lines

  1. import java.io.*;
  2. import java.net.URL;
  3. import java.util.*;
  4. import org.xml.sax.*;
  5. import com.concerto.cm.initialization.*;
  6. import com.concerto.cm.managing.*;
  7. /**
  8.  * This type was created in VisualAge.
  9.  */
  10. public class ConceptManagerActionHandler extends HandlerBase {
  11.     int state;
  12.     int intCondition;
  13.     ConceptManagerInitialization init = null;
  14.     String result = new String();
  15.     String row = new String();
  16. /**
  17.  * IntercettaEvento constructor comment.
  18.  */
  19. public ConceptManagerActionHandler() {
  20.     state = 0;
  21. }
  22. /**
  23.  * This method was created in VisualAge.
  24.  * @param fileNameInput java.lang.String
  25.  * @param instanceInit com.concerto.cm.initialization.ConceptManagerInitialization
  26.  * @exception java.lang.Exception The exception description.
  27.  */
  28. public ConceptManagerActionHandler(java.lang.String fileNameInput, ConceptManagerInitialization instanceInit) throws Exception {
  29.     this.state = 0;
  30.     this.init = instanceInit;
  31.     String prolog = new String();
  32.  
  33.     prolog += "<?xml version=\"1.0\"?>\n";
  34.     prolog += "<DOCTYPE CMIL-SESSION SYSTEM \"cmil.dtd\">\n";
  35.     prolog += "<CMIL-SESSION>\n";
  36.     this.inizia(fileNameInput);
  37.     this.result += "</CMIL-SESSION>\n";
  38.     this.result = prolog + this.result;
  39. }
  40. /**
  41.  * This method was created in VisualAge.
  42.  * @param name java.lang.String
  43.  * @exception org.xml.sax.SAXException The exception description.
  44.  */
  45. public void endElement(java.lang.String name) throws SAXException {
  46.     if (name.equals("CMIL-ACTION")) {
  47.         state = 0;
  48.         this.intCondition = 0;
  49.         this.row = new String();
  50.     }
  51. }
  52. /**
  53.  * This method was created in VisualAge.
  54.  * @return java.lang.String
  55.  */
  56. public String getResult() {
  57.     return this.result;
  58. }
  59. /**
  60.  * This method was created in VisualAge.
  61.  * @param args java.lang.String[]
  62.  */
  63. public void inizia(java.lang.String way) throws Exception{
  64.  
  65.     // get class object for SAX Driver
  66.     Class c = Class.forName("com.ibm.xml.parsers.SAXParser");
  67.     // create instance of the class
  68.     Parser parser = (Parser)c.newInstance();
  69.     // create document handler and register it
  70.     parser.setDocumentHandler(this);
  71.     // parse the document
  72.     parser.parse(way);
  73. }
  74. /**
  75.  * This method was created in VisualAge.
  76.  */
  77. public void startElement(java.lang.String name, org.xml.sax.AttributeList alist) throws SAXException {
  78.     String piece = new String();
  79.     String serialNumber = new String();
  80.     String methodName = new String();
  81.     String parameterLeft = new String();
  82.     String parameterRight = new String();
  83.     Vector calling = new Vector();
  84.     Vector parameter = new Vector();
  85.     ConceptManagerResponse resp = new ConceptManagerResponse();
  86.     ConceptManager action = new ConceptManager();
  87.     boolean flag = false;
  88.     boolean emptyFile = false;
  89.  
  90.     if (name.equals("CMIL-SESSION")||name.equals("CMIL-ACTION-GROUP"))
  91.     {}
  92.     else if (name.equals("CMIL-ACTION")) {
  93.         state = Integer.valueOf(alist.getValue(0)).intValue();
  94.         this.row += alist.getValue(0)+"|";
  95.     }
  96.     else
  97.     {
  98.         this.row += name;
  99.         for (int i = 0; i < alist.getLength(); i++) {
  100.             this.row += "|"+alist.getName(i)+"="+alist.getValue(i);
  101.         }
  102.         if (!this.row.equals("")) {
  103.           StringTokenizer st = new StringTokenizer(this.row,"|");
  104.             
  105.           while(st.hasMoreTokens()) {
  106.               piece = st.nextToken();
  107.               calling.addElement(piece);
  108.           }
  109.           serialNumber = (String) calling.elementAt(0);
  110.           methodName = (String) calling.elementAt(1);
  111.           parameter = new Vector();
  112.           for (int i=2; i<calling.size(); i++) {
  113.               parameter.addElement(calling.elementAt(i));
  114.           }
  115.           if (methodName.equals("CMIL-ASSERT-rootClass")) {
  116.               String className = new String();
  117.               //calling the method cmilAssertRootClass
  118.               for (int i=0; i<parameter.size(); i++) {
  119.                   st = new StringTokenizer((String) parameter.elementAt(i),"=");
  120.                   parameterLeft = st.nextToken();
  121.                   parameterRight = st.nextToken();
  122.                   if (parameterLeft.equals("className")) className = parameterRight;
  123.               }
  124.               try {
  125.                   resp = action.cmilAssertRootClass(className, this.init);
  126.                   if (resp.getStatus() == true) flag = true;
  127.               } catch (com.ibm.knu.atk.KnUError er) {
  128.                     //CMERR011=The specified relation between Frames is not defined in the Concept Manager Repository
  129.               }
  130.               
  131.           } else
  132.           if (methodName.equals("CMIL-ASSERT-class")) {
  133.               String className = new String();
  134.               // calling the method cmilAssertClass
  135.               for (int i=0; i<parameter.size(); i++) {
  136.                   st = new StringTokenizer((String) parameter.elementAt(i),"=");
  137.                   parameterLeft = st.nextToken();
  138.                   parameterRight = st.nextToken();
  139.                   if (parameterLeft.equals("className")) className = parameterRight;
  140.               }
  141.               try {
  142.                   resp = action.cmilAssertClass(className, this.init);
  143.                 if (resp.getStatus() == true) flag = true;
  144.               } catch (com.ibm.knu.atk.KnUError er) {
  145.                     //CMERR011=The specified relation between Frames is not defined in the Concept Manager Repository
  146.               }
  147.           
  148.           } 
  149.           String actionStatus = new String();
  150.           if (flag)
  151.               actionStatus = "OK";
  152.           else
  153.               actionStatus = "ERROR";
  154.           this.result += "      <CMIL-ACTION-OUTPUT serial_number=\""+serialNumber+"\" action_status=\""+actionStatus+"\">\n";
  155.           if (!flag) {
  156.               String msg = new String();
  157.               if (resp.getResponse().elementAt(0).equals("CMERR000")) msg = "The Operation is done";
  158.               else if (resp.getResponse().elementAt(0).equals("CMERR001")) msg = "The Class/Individual name is already defined in the Concept Manager Repository";
  159.               else if (resp.getResponse().elementAt(0).equals("CMERR002")) msg = "The Class/Individual name is not defined in the Concept Manager Repository";
  160.               else if (resp.getResponse().elementAt(0).equals("CMERR003")) msg = "The Class/Individual OID is already defined in the Concept Manager Repository";
  161.               else if (resp.getResponse().elementAt(0).equals("CMERR004")) msg = "The Class/Individual OID is not defined in the Concept Manager Repository";
  162.               else if (resp.getResponse().elementAt(0).equals("CMERR005")) msg = "The Slot Name is already defined in the specified Class/Individual";
  163.               else if (resp.getResponse().elementAt(0).equals("CMERR006")) msg = "The Slot Name is not defined in the specified Class/Individual";
  164.               else if (resp.getResponse().elementAt(0).equals("CMERR007")) msg = "The Facet Type is not valid";
  165.               else if (resp.getResponse().elementAt(0).equals("CMERR008")) msg = "The value supplied doesn't respect the constraint defined from the facets associated to the slot";
  166.               else if (resp.getResponse().elementAt(0).equals("CMERR009")) msg = "The Retract type value is not valid";
  167.               else if (resp.getResponse().elementAt(0).equals("CMERR010")) msg = "The Individual Name is not unique in the Concept Manager Repository";
  168.               else if (resp.getResponse().elementAt(0).equals("CMERR011")) msg = "The specified relation between Frames is not defined in the Concept Manager Repository";
  169.               else if (resp.getResponse().elementAt(0).equals("CMERR012")) msg = "The Slot Value is not defined for the specified Slot name";
  170.               else if (resp.getResponse().elementAt(0).equals("CMERR013")) msg = "The specified relation between Frames is already defined in the Concept Manager Repository";
  171.               this.result += "             <ERROR-CODE>"+msg+"</ERROR-CODE>\n";
  172.                this.result += "      </CMIL-ACTION-OUTPUT>\n";
  173.           } else {
  174.               if (resp.getResponse() != null) {
  175.                   if (resp.response.size() > 0) {
  176.                       for (int i=0; i<resp.response.size(); i++) {
  177.                           if (resp.response.elementAt(i).equals("CMERR000")) resp.response.setElementAt("The Operation is done",i);
  178.                         this.result += "            <RETURN-VALUE>"+resp.response.elementAt(i)+"</RETURN-VALUE>\n";
  179.                       }
  180.                      this.result += "      </CMIL-ACTION-OUTPUT>\n";
  181.                   } else  {
  182.                       this.result += "             <RETURN-VALUE>"+"NO VALUES RETRIEVED"+"</RETURN-VALUE>\n";
  183.                      this.result += "      </CMIL-ACTION-OUTPUT>\n";
  184.                   }
  185.               }
  186.          }
  187.         }
  188.     }
  189. }
  190. }