From: <an...@us...> - 2011-03-17 17:31:58
|
Revision: 8533 http://smartfrog.svn.sourceforge.net/smartfrog/?rev=8533&view=rev Author: anfarr Date: 2011-03-17 17:31:49 +0000 (Thu, 17 Mar 2011) Log Message: ----------- SFOS-1572: Check-in of moved constraints component logic Added Paths: ----------- trunk/core/components/constraints/ trunk/core/components/constraints/build.xml trunk/core/components/constraints/ivy.xml trunk/core/components/constraints/src/ trunk/core/components/constraints/src/org/ trunk/core/components/constraints/src/org/smartfrog/ trunk/core/components/constraints/src/org/smartfrog/sfcore/ trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/ trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/ trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/ trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/ trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/CDBrowser.java trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/EclipseCDAttr.java trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/EclipseCDBrowser.java trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/EclipseModelMatcher.java trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/EclipseSolver.java trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/EclipseStatus.java trunk/core/components/constraints/test/ trunk/core/components/constraints/test/org/ trunk/core/components/constraints/test/org/smartfrog/ trunk/core/components/constraints/test/org/smartfrog/test/ trunk/core/components/constraints/test/org/smartfrog/test/system/ trunk/core/components/constraints/test/org/smartfrog/test/system/constraints/ trunk/core/components/constraints/test/org/smartfrog/test/system/constraints/ConstraintsTest.java trunk/core/components/constraints/test/org/smartfrog/test/system/constraints/CoreSolverTest.java trunk/core/components/constraints/test/org/smartfrog/test/system/constraints/MockSolver.java trunk/core/components/constraints/test/org/smartfrog/test/system/constraints/components.sf trunk/core/components/constraints/test/org/smartfrog/test/system/constraints/ctn1.sf trunk/core/components/constraints/test/org/smartfrog/test/system/constraints/ctn10.sf trunk/core/components/constraints/test/org/smartfrog/test/system/constraints/ctn11.sf trunk/core/components/constraints/test/org/smartfrog/test/system/constraints/ctn12.sf trunk/core/components/constraints/test/org/smartfrog/test/system/constraints/ctn13.sf trunk/core/components/constraints/test/org/smartfrog/test/system/constraints/ctn14.sf trunk/core/components/constraints/test/org/smartfrog/test/system/constraints/ctn15.sf trunk/core/components/constraints/test/org/smartfrog/test/system/constraints/ctn16.sf trunk/core/components/constraints/test/org/smartfrog/test/system/constraints/ctn17.sf trunk/core/components/constraints/test/org/smartfrog/test/system/constraints/ctn18.sf trunk/core/components/constraints/test/org/smartfrog/test/system/constraints/ctn19.sf trunk/core/components/constraints/test/org/smartfrog/test/system/constraints/ctn2.sf trunk/core/components/constraints/test/org/smartfrog/test/system/constraints/ctn3.sf trunk/core/components/constraints/test/org/smartfrog/test/system/constraints/ctn4.sf trunk/core/components/constraints/test/org/smartfrog/test/system/constraints/ctn5.sf trunk/core/components/constraints/test/org/smartfrog/test/system/constraints/ctn6.sf trunk/core/components/constraints/test/org/smartfrog/test/system/constraints/ctn7.sf trunk/core/components/constraints/test/org/smartfrog/test/system/constraints/ctn9.sf trunk/core/components/constraints/test/org/smartfrog/test/system/constraints/ctnuv.sf Added: trunk/core/components/constraints/build.xml =================================================================== --- trunk/core/components/constraints/build.xml (rev 0) +++ trunk/core/components/constraints/build.xml 2011-03-17 17:31:49 UTC (rev 8533) @@ -0,0 +1,53 @@ +<?xml version="1.0"?> + +<!-- +/** (C) Copyright 1998-2009 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ +--> + +<project name="constraints" default="dist" basedir="."> + +<description> +Introduction +============ +Constraint Extensions for SF: the parts that are specific to certain solvers such as Eclipse + +</description> + + <!-- override point --> + <property file="build.properties" /> + <property name="root.dir" location="../../" /> + + + <property name="is.component" value="true" /> + <property name="ivy.enabled" value="true"/> + <property name="system.tests" value="true"/> + + <!-- Import common stuff --> + <!--available file="../../common.xml" property="root.dir" value="../.."/--> + <import file="${root.dir}/common.xml"/> + + <echo message="==================================================================="/> + <echo message="= ${ant.project.name}"/> + +</project> + +<!-- End of file --> + Property changes on: trunk/core/components/constraints/build.xml ___________________________________________________________________ Added: svn:executable + * Added: trunk/core/components/constraints/ivy.xml =================================================================== --- trunk/core/components/constraints/ivy.xml (rev 0) +++ trunk/core/components/constraints/ivy.xml 2011-03-17 17:31:49 UTC (rev 8533) @@ -0,0 +1,60 @@ +<?xml version="1.0" ?> +<?xml-stylesheet type="text/xsl" href="http://ivyrep.jayasoft.org/ivy-doc.xsl"?> +<ivy-module version="1.0"> + <info organisation="org.smartfrog" module="sf-constraints"> + <license name="LGPL"/> + <ivyauthor name="Hewlett-Packard" url="http://www.smartfrog.org"/> + <description> + Solver specific constraint extensions + </description> + </info> +<!-- FIXME: Ivy 1.4.1 buildlist bug + <configurations defaultconfmapping="default"> + <include file="../../antbuild/ivy/configurations.xml"/> + </configurations> + --> +<configurations defaultconfmapping="default"> + <conf name="default" extends="master,runtime" + description="default configuration contains artifacts and runtime dependencies"/> + <conf name="build" visibility="private" + description="artifacts needed to build the application"/> + <conf name="compile" visibility="private" extends="runtime" + description="artifacts needed to compile the application"/> + <conf name="daemon" visibility="private" + description="the classpath needed to run smartfrog daemons"/> + <conf name="test" extends="default,compile" + description="the classpath needed to run tests"/> + <conf name="master" description="contains the artifact but no dependencies"/> + <conf name="redist" description="redistributals excluding smartfrog artifacts"/> + <conf name="runtime" description="runtime but not the artifact" + extends="redist"/> + <conf name="documentation" + description="all documentation artifacts"/> +</configurations> + + <publications> + <!--get the artifact from our module name--> + <artifact conf="master"/> + </publications> + <dependencies> + <dependency org="org.smartfrog" + name="smartfrog" + changing="true" + rev="latest.integration" + conf="compile->services;runtime->services;daemon->services"/> + <dependency org="org.smartfrog" + name="sf-tasks" + changing="true" + rev="latest.integration" + conf="build->default"/> + <dependency org="org.smartfrog" + name="sf-testharness" + changing="true" + rev="latest.integration" + conf="test->default"/> + <dependency org="eclipse-clp" + name="eclipse-clp" + rev="${eclipse-clp.version}" + conf="redist->default"/> + </dependencies> +</ivy-module> Property changes on: trunk/core/components/constraints/ivy.xml ___________________________________________________________________ Added: svn:executable + * Added: trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/CDBrowser.java =================================================================== --- trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/CDBrowser.java (rev 0) +++ trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/CDBrowser.java 2011-03-17 17:31:49 UTC (rev 8533) @@ -0,0 +1,53 @@ +/** (C) Copyright 1998-2008 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ +package org.smartfrog.sfcore.languages.sf.constraints.eclipse; + +/** + * Interface for Component Description browsers used to display sfComfig hierarchy for the purpose of setting user variables + * @author anfarr + * + */ +public interface CDBrowser { + + /** + * Sets EclipseStatus object pertaining to status information for browser + * @param es + */ + void setES(EclipseStatus es); + + /** + * Add attribute to the hierarchy to be displayed + * @param d -- my parent as unspecified object + * @param av -- my attribute name / value as unspecified object + * @param showme -- am I in the immediate component description to be displayed? + * @return tree node which will be used later on to add child attributes to + */ + Object attr(Object d, Object av, boolean showme); + + /** + * Redraw the browser + */ + void redraw(); + + /** + * Kill the browser... + */ + void kill(); +} Property changes on: trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/CDBrowser.java ___________________________________________________________________ Added: svn:executable + * Added: trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/EclipseCDAttr.java =================================================================== --- trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/EclipseCDAttr.java (rev 0) +++ trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/EclipseCDAttr.java 2011-03-17 17:31:49 UTC (rev 8533) @@ -0,0 +1,156 @@ +/** (C) Copyright 1998-2008 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ + +package org.smartfrog.sfcore.languages.sf.constraints.eclipse; + +import java.util.Collection; +import java.util.Iterator; + +import org.smartfrog.sfcore.languages.sf.constraints.FreeVar; + +import com.parctechnologies.eclipse.Atom; +import com.parctechnologies.eclipse.CompoundTermImpl; + +/** + * Records information for a single attribute, used in EclipseSolver's sfConfig browser for user variables + * @author anfarr + * + */ +class EclipseCDAttr { + /** + * Name of attribute + */ + private String name; + + /** + * Value of attribute + */ + private Object val; + + /** + * Range of attribute + */ + private Object range; + + /** + * Whether set + */ + private boolean set; + + /** + * Eclipse Solver + */ + private EclipseSolver solver; + + /** + * Constructor, + * @param solver Eclipse Solver + * @param name Name of attribute + * @param val Value of attribute + */ + EclipseCDAttr(EclipseSolver solver, String name, Object val){ + this.solver = solver; + this.name = name; + this.val = val; + } + + /** + * Is attribute value set + * @return Is value set? + */ + boolean isSet(){ + return set; + } + + /** + * Set whether attribute value is set + * @param set Is set? + */ + void set(boolean set){ + this.set =set; + } + + /** + * Set range of attribute + * @param range + */ + void setRange(Object range){ + this.range =range; + } + + /** + * Set value of attribute + * @param val + */ + void setValue(Object val){ + this.val =val; + } + + /** + * Process setting of attribute value (from range) + * @param entry Attribute value + * @return Whether processing is successful + */ + boolean process_sel(String entry){ + solver.setEclipseCDAttr(this); + Collection c = (Collection) range; + Iterator iter = c.iterator(); + while (iter.hasNext()){ + String el = iter.next().toString(); + if (el.equals(entry)){ + if (val instanceof FreeVar && ((FreeVar)val).getRange() instanceof Boolean){ + if (entry.equals("true")) entry="1"; + else entry="0"; + } + solver.javaToEclipse(new CompoundTermImpl("set", new Atom(name), new Atom(entry))); + return true; + } + } + return false; + } + + /** + * Gets range of attribute as a string + * @return range as string + */ + public String getRangeAsString(){ + return range.toString(); + } + + /** + * Gets attribute name + * @return attribute name + */ + public String getAttrName(){ + return name; + } + + public Object getValue(){ + return val; + } + + public String toString(){ + if (set){ + return name +" has value: "+ val; + } else { + return name +" ranges over: "+ range; + } + } +} Property changes on: trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/EclipseCDAttr.java ___________________________________________________________________ Added: svn:executable + * Added: trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/EclipseCDBrowser.java =================================================================== --- trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/EclipseCDBrowser.java (rev 0) +++ trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/EclipseCDBrowser.java 2011-03-17 17:31:49 UTC (rev 8533) @@ -0,0 +1,283 @@ +/** (C) Copyright 1998-2008 Hewlett-Packard Development Company, LP + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information: www.smartfrog.org + + */ +package org.smartfrog.sfcore.languages.sf.constraints.eclipse; + + +import javax.swing.*; +import javax.swing.event.TreeSelectionEvent; +import javax.swing.event.TreeSelectionListener; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.DefaultTreeModel; +import javax.swing.tree.TreePath; +import javax.swing.tree.TreeSelectionModel; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.net.URL; + + +/** + * Browser for displaying sfComfig hierarchy for the purpose of setting user variables + * + * @author anfarr + */ +public class EclipseCDBrowser extends JFrame implements CDBrowser { + private JScrollPane scrollPane; + private JLabel label; + private JLabel undoLabel; + private JTextField entry; + private JButton setButton; + private JButton undoButton; + private JButton doneButton; + private EclipseStatus eclipseStatus; + private EclipseCDAttr eclipseCDAttr; + private DefaultMutableTreeNode visnode; + private DefaultMutableTreeNode root; + private DefaultTreeModel model; + private JTree tree; + private static final int DEFAULT_WIDTH = 600; + private static final int DEFAULT_HEIGHT = 400; + /** + * Kill the browser... + */ + public void kill() { + setVisible(false); + } + + /** + * Sets EclipseStatus object pertaining to status information for browser + * + * @param est + */ + public void setES(EclipseStatus est) { + eclipseStatus = est; + } + + /** + * Add attribute to the hierarchy to be displayed + * + * @param d -- my parent as unspecified object + * @param av -- my attribute name / value as unspecified object + * @param showme -- am I in the immediate component description to be displayed? + * @return tree node which will be used later on to add child attributes to + */ + public Object attr(Object d, Object av, boolean showme) { + DefaultMutableTreeNode node = new DefaultMutableTreeNode(av); + + if (showme && visnode == null) { + visnode = node; + } + + if (root == null) { + root = node; + } else { + ((DefaultMutableTreeNode) d).add(node); + } + return node; + } + + /** + * Redraws browser... + */ + public void redraw() { + if (!isVisible()) { + init(); + } else { + + if (eclipseStatus.isBack()) { + eclipseStatus.setBack(false); + label.setText("Attribute setting undone. " + label.getText()); + setButton.setEnabled(false); + } + int undo = eclipseStatus.getUndo(); + if (undo > 0) { + undoLabel.setText(eclipseStatus.getUndoLabel()); + undoButton.setText("Undo (" + undo + ")"); + undoButton.setEnabled(true); + } else { + undoLabel.setText(""); + undoButton.setText("Undo"); + undoButton.setEnabled(false); + } + doneButton.setEnabled(eclipseStatus.isDone()); + + repaint(); + } + } + + /** + * Reset browser to initial look... + */ + void reset_display() { + label.setText("Click on an attribute with range to set its value"); + entry.setText(""); + setButton.setEnabled(false); + entry.setEnabled(false); + } + + /** + * Initialise browser... + */ + void init() { + setTitle("sfConfig Browser"); + setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); + + // the root of the class tree is Object + model = new DefaultTreeModel(root); + tree = new JTree(model); + + // set up selection mode + tree.addTreeSelectionListener(new + TreeSelectionListener() { + public void valueChanged(TreeSelectionEvent event) { + // the user selected a different node--update description + TreePath path = tree.getSelectionPath(); + if (path == null) { + return; + } + DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) path.getLastPathComponent(); + Object uobj = selectedNode.getUserObject(); + if (uobj instanceof EclipseCDAttr) { + eclipseCDAttr = (EclipseCDAttr) uobj; + if (eclipseCDAttr.isSet()) { + reset_display(); + } else { + setButton.setEnabled(false); + label.setText(eclipseCDAttr.toString()); + entry.setEnabled(true); + } + } else { + reset_display(); + } + } + }); + + + int mode = TreeSelectionModel.SINGLE_TREE_SELECTION; + tree.getSelectionModel().setSelectionMode(mode); + + Box vbox = Box.createVerticalBox(); + add(vbox, BorderLayout.CENTER); + scrollPane = new JScrollPane(tree); + vbox.add(scrollPane); + + label = new JLabel(); + Box labelbox = Box.createHorizontalBox(); + labelbox.add(Box.createHorizontalGlue()); + labelbox.add(label); + labelbox.add(Box.createHorizontalGlue()); + vbox.add(labelbox); + + vbox.add(Box.createVerticalStrut(10)); + entry = new JTextField(); + vbox.add(Box.createVerticalGlue()); + vbox.add(entry); + vbox.add(Box.createVerticalStrut(10)); + + //set up selection mode + entry.addKeyListener(new KeyAdapter() { + public void keyTyped(KeyEvent event) { + setButton.setEnabled(true); + repaint(); + } + }); + + + JPanel hbox = new JPanel(); + hbox.setLayout(new GridLayout(2, 3)); + vbox.add(hbox); + + setButton = new JButton("Set"); + Box setbox = Box.createHorizontalBox(); + setbox.add(setButton); + setbox.add(Box.createHorizontalGlue()); + hbox.add(setbox); + + undoButton = new JButton("Undo"); + undoButton.setEnabled(false); + Box undobox = Box.createHorizontalBox(); + undobox.add(Box.createHorizontalGlue()); + undobox.add(undoButton); + undobox.add(Box.createHorizontalGlue()); + hbox.add(undobox); + + doneButton = new JButton("Done"); + doneButton.setEnabled(false); + Box donebox = Box.createHorizontalBox(); + donebox.add(Box.createHorizontalGlue()); + donebox.add(doneButton); + hbox.add(donebox); + + undoLabel = new JLabel(""); + hbox.add(new JPanel()); + hbox.add(undoLabel); + + System.out.println("init..4"); + + + reset_display(); + + setButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent event) { + boolean succ = eclipseCDAttr.process_sel(entry.getText()); + if (succ) { + label.setText("Attribute set successfully"); + setButton.setEnabled(false); + entry.setEnabled(false); + } else { + label.setText( + "Value selected not in range:" + eclipseCDAttr.getRangeAsString() + ". Please try again"); + } + entry.setText(""); + } + }); + + undoButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent event) { + eclipseStatus.undo(); + } + }); + + doneButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent event) { + eclipseStatus.done(); + } + }); + + tree.makeVisible(new TreePath(model.getPathToRoot(visnode))); + + URL url = getClass().getResource("HP_ICON.PNG"); + if (url != null) { + Image image = Toolkit.getDefaultToolkit().getImage(url); + if (image != null) { + setIconImage(image); + } + } + + //setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + setVisible(true); + } + + + } + Property changes on: trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/EclipseCDBrowser.java ___________________________________________________________________ Added: svn:executable + * Added: trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/EclipseModelMatcher.java =================================================================== --- trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/EclipseModelMatcher.java (rev 0) +++ trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/EclipseModelMatcher.java 2011-03-17 17:31:49 UTC (rev 8533) @@ -0,0 +1,113 @@ +/** (C) Copyright 1998-2004 Hewlett-Packard Development Company, LP + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information: www.smartfrog.org + + */ +package org.smartfrog.sfcore.languages.sf.constraints.eclipse; + +import com.parctechnologies.eclipse.CompoundTerm; +import com.parctechnologies.eclipse.EclipseEngine; +import com.parctechnologies.eclipse.EclipseException; +import org.smartfrog.sfcore.languages.sf.constraints.*; + +import java.io.File; +import java.io.IOException; +import java.util.HashMap; +import java.util.LinkedHashMap; + +/** + * created 20-Sep-2010 15:34:10 + */ + +public class EclipseModelMatcher extends BaseModelMatcher{ + + /** + * Property prefix for theory files... + */ + private static final String MATCHERS_DIR_PREFIX = "matchers/"; + private static final String MATCHERS_FILE_SUFFIX = ".ecl"; + private static final String MATCHERS_DEFAULT = "default"; + + private static final String E_INCOMPATIBLECAPREQ = "Incompatible types: cap to req:"; + + + private EclipseEngine eclipse; + private String eclipseDir; + + + public EclipseModelMatcher() throws ModelMatcherEngineNotFound, ModelMatcherSelectFailure { + CoreSolver solver = CoreSolver.getInstance(); + if (solver instanceof EclipseSolver){ + eclipse=((EclipseSolver)solver).getEngine(); + eclipseDir= ((EclipseSolver) solver).getEclipseDir(); + } else throw ModelMatcherEngineNotFound.forward(); + + selectDefaultMatcher(); + } + + @Override + public void selectDefaultMatcher() throws ModelMatcherSelectFailure { + selectMatcher(MATCHERS_DEFAULT); + } + + //Need to check that compiling in a new one overwrites existing... + public void selectMatcher(String name) throws ModelMatcherSelectFailure { + try { + eclipse.compile(new File(eclipseDir + EclipseSolver.ECLIPSE_SWITCH + MATCHERS_DIR_PREFIX + name + MATCHERS_FILE_SUFFIX)); + } catch (Exception e) { + throw ModelMatcherSelectFailure.forward(e); + } + } + + @Override + public boolean match(LinkedHashMap<String, Object> componentData, LinkedHashMap<String, Object> modelData) throws IOException, IncompatibleMatchingCapsToReqs { + + HashMap<String, Object[]> current = getCurrentCapacitiesRecord(); + + String imageCapsList = processCapsIntoPrologList(current); + String componentsList = processIntoPrologList(componentData); + String modelList = processIntoPrologList(modelData); + + String goal = "match(" + componentsList + ", " + modelList + ", " + imageCapsList + ")"; + System.out.println("GOAL: "+goal); + + try { + CompoundTerm result = eclipse.rpc(goal); + //We ignore result for now... + } catch (EclipseException e) { + return false; + } + + //Subtract from image capacities... + for (String key: current.keySet()){ + Object[] record = current.get(key); + Object sub = componentData.get(key); + + if (record[1] instanceof Integer){ + if (sub instanceof Integer){ + record[1] = (Integer)record[1] - (Integer)sub; + } else throw IncompatibleMatchingCapsToReqs.forward(E_INCOMPATIBLECAPREQ+" key:"+key); + } else if (record[1] instanceof Float) { + if (sub instanceof Float) { + record[1] = (Float) record[1] - (Float) sub; + } else throw IncompatibleMatchingCapsToReqs.forward(E_INCOMPATIBLECAPREQ + " key:" + key); + } + } + + return true; + } +} Property changes on: trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/EclipseModelMatcher.java ___________________________________________________________________ Added: svn:executable + * Added: trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/EclipseSolver.java =================================================================== --- trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/EclipseSolver.java (rev 0) +++ trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/EclipseSolver.java 2011-03-17 17:31:49 UTC (rev 8533) @@ -0,0 +1,1071 @@ +/** (C) Copyright 1998-2008 Hewlett-Packard Development Company, LP + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information: www.smartfrog.org + + */ +package org.smartfrog.sfcore.languages.sf.constraints.eclipse; + + +import java.io.File; +import java.io.IOException; +import java.util.Calendar; +import java.util.Collection; +import java.util.Collections; +import java.util.GregorianCalendar; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Vector; + +import org.smartfrog.SFParse; +import org.smartfrog.SFSystem; +import org.smartfrog.sfcore.common.Context; +import org.smartfrog.sfcore.common.SFNull; +import org.smartfrog.sfcore.common.SmartFrogResolutionException; +import org.smartfrog.sfcore.common.SmartFrogRuntimeException; +import org.smartfrog.sfcore.componentdescription.ComponentDescription; +import org.smartfrog.sfcore.languages.sf.DefaultParser; +import org.smartfrog.sfcore.languages.sf.constraints.ConstraintResolutionState; +import org.smartfrog.sfcore.languages.sf.constraints.CoreSolver; +import org.smartfrog.sfcore.languages.sf.constraints.FreeVar; +import org.smartfrog.sfcore.languages.sf.constraints.ConstraintResolutionState.ConstraintContext; +import org.smartfrog.sfcore.languages.sf.functions.Constraint; +import org.smartfrog.sfcore.languages.sf.sfcomponentdescription.SFComponentDescriptionImpl; +import org.smartfrog.sfcore.languages.sf.sfreference.SFApplyReference; +import org.smartfrog.sfcore.languages.sf.sfreference.SFReference; +import org.smartfrog.sfcore.reference.AttribReferencePart; +import org.smartfrog.sfcore.reference.Reference; +import org.smartfrog.sfcore.reference.ReferencePart; +import org.smartfrog.sfcore.reference.ReferenceResolver; +import org.smartfrog.sfcore.security.SFClassLoader; + +import com.parctechnologies.eclipse.Atom; +import com.parctechnologies.eclipse.CompoundTerm; +import com.parctechnologies.eclipse.CompoundTermImpl; +import com.parctechnologies.eclipse.EXDRInputStream; +import com.parctechnologies.eclipse.EXDROutputStream; +import com.parctechnologies.eclipse.EclipseEngine; +import com.parctechnologies.eclipse.EclipseEngineOptions; +import com.parctechnologies.eclipse.EmbeddedEclipse; +import com.parctechnologies.eclipse.FromEclipseQueue; +import com.parctechnologies.eclipse.QueueListener; +import com.parctechnologies.eclipse.ToEclipseQueue; + +/** + * Implementation of solver for Eclipse + */ +public class EclipseSolver extends CoreSolver implements Runnable, QueueListener { + + /** + * Default Eclipse options + */ + private EclipseEngineOptions eclipseEngineOptions; + + /** + * Eclipse engine + */ + private EclipseEngine eclipse; + + /** + * Object to send to eclipse side + */ + private Object get_value; + + /** + * Thread for main eclipse goal + */ + private Thread goalThread; + + /** + * sfConfig browser for purpose of setting user variables + */ + private CDBrowser cdBrowser; + + /** + * Are there user variables? + */ + private boolean isUserVars; + + /** + * Component description pertaining to Constraint type being solved + */ + private ComponentDescription solveCD; + + /** + * Queue for coms TO eclipse + */ + private ToEclipseQueue javaToEclipseQueue; + + /** + * Queue for coms FROM eclipse + */ + private FromEclipseQueue eclipseToJavaQueue; + + /** + * Latest constraint goal has finished? + */ + private boolean consFinished = false; + + /** + * Stores any exception thrown from Eclipse thread + */ + private Exception generalError = null; + + /** + * Location (relative switch) of eclipse theory file specific to smartfrog constraint solving within Eclipse + * installation + */ + static final String ECLIPSE_SWITCH = "/smartfrog/"; + + /** + * Property prefix for theory files... + */ + private static final String THEORYFILE_PREFIX = "org.smartfrog.sfcore.languages.sf.constraints.theoryFile"; + + /** + * Property indicating where to find eclipse installation + */ + public static final String ECLIPSEDIR_SPECIFIER = "org.smartfrog.sfcore.languages.sf.constraints.eclipseDir"; + //NOTE: eclipseDir property is a temporary solution pending resolution of best way to include eclipse in release... + + /** + * Property indicating the CD Browser to use + */ + private static final String USERVAR_BROWSER = "org.smartfrog.sfcore.languages.sf.constraints.CDBrowser"; + + /** + * Resolution state for constraint solving... + */ + private ConstraintResolutionState resolutionState; + + /** + * Status of solving for reflection in user var sfConfig browser + */ + private EclipseStatus eclipseStatus; + + /** + * Attributes with ranges to be sought... + */ + private Vector<EclipseCDAttr> rangeAttrs = new Vector<EclipseCDAttr>(); + + /** + * Current attribute in user var sfConfig browser being manipulated + */ + private EclipseCDAttr currentCDAttr; + private static final String DEFAULT_THEORY = "core.ecl"; + + private static long g_count=0x0; + private Calendar g_start; + private String eclipseDir; + + /** + * Protected constructor + */ + public EclipseSolver() throws SmartFrogRuntimeException { + try { + prepareSolver(); + } catch (SmartFrogResolutionException e) { + SFSystem.sfLog().debug("EXCEPTION: "+e); + throw e; + } + } + + public EclipseEngine getEngine(){ + return eclipse; + } + + public String getEclipseDir() { + return eclipseDir; + } + + /** + * Set cuurrent attribute in user var sfConfig browser being manipulated + */ + public void setEclipseCDAttr(EclipseCDAttr ecda) { + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + + currentCDAttr = ecda; + } + + /** + * Eclipse main goal to run in secondary thread + */ + public void run() { + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + + try { + eclipse.rpc("sfsolve"); + } catch (Exception e) { + + generalError = e; + yieldLockFromECRThread(); + } + } + + + /** + * Constraints are possible (ie supported) if this class is loaded... + */ + @Override + public boolean getConstraintsPossible() { + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + + return true; + } + + /** + * Prepare the solver + */ + private void prepareSolver() throws SmartFrogResolutionException { + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + + //Prepare theory... + + String unable = "Unable to load Eclipse-based solver:"; + + // Get Eclipse Installation Directory... + eclipseDir = System.getProperty(ECLIPSEDIR_SPECIFIER); + if (eclipseDir == null) { + eclipseDir = System.getenv("ECLIPSEDIRECTORY"); + } + + //Throw on lack of info re eclipse directory... + if (eclipseDir == null) { + throw new SmartFrogResolutionException( + unable + " eclipse directory property unspecified (" + ECLIPSEDIR_SPECIFIER + + ")"); + } + + //Set up eclipse... + eclipseEngineOptions = new EclipseEngineOptions(new File(eclipseDir)); + + // Connect the Eclipse's standard streams to the JVMs + eclipseEngineOptions.setUseQueues(false); + + // Initialise Eclipse + try { + eclipse = EmbeddedEclipse.getInstance(eclipseEngineOptions); + } catch (Throwable e) { + throw new SmartFrogResolutionException(unable + " can not get eclipse instance, " + e, e); + } + + int idx = 0; + String theoryFile = System.getProperty(THEORYFILE_PREFIX + idx); + if (theoryFile == null) { + theoryFile = DEFAULT_THEORY; + } + + while (theoryFile != null) { + //Consult core theory files + //eclipseDir/... is not necessarily the best place to put the theory files... + try { + eclipse.compile(new File(eclipseDir + ECLIPSE_SWITCH + theoryFile)); + } catch (Exception e) { + throw new SmartFrogResolutionException( + unable + " can not compile theory source: " + theoryFile + " , " + e, e); + } + idx++; + theoryFile = System.getProperty(THEORYFILE_PREFIX + idx); + } + + // Set up the java representation of two queue streams + try { + javaToEclipseQueue = eclipse.getToEclipseQueue("java_to_eclipse"); + eclipseToJavaQueue = eclipse.getFromEclipseQueue("eclipse_to_java"); + eclipseToJavaQueue.setListener(this); + } catch (Exception e) { + throw new SmartFrogResolutionException(unable + " general queue exception, " + e, e); + } + + resetResolutionState(); + } + + + public void doConstraintsWork(Object key) throws SmartFrogResolutionException { + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + + SFSystem.sfLog().debug("key: "+key); + + //if (resolutionState != null){ + Vector<FreeVar> vec = resolutionState.removeLabellingRecordVector(key); + if (vec!=null) { + Constraint constraint = new Constraint(); + ComponentDescription comp = new SFComponentDescriptionImpl(); + comp.sfContext().setOriginatingDescr(comp); + + //Add vars... + try { + for (FreeVar fv: vec){ + String id="unique"+DefaultParser.nextId++; + comp.sfAddAttribute(id, fv); + comp.sfAddTag(id, "sfConstraintAutoVar"); + } + } catch (SmartFrogRuntimeException sfre){ throw new SmartFrogResolutionException(sfre);} + + constraint.doit(comp.sfContext(), null, (ReferenceResolver)null); + } + //} + } + + public void addAutoVar(Object key, FreeVar var) throws SmartFrogResolutionException { + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + + resolutionState.addLabellingRecord(key, var); + } + + + /** + * Reset "backtracked to" Context information + */ + @Override + public void resetDoneBacktracking() { + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + + //if (resolutionState != null) { + resolutionState.resetDoneBacktracking(); + //} + } + + /** + * On backtracking, we have backtracked to the returned context + * + * @return Context to which backtracking has unwound to, null if no backtracking + */ + @Override + public ConstraintContext hasBacktrackedTo() { + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + + //if (resolutionState != null) + return resolutionState.hasBacktrackedTo(); + //else return null; + } + + /** + * Should we undo actions involving contexts and FreeVars? + * + * @param undo Should we? + */ + @Override + public void setShouldUndo(boolean undo) { + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + + //if (resolutionState != null) { + resolutionState.setConstraintsShouldUndo(undo); + //} + } + + /** + * Adds single undo action to current lhr for undo attribute setting in a Context + * + * @param ctxt context for undo action + * @param key key to undo put value + * @param value value to restore + */ + @Override + public void addUndoPut(Context ctxt, Object key, Object value) { + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + + SFSystem.sfLog().debug("key:"+key+", value"+value); + + //if (resolutionState != null) { + resolutionState.addUndoPut(ctxt, key, value); + //} + } + + /** + * Adds single undo action to current lhr for undoing FreeVar info setting + * + * @param fv FreeVar + */ + @Override + public void addUndoFVInfo(FreeVar fv) { + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + + //if (resolutionState != null) { + resolutionState.addUndoFVInfo(fv); + //} + } + + /** + * Adds single undo action to current lhr for undoing FreeVar type string setting + * + * @param fv FreeVar + */ + @Override + public void addUndoFVTypeStr(FreeVar fv) { + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + + //if (resolutionState != null) { + resolutionState.addUndoFVTypeStr(fv); + //} + } + + @Override + public void addUndoFVAutoVarEffect(FreeVar fv, Vector<Reference> autoEffects){ + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + + resolutionState.addUndoFVAutoVarEffect(fv, autoEffects); + } + + @Override + public void addUndoFVAutoVarEffect(FreeVar fv){ + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + + resolutionState.addUndoFVAutoVarEffect(fv); + } + + + /** + * Stop solving altogether + */ + @Override + public void stopSolving() { + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + + javaToEclipse("sfstop"); + goalThread = null; + resetResolutionState(); + Calendar stop = new GregorianCalendar(); + if (isVerbose()){ + System.out.println("Start:"+g_start); + System.out.println("Stop:"+stop); + System.out.println("Label counts:"+g_count); + } + } + + private boolean isVerbose() { + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + + return false; + } + + public void fail() throws Exception { + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + + //Assume that we are up... + get_value = "fail"; + + //Let rip... + doIt(); + } + + + public void doIt() { + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + + consFinished = false; + javaToEclipse(); + + //Lock me to make sure I don't complete before constraint eval does... + synchronized(this){ + while (!consFinished){ + try { + wait(); + }catch (Exception e){}; + } + } + + //Has Eclipse solver thread failed? + if (generalError != null) { + Exception generalErrorold = generalError; + goalThread = null; + generalError = null; + resetResolutionState(); + throw new CoreSolverFatalError(generalErrorold); + } + } + + void resetResolutionState(){ + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + + resolutionState = new ConstraintResolutionState(); + g_count=0; + g_start = new GregorianCalendar(); + } + + /** + * Solve a Constraint goal + */ + @Override + public void solve(ConstraintContext cc, Vector attrs, Vector values, Vector goal, Vector autos, + boolean isuservars, HashMap<FreeVar,Object> assigns) throws Exception { + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + + + //Set comp as current solving comp descr + solveCD = cc.getCD(); + + //Set is user vars? + isUserVars = isuservars; + + //Construct goal + String _attrs = mapValueJE(attrs); + String _values = mapValueJE(values); + String _goal = mapValueJE(goal); + String _autos = mapValueJE(autos); + String verbose = (isVerbose() ? "true" : "false"); + + String assign_s="["; + boolean first=true; + Iterator iter = assigns.keySet().iterator(); + while (iter.hasNext()){ + FreeVar fv = (FreeVar) iter.next(); + Object val = assigns.get(fv); + if (first) first=false; + else assign_s += ", "; + assign_s += "("+val+","+mapValueJE(fv)+")"; + } + assign_s +="]"; + + get_value = "sfsolve(" + _attrs + ", " + _values + ", " + + resolutionState.addConstraintEval(cc) + ", " + _goal + ", " + _autos + ", " + verbose + ", "+ assign_s + + ")"; + + if (isVerbose()) System.out.println(get_value); + + //Allocate new thread for goal and start it + if (goalThread == null) { + goalThread = new Thread(this); + goalThread.start(); + } + + //Let rip + doIt(); + + } + + /** + * Maps Java object to String for transfer to Eclipse + * + * @param v object to be transformed + * @return eclipse string + */ + private String mapValueJE(Object v) throws SmartFrogResolutionException { + return mapValueJE(v, false); + } + + /** + * Maps Java object to String for transfer to Eclipse + * + * @param v object to be transformed + * @param quoted indicates whether Strings should be double quoted + * @return eclipse string + */ + public String mapValueJE(Object v, boolean quoted) throws SmartFrogResolutionException { + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + SFSystem.sfLog().debug("VALUE: "+v); + + if (v instanceof FreeVar) { + FreeVar fv = (FreeVar) v; + if (fv.getConsEvalKey() != null) { + if (fv.getConsEvalIdx() == -1) { + fv.setConsEvalIdx(resolutionState.getConsEvalIdx() + 1); //+1 as yet to add entry + + String range_s = "null"; + Object range = fv.getRange(); + if (range != null) { + if (range instanceof String) { + range_s = (String) range; + } else if (range instanceof Vector) { + range_s = mapValueJE(range); + } else if (range instanceof Integer || range instanceof Boolean) { + range_s = "integer"; + } else { + throw new SmartFrogResolutionException("Invalid range specifier for FreeVar: " + v); + } + } + + Object defVal = fv.getDefVal(); + String defVal_s = (defVal != null ? ", " + defVal.toString() : ""); + return "sfvar(" + range_s + defVal_s + ")"; + + } else { + return "sfref(" + fv.getConsEvalIdx() + ", " + fv.getConsEvalKey() + ")"; + } + } else { + return v.toString(); + } + } else if (v instanceof Number) { + return v.toString(); + } else if (v instanceof Vector) { + String val = "["; + boolean first = true; + Iterator it = ((Vector) v).iterator(); + while (it.hasNext()) { + if (first) { + first = false; + } else { + val += ", "; + } + + val += mapValueJE(it.next(), quoted); + } + val += "]"; + return val; + } else if (v instanceof String) { + if (quoted) { + return "\"" + v + "\""; + } else { + return (String) v; + } + } else if (v instanceof SFNull) { + return "sfnull"; + } else if (v instanceof SFReference) { + SFReference vref = (SFReference)v; + if (vref.size()==0) return null; + ReferencePart rp = ((SFReference) v).firstElement(); + if (rp instanceof AttribReferencePart) { + String ret_s = ((AttribReferencePart) rp).getValue().toString(); + if (quoted) ret_s = "\"" + ret_s + "\""; + return ret_s; + } else { + return null; + } + } else if (v instanceof ComponentDescription) { + return "sfcd"; + } else if (v instanceof Boolean) { + return ((Boolean) v).booleanValue()?"1":"0"; + } else { + return null; + } + } + + + /** + * Maps Eclipse object to Java object after transfer from Eclipse + * + * @param v object to be transformed + * @return transformed object + */ + private Object mapValueEJ(Object v) { + return mapValueEJ(v, false); + } + + /** + * Maps Eclipse object to Java object after transfer from Eclipse + * + * @param v object to be transformed + * @param ref_create indicates whether references should be created for atoms -- used for subtyping directives + * @return transformed object + */ + private Object mapValueEJ(Object v, boolean ref_create) { + SFSystem.sfLog().debug("VALUE: " + v); + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + if (v == null) { + return new FreeVar(); + } else if (v.equals(Collections.EMPTY_LIST)) { + return new Vector(); + } else if (v instanceof Number) { + return v; + } else if (v instanceof Collection) { + Vector result = new Vector(); + Iterator it = ((Collection) v).iterator(); + while (it.hasNext()) { + result.add(mapValueEJ(it.next(), ref_create)); + } + return result; + } else if (v instanceof String) { + return v; + } else if (v instanceof Atom) { + Atom va = (Atom) v; + if (va.functor().equals("sfnull")) { + return SFNull.get(); + } else { + String va_s = va.functor(); + try { + if (ref_create) { + return Reference.fromString(va_s); + } + return va_s; + } catch (SmartFrogResolutionException sfre) { + throw new RuntimeException( + "mapValueEJ: Trouble in creating reference from attribute string for subtyping. ", + sfre); + } + } + } else { + throw new RuntimeException("mapValueEJ: unknown data *from* solver " + v); + } + } + + + /** + * Populate sfConfig browser for setting user variables... + */ + private void populateBrowser() { + Object root = cdBrowser.attr(null, "sfConfig", false); + populateBrowser(orig, root, false); + } + + /** + * Populate sfConfig browser for setting user variables... + * + * @param cd current component description being added to browser + * @param root browser object corresponding to sfConfig + * @param showme whether I should be shown -- determined by whether I am the Constraint component description + * currently being solved... + */ + private void populateBrowser(ComponentDescription cd, Object root, boolean showme) { + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + Iterator attriter = cd.sfAttributes(); + Context cxt = cd.sfContext(); + //String cxts = create_ref_str(cd); + while (attriter.hasNext()) { + Object attr = attriter.next(); + Object val = null; + + try { + val = cxt.sfResolveAttribute(attr); + } catch (Exception e) { + throw new RuntimeException("Can not resolve attribute when populating browser with attribute "+attr, e); + } + + if (val instanceof SFApplyReference) { + SFApplyReference val_ar = (SFApplyReference) val; + val = val_ar.getComponentDescription(); + } + + if (val instanceof ComponentDescription) { + boolean showkids = (!showme && solveCD == val); + Object chroot = cdBrowser.attr(root, attr.toString(), showme); + populateBrowser((ComponentDescription) val, chroot, showkids); + } else { + EclipseCDAttr ecda = new EclipseCDAttr(this, attr.toString(), val); + + cdBrowser.attr(root, ecda, showme); + try { + if (cd == solveCD && cxt.sfContainsTag(attr, "sfConstraintUserVar") && val instanceof FreeVar) { + rangeAttrs.add(ecda); + ecda.set(false); + } else { + ecda.set(true); + } + } catch (Exception e) { + throw new RuntimeException("Can not check attribute for tag", e); + } + + } + + } + + } + + /** + * Kill sfConfig browser for user variables + */ + public void killBrowser() { + cdBrowser.kill(); + } + + /** + * Communicate supplied parameter to Eclipse side + * + * @param val Object to be sent + */ + public void javaToEclipse(Object val) { + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + get_value = val; + javaToEclipse(); + } + + /** + * Communicate m_get_val to Eclipse side + */ + public void javaToEclipse() { + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + try { + javaToEclipseQueue.setListener(this); + } catch (Exception e) { + throw new RuntimeException("Unanable to reset JtoE listener", e); + } + } + + + /** + * Initiated by Eclipse side -- process user variables in Constraint description... + */ + void sfuser() { + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + + //If no user variables, then we are done... + if (!isUserVars) { + javaToEclipse(new Atom("done")); + return; + } + + //Get sfConfig browser class + String classname = System.getProperty(USERVAR_BROWSER); + if (classname == null) { + throw new RuntimeException("Can not instantiate CD Browser, classname property not set..."); + } + + try { + cdBrowser = (CDBrowser) SFClassLoader.forName(classname).newInstance(); + } catch (Exception e) { + throw new RuntimeException("Can not instantiate CD Browser", e); + } + + //Populate the browser + + populateBrowser(); + + //User variables to be set in m_rangeAttrs, communicate these to eclipse side to get ranges... + if (rangeAttrs.size() != 0) { + + List ranges = new LinkedList(); + Iterator raiter = rangeAttrs.iterator(); + while (raiter.hasNext()) { + EclipseCDAttr ecda = (EclipseCDAttr) raiter.next(); + ranges.add(ecda.getAttrName()); + ... [truncated message content] |