Commits

Kevin A. Archie  committed 1757b96

added export, describe statements

  • Participants
  • Parent commits 01bc30b
  • Tags v0.1.1

Comments (0)

Files changed (7)

File ecat-edit/pom.xml

   <groupId>org.nrg</groupId>
   <artifactId>ecat-edit</artifactId>
   <packaging>jar</packaging>
-  <version>0.1.0</version>
+  <version>0.1.1</version>
   <name>ecat-edit</name>
   <parent>
     <groupId>org.nrg</groupId>
     <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-api</artifactId>
-      <version>1.5.10</version>
+      <version>[1.5.11,)</version>
+    </dependency>
+        <dependency>
+        <groupId>org.slf4j</groupId>
+        <artifactId>slf4j-simple</artifactId>
+        <version>[1.5.11,)</version>
+        <scope>test</scope>
     </dependency>
     <dependency>
       <groupId>org.antlr</groupId>

File ecat-edit/src/main/antlr3/org/nrg/ecat/edit/EditECATASTParser.g

 	|	^(HIDDEN id=ID) {
 			getVariable(id).setIsHidden(true);
 		}
+	|	^(EXPORT id=ID field=STRING) {
+			getVariable(id).setExportField(extractString(field));
+		}
 	;
 	
 echo

File ecat-edit/src/main/antlr3/org/nrg/ecat/edit/EditECATLexer.g

 NEW	:	'new';
 DESCRIBE:	'describe';
 HIDDEN	:	'hidden';
+EXPORT  :	'export';
 
 ID  :	('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')*
     ;

File ecat-edit/src/main/antlr3/org/nrg/ecat/edit/EditECATParser.g

 description
 	:	DESCRIBE ID STRING -> ^(DESCRIBE ID STRING)
 	|	DESCRIBE ID HIDDEN -> ^(HIDDEN ID)
+	|	EXPORT ID STRING   -> ^(EXPORT ID STRING)
 	;
 	
 term	:	STRING

