private void saveModelElementContainer(NetType iNet, ModelElementContainer elementContainer)
{
Iterator<AbstractPetriNetElementModel> root2Iter = elementContainer.getRootElements().iterator();
while (root2Iter.hasNext())
{
AbstractPetriNetElementModel currentModel = (AbstractPetriNetElementModel) root2Iter.next();
/* ##### PLACES ##### */
if (currentModel.getType() == AbstractPetriNetElementModel.PLACE_TYPE)
{
initPlace(iNet.addNewPlace(), (PlaceModel) currentModel);
} else if (currentModel.getType() == AbstractPetriNetElementModel.TRANS_SIMPLE_TYPE)
/* ##### TRANSITION ##### */
{
initTransition(iNet.addNewTransition(), (TransitionModel) currentModel, null);
} else if (currentModel.getType() == AbstractPetriNetElementModel.SUBP_TYPE)
{
// A sub-process is a reference transition with an associated page
// First, generate the transition itself
initTransition(iNet.addNewTransition(), (TransitionModel) currentModel, null);
// Create the page and add the sub-net to it
// by calling ourselves recursively
Page newPage = iNet.addNewPage();
// Associate the new page with the ID of the sub-process model
// so it can be assigned back later on when importing the net
newPage.setId(currentModel.getId());
// Create a new XMLBean representing the sub-net
NetType newNet = newPage.addNewNet();
ModelElementContainer subProcessContainer =
((SubProcessModel)currentModel).getSimpleTransContainer();
EditorLayoutInfo subProcessLayout =subProcessContainer.getEditorLayoutInfo();
if (subProcessLayout!=null)
{
// This sub-process model stores some information about
// the layout of the subprocessor editor
// Convert it to XMLBeans information and store it
NetToolspecificType subPToolSpec = newNet.addNewToolspecific();
subPToolSpec.setTool("WoPeD");
subPToolSpec.setVersion("1.0");
// graphics
GraphicsSimpleType iGraphicsNet = subPToolSpec.addNewBounds();
if (subProcessLayout.getSavedSize() != null)
{
DimensionType dim = iGraphicsNet.addNewDimension();
dim.setX(new BigDecimal(subProcessLayout.getSavedSize().getWidth()));
dim.setY(new BigDecimal(subProcessLayout.getSavedSize().getHeight()));
}
if (subProcessLayout.getSavedLocation() != null)
{
PositionType location = iGraphicsNet.addNewPosition();
location.setX(new BigDecimal(subProcessLayout.getSavedLocation().getX()));
location.setY(new BigDecimal(subProcessLayout.getSavedLocation().getY()));
}
// Store the width of the tree view
subPToolSpec.setTreeWidthRight(subProcessLayout.getTreeViewWidthRight());
subPToolSpec.setOverviewPanelVisible(subProcessLayout.getOverviewPanelVisible());
subPToolSpec.setTreeHeightOverview(subProcessLayout.getTreeHeightOverview());
subPToolSpec.setTreePanelVisible(subProcessLayout.getTreePanelVisible());
}
// Call ourselves recursively to store the sub-process net
saveModelElementContainer(newNet, subProcessContainer);
} else if (currentModel.getType() == AbstractPetriNetElementModel.TRANS_OPERATOR_TYPE)
{
// Special handling code for operators:
// Instead of the operator itself, the inner transitions and places
// will be written to the PNML file
// Their location (screen coordinates) are those of the original operator
// (and also have to be because the operator screen location is not stored separately
// but restored from its replacement elements)
LoggerManager.debug(Constants.FILE_LOGGER, " ... Setting InnerTtransitions for Operator (ID:" + currentModel.getId() + ")");
OperatorTransitionModel operatorModel = (OperatorTransitionModel) currentModel;
Iterator<AbstractPetriNetElementModel> simpleTransIter = operatorModel.getSimpleTransContainer().getElementsByType(AbstractPetriNetElementModel.TRANS_SIMPLE_TYPE).values().iterator();
while (simpleTransIter.hasNext())
{
AbstractPetriNetElementModel simpleTransModel = (AbstractPetriNetElementModel) simpleTransIter.next();
if (simpleTransModel != null // Sometimes the iterator
// returns null...
&& operatorModel.getSimpleTransContainer().getElementById(simpleTransModel.getId()).getType() == AbstractPetriNetElementModel.TRANS_SIMPLE_TYPE)
{
initTransition(iNet.addNewTransition(), (TransitionModel) operatorModel.getSimpleTransContainer().getElementById(simpleTransModel.getId()), operatorModel);
}
}
if (operatorModel.getCenterPlace() != null)
{
PlaceType iCenterPlace = initPlace(iNet.addNewPlace(), operatorModel.getCenterPlace());
initToolspecific(iCenterPlace.addNewToolspecific(), operatorModel.getCenterPlace(), operatorModel.getId(), operatorModel.getOperatorType());
}
LoggerManager.debug(Constants.FILE_LOGGER, " ... InnerTtransitions set.");
}
for (int i = 0; i < statusBars.length; i++)
statusBars[i].nextStep();
}
/* ##### ARCS ##### */
// When iterating through our arcs, we remember all
// transitions that are either source or destination of
// any arc we encounter
// Instead of serializing the arc itself, we serialize
// the "inner arcs" of all such transitions
// To sort out duplicates, we create a set
Set<AbstractPetriNetElementModel> connectedTransitions = new HashSet<AbstractPetriNetElementModel>();
Iterator<String> arcIter = elementContainer.getArcMap().keySet().iterator();
while (arcIter.hasNext())
{
ArcModel currentArc = elementContainer.getArcById(arcIter.next());
AbstractPetriNetElementModel currentTargetModel = (AbstractPetriNetElementModel) elementContainer.getElementById(currentArc.getTargetId());
AbstractPetriNetElementModel currentSourceModel = (AbstractPetriNetElementModel) elementContainer.getElementById(currentArc.getSourceId());
// Remember either source or target if it is a transition
// Please note that one special condition of petri nets is that
// a transition is never directly connected to another transition
// so either source or target may be a transition, never both
if (currentTargetModel.getType() == AbstractPetriNetElementModel.TRANS_OPERATOR_TYPE)
connectedTransitions.add(currentTargetModel);
else if (currentSourceModel.getType() == AbstractPetriNetElementModel.TRANS_OPERATOR_TYPE)
connectedTransitions.add(currentSourceModel);
else
{
// The current arc is not connected to any transition
// We do not need to take care of any inner arcs