bpelreader.java
来自「ejb3 java session bean」· Java 代码 · 共 1,370 行 · 第 1/4 页
JAVA
1,370 行
else { Problem problem = new Problem(Problem.LEVEL_ERROR, "property not found: " + property.getQName()); problem.setResource(wsdlDef.getDocumentBaseURI()); problemHandler.add(problem); } // message Message message = alias.getMessage(); if (message != null) { // check the message definition exists if (!message.isUndefined()) { // register property alias in message type MessageType type = importDefinition.getMessageType(message.getQName()); type.addPropertyAlias(alias); } else { Problem problem = new Problem(Problem.LEVEL_ERROR, "message not found: " + message.getQName()); problem.setResource(wsdlDef.getDocumentBaseURI()); problemHandler.add(problem); } } else { QName element = alias.getElement(); if (element != null) importDefinition.getElementType(element).addPropertyAlias(alias); else { QName type = alias.getType(); if (type != null) importDefinition.getSchemaType(type).addPropertyAlias(alias); else { Problem problem = new Problem(Problem.LEVEL_ERROR, "neither message, element nor type specified in property alias"); problem.setResource(wsdlDef.getDocumentBaseURI()); problemHandler.add(problem); } } } // query PropertyQuery query = alias.getQuery(); if (query != null) { // namespaces query.setNamespaces(processDefinition.addNamespaces(query.getNamespaces())); // language if (query.getLanguage() == null) query.setLanguage(processDefinition.getQueryLanguage()); // syntax try { query.parse(); } catch (BpelException e) { Problem problem = new Problem(Problem.LEVEL_ERROR, "could not parse query: " + query.getText(), e); problem.setResource(wsdlDef.getDocumentBaseURI()); problemHandler.add(problem); } } } // deal with imported definitions for (Iterator l = wsdlDef.getImports().values().iterator(); l.hasNext();) { List imports = (List) l.next(); for (int i = 0, n = imports.size(); i < n; i++) { javax.wsdl.Import _import = (javax.wsdl.Import) imports.get(i); registerPropertyAliases(importDefinition, _import.getDefinition()); } } } // process properties // ////////////////////////////////////////////////////////////// protected void readProcessAttributes(Element processElem, BpelProcessDefinition processDefinition) { // name & namespace processDefinition.setName(processElem.getAttribute(BpelConstants.ATTR_NAME)); processDefinition.setTargetNamespace(processElem.getAttribute(BpelConstants.ATTR_TARGET_NAMESPACE)); // query & expression language processDefinition.setQueryLanguage(XmlUtil.getAttribute(processElem, BpelConstants.ATTR_QUERY_LANGUAGE)); processDefinition.setExpressionLanguage(XmlUtil.getAttribute(processElem, BpelConstants.ATTR_EXPRESSION_LANGUAGE)); // suppress join failure Attr suppressAttr = processElem.getAttributeNode(BpelConstants.ATTR_SUPPRESS_JOIN_FAILURE); processDefinition.getGlobalScope().setSuppressJoinFailure( readTBoolean(suppressAttr, Boolean.FALSE)); } protected void readImports(Element processElem, ImportDefinition importDefinition, ProcessWsdlLocator wsdlLocator) { Iterator importElemIt = XmlUtil.getElements(processElem, BpelConstants.NS_BPEL, BpelConstants.ELEM_IMPORT); if (importElemIt.hasNext()) { // process document explicitly imports documents // read only those documents do { Element importElem = (Element) importElemIt.next(); Import _import = readImport(importElem); importDefinition.addImport(_import); if (Import.Type.WSDL.equals(_import.getType())) { // read wsdl document readImportWsdlDefinition(_import, wsdlLocator); // verify the wsdl target namespace matches the import namespace Definition def = (Definition) _import.getDocument(); if (!_import.getNamespace().equals(def.getTargetNamespace())) { problemHandler.add(new ParseProblem("namespace does not match wsdl target namespace", importElem)); } } } while (importElemIt.hasNext()); } else if (importDefinition.getImports().isEmpty()) { /* * process document has no explicit imports and no imports were supplied by the definition * descriptor; fall back to master wsdl definition */ Import masterImport = createMasterWsdlImport(wsdlLocator); importDefinition.addImport(masterImport); // read wsdl document readImportWsdlDefinition(masterImport, wsdlLocator); // set the import namespace to the wsdl target namespace Definition masterWsdl = (Definition) masterImport.getDocument(); masterImport.setNamespace(masterWsdl.getTargetNamespace()); } } protected Import readImport(Element importElem) { Import _import = new Import(); _import.setNamespace(importElem.getAttribute(BpelConstants.ATTR_NAMESPACE)); _import.setLocation(importElem.getAttribute(BpelConstants.ATTR_LOCATION)); _import.setType(Import.Type.valueOf(importElem.getAttribute(BpelConstants.ATTR_IMPORT_TYPE))); return _import; } protected Import createMasterWsdlImport(ProcessWsdlLocator wsdlLocator) { // determine master wsdl location String processPath = wsdlLocator.getProcessURI().getPath(); int beginIndex = processPath.lastIndexOf('/'); if (beginIndex != -1) ++beginIndex; else beginIndex = 0; int endIndex = processPath.lastIndexOf('.'); if (endIndex == -1 || beginIndex >= endIndex) { problemHandler.add(new Problem(Problem.LEVEL_ERROR, "cannot extract file name from process path: " + processPath)); return new Import(); } String wsdlFile = processPath.substring(beginIndex, endIndex) + ".wsdl"; // create import for master wsdl Import masterImport = new Import(); masterImport.setLocation(wsdlFile); masterImport.setType(Import.Type.WSDL); return masterImport; } public void readImportWsdlDefinition(Import _import, ProcessWsdlLocator wsdlLocator) { String location = _import.getLocation(); Definition definition; try { // set import location as the base URI of the given WSDL locator wsdlLocator.resolveBaseURI(location); // read imported WSDL document WSDLReader reader = WsdlUtil.getFactory().newWSDLReader(); definition = reader.readWSDL(wsdlLocator); log.debug("read wsdl document: " + location); } catch (WSDLException e) { problemHandler.add(new Problem(Problem.LEVEL_ERROR, "could not read wsdl document", e)); // patch missing definition definition = WsdlUtil.getFactory().newDefinition(); definition.setDocumentBaseURI(location); if (_import.getNamespace() != null) definition.setTargetNamespace(_import.getNamespace()); } _import.setDocument(definition); } public Boolean readTBoolean(Attr attribute, Boolean defaultValue) { if (attribute == null) return defaultValue; String text = attribute.getValue(); return BpelConstants.YES.equals(text) ? Boolean.TRUE : BpelConstants.NO.equals(text) ? Boolean.FALSE : defaultValue; } public Expression readExpression(Element enclosingElem, CompositeActivity parent) { Expression expression = new Expression(); readExpression(enclosingElem, parent, expression); return expression; } protected void readExpression(Element enclosingElem, CompositeActivity parent, Expression expression) { // text content expression.setText(DatatypeUtil.toString(enclosingElem)); // namespaces BpelProcessDefinition processDefinition = parent.getBpelProcessDefinition(); expression.setNamespaces(processDefinition.addNamespaces(XmlUtil.findNamespaceDeclarations(enclosingElem))); // language String language = XmlUtil.getAttribute(enclosingElem, BpelConstants.ATTR_EXPRESSION_LANGUAGE); if (language == null) language = processDefinition.getExpressionLanguage(); expression.setLanguage(language); // parsing try { expression.parse(); } catch (BpelException e) { problemHandler.add(new ParseProblem("could not parse expression", enclosingElem, e)); } } // scope definition properties // ////////////////////////////////////////////////////////////// public void readScope(Element scopeElem, Scope scope) { scope.installFaultExceptionHandler(); // partner links Element partnerLinksElem = XmlUtil.getElement(scopeElem, BpelConstants.NS_BPEL, BpelConstants.ELEM_PARTNER_LINKS); if (partnerLinksElem != null) scope.setPartnerLinks(readPartnerLinks(partnerLinksElem, scope)); // variables Element variablesElem = XmlUtil.getElement(scopeElem, BpelConstants.NS_BPEL, BpelConstants.ELEM_VARIABLES); if (variablesElem != null) scope.setVariables(readVariables(variablesElem, scope)); // correlation sets Element setsElem = XmlUtil.getElement(scopeElem, BpelConstants.NS_BPEL, BpelConstants.ELEM_CORRELATION_SETS); if (setsElem != null) scope.setCorrelationSets(readCorrelationSets(setsElem, scope)); /* * read activity before FCT handlers; compensateScope requires the activity be present in order * to locate the nested scope */ Element activityElem = getActivityElement(scopeElem); readActivity(activityElem, scope); // fault handlers Element faultHandlersElem = XmlUtil.getElement(scopeElem, BpelConstants.NS_BPEL, BpelConstants.ELEM_FAULT_HANDLERS); if (faultHandlersElem != null) readFaultHandlers(faultHandlersElem, scope); // compensation handler Element compensationHandlerElem = XmlUtil.getElement(scopeElem, BpelConstants.NS_BPEL, BpelConstants.ELEM_COMPENSATION_HANDLER); if (compensationHandlerElem != null) readCompensationHandler(compensationHandlerElem, scope); // termination handler Element terminationHandlerElem = XmlUtil.getElement(scopeElem, BpelConstants.NS_BPEL, BpelConstants.ELEM_TERMINATION_HANDLER); if (terminationHandlerElem != null) { readTerminationHandler(terminationHandlerElem, scope); } else { // install BPEL4WS 1.1 forced termination handler Catch forcedTerminationHandler = scope.selectCatch(BpelConstants.FAULT_FORCED_TERMINATION); if (forcedTerminationHandler != null) scope.setTerminationHandler(forcedTerminationHandler); } // event handlers Element eventHandlersElem = XmlUtil.getElement(scopeElem, BpelConstants.NS_BPEL, BpelConstants.ELEM_EVENT_HANDLERS); if (eventHandlersElem != null) readEventHandlers(eventHandlersElem, scope); } public void readCompensationHandler(Element handlerElem, Scope scope) { Handler handler = new Handler(); // register handler before reading activity so that scope definitions are // available scope.setCompensationHandler(handler); // read handler activity Activity activity = readActivity(getActivityElement(handlerElem), handler); handler.setActivity(activity); } protected void readTerminationHandler(Element handlerElem, Scope scope) { Handler handler = new Handler(); // register handler before reading activity so that scope definitions are // available scope.setTerminationHandler(handler); // read handler activity Activity activity = readActivity(getActivityElement(handlerElem), handler); handler.setActivity(activity); } public void readFaultHandlers(Element faultHandlersElem, Scope scope) { // catch elements Iterator catchElemIt = XmlUtil.getElements(faultHandlersElem, BpelConstants.NS_BPEL, BpelConstants.ELEM_CATCH); while (catchElemIt.hasNext()) { Element catchElem = (Element) catchElemIt.next(); readCatch(catchElem, scope); } // catchAll element Element catchAllElem = XmlUtil.getElement(faultHandlersElem, BpelConstants.NS_BPEL, BpelConstants.ELEM_CATCH_ALL); if (catchAllElem != null) readCatchAll(catchAllElem, scope); } protected void readCatch(Element catchElem, Scope scope) { // the valid configuration for a catch is: // faultName OR (faultVariable AND (elementType XOR messageType)) Catch catcher = new Catch(); // fault name QName faultName = getFaultName(catchElem); catcher.setFaultName(faultName); // fault variable VariableDefinition faultVariable = getFaultVariable(catchElem, scope);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?