1// BEGIN LICENSE BLOCK
2// Version: CMPL 1.1
3//
4// The contents of this file are subject to the Cisco-style Mozilla Public
5// License Version 1.1 (the "License"); you may not use this file except
6// in compliance with the License.  You may obtain a copy of the License
7// at www.eclipse-clp.org/license.
8//
9// Software distributed under the License is distributed on an "AS IS"
10// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See
11// the License for the specific language governing rights and limitations
12// under the License.
13//
14// The Original Code is  The ECLiPSe Constraint Logic Programming System.
15// The Initial Developer of the Original Code is  Cisco Systems, Inc.
16// Portions created by the Initial Developer are
17// Copyright (C) 2001 - 2006 Cisco Systems, Inc.  All Rights Reserved.
18//
19// Contributor(s): Josh Singer, Parc Technologies
20//
21// END LICENSE BLOCK
22
23//Title:        Java/ECLiPSe interface
24//Version:      $Id: DataExample2.java,v 1.1 2006/09/23 01:54:12 snovello Exp $
25//Author:       Josh Singer
26//Company:      Parc Technologies
27//Description:  Java/ECLiPSe Interface example Java program
28import com.parctechnologies.eclipse.*;
29import java.io.*;
30import java.util.*;
31
32public class DataExample2
33{
34  public static void main(String[] args) throws Exception
35  {
36    // Create some default Eclipse options
37    EclipseEngineOptions eclipseEngineOptions = new EclipseEngineOptions();
38    // Object representing the Eclipse process
39    EclipseEngine eclipse;
40
41    // Connect the Eclipse's standard streams to the JVM's
42    eclipseEngineOptions.setUseQueues(false);
43
44    // Initialise Eclipse
45    eclipse = EmbeddedEclipse.getInstance(eclipseEngineOptions);
46
47    // Construct a collection
48    Collection a_collection = construct_collection();
49
50    // Write out the collection
51    System.out.println(a_collection);
52
53    // Get Eclipse to write the collection (a list) to stdout and flush
54    eclipse.rpc(
55		new CompoundTermImpl(",",
56			      new CompoundTermImpl("write",
57					    new Atom("output"),a_collection),
58			      new CompoundTermImpl("flush", new Atom("output"))
59			      )
60		);
61
62    // Destroy the Eclipse process
63    ((EmbeddedEclipse) eclipse).destroy();
64
65  }
66
67  // Construct a collection in Java to represent the Eclipse
68  // list [1, foo(3.5), bar].
69  private static Collection construct_collection()
70  {
71      Collection theCollection = new LinkedList();
72
73      theCollection.add(new Integer(1));
74      theCollection.add(new CompoundTermImpl("foo", new Double(3.5)));
75      theCollection.add(new Atom("bar"));
76
77      return(theCollection);
78  }
79
80}
81
82