本文整理汇总了Java中org.camunda.bpm.model.xml.instance.ModelElementInstance类的典型用法代码示例。如果您正苦于以下问题:Java ModelElementInstance类的具体用法?Java ModelElementInstance怎么用?Java ModelElementInstance使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ModelElementInstance类属于org.camunda.bpm.model.xml.instance包,在下文中一共展示了ModelElementInstance类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: starting
import org.camunda.bpm.model.xml.instance.ModelElementInstance; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
protected void starting(Description description) {
String className = description.getClassName();
assertThat(className).endsWith("Test");
className = className.substring(0, className.length() - "Test".length());
Class<? extends ModelElementInstance> instanceClass;
try {
instanceClass = (Class<? extends ModelElementInstance>) Class.forName(className);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
modelInstance = Dmn.createEmptyModel();
model = modelInstance.getModel();
modelElementType = model.getType(instanceClass);
}
示例2: handleEvent
import org.camunda.bpm.model.xml.instance.ModelElementInstance; //导入依赖的package包/类
/**
* Events aren't reported like SequenceFlows and Activities, so we need
* special handling. If a sequence flow has an event as the source or the
* target, we add it to the coverage. It's pretty straight forward if a
* sequence flow is active, then it's source has been covered anyway and it
* will most definitely arrive at its target.
*
* @param transitionId
* @param processDefinition
* @param repositoryService
*/
private void handleEvent(String transitionId, ProcessDefinition processDefinition,
RepositoryService repositoryService) {
final BpmnModelInstance modelInstance = repositoryService.getBpmnModelInstance(processDefinition.getId());
final ModelElementInstance modelElement = modelInstance.getModelElementById(transitionId);
if (modelElement.getElementType().getInstanceType() == SequenceFlow.class) {
final SequenceFlow sequenceFlow = (SequenceFlow) modelElement;
// If there is an event at the sequence flow source add it to the
// coverage
final FlowNode source = sequenceFlow.getSource();
addEventToCoverage(processDefinition, source);
// If there is an event at the sequence flow target add it to the
// coverage
final FlowNode target = sequenceFlow.getTarget();
addEventToCoverage(processDefinition, target);
}
}
开发者ID:camunda,项目名称:camunda-bpm-process-test-coverage,代码行数:35,代码来源:PathCoverageExecutionListener.java
示例3: updateAfterReplacement
import org.camunda.bpm.model.xml.instance.ModelElementInstance; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
public void updateAfterReplacement() {
super.updateAfterReplacement();
Collection<Reference> incomingReferences = getIncomingReferencesByType(SequenceFlow.class);
for (Reference<?> reference : incomingReferences) {
for (ModelElementInstance sourceElement : reference.findReferenceSourceElements(this)) {
String referenceIdentifier = reference.getReferenceIdentifier(sourceElement);
if (referenceIdentifier != null && referenceIdentifier.equals(getId()) && reference instanceof AttributeReference) {
String attributeName = ((AttributeReference) reference).getReferenceSourceAttribute().getAttributeName();
if (attributeName.equals(BPMN_ATTRIBUTE_SOURCE_REF)) {
getOutgoing().add((SequenceFlow) sourceElement);
}
else if (attributeName.equals(BPMN_ATTRIBUTE_TARGET_REF)) {
getIncoming().add((SequenceFlow) sourceElement);
}
}
}
}
}
示例4: performAddOperation
import org.camunda.bpm.model.xml.instance.ModelElementInstance; //导入依赖的package包/类
protected void performAddOperation(ModelElementInstanceImpl referenceSourceParentElement, Target referenceTargetElement) {
ModelInstanceImpl modelInstance = referenceSourceParentElement.getModelInstance();
String referenceTargetIdentifier = referenceTargetAttribute.getValue(referenceTargetElement);
ModelElementInstance existingElement = modelInstance.getModelElementById(referenceTargetIdentifier);
if (existingElement == null || !existingElement.equals(referenceTargetElement)) {
throw new ModelReferenceException("Cannot create reference to model element " + referenceTargetElement
+": element is not part of model. Please connect element to the model first.");
}
else {
Collection<Source> referenceSourceElements = referenceSourceCollection.get(referenceSourceParentElement);
Source referenceSourceElement = modelInstance.newInstance(referenceSourceType);
referenceSourceElements.add(referenceSourceElement);
setReferenceIdentifier(referenceSourceElement, referenceTargetIdentifier);
}
}
示例5: testCreateEmptyProcess
import org.camunda.bpm.model.xml.instance.ModelElementInstance; //导入依赖的package包/类
@Test
public void testCreateEmptyProcess() {
modelInstance = Bpmn.createProcess()
.done();
Definitions definitions = modelInstance.getDefinitions();
assertThat(definitions).isNotNull();
assertThat(definitions.getTargetNamespace()).isEqualTo(BPMN20_NS);
Collection<ModelElementInstance> processes = modelInstance.getModelElementsByType(processType);
assertThat(processes)
.hasSize(1);
Process process = (Process) processes.iterator().next();
assertThat(process.getId()).isNotNull();
}
示例6: getReferenceIdentifier
import org.camunda.bpm.model.xml.instance.ModelElementInstance; //导入依赖的package包/类
@Override
public String getReferenceIdentifier(ModelElementInstance referenceSourceElement) {
// TODO: implement something more robust (CAM-4028)
String identifier = referenceSourceElement.getAttributeValue("href");
if (identifier != null) {
String[] parts = identifier.split("#");
if (parts.length > 1) {
return parts[parts.length - 1];
}
else {
return parts[0];
}
}
else {
return null;
}
}
示例7: validate
import org.camunda.bpm.model.xml.instance.ModelElementInstance; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
public ValidationResults validate() {
ValidationResultsCollectorImpl resultsCollector = new ValidationResultsCollectorImpl();
for (ModelElementValidator validator : validators) {
Class<? extends ModelElementInstance> elementType = validator.getElementType();
Collection<? extends ModelElementInstance> modelElementsByType = modelInstanceImpl.getModelElementsByType(elementType);
for (ModelElementInstance element : modelElementsByType) {
resultsCollector.setCurrentElement(element);
try {
validator.validate(element, resultsCollector);
}
catch(RuntimeException e) {
throw new RuntimeException("Validator " + validator + " threw an exception while validating "+element, e);
}
}
}
return resultsCollector.getResults();
}
示例8: replaceChildElement
import org.camunda.bpm.model.xml.instance.ModelElementInstance; //导入依赖的package包/类
public void replaceChildElement(ModelElementInstance existingChild, ModelElementInstance newChild) {
DomElement existingChildDomElement = existingChild.getDomElement();
DomElement newChildDomElement = newChild.getDomElement();
// unlink (remove all references) of child elements
((ModelElementInstanceImpl) existingChild).unlinkAllChildReferences();
// update incoming references from old to new child element
updateIncomingReferences(existingChild, newChild);
// replace the existing child with the new child in the DOM
domElement.replaceChild(newChildDomElement, existingChildDomElement);
// execute after replacement updates
newChild.updateAfterReplacement();
}
示例9: updateIncomingReferences
import org.camunda.bpm.model.xml.instance.ModelElementInstance; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private void updateIncomingReferences(ModelElementInstance oldInstance, ModelElementInstance newInstance) {
String oldId = oldInstance.getAttributeValue("id");
String newId = newInstance.getAttributeValue("id");
if (oldId == null || newId == null) {
return;
}
Collection<Attribute<?>> attributes = ((ModelElementTypeImpl) oldInstance.getElementType()).getAllAttributes();
for (Attribute<?> attribute : attributes) {
if (attribute.isIdAttribute()) {
for (Reference<?> incomingReference : attribute.getIncomingReferences()) {
((ReferenceImpl<ModelElementInstance>) incomingReference).referencedElementUpdated(newInstance, oldId, newId);
}
}
}
}
示例10: getReferenceTargetElement
import org.camunda.bpm.model.xml.instance.ModelElementInstance; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public Target getReferenceTargetElement(ModelElementInstanceImpl referenceSourceParentElement) {
Source referenceSource = getReferenceSource(referenceSourceParentElement);
if (referenceSource != null) {
String identifier = getReferenceIdentifier(referenceSource);
ModelElementInstance referenceTargetElement = referenceSourceParentElement.getModelInstance().getModelElementById(identifier);
if (referenceTargetElement != null) {
return (Target) referenceTargetElement;
}
else {
throw new ModelException("Unable to find a model element instance for id " + identifier);
}
}
else {
return null;
}
}
示例11: findElementToInsertAfter
import org.camunda.bpm.model.xml.instance.ModelElementInstance; //导入依赖的package包/类
/**
* Returns the element after which the new element should be inserted in the DOM document.
*
* @param elementToInsert the new element to insert
* @return the element to insert after or null
*/
private ModelElementInstance findElementToInsertAfter(ModelElementInstance elementToInsert) {
List<ModelElementType> childElementTypes = elementType.getAllChildElementTypes();
List<DomElement> childDomElements = domElement.getChildElements();
Collection<ModelElementInstance> childElements = ModelUtil.getModelElementCollection(childDomElements, modelInstance);
ModelElementInstance insertAfterElement = null;
int newElementTypeIndex = ModelUtil.getIndexOfElementType(elementToInsert, childElementTypes);
for (ModelElementInstance childElement : childElements) {
int childElementTypeIndex = ModelUtil.getIndexOfElementType(childElement, childElementTypes);
if (newElementTypeIndex >= childElementTypeIndex) {
insertAfterElement = childElement;
}
else {
break;
}
}
return insertAfterElement;
}
示例12: getReferenceTargetElement
import org.camunda.bpm.model.xml.instance.ModelElementInstance; //导入依赖的package包/类
/**
* Get the reference target model element instance
*
* @param referenceSourceElement the reference source model element instance
* @return the reference target model element instance or null if not set
*/
@SuppressWarnings("unchecked")
public T getReferenceTargetElement(ModelElementInstance referenceSourceElement) {
String identifier = getReferenceIdentifier(referenceSourceElement);
ModelElementInstance referenceTargetElement = referenceSourceElement.getModelInstance().getModelElementById(identifier);
if (referenceTargetElement != null) {
try {
return (T) referenceTargetElement;
} catch(ClassCastException e) {
throw new ModelReferenceException("Element " + referenceSourceElement + " references element " + referenceTargetElement + " of wrong type. "
+ "Expecting " + referenceTargetAttribute.getOwningElementType() + " got " + referenceTargetElement.getElementType());
}
}
else {
return null;
}
}
示例13: testModelApiUtf8Bug
import org.camunda.bpm.model.xml.instance.ModelElementInstance; //导入依赖的package包/类
@Test
public void testModelApiUtf8Bug() throws UnsupportedEncodingException {
BpmnModelInstance modelInstance = Bpmn.readModelFromStream(this.getClass().getResourceAsStream("/umlauts.bpmn"));
Collection<ModelElementInstance> serviceTasks = modelInstance.getModelElementsByType(modelInstance.getModel().getType(ServiceTask.class));
assertEquals(1, serviceTasks.size());
ServiceTask serviceTask = (ServiceTask) serviceTasks.iterator().next();
serviceTask.setCamundaExpression("#{true}");
String xmlString = Bpmn.convertToString(modelInstance);
org.camunda.bpm.engine.repository.Deployment deployment = processEngine().getRepositoryService().createDeployment() //
.addInputStream("umlauts.bpmn", new ByteArrayInputStream(xmlString.getBytes("UTF-8"))).deploy();
processEngine().getRepositoryService().deleteDeployment(deployment.getId(), true);
}
开发者ID:camunda-consulting,项目名称:camunda-util-demo-data-generator,代码行数:16,代码来源:DemoDataGeneratorTest.java
示例14: buildTask
import org.camunda.bpm.model.xml.instance.ModelElementInstance; //导入依赖的package包/类
@Override
public AbstractTaskBuilder buildTask(AbstractFlowNodeBuilder builder, Map<String, Object> taskData)
{
final AbstractTaskBuilder taskBuilder = super.buildTask(builder, taskData);
if (! (taskBuilder instanceof ServiceTaskBuilder)) {
throw new RuntimeException("only service tasks are supported");
}
ServiceTaskBuilder serviceTaskBuilder = (ServiceTaskBuilder) taskBuilder;
final String taskType = (String) taskData.get("type");
final Integer retries = (Integer) taskData.get("retries");
final ServiceTask serviceTask = serviceTaskBuilder.getElement();
final ExtensionElements extensionElements = serviceTask.getModelInstance().newInstance(ExtensionElements.class);
final ModelElementInstance taskDefinition = extensionElements.addExtensionElement(TNGP_NAMESPACE, TASK_DEFINITION_ELEMENT);
taskDefinition.setAttributeValue(TASK_TYPE_ATTRIBUTE, taskType);
if (retries != null)
{
taskDefinition.setAttributeValue(TASK_RETRIES_ATTRIBUTE, String.valueOf(retries));
}
serviceTask.setExtensionElements(extensionElements);
return serviceTaskBuilder;
}
示例15: testSimpleModel
import org.camunda.bpm.model.xml.instance.ModelElementInstance; //导入依赖的package包/类
@Test
public void testSimpleModel() throws FileNotFoundException {
final BpmnModelInstance modelInstance = transformer.transform(ZeebeTransformerTest.class.getResourceAsStream(MODEL_FILENAME));
ServiceTask serviceTask = modelInstance.getModelElementById("TASK_1");
final ExtensionElements extensionElements = serviceTask.getExtensionElements();
assertNotNull(extensionElements);
List<ModelElementInstance> elements = new ArrayList<ModelElementInstance>(extensionElements.getElements());
assertEquals(1, elements.size());
ModelElementInstance taskDefinition = elements.get(0);
assertEquals(ZeebeTaskFactory.TNGP_NAMESPACE, taskDefinition.getDomElement().getNamespaceURI().toString());
assertEquals("someType", taskDefinition.getAttributeValue("type"));
assertTrue(taskDefinition.getDomElement().hasAttribute("retries"));
assertEquals("3", taskDefinition.getAttributeValue("retries"));
ServiceTask serviceTask2 = modelInstance.getModelElementById("TASK_2");
elements = new ArrayList<ModelElementInstance>(serviceTask2.getExtensionElements().getElements());
assertEquals(1, elements.size());
taskDefinition = elements.get(0);
assertEquals(ZeebeTaskFactory.TNGP_NAMESPACE, taskDefinition.getDomElement().getNamespaceURI().toString());
assertEquals("someOtherType", taskDefinition.getAttributeValue("type"));
assertFalse(taskDefinition.getDomElement().hasAttribute("retries"));
}