Skip to content

Commit

Permalink
impl
Browse files Browse the repository at this point in the history
Issue #339
  • Loading branch information
rsoika committed Mar 1, 2024
1 parent 73763f8 commit cade742
Show file tree
Hide file tree
Showing 19 changed files with 210 additions and 4,039 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;

import org.w3c.dom.ls.LSInput;
import org.w3c.dom.ls.LSResourceResolver;
Expand All @@ -17,4 +18,89 @@ public LSInput resolveResource(String type, String namespaceURI, String publicId
input.setCharacterStream(new InputStreamReader(stream));
return input;
}

/**
* Inner class implementing a LSInput
*/
class XSDLSInputImpl implements LSInput {
private Reader characterStream;
private InputStream byteStream;
private String stringData;
private String systemId;
private String publicId;
private String baseURI;
private String encoding;
private boolean certifiedText;

// Getters and setters here
public Reader getCharacterStream() {
return characterStream;
}

public void setCharacterStream(Reader characterStream) {
this.characterStream = characterStream;
}

public InputStream getByteStream() {
return byteStream;
}

public void setByteStream(InputStream byteStream) {
this.byteStream = byteStream;
}

public String getStringData() {
return stringData;
}

public void setStringData(String stringData) {
this.stringData = stringData;
}

public String getSystemId() {
return systemId;
}

public void setSystemId(String systemId) {
this.systemId = systemId;
}

public String getPublicId() {
return publicId;
}

public void setPublicId(String publicId) {
this.publicId = publicId;
}

public String getBaseURI() {
return baseURI;
}

public void setBaseURI(String baseURI) {
this.baseURI = baseURI;
}

public String getEncoding() {
return encoding;
}

public void setEncoding(String encoding) {
this.encoding = encoding;
}

public boolean isCertifiedText() {
return certifiedText;
}

public void setCertifiedText(boolean certifiedText) {
this.certifiedText = certifiedText;
}

@Override
public boolean getCertifiedText() {
throw new UnsupportedOperationException("Unimplemented method 'getCertifiedText'");
}
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,45 @@

import org.xml.sax.SAXException;

/**
*
* The XSDValidator can be used for a strict validation of a BPMN file against
* the BPMNF 2.0 XSD files. The XSD files are part of this package.
*
* The validation is a strict mode and is not used directly in the Open-BPMN
* validation architecture.
*
* See also
*
* https://stackoverflow.com/questions/2342808/how-to-validate-an-xml-file-using-java-with-an-xsd-having-an-include
*
* https://blog.frankel.ch/xml-validation-with-importedincluded-schemas/
*
*/
public class XSDValidator {
private static Logger logger = Logger.getLogger(XSDValidator.class.getName());

public boolean validate(String xmlFilePath) throws SAXException, IOException {

// Path to the XSD files
// Path to the XSD files (located in class path)
String xsdFilePath1 = "/BPMN20.xsd";

InputStream xmlInputStream = getClass().getResourceAsStream(xmlFilePath);
InputStream xsdInputStream1 = getClass().getResourceAsStream(xsdFilePath1);

if (xmlInputStream == null || xsdInputStream1 == null) {

}
logger.info("...validate model...");
logger.finest("...validate bpmn 2.0 model...");

// create SchemaFactory

SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
schemaFactory.setResourceResolver(new XSDClasspathResourceResolver());

// Lade die XSD-Dateien in ein Schema
// create the validator from BPMN 2.0 Schema
Schema schema = schemaFactory.newSchema(new Source[] {
new StreamSource(xsdInputStream1)
});

// Erstelle einen Validator aus dem Schema
Validator validator = schema.newValidator();

// Validiere die XML-Datei
validator.validate(new StreamSource(xmlInputStream));

System.out.println("Validation successful.");

logger.info("...validation completed");
logger.finest("...validation completed");
return true;
}

Expand Down
93 changes: 49 additions & 44 deletions open-bpmn.metamodel/src/main/resources/BPMNDI.xsd
Original file line number Diff line number Diff line change
@@ -1,99 +1,104 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" targetNamespace="http://www.omg.org/spec/BPMN/20100524/DI" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
xmlns:dc="http://www.omg.org/spec/DD/20100524/DC"
xmlns:di="http://www.omg.org/spec/DD/20100524/DI"
targetNamespace="http://www.omg.org/spec/BPMN/20100524/DI" elementFormDefault="qualified"
attributeFormDefault="unqualified">

<xsd:import namespace="http://www.omg.org/spec/DD/20100524/DC" schemaLocation="DC.xsd" />
<xsd:import namespace="http://www.omg.org/spec/DD/20100524/DI" schemaLocation="DI.xsd" />

<xsd:element name="BPMNDiagram" type="bpmndi:BPMNDiagram" />
<xsd:element name="BPMNPlane" type="bpmndi:BPMNPlane" />
<xsd:element name="BPMNLabelStyle" type="bpmndi:BPMNLabelStyle" />
<xsd:element name="BPMNShape" type="bpmndi:BPMNShape" substitutionGroup="di:DiagramElement" />
<xsd:element name="BPMNLabel" type="bpmndi:BPMNLabel" />
<xsd:element name="BPMNEdge" type="bpmndi:BPMNEdge" substitutionGroup="di:DiagramElement" />

<xsd:import namespace="http://www.omg.org/spec/DD/20100524/DC" schemaLocation="DC.xsd"/>
<xsd:import namespace="http://www.omg.org/spec/DD/20100524/DI" schemaLocation="DI.xsd"/>

<xsd:element name="BPMNDiagram" type="bpmndi:BPMNDiagram"/>
<xsd:element name="BPMNPlane" type="bpmndi:BPMNPlane"/>
<xsd:element name="BPMNLabelStyle" type="bpmndi:BPMNLabelStyle"/>
<xsd:element name="BPMNShape" type="bpmndi:BPMNShape" substitutionGroup="di:DiagramElement"/>
<xsd:element name="BPMNLabel" type="bpmndi:BPMNLabel"/>
<xsd:element name="BPMNEdge" type="bpmndi:BPMNEdge" substitutionGroup="di:DiagramElement"/>

<xsd:complexType name="BPMNDiagram">
<xsd:complexContent>
<xsd:extension base="di:Diagram">
<xsd:sequence>
<xsd:element ref="bpmndi:BPMNPlane"/>
<xsd:element ref="bpmndi:BPMNLabelStyle" maxOccurs="unbounded" minOccurs="0"/>
<xsd:element ref="bpmndi:BPMNPlane" />
<xsd:element ref="bpmndi:BPMNLabelStyle" maxOccurs="unbounded" minOccurs="0" />
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

<xsd:complexType name="BPMNPlane">
<xsd:complexContent>
<xsd:extension base="di:Plane">
<xsd:attribute name="bpmnElement" type="xsd:QName"/>
<xsd:attribute name="bpmnElement" type="xsd:QName" />
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

<xsd:complexType name="BPMNEdge">
<xsd:complexContent>
<xsd:extension base="di:LabeledEdge">
<xsd:sequence>
<xsd:element ref="bpmndi:BPMNLabel" minOccurs="0"/>
<xsd:element ref="bpmndi:BPMNLabel" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="bpmnElement" type="xsd:QName"/>
<xsd:attribute name="sourceElement" type="xsd:QName"/>
<xsd:attribute name="targetElement" type="xsd:QName"/>
<xsd:attribute name="messageVisibleKind" type="bpmndi:MessageVisibleKind"/>
<xsd:attribute name="bpmnElement" type="xsd:QName" />
<xsd:attribute name="sourceElement" type="xsd:QName" />
<xsd:attribute name="targetElement" type="xsd:QName" />
<xsd:attribute name="messageVisibleKind" type="bpmndi:MessageVisibleKind" />
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

<xsd:complexType name="BPMNShape">
<xsd:complexContent>
<xsd:extension base="di:LabeledShape">
<xsd:sequence>
<xsd:element ref="bpmndi:BPMNLabel" minOccurs="0"/>
<xsd:element ref="bpmndi:BPMNLabel" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="bpmnElement" type="xsd:QName"/>
<xsd:attribute name="isHorizontal" type="xsd:boolean"/>
<xsd:attribute name="isExpanded" type="xsd:boolean"/>
<xsd:attribute name="isMarkerVisible" type="xsd:boolean"/>
<xsd:attribute name="isMessageVisible" type="xsd:boolean"/>
<xsd:attribute name="participantBandKind" type="bpmndi:ParticipantBandKind"/>
<xsd:attribute name="choreographyActivityShape" type="xsd:QName"/>
<xsd:attribute name="bpmnElement" type="xsd:QName" />
<xsd:attribute name="isHorizontal" type="xsd:boolean" />
<xsd:attribute name="isExpanded" type="xsd:boolean" />
<xsd:attribute name="isMarkerVisible" type="xsd:boolean" />
<xsd:attribute name="isMessageVisible" type="xsd:boolean" />
<xsd:attribute name="participantBandKind" type="bpmndi:ParticipantBandKind" />
<xsd:attribute name="choreographyActivityShape" type="xsd:QName" />
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

<xsd:complexType name="BPMNLabel">
<xsd:complexContent>
<xsd:extension base="di:Label">
<xsd:attribute name="labelStyle" type="xsd:QName"/>
<xsd:attribute name="labelStyle" type="xsd:QName" />
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

<xsd:complexType name="BPMNLabelStyle">
<xsd:complexContent>
<xsd:extension base="di:Style">
<xsd:sequence>
<xsd:element ref="dc:Font"/>
<xsd:element ref="dc:Font" />
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

<xsd:simpleType name="ParticipantBandKind">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="top_initiating"/>
<xsd:enumeration value="middle_initiating"/>
<xsd:enumeration value="bottom_initiating"/>
<xsd:enumeration value="top_non_initiating"/>
<xsd:enumeration value="middle_non_initiating"/>
<xsd:enumeration value="bottom_non_initiating"/>
<xsd:enumeration value="top_initiating" />
<xsd:enumeration value="middle_initiating" />
<xsd:enumeration value="bottom_initiating" />
<xsd:enumeration value="top_non_initiating" />
<xsd:enumeration value="middle_non_initiating" />
<xsd:enumeration value="bottom_non_initiating" />
</xsd:restriction>
</xsd:simpleType>

<xsd:simpleType name="MessageVisibleKind">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="initiating"/>
<xsd:enumeration value="non_initiating"/>
<xsd:enumeration value="initiating" />
<xsd:enumeration value="non_initiating" />
</xsd:restriction>
</xsd:simpleType>

Expand Down
Loading

0 comments on commit cade742

Please sign in to comment.