private Element doFindImportedElement(QName eltQName,Set<XmlObject> visited) throws BPMNException { for(Import i : getImports()){ XmlObject content = i.getImportContent(); if(visited.contains(content)) { continue; visited.add(content); if(i.isXSDImport()){ Element e = SchemaHelper.findElementByQName(i.getSchema(), eltQName); if(e!=null){ return e; else if(i.isWSDL11Import()){ Element e = SchemaHelper.findElementByQName(i.getWSDL11Definitions(), eltQName); if(e!=null){ return e; else if(i.isBPMN20Import()){ Element e = i.getBPMNDefinitions().findImportedElement(eltQName); if(e!=null){ return e;
@Override public Import getImport(String namespace) { for(Import i : getImports()) { if(i.hasNamespace() && i.getNamespace().equals(namespace)) { return i; } } return null; }
Map<String,String> prefixes = defs.findImportPrefixes(); for(Import impt : imports){ String prefix = prefixes.get(impt.getNamespace()); ImportBean importBean; if(impt.isXSDImport()){ importBean = ImportAdapter.adaptSchemaImport(prefix, impt.getLocation(), impt.getSchema()); else if(impt.isWSDL11Import()) { importBean = ImportAdapter.adaptWSDLImport(prefix, impt.getLocation(), impt.getWSDL11Definitions()); else if(impt.isBPMN20Import()) { importBean = ImportAdapter.adaptBPMNImport(prefix, impt.getLocation(), impt.getBPMNDefinitions()); NamespaceDeclaration nsd = new NamespaceDeclaration(null, impt.getNamespace()); importBean = new ImportBean(nsd); importBean.setLocation(impt.getLocation().toString()); importBean.setImportType(impt.getImportType().toString());
/** * Searches for a BPMN element in the given Definitions and its BPMN 2.0 imports * @param <T> * @param defs * @param ref Id or {import namespace}Id * @param wantedClass * @return * @throws BPMNException */ public static <T extends BaseElement> T findBPMNObject(Definitions defs, QName ref, Class<T> wantedClass) throws BPMNException { if(ref!=null) { if(ref.getNamespaceURI()==null || ref.getNamespaceURI().isEmpty()) { return findObjectInDefinitions(defs, ref.getLocalPart(), wantedClass); } Import impt = defs.getImport(ref.getNamespaceURI()); if(impt!=null && impt.isBPMN20Import()) { Definitions importedDefs = impt.getBPMNDefinitions(); return findObjectInDefinitions(importedDefs, ref.getLocalPart(), wantedClass); } } throw new BPMNException("No bpmn element has been found for this QName : "+ref); }
@Override public Map<String,String> findImportPrefixes() { Map<String,String> result = new HashMap<String, String>(); if(hasImport()) { Node defsNode = getXmlObjectDOMNode(); for(int i=0; i<defsNode.getAttributes().getLength(); i++) { Attr attr = (Attr) defsNode.getAttributes().item(i); if(attr.getName().startsWith("xmlns:")) { Import impt = getImport(attr.getValue()); if(impt!=null) { String prefix = attr.getName().replace("xmlns:", ""); result.put(impt.getNamespace(), prefix); } } } } return result; }