Skip to content

Commit

Permalink
first draft
Browse files Browse the repository at this point in the history
Issue #339
  • Loading branch information
rsoika committed Mar 1, 2024
1 parent f46b3cc commit 73763f8
Show file tree
Hide file tree
Showing 22 changed files with 5,924 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.openbpmn.bpmn.validation;

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

import org.w3c.dom.ls.LSInput;
import org.w3c.dom.ls.LSResourceResolver;

public class XSDClasspathResourceResolver implements LSResourceResolver {
@Override
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
XSDLSInputImpl input = new XSDLSInputImpl();
InputStream stream = getClass().getClassLoader().getResourceAsStream(systemId);
input.setPublicId(publicId);
input.setSystemId(systemId);
input.setBaseURI(baseURI);
input.setCharacterStream(new InputStreamReader(stream));
return input;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package org.openbpmn.bpmn.validation;

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

import org.w3c.dom.ls.LSInput;

public 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'");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.openbpmn.bpmn.validation;

import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Logger;

import javax.xml.XMLConstants;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;

import org.xml.sax.SAXException;

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
String xsdFilePath1 = "/BPMN20.xsd";

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

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

}
logger.info("...validate model...");

// create SchemaFactory

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

// Lade die XSD-Dateien in ein 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");
return true;
}

}
39 changes: 39 additions & 0 deletions open-bpmn.metamodel/src/main/resources/BPMN20.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema elementFormDefault="qualified" attributeFormDefault="unqualified"
xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
targetNamespace="http://www.omg.org/spec/BPMN/20100524/MODEL">

<xsd:import namespace="http://www.omg.org/spec/BPMN/20100524/DI" schemaLocation="BPMNDI.xsd" />
<xsd:include schemaLocation="Semantic.xsd" />

<xsd:element name="definitions" type="tDefinitions" />
<xsd:complexType name="tDefinitions">
<xsd:sequence>
<xsd:element ref="import" minOccurs="0" maxOccurs="unbounded" />
<xsd:element ref="extension" minOccurs="0" maxOccurs="unbounded" />
<xsd:element ref="rootElement" minOccurs="0" maxOccurs="unbounded" />
<xsd:element ref="bpmndi:BPMNDiagram" minOccurs="0" maxOccurs="unbounded" />
<xsd:element ref="relationship" minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>
<xsd:attribute name="id" type="xsd:ID" use="optional" />
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="targetNamespace" type="xsd:anyURI" use="required" />
<xsd:attribute name="expressionLanguage" type="xsd:anyURI" use="optional"
default="http://www.w3.org/1999/XPath" />
<xsd:attribute name="typeLanguage" type="xsd:anyURI" use="optional"
default="http://www.w3.org/2001/XMLSchema" />
<xsd:attribute name="exporter" type="xsd:string" />
<xsd:attribute name="exporterVersion" type="xsd:string" />
<xsd:anyAttribute namespace="##other" processContents="lax" />
</xsd:complexType>

<xsd:element name="import" type="tImport" />
<xsd:complexType name="tImport">
<xsd:attribute name="namespace" type="xsd:anyURI" use="required" />
<xsd:attribute name="location" type="xsd:string" use="required" />
<xsd:attribute name="importType" type="xsd:anyURI" use="required" />
</xsd:complexType>

</xsd:schema>
100 changes: 100 additions & 0 deletions open-bpmn.metamodel/src/main/resources/BPMNDI.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?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: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: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: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: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: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: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:extension>
</xsd:complexContent>
</xsd:complexType>

<xsd:complexType name="BPMNLabel">
<xsd:complexContent>
<xsd:extension base="di:Label">
<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: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:restriction>
</xsd:simpleType>

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

</xsd:schema>
29 changes: 29 additions & 0 deletions open-bpmn.metamodel/src/main/resources/DC.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" targetNamespace="http://www.omg.org/spec/DD/20100524/DC" elementFormDefault="qualified" attributeFormDefault="unqualified">

<xsd:element name="Font" type="dc:Font"/>
<xsd:element name="Point" type="dc:Point"/>
<xsd:element name="Bounds" type="dc:Bounds"/>

<xsd:complexType name="Font">
<xsd:attribute name="name" type="xsd:string"/>
<xsd:attribute name="size" type="xsd:double"/>
<xsd:attribute name="isBold" type="xsd:boolean"/>
<xsd:attribute name="isItalic" type="xsd:boolean"/>
<xsd:attribute name="isUnderline" type="xsd:boolean"/>
<xsd:attribute name="isStrikeThrough" type="xsd:boolean"/>
</xsd:complexType>

<xsd:complexType name="Point">
<xsd:attribute name="x" type="xsd:double" use="required"/>
<xsd:attribute name="y" type="xsd:double" use="required"/>
</xsd:complexType>

<xsd:complexType name="Bounds">
<xsd:attribute name="x" type="xsd:double" use="required"/>
<xsd:attribute name="y" type="xsd:double" use="required"/>
<xsd:attribute name="width" type="xsd:double" use="required"/>
<xsd:attribute name="height" type="xsd:double" use="required"/>
</xsd:complexType>

</xsd:schema>
Loading

0 comments on commit 73763f8

Please sign in to comment.