Skip to content

Commit

Permalink
Merge pull request #115 from LEMS/experimental
Browse files Browse the repository at this point in the history
Meta annotation updates
  • Loading branch information
pgleeson committed Sep 11, 2023
2 parents a7a7b86 + ef30e87 commit 2ca3860
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 15 deletions.
9 changes: 7 additions & 2 deletions src/main/java/org/lemsml/jlems/core/reader/LemsFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.lemsml.jlems.core.type.dynamics.*;
import org.lemsml.jlems.core.type.structure.*;
import org.lemsml.jlems.core.type.simulation.Record;

import org.lemsml.jlems.core.type.simulation.*;

import org.lemsml.jlems.core.type.procedure.*;
Expand Down Expand Up @@ -764,10 +765,10 @@ private Child buildChild(XMLElement xel) {
ret.name = parseString(xv);
} else if (xn.equals("type")) {
ret.type = parseString(xv);
} else if (xn.equals("description")) {
ret.description = parseString(xv);
} else if (xn.equals("substitute")) {
ret.substitute = parseString(xv);
} else if (xn.equals("description")) {
ret.description = parseString(xv);
} else {
E.warning("Unrecognized attribute " + xa + " " + xv);
}
Expand Down Expand Up @@ -810,6 +811,8 @@ private Link buildLink(XMLElement xel) {
ret.name = parseString(xv);
} else if (xn.equals("type")) {
ret.type = parseString(xv);
} else if (xn.equals("description")) {
ret.description = parseString(xv);
} else if (xn.equals("root")) {
ret.root = parseString(xv);
} else if (xn.equals("isAny")) {
Expand Down Expand Up @@ -2423,6 +2426,8 @@ private Simulation buildSimulation(XMLElement xel) {
ret.dataWriters.add((DataWriter)obj);
} else if (obj instanceof EventWriter) {
ret.eventWriters.add((EventWriter)obj);
} else if (obj instanceof Meta) {
ret.metas.add((Meta)obj);
} else {
E.warning("Unrecognized element ("+xn+"): " + cel);
}
Expand Down
26 changes: 14 additions & 12 deletions src/main/java/org/lemsml/jlems/core/type/Meta.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,36 @@
import java.util.ArrayList;
import java.util.HashMap;

import org.lemsml.jlems.core.annotation.ModelElement;
import org.lemsml.jlems.core.sim.ContentError;
import org.lemsml.jlems.core.xml.XMLAttribute;
import org.lemsml.jlems.core.xml.XMLElement;


// RawValued indicates that XML found inside Meta elements should be treated

// RawValued indicates that XML found inside Meta elements should be treated
// processed into an element tree, but not interpreted as lems elements.
// other tools can do their own thing with the content
@ModelElement(info="Meta element to provide arbitrary metadata to LEMS simulations. Note that this is not processed by the LEMS interpreter.")
public class Meta {

public String context;

public XMLElement valueWrapper = new XMLElement("wrapper");

private XMLElement p_sourceXML;

public ArrayList<MetaItem> items = new ArrayList<MetaItem>();



public Meta() {

}

public void setSource(XMLElement xe) {
p_sourceXML = xe;
}

public void addXMLElement(XMLElement xe) {
valueWrapper.add(xe);
// E.info("Set VW " + xe.toXMLString(""));
Expand All @@ -45,15 +47,15 @@ public HashMap<String, String> getAttributes() {
}
return ret;
}


public void add(Object obj) throws ContentError {
if (obj instanceof MetaItem) {
items.add((MetaItem)obj);
} else {
throw new ContentError("cant add " + obj);
}
}
}

public MetaItem newItem(String nm) {
MetaItem ret = new MetaItem(nm);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.lemsml.jlems.core.type.ComponentType;
import org.lemsml.jlems.core.type.Lems;
import org.lemsml.jlems.core.type.LemsCollection;
import org.lemsml.jlems.core.type.Meta;



Expand All @@ -29,6 +30,8 @@ public class Simulation {

public transient LemsCollection <EventWriter> eventWriters = new LemsCollection<EventWriter>();

public transient LemsCollection <Meta> metas = new LemsCollection<Meta>();


public static int idCounter = 0;

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/lemsml/jlems/io/reader/LemsClasses.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ private ArrayList<LemsClass> getStructureClasses() {
ArrayList<LemsClass> ret = new ArrayList<LemsClass>();
String section = "structure";
ret.add(new LemsClass(Structure.class, section));
ret.add(new LemsClass(BuildElement.class, section));
// ret.add(new LemsClass(BuildElement.class, section)); -> abstract
ret.add(new LemsClass(MultiInstantiate.class, section));
ret.add(new LemsClass(CoInstantiate.class, section));
ret.add(new LemsClass(Assign.class, section));
Expand All @@ -199,6 +199,7 @@ private ArrayList<LemsClass> getComponentTypeClasses() {
ArrayList<LemsClass> ret = new ArrayList<LemsClass>();

String section = "componenttypes";
ret.add(new LemsClass(Component.class, section));
ret.add(new LemsClass(ComponentType.class, section));
ret.add(new LemsClass(Parameter.class, section));
ret.add(new LemsClass(PathParameter.class, section));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ private String generateJava() {
sb.append("import org.lemsml.jlems.core.type.*;\n");
sb.append("import org.lemsml.jlems.core.type.dynamics.*;\n");
sb.append("import org.lemsml.jlems.core.type.structure.*;\n");
sb.append("import org.lemsml.jlems.core.type.simulation.Record;\n\n"); // Record is ambiguous
sb.append("import org.lemsml.jlems.core.type.simulation.*;\n\n");
sb.append("import org.lemsml.jlems.core.type.procedure.*;\n\n");
sb.append("import org.lemsml.jlems.core.type.geometry.*;\n\n");
Expand Down

0 comments on commit 2ca3860

Please sign in to comment.