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) 2006 Cisco Systems, Inc.  All Rights Reserved.
18//
19// Contributor(s):
20//
21// END LICENSE BLOCK
22
23package com.parctechnologies.eclipse.visualisation;
24
25import com.parctechnologies.eclipse.*;
26import java.io.Serializable;
27
28public class ElementType implements Serializable
29{
30  private static String changeable = "changeable";
31  private static String any = "any";
32  private static String numericBounds = "numeric_bounds";
33  private static String graphData = "graph_data";
34
35  /**
36   * Set to the module implementing the "changeable" variable
37   * interface, or null if not changeable
38   **/
39  protected String changeableSolver;
40
41  protected ElementType() {
42    this.changeableSolver = null;
43  }
44
45  /**
46   * Read the solver for this changeable element type, or null.
47   **/
48  public String getChangeableSolver() {
49    return changeableSolver;
50  }
51
52  static ElementType parseFromCompoundTerm(CompoundTerm term)
53    throws VisException
54  {
55    if(changeable.equals(term.functor()) && term.arity()==2)
56    {
57      try
58      {
59        CompoundTerm solverTerm = (CompoundTerm)(term.arg(1));
60        CompoundTerm typeTerm = (CompoundTerm)(term.arg(2));
61        ElementType type = parseFromCompoundTerm(typeTerm);
62        type.changeableSolver = solverTerm.functor();
63        return type;
64      }
65      catch(ClassCastException cce)
66      {
67        throw new VisException("Could not parse changeable element type from "+term);
68      }
69    }
70    if(any.equals(term.functor()))
71    {
72      return(new AnyElementType());
73    }
74
75    if(numericBounds.equals(term.functor()))
76    {
77      return(new NumericBounds());
78    }
79
80    if(graphData.equals(term.functor()))
81    {
82      return(new GraphData());
83    }
84    throw new VisException("Could not parse element type from "+term);
85  }
86
87}
88