File ecat-edit/src/main/java/org/nrg/ecat/edit/ScriptReferencedVariable.java

  *
  */
 public class ScriptReferencedVariable implements Variable {
-	private final Logger logger = LoggerFactory.getLogger(ScriptReferencedVariable.class);
-	private final String name;
-	private Object value = null;
-	private Value initValue = null;
-	private boolean isHidden = false;
-	private String description = null;
-	
-	public ScriptReferencedVariable(final String name) {
-		this.name = name;
-	}
-	
-	/* (non-Javadoc)
-	 * @see org.nrg.ecat.edit.Variable#getDescription()
-	 */
-	public String getDescription() { return description; }
+    private final Logger logger = LoggerFactory.getLogger(ScriptReferencedVariable.class);
+    private final String name;
+    private Object value = null;
+    private Value initValue = null;
+    private boolean isHidden = false;
+    private String description = null;
+    private String exportField = null;
 
-	/* (non-Javadoc)
-	 * @see org.nrg.ecat.edit.Variable#getInitialValue()
-	 */
-	public Value getInitialValue() { return initValue; }
+    public ScriptReferencedVariable(final String name) {
+        this.name = name;
+    }
 
-	/* (non-Javadoc)
-	 * @see org.nrg.ecat.edit.Variable#getName()
-	 */
-	public String getName() { return name; }
+    /* (non-Javadoc)
+     * @see org.nrg.ecat.edit.Variable#getDescription()
+     */
+    public String getDescription() { return description; }
 
-	/* (non-Javadoc)
-	 * @see org.nrg.ecat.edit.Variable#getValue()
-	 */
-	public Object getValue() { return value; }
+    /*
+     * (non-Javadoc)
+     * @see org.nrg.ecat.edit.Variable#getExportField()
+     */
+    public String getExportField() { return exportField; }
 
-	/* (non-Javadoc)
-	 * @see org.nrg.ecat.edit.Variable#isHidden()
-	 */
-	public boolean isHidden() { return isHidden; }
+    /* (non-Javadoc)
+     * @see org.nrg.ecat.edit.Variable#getInitialValue()
+     */
+    public Value getInitialValue() { return initValue; }
 
-	/* (non-Javadoc)
-	 * @see org.nrg.ecat.edit.Variable#setDescription(java.lang.String)
-	 */
-	public void setDescription(final String description) {
-		this.description = description;
-	}
+    /* (non-Javadoc)
+     * @see org.nrg.ecat.edit.Variable#getName()
+     */
+    public String getName() { return name; }
 
-	/* (non-Javadoc)
-	 * @see org.nrg.ecat.edit.Variable#setInitialValue(org.nrg.ecat.edit.Value)
-	 */
-	public void setInitialValue(final Value value) throws MultipleInitializationException{
-		if (null == initValue) {
-			logger.trace(this + " initial value set to " + value);
-			initValue = value;
-		} else {
-			throw new MultipleInitializationException(this, value);
-		}
-	}
+    /* (non-Javadoc)
+     * @see org.nrg.ecat.edit.Variable#getValue()
+     */
+    public Object getValue() { return value; }
 
-	/* (non-Javadoc)
-	 * @see org.nrg.ecat.edit.Variable#setIsHidden(boolean)
-	 */
-	public void setIsHidden(final boolean isHidden) {
-		this.isHidden = isHidden;
-	}
+    /* (non-Javadoc)
+     * @see org.nrg.ecat.edit.Variable#isHidden()
+     */
+    public boolean isHidden() { return isHidden; }
 
-	/* (non-Javadoc)
-	 * @see org.nrg.ecat.edit.Variable#setValue(java.lang.Object)
-	 */
-	public void setValue(final Object value) {
-		logger.trace(this + " value set to " + value);
-		this.value = value;
-	}
+    /* (non-Javadoc)
+     * @see org.nrg.ecat.edit.Variable#setDescription(java.lang.String)
+     */
+    public void setDescription(final String description) {
+        this.description = description;
+    }
 
-	/*
-	 * (non-Javadoc)
-	 * @see java.lang.Object#toString()
-	 */
-	public String toString() {
-		final StringBuffer sb = new StringBuffer(super.toString());
-		return sb.append(" (").append(name).append(")").toString();
-	}
+    /*
+     * (non-Javadoc)
+     * @see org.nrg.ecat.edit.Variable#setExportField(java.lang.String)
+     */
+    public void setExportField(final String exportField) {
+        this.exportField = exportField;
+    }
+
+    /* (non-Javadoc)
+     * @see org.nrg.ecat.edit.Variable#setInitialValue(org.nrg.ecat.edit.Value)
+     */
+    public void setInitialValue(final Value value) throws MultipleInitializationException{
+        if (null == initValue) {
+            logger.trace("{} initial value set to {}", this, value);
+            initValue = value;
+        } else {
+            throw new MultipleInitializationException(this, value);
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.nrg.ecat.edit.Variable#setIsHidden(boolean)
+     */
+    public void setIsHidden(final boolean isHidden) {
+        this.isHidden = isHidden;
+    }
+
+    /* (non-Javadoc)
+     * @see org.nrg.ecat.edit.Variable#setValue(java.lang.Object)
+     */
+    public void setValue(final Object value) {
+        logger.trace("{} value set to {}", this, value);
+        this.value = value;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see java.lang.Object#toString()
+     */
+    public String toString() {
+        final StringBuffer sb = new StringBuffer(super.toString());
+        return sb.append(" (").append(name).append(")").toString();
+    }
 }

File ecat-edit/src/main/java/org/nrg/ecat/edit/Variable.java

 package org.nrg.ecat.edit;
 
 /**
- * @author Kevin A. Archie <karchie@npg.wustl.edu>
+ * @author Kevin A. Archie <karchie@wustl.edu>
  *
  */
 public interface Variable {
-	String getDescription();
-	String getName();
-	Value getInitialValue();
-	Object getValue();
-	boolean isHidden();
-	void setDescription(String description);
-	void setInitialValue(Value value) throws MultipleInitializationException;
-	void setIsHidden(boolean isHidden);
-	void setValue(Object value);
+    String getDescription();
+    String getExportField();
+    String getName();
+    Value getInitialValue();
+    Object getValue();
+    boolean isHidden();
+    void setDescription(String description);
+    void setExportField(String exportField);
+    void setInitialValue(Value value) throws MultipleInitializationException;
+    void setIsHidden(boolean isHidden);
+    void setValue(Object value);
 }

File ecat-edit/src/test/java/org/nrg/ecat/edit/ScriptApplicatorTest.java

+/**
+ * Copyright (c) 2010 Washington University
+ */
+package org.nrg.ecat.edit;
+
+import java.io.ByteArrayInputStream;
+import java.util.Collections;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Kevin A. Archie <karchie@wustl.edu>
+ *
+ */
+public class ScriptApplicatorTest extends TestCase {
+    private static final Map fns = Collections.emptyMap();
+    
+    private static final String S_DESCRIPTION = "describe foo \"Description\"\nbar := foo\n";
+    
+    private static final String S_EXPORT_FIELD = "export foo \"baz:/my/export/path\"\nbar := foo\n";
+
+    private ByteArrayInputStream bytes(final String s) {
+        return new ByteArrayInputStream(s.getBytes());
+    }
+    
+
+    public void testDescription() throws Exception {
+        final ScriptApplicator applicator = new ScriptApplicator(bytes(S_DESCRIPTION), fns);
+        final Variable foo = applicator.getVariable("foo");
+        assertEquals("Description", foo.getDescription());
+        final Variable bar = applicator.getVariable("bar");
+        assertNull(bar.getDescription());
+    }
+    
+    public void testExportField() throws Exception {
+        final ScriptApplicator applicator = new ScriptApplicator(bytes(S_EXPORT_FIELD), fns);
+        final Variable foo = applicator.getVariable("foo");
+        assertEquals("baz:/my/export/path", foo.getExportField());
+        final Variable bar = applicator.getVariable("bar");
+        assertNull(bar.getExportField());   
+    }
+}