Skip to content

Commit

Permalink
change model for backward compatability
Browse files Browse the repository at this point in the history
  • Loading branch information
Dong committed Aug 22, 2014
1 parent e96efaf commit 6509868
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 43 deletions.
17 changes: 0 additions & 17 deletions AncestorView/bin/META-INF/MANIFEST.MF

This file was deleted.

7 changes: 0 additions & 7 deletions AncestorView/bin/OSGI-INF/services.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@
*/
public class ActivityComponent extends CostFunctionComponent implements DurationCapability{
private ObjectManager objectManager = new ObjectManager.ExplicitObjectManager();
private final AtomicReference<ActivityData> model = new AtomicReference<ActivityData>(new ActivityData());
private final AtomicReference<ActivityModelRole> model = new AtomicReference<ActivityModelRole>(new ActivityModelRole());

/**
* Get the underlying data about this Activity (start time, end time, costs, type...)
* @return underlying activity data
*/
public ActivityData getData() {
return model.get();
return getModel().getData();
}

@Override
Expand Down Expand Up @@ -106,21 +106,21 @@ protected <T> T handleGetCapability(Class<T> capability) {
return capability.cast(new ActivityGraphData());
}
if (capability.isAssignableFrom(ModelStatePersistence.class)) {
JAXBModelStatePersistence<ActivityData> persistence = new JAXBModelStatePersistence<ActivityData>() {
JAXBModelStatePersistence<ActivityModelRole> persistence = new JAXBModelStatePersistence<ActivityModelRole>() {

@Override
protected ActivityData getStateToPersist() {
protected ActivityModelRole getStateToPersist() {
return model.get();
}

@Override
protected void setPersistentState(ActivityData modelState) {
protected void setPersistentState(ActivityModelRole modelState) {
model.set(modelState);
}

@Override
protected Class<ActivityData> getJAXBClass() {
return ActivityData.class;
protected Class<ActivityModelRole> getJAXBClass() {
return ActivityModelRole.class;
}

};
Expand All @@ -134,7 +134,7 @@ protected Class<ActivityData> getJAXBClass() {
public List<CostFunctionCapability> getInternalCostFunctions() {
List<CostFunctionCapability> internal = new ArrayList<CostFunctionCapability>();
for(CostType type: CostType.values()) {
double value = Double.valueOf(getModel().getValue(type.getName()));
double value = Double.valueOf(getData().getValue(type.getName()));
if (value != 0.0) {
internal.add(new CostFunctionStub(type));
}
Expand Down Expand Up @@ -171,7 +171,7 @@ private List<CostWrapper> getCostWrappers() {
* Get the container for underlying Activity data
* @return the container for underlying Activity data (its model)
*/
public ActivityData getModel() {
public ActivityModelRole getModel() {
return model.get();
}

Expand Down Expand Up @@ -427,17 +427,17 @@ public void setAsText(String text) throws IllegalArgumentException {
@Override
public Object getValue() {
return new ActivityCustomProperty(tagPropertyEditor.getValue(),
getModel().getValue("url"),
getModel().getValue("procedureUrl"));
getData().getValue("url"),
getData().getValue("procedureUrl"));
}

@Override
public void setValue(Object value) throws IllegalArgumentException {
if (value instanceof ActivityCustomProperty) {
ActivityCustomProperty property = (ActivityCustomProperty) value;
tagPropertyEditor.setValue(property.getTagStyleChildren());
getModel().setValue("url", property.getUrl());
getModel().setValue("procedureUrl", property.getProcedureUrl());
getData().setValue("url", property.getUrl());
getData().setValue("procedureUrl", property.getProcedureUrl());
} else {
throw new IllegalArgumentException(
ActivityCustomProperty.class.getName() +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public AbstractComponent createActivity(
ComponentRegistry registry = ActivityCreationServiceImpl.registry.get();
ActivityComponent activity =
registry.newInstance(ActivityComponent.class, parent);
activity.getModel().setValue("startTime", String.valueOf(0L));
activity.getModel().setValue("endTime", String.valueOf(30L * 60L * 1000L));
activity.getData().setValue("startTime", String.valueOf(0L));
activity.getData().setValue("endTime", String.valueOf(30L * 60L * 1000L));
/** activity.getModel().setValue("POWER", String.valueOf(Double.NaN));
activity.getModel().setValue("IMPEDANCE", String.valueOf(Double.NaN));
activity.getModel().setValue("COMM", String.valueOf(Double.NaN)); */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*******************************************************************************/
package gov.nasa.arc.mct.scenario.component;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -82,4 +83,68 @@ public void setDurationTime(long duration)
properties.put("endTime", String.valueOf(startTime + duration));
}

public double getPower() {
return Double.valueOf(getValue("POWER"));
}

public void setPower(double power) {
setValue("POWER", String.valueOf(power));
}

public double getComm() {
return Double.valueOf(getValue("COMM"));
}

public void setComm(double comm) {
setValue("COMM", String.valueOf(comm));
}

public String getActivityType() {
return getValue("type");
}

public void setActivityType(String type) {
setValue("type", type);
}

public String getNotes() {
return getValue("notes");
}

public void setNotes(String notes) {
setValue("notes", notes);
}

public Date getStartTime() {
return new Date(Long.valueOf(getValue("startTime")));
}

public void setStartDate(Date startDate) {
setValue("startTime", String.valueOf(startDate.getTime()));
}

public Date getEndTime() {
return new Date(Long.valueOf(getValue("endTime")));
}

public void setEndDate(Date endDate) {
setValue("endTime", String.valueOf(endDate.getTime()));
}

public String getUrl() {
return getValue("url");
}

public void setUrl(String url) {
setValue("url", url);
}

public String getProcedureUrl() {
return getValue("procedureUrl");
}

public void setProcedureUrl(String procedureUrl) {
setValue("procedureUrl", procedureUrl);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ public void setUrl(String url) {
this.url = url;
}

public double getPower() {
return get("POWER");
}
public void setPower(double power) {
set("POWER", power);
}
public double getComms() {
return get("COMM");
}
public void setComms(double comms) {
set("COMM", comms);
}

public void set(String typeName, double value) {
costs.put(typeName, value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public NotesPropertyEditor(AbstractComponent component) {
@Override
public String getAsText() {
if (component instanceof ActivityComponent) {
return ((ActivityComponent) component).getModel().getValue("notes");
return ((ActivityComponent) component).getData().getValue("notes");
} else if (component instanceof DecisionComponent) {
return ((DecisionComponent) component).getModel().getData().getNotes();
} else {
Expand All @@ -66,7 +66,7 @@ public void setAsText(String newValue) throws IllegalArgumentException {
throw new IllegalArgumentException("Cannot be null");
}
if (component instanceof ActivityComponent) {
((ActivityComponent) component).getModel().setValue("notes", newValue);
((ActivityComponent) component).getData().setValue("notes", newValue);
} else if (component instanceof DecisionComponent) {
((DecisionComponent) component).getModel().getData().setNotes(newValue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public TypePropertyEditor(AbstractComponent component) {

@Override
public String getAsText() {
String typeData = activityComponent.getModel().getValue("type");
String typeData = activityComponent.getData().getValue("type");
return typeData;
}

Expand All @@ -57,7 +57,7 @@ public void setAsText(String newValue) throws IllegalArgumentException {
if (verify(newValue) != null) {
throw new IllegalArgumentException(result);
}
ActivityData businessModel = activityComponent.getModel();
ActivityData businessModel = activityComponent.getData();
businessModel.setValue("type", newValue);

}
Expand Down

0 comments on commit 6509868

Please sign in to comment.