下面列出了怎么用org.eclipse.emf.ecore.util.FeatureMap.Entry的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* 判断表单是否空
*
* @param flowElement
*/
private static void verifyFormIsNull(FlowElement flowElement,StringBuffer sb) {
if (flowElement instanceof UserTask) {
UserTask userTask = (UserTask) flowElement;
for (ExtensionAttributeValue extensionAttributeValue : userTask.getExtensionValues()) {
FeatureMap extensionElements = extensionAttributeValue.getValue();
for (Entry entry : extensionElements) {
if (entry.getValue() instanceof FormUri) {
FormUri formUri = (FormUri) entry.getValue();
if (formUri.getExpression().getValue() != null || !(formUri.getExpression().getValue().equals(""))) {
return;
}
}
}
}
sb.append(userTask.getId() + "节点没有设置表单;" + "");
}
}
/**
* 验证所有人工节点含有处理命令
*
* @param flowElement
*/
private static void allUserTaskNodeHaveTaskCommand(FlowElement flowElement,StringBuffer sb) {
if (flowElement instanceof UserTask) {
for (ExtensionAttributeValue extensionAttributeValue : ((UserTask) flowElement).getExtensionValues()) {
FeatureMap extensionElements = extensionAttributeValue.getValue();
for (Entry entry : extensionElements) {
if (entry.getValue() instanceof TaskCommand) {
TaskCommand taskCommand = (TaskCommand) entry.getValue();
if (taskCommand != null) {
return;
}
}
}
}
sb.append(((UserTask) flowElement).getId() + "节点没有设置处理命令;" + "");
}
}
/**
* 验证总方法
*
* @return 通过返回异常信息,""表示通过
*/
public static String verifyAll(Process process) {
StringBuffer sb = new StringBuffer();
List<FlowElement> flowElements = process.getFlowElements();
// 先验证主流程信息
verificationProc(flowElements,sb);
isSubmitNodeHasUserCommand(flowElements,sb);
processDefaultTitleAndDefaultForm(process,sb);
boolean yzForm = true;
if (process.getExtensionValues().size() > 0) {
for (ExtensionAttributeValue extensionAttributeValue : process.getExtensionValues()) {
FeatureMap extensionElements = extensionAttributeValue.getValue();
for (Entry entry : extensionElements) {
if (entry.getValue() instanceof FormUri) {
FormUri formUri = (FormUri) entry.getValue();
if (formUri.getExpression().getValue() == null || formUri.getExpression().getValue().equals("")) {
yzForm = true;
} else {
yzForm = false;
}
break;
}
}
}
}
if (yzForm) {
verifyFormIsNull(flowElements,sb);
}
// 循环主流程所有节点
for (FlowElement flowElement :process.getFlowElements()) {
// 如果发现是子流程则进行递归
if (flowElement instanceof SubProcess) {
getSubProcessElement((SubProcess) flowElement, yzForm,sb);
}
}
if (sb.length() > 0 && !sb.toString().equals("子流程验证信息:")) {
return sb.toString();
}
return "";
}
private static void processDefaultTitleAndDefaultForm(Process process,StringBuffer sb) {
boolean formUriYZ = false;
boolean taskSubjectYZ = false;
if (process.getExtensionValues().size() > 0) {
for (ExtensionAttributeValue extensionAttributeValue : process.getExtensionValues()) {
FeatureMap extensionElements = extensionAttributeValue.getValue();
for (Entry entry : extensionElements) {
if (entry.getValue() instanceof FormUri) {
FormUri formUri = (FormUri) entry.getValue();
if (formUri.getExpression().getValue() != null && !formUri.getExpression().getValue().equals("")) {
formUriYZ = true;
}
}
if (entry.getValue() instanceof TaskSubject) {
TaskSubject taskSubject = (TaskSubject) entry.getValue();
if (taskSubject.getExpression().getValue() != null && !taskSubject.getExpression().getValue().equals("")) {
taskSubjectYZ = true;
}
}
}
}
}
if (formUriYZ && taskSubjectYZ) {
return;
} else {
if (!formUriYZ) {
sb.append("流程定义上默认表单不能为空;" + "");
}
if (!taskSubjectYZ) {
sb.append("流程定义上默认任务主题不能为空;" + "");
}
}
return;
}
/**
* 判断所有人工任务节点都有任务分配
*
* @param flowElements
*/
public static void allUserTaskNodeHaveTaskAssignment(List<FlowElement> flowElements,StringBuffer sb) {
for (FlowElement flowElement : flowElements) {
if (flowElement instanceof UserTask) {
UserTask userTask = (UserTask) flowElement;
if (userTask.getResources().size() < 1) {
sb.append(userTask.getId() + "节点没有设置任务分配;" + "");
}
LoopCharacteristics loopCharacteristics = userTask.getLoopCharacteristics();
if (loopCharacteristics instanceof MultiInstanceLoopCharacteristics) {
for (ExtensionAttributeValue extensionAttributeValue : userTask.getExtensionValues()) {
FeatureMap extensionElements = extensionAttributeValue.getValue();
for (Entry entry : extensionElements) {
if (entry.getValue() instanceof TaskCommand) {
TaskCommand taskCommand = (TaskCommand) entry.getValue();
if (taskCommand.getCommandType().equals("rollBack")) {
sb.append(((UserTask) flowElement).getId() + " 含有多实例的节点不能做退回处理;" + "");
}
}
}
}
}
}
}
}
/**
* @param performerAssign
* @return
*/
private String getPerformerAssignValue(ExtendedAttributeType performerAssign) {
for (final FeatureMap.Entry entry : performerAssign.getMixed()) {
if (entry.getValue() instanceof AnyType) {
final AnyType any = (AnyType) entry.getValue();
final String tag = entry.getEStructuralFeature().getName();
if (tag.toLowerCase().equals("callback") || tag.toLowerCase().equals("custom")) {
return (String) any.getMixed().get(0).getValue();
}
}
}
return null;
}
/**
* @param hook
* @return
*/
private ConnectorEvent getEvent(ExtendedAttributeType hook) {
for (final FeatureMap.Entry entry : hook.getMixed()) {
if (entry.getValue() instanceof AnyType) {
final AnyType any = (AnyType) entry.getValue();
final String tag = entry.getEStructuralFeature().getName();
if (tag.equals("HookEventName")) {
final String hookEventName = (String) any.getMixed().get(0).getValue();
if (hookEventName.equals("task:onReady")) {
return ConnectorEvent.ON_ENTER;
} else if (hookEventName.equals("task:onStart")) {
return ConnectorEvent.ON_ENTER;
} else if (hookEventName.equals("task:onFinish")) {
return ConnectorEvent.ON_FINISH;
} else if (hookEventName.equals("task:onSuspend")) {
return ConnectorEvent.ON_ENTER;
} else if (hookEventName.equals("task:onResume")) {
return ConnectorEvent.ON_ENTER;
} else if (hookEventName.equals("task:onCancel")) {
return ConnectorEvent.ON_ENTER;
} else if (hookEventName.equals("automatic:onEnter")) {
return ConnectorEvent.ON_ENTER;
}
}
}
}
return null;
}
protected void updateXMLNamespaceIfNeeded(final DocumentRoot docRoot) {
for (final java.util.Map.Entry<String, String> entry : docRoot
.getXMLNSPrefixMap().entrySet()) {
if ("http://jcp.org/en/jsr/detail?id=270".equals(entry
.getValue())) {
JAVA_XMLNS = entry.getKey();
} else if ("http://www.bonitasoft.org/studio/connector/definition/6.0"
.equals(entry.getValue())) {
XMLNS_HTTP_BONITASOFT_COM_BONITA_CONNECTOR_DEFINITION = entry
.getKey();
}
}
}
protected String retrieveDocumentation(final TBaseElement baseElement) {
final StringBuilder sb = new StringBuilder();
for (final TDocumentation doc : baseElement.getDocumentation()) {
final Iterator<org.eclipse.emf.ecore.util.FeatureMap.Entry> iterator = doc
.getMixed().iterator();
while (iterator.hasNext()) {
final FeatureMap.Entry entry = iterator.next();
if (FeatureMapUtil.isText(entry)) {
sb.append(entry.getValue()).append("\n");
}
}
}
final String documentation = sb.toString();
return documentation;
}
protected String getAssignmentValue(final TExpression to) {
if (to != null) {
final FeatureMap mixed = to.getMixed();
if (mixed != null && !mixed.isEmpty()) {
final Entry entry = mixed.get(0);
if (entry != null) {
return (String) entry.getValue();
}
}
}
return "";
}
private String retrieveDefaultValueContent(final TExpression fromExpression) {
String defaultValueContent = "";
final FeatureMap fromMixed = fromExpression
.getMixed();
if (fromMixed != null && !fromMixed.isEmpty()) {
final Entry fromEntry = fromMixed.get(0);
if (fromEntry != null) {
defaultValueContent = (String) fromEntry
.getValue();
}
}
return defaultValueContent;
}
private Hive createHive ( final String ref, final FeatureMap featureMap ) throws Exception
{
final Entry first = featureMap.get ( 0 );
final BundleContextHiveFactory factory = new BundleContextHiveFactory ( HivesPlugin.getDefault ().getBundle ().getBundleContext () );
return factory.createHive ( ref, (EObject)first.getValue () );
}
private Expression getExtensionExpression(BaseElement baseElement) {
if (baseElement.getExtensionValues().size() > 0) {
for (ExtensionAttributeValue extensionAttributeValue : baseElement.getExtensionValues()) {
FeatureMap extensionElements = extensionAttributeValue.getValue();
for (Entry entry : extensionElements) {
if (entry.getValue() instanceof Expression) {
Expression expression= (Expression) entry.getValue();
return expression;
}
}
}
}
return null;
}
protected void createBonitaData(final TFlowElement flowElement,
final boolean isMultiple, final QName itemDef, final boolean isTransient)
throws ProcBuilderException {
final TItemDefinition itemDefinition = getItemDefinition(itemDef);
String id = null;
DataType dataType = null;
if (itemDefinition != null) {
if (itemDefinition.getId() != null) {
id = flowElement.getId();
} else {
id = "data" + dataNameByItemDefinition.size();
}
dataType = getDataType(itemDefinition);
} else {
if (flowElement.getId() != null) {
id = flowElement.getId();
} else {
id = "data" + dataNameByItemDefinition.size();
}
dataType = DataType.STRING;
}
final String name = createBonitaDataName(flowElement, id);
String defaultValueContent = "";
String defaultValueReturnType = "";
String defaultValueInterpreter = "";
if (flowElement instanceof TActivity) {
for (final TDataInputAssociation dataInputAssociation : ((TActivity) flowElement).getDataInputAssociation()) {
for (final TAssignment assignment : dataInputAssociation.getAssignment()) {
final TExpression to = assignment.getTo();
if (to != null) {
final FeatureMap toMixed = to.getMixed();
if (toMixed != null && !toMixed.isEmpty()) {
final Entry entry = toMixed.get(0);
if (entry != null) {
final String entryValue = (String) entry.getValue();// .replaceFirst(Matcher.quoteReplacement("getDataInput('"),
// "").replace(Matcher.quoteReplacement("\')"),
// "");
final TDataInput dataInput = getDataInputById((TActivity) flowElement, entryValue);
if (dataInput != null) {
final TProperty property = getPropertyByItemSubjectRef((TActivity) flowElement,
dataInput.getItemSubjectRef());
if (property != null) {
final TExpression fromExpression = assignment.getFrom();
defaultValueContent = retrieveDefaultValueContent(fromExpression);
if (fromExpression instanceof TFormalExpression) {
final TFormalExpression fromFormalExpression = (TFormalExpression) fromExpression;
defaultValueInterpreter = retrieveDefaultValueInterpreter(fromFormalExpression);
final QName evaluatesToTypeRef = fromFormalExpression.getEvaluatesToTypeRef();
if (evaluatesToTypeRef != null) {
defaultValueReturnType = evaluatesToTypeRef.getLocalPart();
}
}
}
}
}
}
}
}
}
}
if (IProcBuilder.DataType.XML.equals(dataType)) {
builder.addXMLData(id, name, defaultValueContent,
defaultValueReturnType, defaultValueInterpreter,
itemDefinition.getStructureRef().getLocalPart(),
itemDefinition.getStructureRef().getNamespaceURI(),
isMultiple, isTransient, ExpressionConstants.XPATH_TYPE);
} else if (IProcBuilder.DataType.JAVA.equals(dataType)) {
builder.addJavaData(id, name, defaultValueContent,
defaultValueReturnType, defaultValueInterpreter,
itemDefinition.getStructureRef().getLocalPart(),
isMultiple, isTransient, ExpressionConstants.JAVA_TYPE);
} else {
String defaultValueExpressionType = null;
if ("http://groovy.codehaus.org/".equals(defaultValueInterpreter)) {
defaultValueExpressionType = ExpressionConstants.SCRIPT_TYPE;
} else if ("http://www.w3.org/1999/XPath".equals(defaultValueInterpreter)) {
defaultValueExpressionType = ExpressionConstants.CONSTANT_TYPE;
}
builder.addData(id, name, defaultValueContent,
defaultValueReturnType, defaultValueInterpreter,
isMultiple, isTransient, dataType,
defaultValueExpressionType);// TODO how to define the real
// type of the expression??
}
if (itemDefinition != null) {
dataNameByItemDefinition.put(itemDefinition.getId(), name);
}
}