![]() | The Apache Xerces2 XML parser for Java from xerces.apache.org (version 2.11.0 was used for this example). The example assumes it to be installed in c:\java\xerces-2_11_0 on Windows platforms (if you install it elsewhere, remember to edit the %xercesdir% variable in the compile and execution batch file shown in Listing 3). |
![]() | The Apache Axis SOAP library from axis.apache.org/axis (for this example, we used version 1.4 bin). It is assumed to be installed in c:\java\axis-1_4 (if located elsewhere, change %axisdir% variable in the batch file shown in Listing 3). |
01 import java.util.*;
02
03 class APIExampleApp {
04 public static void main(String[] args) {
05
06 com.metacase.API.MetaEditAPI meServer = null;
07 com.metacase.API.MetaEditAPIPortType port = null;
08 com.metacase.API.METype graphType = new com.metacase.API.METype();
09 com.metacase.API.MEOop[] graphs = null;
10 com.metacase.API.METype objectType = new com.metacase.API.METype();
11 com.metacase.API.MEAny[] props = new com.metacase.API.MEAny[1];
12 com.metacase.API.MEAny[] values = new com.metacase.API.MEAny[1];
13 com.metacase.API.MEAny area, np;
14 com.metacase.API.MEAny newObjectAny = new com.metacase.API.MEAny();
15 com.metacase.API.MEOop newObject = new com.metacase.API.MEOop();
16 com.metacase.API.MEOop[] diagrams = null;
17 com.metacase.API.MEAny place = new com.metacase.API.MEAny();
18 com.metacase.API.MEAny nullAny = new com.metacase.API.MEAny();
19 com.metacase.API.MEAny textAny = new com.metacase.API.MEAny();
20
21 try {
22 meServer = new com.metacase.API.MetaEditAPILocator();
23 port = meServer.getMetaEditAPIPort();
24 } catch (Exception ex) { System.err.println(ex.getMessage()); System.exit(1); }
25
26 graphType.setName("WatchFamily");
27 try {
28 graphs = port.allGoodInstances(graphType);
29 } catch (Exception ex) { System.err.println(ex.getMessage()); System.exit(1); }
30 if(graphs.length == 0) System.exit(2); // No WatchFamily graphs found
31 objectType.setName("Note [Watch]");
32 nullAny.setMeType("MENull");
33 nullAny.setMeValue("");
34 props[0] = nullAny;
35 textAny.setMeType("Text");
36 textAny.setMeValue("'A new note created by the API'");
37 values[0] = textAny;
38 np = area = nullAny;
39 try {
40 newObjectAny = port.instProps(objectType, props, values, np, area);
41 } catch (Exception ex) { System.err.println(ex.getMessage()); System.exit(1); }
42 if(!newObjectAny.getMeType().equals("MEOop"))
43 System.exit(3); // No object created
44 StringTokenizer st = new StringTokenizer(newObjectAny.getMeValue(), "_", false);
45 newObject.setAreaID(Integer.parseInt(st.nextToken()));
46 newObject.setObjectID(Integer.parseInt(st.nextToken()));
47 try {
48 port.addToGraph(newObject, graphs[0]);
49 } catch (Exception ex) { System.err.println(ex.getMessage()); System.exit(1); }
50 try {
51 diagrams = port.diagrams(graphs[0]);
52 } catch (Exception ex) { System.err.println(ex.getMessage()); System.exit(1); }
53 if(diagrams.length == 0) System.exit(4); // No existing diagrams found
54 place.setMeType("Point");
55 place.setMeValue("400,360");
56 try {
57 port.addNewObjectRepFor(diagrams[0], newObject, 0,place);
58 } catch (Exception ex) { System.err.println(ex.getMessage()); System.exit(1); }
59 try {
60 port.animate(graphs[0], newObject);
61 } catch (Exception ex) { System.err.println(ex.getMessage()); System.exit(1); }
62 }
63 }Listing 2. Sample Java application using the API.
01 set path=%path%;c:\Program Files\Java\jdk1.7.0_51\bin 02 set axisdir=c:\java\axis-1_4 03 set xercesdir=c:\java\xerces-2_11_0 04 set classpath=%axisdir%\lib\*;%xercesdir%\*;. 05 java org.apache.axis.wsdl.WSDL2Java -p com.metacase.API MetaEdit.wsdl 06 javac APIExampleApp.java com\metacase\API\*.java
Listing 3. Sample script for compiling Java code with SOAP extensions.