private void createJavaBeansInstances(EditorVC editor)
{
ModelElementContainer elementContainer = editor.getModelProcessor().getElementContainer();
PetriNetModelProcessor petrinetModel = (PetriNetModelProcessor) editor.getModelProcessor();
pnmlDoc = PnmlDocument.Factory.newInstance();
PnmlType iPnml = pnmlDoc.addNewPnml();
// Initialisieren der Statusbar
int resources = petrinetModel.getResources().size();
int roles = petrinetModel.getRoles().size();
int orgaUnits = petrinetModel.getOrganizationUnits().size();
int resourcesMapping = petrinetModel.getResourceMapping().size();
int rootElements = elementContainer.getRootElements().size();
int arcs = elementContainer.getArcMap().size();
// TODO (blackfox) - extend statusbars for simulations
for (int i = 0; i < statusBars.length; i++)
statusBars[i].startProgress("Save to File", resources + roles + resourcesMapping + orgaUnits + rootElements + arcs);
// ------------------------------
// pnmlDoc.documentProperties();
XmlCursor cursor = iPnml.newCursor();
cursor.insertComment(comment);
/* ##### NET ##### */
NetType iNet = iPnml.addNewNet();
// attr type
iNet.setType(petrinetModel.getType());
// attr id
iNet.setId(petrinetModel.getId());
// name
if (petrinetModel.getName() != null)
{
iNet.addNewName().setText(petrinetModel.getName());
}
if (ConfigurationManager.getConfiguration().isExportToolspecific())
{
NetToolspecificType iNetToolSpec = iNet.addNewToolspecific();
iNetToolSpec.setTool("WoPeD");
iNetToolSpec.setVersion("1.0"); //TODO Version aus properties �bernehmen!?
//get PartnerLinks
TPartnerLinks iPLs = iNetToolSpec.addNewPartnerLinks();
Iterator<Partnerlink> plist = petrinetModel.getElementContainer().getPartnerlinkList().getPartnerlinkList().iterator();
while (plist.hasNext()){
Partnerlink link = plist.next();
org.woped.pnml.TPartnerLink iPL = iPLs.addNewPartnerLink();
iPL.setName(link.getName());
iPL.setPartnerLinkType(link.getPartnerlinkTypeByQName());
iPL.setPartnerRole(link.getPartnerlinkRole());
iPL.setMyRole(link.getMyRole());
iPL.setWSDL(link.getWsdlUrl());
}
//get Variables
TVariables iVs = iNetToolSpec.addNewVariables();
int VarCounter=0;
while (petrinetModel.getElementContainer().getVariableList().getBpelCode().sizeOfVariableArray()>VarCounter){
org.woped.pnml.TVariable iVar = iVs.addNewVariable();
iVar.setName(petrinetModel.getElementContainer().getTVariablesList().getVariableArray(VarCounter).getName());
iVar.setType(petrinetModel.getElementContainer().getTVariablesList().getVariableArray(VarCounter).getType());
VarCounter++;
}
// scale
iNetToolSpec.setScale((int)(editor.getGraph().getScale() * 100));
// graphics
GraphicsSimpleType iGraphicsNet = iNetToolSpec.addNewBounds();
EditorLayoutInfo layoutInfo = editor.getEditorPanel().getSavedLayoutInfo();
if (layoutInfo.getSavedSize() != null)
{
DimensionType dim = iGraphicsNet.addNewDimension();
dim.setX(new BigDecimal(layoutInfo.getSavedSize().getWidth()));
dim.setY(new BigDecimal(layoutInfo.getSavedSize().getHeight()));
}
if (layoutInfo.getSavedLocation() != null)
{
PositionType location = iGraphicsNet.addNewPosition();
location.setX(new BigDecimal(layoutInfo.getSavedLocation().getX()));
location.setY(new BigDecimal(layoutInfo.getSavedLocation().getY()));
}
// Store the width of the tree view and the height of the overview
if(layoutInfo.getTreeViewWidthRight()!=0){
iNetToolSpec.setTreeWidthRight(layoutInfo.getTreeViewWidthRight());
}else{
iNetToolSpec.setTreeWidthRight(layoutInfo.getTreeViewWidth());
}
iNetToolSpec.setOverviewPanelVisible(layoutInfo.getOverviewPanelVisible());
iNetToolSpec.setTreeHeightOverview(layoutInfo.getTreeHeightOverview());
iNetToolSpec.setTreePanelVisible(layoutInfo.getTreePanelVisible());
//verticalLayout
iNetToolSpec.setVerticalLayout(editor.isRotateSelected());
// resources
ResourcesType iNetResources = iNetToolSpec.addNewResources();
// Rescources
ResourceType iResourceType;
ResourceModel rModelTemp;
for (Iterator<ResourceModel> iter = petrinetModel.getResources().iterator(); iter.hasNext();)
{
rModelTemp = (ResourceModel) iter.next();
iResourceType = iNetResources.addNewResource();
iResourceType.setName(rModelTemp.getName());
for (int i = 0; i < statusBars.length; i++)
statusBars[i].nextStep();
}
// Roles
RoleType iRoleType;
ResourceClassModel roleModelTemp;
for (Iterator<ResourceClassModel> iter = petrinetModel.getRoles().iterator(); iter.hasNext();)
{
roleModelTemp = (ResourceClassModel) iter.next();
iRoleType = iNetResources.addNewRole();
iRoleType.setName(roleModelTemp.getName());
if(roleModelTemp.getSuperModels()!= null){
for (Iterator<ResourceClassModel> i = roleModelTemp.getSuperModels();i.hasNext();)
{
ResourceClassModel superMe = i.next();
SuperModelType newSuper =iRoleType.addNewSuperModel();
newSuper.setName(superMe.getName());
}
}
for (int i = 0; i < statusBars.length; i++)
statusBars[i].nextStep();
}
// Orga Units
OrganizationUnitType iOrganizationUnitType;
ResourceClassModel orgunitModelTemp;
for (Iterator<ResourceClassModel> iter = petrinetModel.getOrganizationUnits().iterator(); iter.hasNext();)
{
orgunitModelTemp = (ResourceClassModel) iter.next();
iOrganizationUnitType = iNetResources.addNewOrganizationUnit();
iOrganizationUnitType.setName(orgunitModelTemp.getName());
if(orgunitModelTemp.getSuperModels()!=null){
for (Iterator<ResourceClassModel> i = orgunitModelTemp.getSuperModels();i.hasNext();)
{
ResourceClassModel superMe = i.next();
SuperModelType newSuper= iOrganizationUnitType.addNewSuperModel();
newSuper.setName(superMe.getName());
}
}
for (int i = 0; i < statusBars.length; i++)
statusBars[i].nextStep();
}
// ResourceMap
ResourceMappingType iNetResourceMap;
for (Iterator<String> iter = petrinetModel.getResourceMapping().keySet().iterator();iter.hasNext();)
{
String tempResourceClass = (String) iter.next();
Vector<String> values = petrinetModel.getResourceMapping().get(tempResourceClass);
// TODO check if mapping exists NullPointerExeption bei
// speicherung ge�nderter orgUnit die keine zugeordnete Resource
// hat!
for (Iterator<String> iterator = values.iterator(); iterator.hasNext();)
{
iNetResourceMap = iNetResources.addNewResourceMapping();
iNetResourceMap.setResourceClass(tempResourceClass);
iNetResourceMap.setResourceID(iterator.next().toString());
}
for (int i = 0; i < statusBars.length; i++)
statusBars[i].nextStep();
}
// Simulations
SimulationsType iNetSimulations = iNetToolSpec.addNewSimulations();
SimulationType iSimulation;
TransitionsequenceType iTransitionsequence;
OccuredtransitionType iOccuredTransition;
for (Iterator<SimulationModel> iter = petrinetModel.getSimulations().iterator();iter.hasNext();)
{
SimulationModel currSimulation = iter.next();
// check if current fingerprint of the net equals the imported one
// if not ask the user if he want's to keep the simulation
//
// this check is performed as well on:
// - fileixport
// - loading a simulation
// when you change it here please do at those locations as well
int answer = 0;
Date simulationCreationDate = currSimulation.getSavedDate();
if(!petrinetModel.isLogicalFingerprintEqual(currSimulation.getFingerprint()))
{
Object[] options = {Messages.getString("Tokengame.ChangedNetDialog.ButtonKeep"),Messages.getString("Tokengame.ChangedNetDialog.ButtonDelete")};
// get the localized message text
String message = Messages.getString("Tokengame.ChangedNetDialog.Export.Message");
// fill the message text dynamically with the simulationname and simulationdate
message = message.replaceAll("##SIMULATIONNAME##", currSimulation.getName());
message = message.replaceAll("##SIMULATIONDATE##", DateFormat.getDateInstance().format(currSimulation.getSavedDate()));
answer = JOptionPane.showOptionDialog(null, message, Messages.getString("Tokengame.ChangedNetDialog.Title"), JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]);
// if the user didn't choose one of the buttons but closed the OptionDialog don't drop the simulation
if(answer == -1)
{
answer = 0;
}
}
if(answer == 0)
{
iSimulation = iNetSimulations.addNewSimulation();
iSimulation.setId(currSimulation.getId());
iSimulation.setSimulationname(currSimulation.getName());
Calendar cal = Calendar.getInstance();
cal.setTime(simulationCreationDate);
iSimulation.setSimulationdate(cal);
iTransitionsequence = iSimulation.addNewTransitionsequence();
for(Iterator<TransitionModel> iterator = currSimulation.getOccuredTransitions().iterator();iterator.hasNext();)
{
iOccuredTransition = iTransitionsequence.addNewOccuredtransition();
iOccuredTransition.setTransitionID((iterator.next()).getId());
}
iSimulation.setNetFingerprint(currSimulation.getFingerprint());
LoggerManager.debug(Constants.FILE_LOGGER, " ... Simulation (ID:" + currSimulation.getId() + ") set");
}
else
{
LoggerManager.debug(Constants.FILE_LOGGER, " ... Simulation (ID:" + currSimulation.getId() + ") dropped by user");
}
}
// toolspecific
for (short i = 0; i < petrinetModel.getUnknownToolSpecs().size(); i++)
{
iNet.addNewToolspecific();
if (petrinetModel.getUnknownToolSpecs().get(i) instanceof ToolspecificType)
{
iNet.setToolspecificArray(iNet.getToolspecificArray().length - 1, (NetToolspecificType) petrinetModel.getUnknownToolSpecs().get(i));
}
}
}
// Now save the root model element container into the
// NetType XMLBean holding our net