bpelreader.java
来自「ejb3 java session bean」· Java 代码 · 共 1,370 行 · 第 1/4 页
JAVA
1,370 行
if (faultVariable != null) { catcher.setFaultVariable(faultVariable); } else if (faultName == null) { problemHandler.add(new ParseProblem("catch must specify faultName, faultVariable or both", catchElem)); } // register handler before reading activity so that variable, partnerLink // and correlationSet definitions are available scope.addCatch(catcher); // activity Activity activity = readActivity(getActivityElement(catchElem), catcher); catcher.setActivity(activity); } private QName getFaultName(Element catchElem) { Attr faultName = catchElem.getAttributeNode(BpelConstants.ATTR_FAULT_NAME); return faultName != null ? XmlUtil.getQNameValue(faultName) : null; } private VariableDefinition getFaultVariable(Element catchElem, Scope scope) { VariableDefinition faultVariable = null; String faultVariableAttr = XmlUtil.getAttribute(catchElem, BpelConstants.ATTR_FAULT_VARIABLE); if (faultVariableAttr != null) { VariableType faultType = getFaultType(catchElem, scope.getBpelProcessDefinition() .getImportDefinition()); if (faultType != null) { // create variable local to handler faultVariable = new VariableDefinition(); faultVariable.setName(faultVariableAttr); faultVariable.setType(faultType); } // BPEL-199 parse BPEL4WS 1.1 fault handler else { // retrieve variable from enclosing scope faultVariable = scope.findVariable(faultVariableAttr); // check variable exists if (faultVariable == null) { problemHandler.add(new ParseProblem("variable not found", catchElem)); } // check variable is of message type else if (!faultVariable.getType().isMessage()) { problemHandler.add(new ParseProblem("catch must reference a message variable", catchElem)); } } } return faultVariable; } private VariableType getFaultType(Element catchElem, ImportDefinition importDefinition) { VariableType type = null; Attr messageType = catchElem.getAttributeNode(BpelConstants.ATTR_FAULT_MESSAGE_TYPE); Attr elementName = catchElem.getAttributeNode(BpelConstants.ATTR_FAULT_ELEMENT); if (messageType != null) { if (elementName != null) problemHandler.add(new ParseProblem("found more than one fault type specifier", catchElem)); type = getMessageType(catchElem, messageType, importDefinition); } else if (elementName != null) type = getElementType(catchElem, elementName, importDefinition); return type; } protected void readCatchAll(Element catchAllElem, Scope scope) { Handler handler = new Handler(); // register handler before reading activity so that in-scope definitions are available scope.setCatchAll(handler); // read handler activity Activity activity = readActivity(getActivityElement(catchAllElem), handler); handler.setActivity(activity); } protected void readEventHandlers(Element eventHandlersElem, Scope scope) { // onEvents for (Iterator i = XmlUtil.getElements(eventHandlersElem, BpelConstants.NS_BPEL, BpelConstants.ELEM_ON_EVENT); i.hasNext();) { OnEvent onEvent = new OnEvent(); scope.addOnEvent(onEvent); readOnEvent((Element) i.next(), onEvent); } // onAlarms for (Iterator i = XmlUtil.getElements(eventHandlersElem, BpelConstants.NS_BPEL, BpelConstants.ELEM_ON_ALARM); i.hasNext();) { OnAlarm onAlarm = new OnAlarm(); scope.addOnAlarm(onAlarm); readOnAlarm((Element) i.next(), onAlarm); } } protected void readOnEvent(Element onEventElem, OnEvent onEvent) { // the attribute messageType indicates a variable declaration Attr messageType = onEventElem.getAttributeNode(BpelConstants.ATTR_MESSAGE_TYPE); if (messageType != null) { VariableDefinition variable = new VariableDefinition(); // name String name = XmlUtil.getAttribute(onEventElem, BpelConstants.ATTR_VARIABLE); variable.setName(name); // type VariableType type = getMessageType(onEventElem, messageType, onEvent.getBpelProcessDefinition().getImportDefinition()); variable.setType(type); // onEvent onEvent.setVariableDefinition(variable); } // receiver ReceiveAction receiveAction = readReceiveAction(onEventElem, onEvent); onEvent.setAction(receiveAction); // activity Element activityElem = getActivityElement(onEventElem); onEvent.setActivity(readActivity(activityElem, onEvent)); } protected OnAlarm readOnAlarm(Element onAlarmElem, OnAlarm onAlarm) { // alarm onAlarm.setAction(readAlarmAction(onAlarmElem, onAlarm)); // activity Element activityElem = getActivityElement(onAlarmElem); onAlarm.setActivity(readActivity(activityElem, onAlarm)); return onAlarm; } protected Map readVariables(Element variablesElem, CompositeActivity parent) { Map variables = new HashMap(); ImportDefinition importDefinition = parent.getBpelProcessDefinition().getImportDefinition(); for (Iterator i = XmlUtil.getElements(variablesElem, BpelConstants.NS_BPEL, BpelConstants.ELEM_VARIABLE); i.hasNext();) { Element variableElem = (Element) i.next(); VariableDefinition variable = readVariable(variableElem, importDefinition); String variableName = variable.getName(); if (!variables.containsKey(variableName)) variables.put(variableName, variable); else problemHandler.add(new ParseProblem("duplicate local name", variableElem)); } return variables; } protected VariableDefinition readVariable(Element variableElem, ImportDefinition importDefinition) { VariableDefinition variable = new VariableDefinition(); // name variable.setName(variableElem.getAttribute(BpelConstants.ATTR_NAME)); // type variable.setType(getVariableType(variableElem, importDefinition)); return variable; } private VariableType getVariableType(Element variableElem, ImportDefinition importDefinition) { VariableType type; Attr schemaType = variableElem.getAttributeNode(BpelConstants.ATTR_TYPE); Attr elementName = variableElem.getAttributeNode(BpelConstants.ATTR_ELEMENT); Attr messageType = variableElem.getAttributeNode(BpelConstants.ATTR_MESSAGE_TYPE); if (messageType != null) { if (schemaType != null || elementName != null) problemHandler.add(new ParseProblem("more than one type specifier present", variableElem)); type = getMessageType(variableElem, messageType, importDefinition); } else if (schemaType != null) { if (elementName != null) problemHandler.add(new ParseProblem("more than one type specifier present", variableElem)); type = getSchemaType(variableElem, schemaType, importDefinition); } else if (elementName != null) { type = getElementType(variableElem, elementName, importDefinition); } else { problemHandler.add(new ParseProblem("no type specifier present", variableElem)); type = null; } return type; } private MessageType getMessageType(Element contextElem, Attr typeAttr, ImportDefinition importDefinition) { QName typeName = XmlUtil.getQNameValue(typeAttr); MessageType type = importDefinition.getMessageType(typeName); if (type == null) { // patch missing type Message message = WsdlUtil.getSharedDefinition().createMessage(); message.setQName(typeName); type = new MessageType(message); problemHandler.add(new ParseProblem("message type not found", contextElem)); } return type; } private ElementType getElementType(Element contextElem, Attr elementAttr, ImportDefinition importDefinition) { QName elementName = XmlUtil.getQNameValue(elementAttr); ElementType type = importDefinition.getElementType(elementName); if (type == null) { // patch missing type type = new ElementType(elementName); problemHandler.add(new ParseProblem("element not found", contextElem)); } return type; } private SchemaType getSchemaType(Element contextElem, Attr typeAttr, ImportDefinition importDefinition) { QName typeName = XmlUtil.getQNameValue(typeAttr); SchemaType type = importDefinition.getSchemaType(typeName); if (type == null) { // patch missing type type = new SchemaType(typeName); problemHandler.add(new ParseProblem("schema type not found", contextElem)); } return type; } // service properties // ////////////////////////////////////////////////////////////// protected Map readCorrelationSets(Element setsElem, CompositeActivity superState) { Map correlationSets = new HashMap(); ImportDefinition importDefinition = superState.getBpelProcessDefinition().getImportDefinition(); for (Iterator i = XmlUtil.getElements(setsElem, BpelConstants.NS_BPEL, BpelConstants.ELEM_CORRELATION_SET); i.hasNext();) { Element setElem = (Element) i.next(); CorrelationSetDefinition set = readCorrelationSet(setElem, importDefinition); String setName = set.getName(); if (!correlationSets.containsKey(setName)) correlationSets.put(setName, set); else problemHandler.add(new ParseProblem("duplicate local name", setElem)); } return correlationSets; } protected CorrelationSetDefinition readCorrelationSet(Element setElem, ImportDefinition importDefinition) { CorrelationSetDefinition set = new CorrelationSetDefinition(); // properties String[] propertyNames = setElem.getAttribute(BpelConstants.ATTR_PROPERTIES).split("\\s"); for (int p = 0; p < propertyNames.length; p++) { QName propertyName = XmlUtil.parseQName(propertyNames[p], setElem); Property property = importDefinition.getProperty(propertyName); if (property == null) { problemHandler.add(new ParseProblem("property not found: " + propertyName, setElem)); // patch the missing property try { property = (Property) WsdlUtil.getSharedExtensionRegistry().createExtension( Definition.class, WsdlConstants.Q_PROPERTY); property.setQName(propertyName); } catch (WSDLException e) { // should not happen throw new AssertionError(e); } } set.addProperty(property); } // name set.setName(setElem.getAttribute(BpelConstants.ATTR_NAME)); return set; } protected Map readPartnerLinks(Element partnerLinksElem, CompositeActivity parent) { Map partnerLinks = new HashMap(); for (Iterator i = XmlUtil.getElements(partnerLinksElem, BpelConstants.NS_BPEL, BpelConstants.ELEM_PARTNER_LINK); i.hasNext();) { Element partnerLinkElem = (Element) i.next(); PartnerLinkDefinition partnerLink = readPartnerLink(partnerLinkElem, parent); String plinkName = partnerLink.getName(); if (!partnerLinks.containsKey(plinkName)) partnerLinks.put(plinkName, partnerLink); else problemHandler.add(new ParseProblem("duplicate local name", partnerLinkElem)); } return partnerLinks; } protected PartnerLinkDefinition readPartnerLink(Element partnerLinkElem, CompositeActivity parent) { PartnerLinkDefinition partnerLink = new PartnerLinkDefinition(); partnerLink.setName(partnerLinkElem.getAttribute(BpelConstants.ATTR_NAME)); // partner link type QName typeName = XmlUtil.getQNameValue(partnerLinkElem.getAttributeNode(BpelConstants.ATTR_PARTNER_LINK_TYPE)); PartnerLinkType type = parent.getBpelProcessDefinition() .getImportDefinition() .getPartnerLinkType(typeName); if (type == null) { problemHandler.add(new ParseProblem("partner link type not found", partnerLinkElem)); return partnerLink; } partnerLink.setPartnerLinkType(type); String myRoleName = XmlUtil.getAttribute(partnerLinkElem, BpelConstants.ATTR_MY_ROLE); String partnerRoleName = XmlUtil.getAttribute(partnerLinkElem, BpelConstants.ATTR_PARTNER_ROLE); boolean partnerFirst = false; // first role Role role = type.getFirstRole(); String roleName = role.getName(); if (roleName.equals(myRoleName)) { partnerLink.setMyRole(role); } else if (roleName.equals(partnerRoleName)) { partnerLink.setPartnerRole(role); partnerFirst = true; } else { problemHandler.add(new ParseProblem( "neither my role nor partner role match the first partner link type role", partnerLinkElem)); return partnerLink; } PortType portType = role.getPortType(); if (portType.isUndefined()) { problemHandler.add(new ParseProblem("port type not found: " + portType.getQName(), partnerLinkElem)); } // second role role = type.getSecondRole(); if (role != null) { roleName = role.getName(); if (partnerFirst) { if (!roleName.equals(myRoleName)) { problemHandler.add(new ParseProblem( "my role does not match the second partner link type role", partnerLinkElem)); } partnerLink.setMyRole(role); } else {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?