bpelreader.java
来自「ejb3 java session bean」· Java 代码 · 共 1,370 行 · 第 1/4 页
JAVA
1,370 行
if (!roleName.equals(partnerRoleName)) { problemHandler.add(new ParseProblem( "partner role does not match the second partner link type role", partnerLinkElem)); } partnerLink.setPartnerRole(role); } portType = role.getPortType(); if (portType.isUndefined()) { problemHandler.add(new ParseProblem("port type not found: " + portType.getQName(), partnerLinkElem)); } } else if (partnerFirst ? myRoleName != null : partnerRoleName != null) problemHandler.add(new ParseProblem("partner link type has one role only", partnerLinkElem)); return partnerLink; } public ReceiveAction readReceiveAction(Element receiveElem, CompositeActivity parent) { ReceiveAction receiveAction = new ReceiveAction(); // partner link String partnerLinkName = receiveElem.getAttribute(BpelConstants.ATTR_PARTNER_LINK); PartnerLinkDefinition partnerLink = parent.findPartnerLink(partnerLinkName); if (partnerLink == null) { problemHandler.add(new ParseProblem("partner link not found", receiveElem)); return receiveAction; } receiveAction.setPartnerLink(partnerLink); // port type Role myRole = partnerLink.getMyRole(); // BPEL-181 detect absence of my role if (myRole == null) { problemHandler.add(new ParseProblem("my role not found", receiveElem)); return receiveAction; } PortType portType = getMessageActivityPortType(receiveElem, myRole); // operation Operation operation = getMessageActivityOperation(receiveElem, portType); receiveAction.setOperation(operation); // message exchange // BPEL-74: map the empty message exchange to null for compatibility with Oracle receiveAction.setMessageExchange(XmlUtil.getAttribute(receiveElem, BpelConstants.ATTR_MESSAGE_EXCHANGE)); // variable VariableDefinition variable = getMessageActivityVariable(receiveElem, BpelConstants.ATTR_VARIABLE, parent, operation.getInput().getMessage()); receiveAction.setVariable(variable); // correlations Element correlationsElem = XmlUtil.getElement(receiveElem, BpelConstants.NS_BPEL, BpelConstants.ELEM_CORRELATIONS); if (correlationsElem != null) receiveAction.setCorrelations(readCorrelations(correlationsElem, parent, variable)); return receiveAction; } public Correlations readCorrelations(Element correlationsElem, CompositeActivity parent, VariableDefinition variable) { Correlations correlations = new Correlations(); Iterator correlationElemIt = XmlUtil.getElements(correlationsElem, BpelConstants.NS_BPEL, BpelConstants.ELEM_CORRELATION); while (correlationElemIt.hasNext()) { Element correlationElem = (Element) correlationElemIt.next(); Correlation correlation = readCorrelation(correlationElem, parent); checkVariableProperties(variable, correlation.getSet(), correlationElem); correlations.addCorrelation(correlation); } return correlations; } public Correlation readCorrelation(Element correlationElem, CompositeActivity parent) { Correlation correlation = new Correlation(); // correlation set String setName = correlationElem.getAttribute(BpelConstants.ATTR_SET); CorrelationSetDefinition set = parent.findCorrelationSet(setName); if (set == null) { problemHandler.add(new ParseProblem("correlation set not found", correlationElem)); set = new CorrelationSetDefinition(); set.setName(setName); } correlation.setSet(set); // initiate mode correlation.setInitiate(Initiate.valueOf(XmlUtil.getAttribute(correlationElem, BpelConstants.ATTR_INITIATE))); return correlation; } PortType getMessageActivityPortType(Element serviceElem, Role role) { PortType effectivePortType = role.getPortType(); // validate port type attribute, if present Attr portTypeAttr = serviceElem.getAttributeNode(BpelConstants.ATTR_PORT_TYPE); if (portTypeAttr != null) { QName portTypeName = XmlUtil.getQNameValue(portTypeAttr); if (!effectivePortType.getQName().equals(portTypeName)) { problemHandler.add(new ParseProblem( "port type mismatch between message activity and partner link", serviceElem)); } } return effectivePortType; } Operation getMessageActivityOperation(Element serviceElem, PortType portType) { String operationName = serviceElem.getAttribute(BpelConstants.ATTR_OPERATION); Operation operation = portType.getOperation(operationName, null, null); if (operation == null) { problemHandler.add(new ParseProblem("operation not found", serviceElem)); // patch missing operation operation = WsdlUtil.getSharedDefinition().createOperation(); operation.setName(operationName); } else { OperationType style = operation.getStyle(); if (style == OperationType.SOLICIT_RESPONSE || style == OperationType.NOTIFICATION) problemHandler.add(new ParseProblem("operation style not supported", serviceElem)); } return operation; } VariableDefinition getMessageActivityVariable(Element serviceElem, String variableAttr, CompositeActivity parent, Message activityMessage) { VariableDefinition variable; // get variable name String variableName = XmlUtil.getAttribute(serviceElem, variableAttr); if (variableName == null) { problemHandler.add(new ParseProblem(variableAttr + " attribute is missing", serviceElem)); // patch missing variable variable = new VariableDefinition(); variable.setName("unnamed"); return variable; } // find variable definition variable = parent.findVariable(variableName); if (variable == null) { problemHandler.add(new ParseProblem(variableAttr + " not found", serviceElem)); // create a variable stub variable = new VariableDefinition(); variable.setName(variableName); variable.setType(parent.getBpelProcessDefinition().getImportDefinition().getMessageType( activityMessage.getQName())); } // validate type else if (!variable.getType().getName().equals(activityMessage.getQName())) { problemHandler.add(new ParseProblem(variableAttr + " type is not applicable for the operation", serviceElem)); } return variable; } void checkVariableProperties(VariableDefinition variable, CorrelationSetDefinition set, Element correlationElem) { Map variableProperties = variable.getType().getPropertyAliases(); for (Iterator i = set.getProperties().iterator(); i.hasNext();) { Property property = (Property) i.next(); QName propertyName = property.getQName(); if (!variableProperties.containsKey(propertyName)) { problemHandler.add(new ParseProblem("property '" + propertyName + "' does not appear in variable '" + variable.getName() + "'", correlationElem)); } } } // alarm properties // ////////////////////////////////////////////////////////////// public AlarmAction readAlarmAction(Element element, CompositeActivity parent) { AlarmAction alarmAction = new AlarmAction(); // for Element forElem = XmlUtil.getElement(element, BpelConstants.NS_BPEL, BpelConstants.ELEM_FOR); if (forElem != null) { alarmAction.setFor(readExpression(forElem, parent)); } else { // until Element untilElem = XmlUtil.getElement(element, BpelConstants.NS_BPEL, BpelConstants.ELEM_UNTIL); if (untilElem != null) alarmAction.setUntil(readExpression(untilElem, parent)); } // repeat every Element repeatEveryElem = XmlUtil.getElement(element, BpelConstants.NS_BPEL, BpelConstants.ELEM_REPEAT_EVERY); if (repeatEveryElem != null) alarmAction.setRepeatEvery(readExpression(repeatEveryElem, parent)); return alarmAction; } // child activities // ////////////////////////////////////////////////////////////// public Activity readActivity(Element activityElem, CompositeActivity parent) { if (activityElem == null) { // patch the missing activity return new Empty(); } ActivityReader parser = (ActivityReader) activityReaders.get(activityElem.getLocalName()); return parser.read(activityElem, parent); } protected Element getActivityElement(Element parent) { for (Node child = parent.getFirstChild(); child != null; child = child.getNextSibling()) { if (ActivityElementPredicate.evaluate(child)) return (Element) child; } problemHandler.add(new ParseProblem("activity not found", parent)); return null; } protected Iterator getActivityElements(Element parent) { return new FilterIterator(new NodeIterator(parent), ActivityElementPredicate.INSTANCE); } protected ActivityReader getActivityReader(String name) { return (ActivityReader) activityReaders.get(name); } private Map createActivityReaders() { HashMap activityReaders = new HashMap(); // walk through registered reader classes Iterator readerClassIt = activityReaderClasses.entrySet().iterator(); while (readerClassIt.hasNext()) { Entry readerClassEntry = (Entry) readerClassIt.next(); Object activityName = readerClassEntry.getKey(); Class readerClass = (Class) readerClassEntry.getValue(); try { // instantiate activity reader ActivityReader reader = (ActivityReader) readerClass.newInstance(); // associate activity reader with this bpel reader reader.setBpelReader(this); activityReaders.put(activityName, reader); } catch (InstantiationException e) { log.warn("reader class not instantiable: " + readerClass.getName(), e); } catch (IllegalAccessException e) { log.warn("reader class or constructor not public: " + readerClass.getName(), e); } } return activityReaders; } public ProblemHandler getProblemHandler() { return problemHandler; } public void setProblemHandler(ProblemHandler problemHandler) { this.problemHandler = problemHandler; } private static Map readActivityReaderClasses() { // get activity readers resource name String resource = JbpmConfiguration.Configs.getString(RESOURCE_ACTIVITY_READERS); // parse activity readers document Element readersElem; try { readersElem = XmlUtil.parseResource(resource); } catch (SAXException e) { log.error("activity readers document contains invalid xml: " + resource, e); return Collections.EMPTY_MAP; } catch (IOException e) { log.error("could not read activity readers document: " + resource, e); return Collections.EMPTY_MAP; } // walk through activityReader elements HashMap activityReaderClasses = new HashMap(); Iterator readerElemIt = XmlUtil.getElements(readersElem, null, "activityReader"); while (readerElemIt.hasNext()) { Element readerElem = (Element) readerElemIt.next(); String activityName = readerElem.getAttribute("name"); // load reader class String readerClassName = readerElem.getAttribute("class"); Class readerClass = ClassLoaderUtil.loadClass(readerClassName); // validate reader class if (!ActivityReader.class.isAssignableFrom(readerClass)) { log.warn("not an activity reader: " + readerClassName); continue; } // register reader class activityReaderClasses.put(activityName, readerClass); log.debug("registered activity reader: name=" + activityName + ", class=" + readerClassName); } return activityReaderClasses; } private static class ActivityElementPredicate implements Predicate { private static String[] BPEL_2_ACTIVITIES = { BpelConstants.ELEM_EMPTY, BpelConstants.ELEM_RECEIVE, BpelConstants.ELEM_REPLY, BpelConstants.ELEM_INVOKE, BpelConstants.ELEM_ASSIGN, BpelConstants.ELEM_THROW, BpelConstants.ELEM_EXIT, BpelConstants.ELEM_WAIT, BpelConstants.ELEM_SEQUENCE, BpelConstants.ELEM_IF, "switch", BpelConstants.ELEM_WHILE, BpelConstants.ELEM_PICK, BpelConstants.ELEM_FLOW, BpelConstants.ELEM_SCOPE, BpelConstants.ELEM_COMPENSATE, BpelConstants.ELEM_COMPENSATE_SCOPE, BpelConstants.ELEM_RETHROW, BpelConstants.ELEM_VALIDATE }; private static final Set activityNames = new HashSet( Arrays.asList(ActivityElementPredicate.BPEL_2_ACTIVITIES)); static final Predicate INSTANCE = new ActivityElementPredicate(); private ActivityElementPredicate() { } public boolean evaluate(Object arg) { return evaluate((Node) arg); } static boolean evaluate(Node node) { /* * the node is an activity if (1) it is an element, (2) its namespace URI matches the BPEL * namespace and (3) the set of activity names contains its local name */ return node.getNodeType() == Node.ELEMENT_NODE && BpelConstants.NS_BPEL.equals(node.getNamespaceURI()) && activityNames.contains(node.getLocalName()); } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?