From 7fec640e0c85719adf948e42fc945a5e13ad04ab Mon Sep 17 00:00:00 2001 From: Philip Helger Date: Tue, 17 Sep 2024 10:29:14 +0200 Subject: [PATCH] API extension for #65 --- .../com/helger/ubl20/EUBL20DocumentType.java | 30 +++++++++ .../helger/ubl20/EUBL20DocumentTypeTest.java | 17 +++++ .../com/helger/ubl22/EUBL22DocumentType.java | 30 +++++++++ .../helger/ubl22/EUBL22DocumentTypeTest.java | 11 ++++ .../com/helger/ubl23/EUBL23DocumentType.java | 30 +++++++++ .../helger/ubl23/EUBL23DocumentTypeTest.java | 11 ++++ .../com/helger/ubl24/EUBL24DocumentType.java | 30 +++++++++ .../helger/ubl24/EUBL24DocumentTypeTest.java | 63 +++++++++++++++++++ 8 files changed, 222 insertions(+) create mode 100644 ph-ubl24/src/test/java/com/helger/ubl24/EUBL24DocumentTypeTest.java diff --git a/ph-ubl20/src/main/java/com/helger/ubl20/EUBL20DocumentType.java b/ph-ubl20/src/main/java/com/helger/ubl20/EUBL20DocumentType.java index f2cc8b5c..c73e0a2b 100644 --- a/ph-ubl20/src/main/java/com/helger/ubl20/EUBL20DocumentType.java +++ b/ph-ubl20/src/main/java/com/helger/ubl20/EUBL20DocumentType.java @@ -22,6 +22,8 @@ import com.helger.commons.annotation.ReturnsMutableCopy; import com.helger.commons.collection.impl.ICommonsList; import com.helger.commons.io.resource.ClassPathResource; +import com.helger.commons.lang.ClassHelper; +import com.helger.commons.string.StringHelper; /** * Enumeration with all available UBL 2.0 document types. @@ -84,11 +86,15 @@ public enum EUBL20DocumentType private final Class m_aImplClass; private final ICommonsList m_aXSDs; + private final String m_sRootElementLocalName; + private final String m_sRootElementNSURI; EUBL20DocumentType (@Nonnull final Class aClass, @Nonnull final ICommonsList aXSDs) { m_aImplClass = aClass; m_aXSDs = aXSDs; + m_sRootElementLocalName = StringHelper.trimEnd (ClassHelper.getClassLocalName (aClass), "Type"); + m_sRootElementNSURI = aClass.getPackage ().getAnnotation (jakarta.xml.bind.annotation.XmlSchema.class).namespace (); } @Nonnull @@ -104,4 +110,28 @@ public ICommonsList getAllXSDResources () { return m_aXSDs.getClone (); } + + /** + * @return The local element name of the root element of this document type. + * E.g. OrderCancellation for "Order Cancellation". + */ + @Nonnull + @Nonempty + public String getRootElementLocalName () + { + return m_sRootElementLocalName; + } + + /** + * @return The XML namespace URI of the root element of this document type. + * E.g. + * urn:oasis:names:specification:ubl:schema:xsd:OrderCancellation-2 + * for "Order Cancellation". + */ + @Nonnull + @Nonempty + public String getRootElementNamespaceURI () + { + return m_sRootElementNSURI; + } } diff --git a/ph-ubl20/src/test/java/com/helger/ubl20/EUBL20DocumentTypeTest.java b/ph-ubl20/src/test/java/com/helger/ubl20/EUBL20DocumentTypeTest.java index 236e88dc..02684c6a 100644 --- a/ph-ubl20/src/test/java/com/helger/ubl20/EUBL20DocumentTypeTest.java +++ b/ph-ubl20/src/test/java/com/helger/ubl20/EUBL20DocumentTypeTest.java @@ -16,13 +16,17 @@ */ package com.helger.ubl20; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import org.junit.Test; +import com.helger.commons.collection.impl.CommonsHashSet; +import com.helger.commons.collection.impl.ICommonsSet; import com.helger.commons.io.resource.IReadableResource; +import com.helger.commons.string.StringHelper; /** * Test class for class {@link EUBL20DocumentType}. @@ -34,13 +38,26 @@ public final class EUBL20DocumentTypeTest @Test public void testAll () { + final ICommonsSet > aClasses = new CommonsHashSet <> (); + final ICommonsSet aFilenames = new CommonsHashSet <> (); for (final EUBL20DocumentType e : EUBL20DocumentType.values ()) { assertNotNull (e.getImplementationClass ()); + assertTrue (e.getAllXSDResources ().size () >= 1); for (final IReadableResource aRes : e.getAllXSDResources ()) assertTrue (e.name (), aRes.exists ()); + + assertTrue (StringHelper.hasText (e.getRootElementLocalName ())); + assertTrue (StringHelper.hasText (e.getRootElementNamespaceURI ())); + assertSame (e, EUBL20DocumentType.valueOf (e.name ())); + assertTrue (aClasses.add (e.getImplementationClass ())); + assertTrue (aFilenames.add (e.getAllXSDResources ().getLastOrNull ().getPath ())); } + + assertEquals ("OrderCancellation", EUBL20DocumentType.ORDER_CANCELLATION.getRootElementLocalName ()); + assertEquals ("urn:oasis:names:specification:ubl:schema:xsd:OrderCancellation-2", + EUBL20DocumentType.ORDER_CANCELLATION.getRootElementNamespaceURI ()); } } diff --git a/ph-ubl22/src/main/java/com/helger/ubl22/EUBL22DocumentType.java b/ph-ubl22/src/main/java/com/helger/ubl22/EUBL22DocumentType.java index 02656dc7..152db1fb 100644 --- a/ph-ubl22/src/main/java/com/helger/ubl22/EUBL22DocumentType.java +++ b/ph-ubl22/src/main/java/com/helger/ubl22/EUBL22DocumentType.java @@ -23,6 +23,8 @@ import com.helger.commons.annotation.Since; import com.helger.commons.collection.impl.ICommonsList; import com.helger.commons.io.resource.ClassPathResource; +import com.helger.commons.lang.ClassHelper; +import com.helger.commons.string.StringHelper; /** * Enumeration with all available UBL 2.2 document types. @@ -195,11 +197,15 @@ public enum EUBL22DocumentType private final Class m_aImplClass; private final ICommonsList m_aXSDs; + private final String m_sRootElementLocalName; + private final String m_sRootElementNSURI; EUBL22DocumentType (@Nonnull final Class aClass, @Nonnull final ICommonsList aXSDs) { m_aImplClass = aClass; m_aXSDs = aXSDs; + m_sRootElementLocalName = StringHelper.trimEnd (ClassHelper.getClassLocalName (aClass), "Type"); + m_sRootElementNSURI = aClass.getPackage ().getAnnotation (jakarta.xml.bind.annotation.XmlSchema.class).namespace (); } @Nonnull @@ -215,4 +221,28 @@ public ICommonsList getAllXSDResources () { return m_aXSDs.getClone (); } + + /** + * @return The local element name of the root element of this document type. + * E.g. OrderCancellation for "Order Cancellation". + */ + @Nonnull + @Nonempty + public String getRootElementLocalName () + { + return m_sRootElementLocalName; + } + + /** + * @return The XML namespace URI of the root element of this document type. + * E.g. + * urn:oasis:names:specification:ubl:schema:xsd:OrderCancellation-2 + * for "Order Cancellation". + */ + @Nonnull + @Nonempty + public String getRootElementNamespaceURI () + { + return m_sRootElementNSURI; + } } diff --git a/ph-ubl22/src/test/java/com/helger/ubl22/EUBL22DocumentTypeTest.java b/ph-ubl22/src/test/java/com/helger/ubl22/EUBL22DocumentTypeTest.java index 89d9ccc8..7a1c5841 100644 --- a/ph-ubl22/src/test/java/com/helger/ubl22/EUBL22DocumentTypeTest.java +++ b/ph-ubl22/src/test/java/com/helger/ubl22/EUBL22DocumentTypeTest.java @@ -16,6 +16,7 @@ */ package com.helger.ubl22; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; @@ -25,6 +26,7 @@ import com.helger.commons.collection.impl.CommonsHashSet; import com.helger.commons.collection.impl.ICommonsSet; import com.helger.commons.io.resource.IReadableResource; +import com.helger.commons.string.StringHelper; /** * Test class for class {@link EUBL22DocumentType}. @@ -41,12 +43,21 @@ public void testAll () for (final EUBL22DocumentType e : EUBL22DocumentType.values ()) { assertNotNull (e.getImplementationClass ()); + assertTrue (e.getAllXSDResources ().size () >= 1); for (final IReadableResource aRes : e.getAllXSDResources ()) assertTrue (e.name (), aRes.exists ()); + + assertTrue (StringHelper.hasText (e.getRootElementLocalName ())); + assertTrue (StringHelper.hasText (e.getRootElementNamespaceURI ())); + assertSame (e, EUBL22DocumentType.valueOf (e.name ())); assertTrue (aClasses.add (e.getImplementationClass ())); assertTrue (aFilenames.add (e.getAllXSDResources ().getLastOrNull ().getPath ())); } + + assertEquals ("OrderCancellation", EUBL22DocumentType.ORDER_CANCELLATION.getRootElementLocalName ()); + assertEquals ("urn:oasis:names:specification:ubl:schema:xsd:OrderCancellation-2", + EUBL22DocumentType.ORDER_CANCELLATION.getRootElementNamespaceURI ()); } } diff --git a/ph-ubl23/src/main/java/com/helger/ubl23/EUBL23DocumentType.java b/ph-ubl23/src/main/java/com/helger/ubl23/EUBL23DocumentType.java index 349a432b..64c49a1f 100644 --- a/ph-ubl23/src/main/java/com/helger/ubl23/EUBL23DocumentType.java +++ b/ph-ubl23/src/main/java/com/helger/ubl23/EUBL23DocumentType.java @@ -23,6 +23,8 @@ import com.helger.commons.annotation.Since; import com.helger.commons.collection.impl.ICommonsList; import com.helger.commons.io.resource.ClassPathResource; +import com.helger.commons.lang.ClassHelper; +import com.helger.commons.string.StringHelper; /** * Enumeration with all available UBL 2.3 document types. @@ -210,11 +212,15 @@ public enum EUBL23DocumentType private final Class m_aImplClass; private final ICommonsList m_aXSDs; + private final String m_sRootElementLocalName; + private final String m_sRootElementNSURI; EUBL23DocumentType (@Nonnull final Class aClass, @Nonnull final ICommonsList aXSDs) { m_aImplClass = aClass; m_aXSDs = aXSDs; + m_sRootElementLocalName = StringHelper.trimEnd (ClassHelper.getClassLocalName (aClass), "Type"); + m_sRootElementNSURI = aClass.getPackage ().getAnnotation (jakarta.xml.bind.annotation.XmlSchema.class).namespace (); } @Nonnull @@ -230,4 +236,28 @@ public ICommonsList getAllXSDResources () { return m_aXSDs.getClone (); } + + /** + * @return The local element name of the root element of this document type. + * E.g. OrderCancellation for "Order Cancellation". + */ + @Nonnull + @Nonempty + public String getRootElementLocalName () + { + return m_sRootElementLocalName; + } + + /** + * @return The XML namespace URI of the root element of this document type. + * E.g. + * urn:oasis:names:specification:ubl:schema:xsd:OrderCancellation-2 + * for "Order Cancellation". + */ + @Nonnull + @Nonempty + public String getRootElementNamespaceURI () + { + return m_sRootElementNSURI; + } } diff --git a/ph-ubl23/src/test/java/com/helger/ubl23/EUBL23DocumentTypeTest.java b/ph-ubl23/src/test/java/com/helger/ubl23/EUBL23DocumentTypeTest.java index 0e77645a..93cbd5bc 100644 --- a/ph-ubl23/src/test/java/com/helger/ubl23/EUBL23DocumentTypeTest.java +++ b/ph-ubl23/src/test/java/com/helger/ubl23/EUBL23DocumentTypeTest.java @@ -16,6 +16,7 @@ */ package com.helger.ubl23; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; @@ -25,6 +26,7 @@ import com.helger.commons.collection.impl.CommonsHashSet; import com.helger.commons.collection.impl.ICommonsSet; import com.helger.commons.io.resource.IReadableResource; +import com.helger.commons.string.StringHelper; /** * Test class for class {@link EUBL23DocumentType}. @@ -41,12 +43,21 @@ public void testAll () for (final EUBL23DocumentType e : EUBL23DocumentType.values ()) { assertNotNull (e.getImplementationClass ()); + assertTrue (e.getAllXSDResources ().size () >= 1); for (final IReadableResource aRes : e.getAllXSDResources ()) assertTrue (e.name (), aRes.exists ()); + + assertTrue (StringHelper.hasText (e.getRootElementLocalName ())); + assertTrue (StringHelper.hasText (e.getRootElementNamespaceURI ())); + assertSame (e, EUBL23DocumentType.valueOf (e.name ())); assertTrue (aClasses.add (e.getImplementationClass ())); assertTrue (aFilenames.add (e.getAllXSDResources ().getLastOrNull ().getPath ())); } + + assertEquals ("OrderCancellation", EUBL23DocumentType.ORDER_CANCELLATION.getRootElementLocalName ()); + assertEquals ("urn:oasis:names:specification:ubl:schema:xsd:OrderCancellation-2", + EUBL23DocumentType.ORDER_CANCELLATION.getRootElementNamespaceURI ()); } } diff --git a/ph-ubl24/src/main/java/com/helger/ubl24/EUBL24DocumentType.java b/ph-ubl24/src/main/java/com/helger/ubl24/EUBL24DocumentType.java index 23777d74..fcfbd800 100644 --- a/ph-ubl24/src/main/java/com/helger/ubl24/EUBL24DocumentType.java +++ b/ph-ubl24/src/main/java/com/helger/ubl24/EUBL24DocumentType.java @@ -23,6 +23,8 @@ import com.helger.commons.annotation.Since; import com.helger.commons.collection.impl.ICommonsList; import com.helger.commons.io.resource.ClassPathResource; +import com.helger.commons.lang.ClassHelper; +import com.helger.commons.string.StringHelper; /** * Enumeration with all available UBL 2.4 document types. @@ -206,11 +208,15 @@ public enum EUBL24DocumentType private final Class m_aImplClass; private final ICommonsList m_aXSDs; + private final String m_sRootElementLocalName; + private final String m_sRootElementNSURI; EUBL24DocumentType (@Nonnull final Class aClass, @Nonnull final ICommonsList aXSDs) { m_aImplClass = aClass; m_aXSDs = aXSDs; + m_sRootElementLocalName = StringHelper.trimEnd (ClassHelper.getClassLocalName (aClass), "Type"); + m_sRootElementNSURI = aClass.getPackage ().getAnnotation (jakarta.xml.bind.annotation.XmlSchema.class).namespace (); } @Nonnull @@ -226,4 +232,28 @@ public ICommonsList getAllXSDResources () { return m_aXSDs.getClone (); } + + /** + * @return The local element name of the root element of this document type. + * E.g. OrderCancellation for "Order Cancellation". + */ + @Nonnull + @Nonempty + public String getRootElementLocalName () + { + return m_sRootElementLocalName; + } + + /** + * @return The XML namespace URI of the root element of this document type. + * E.g. + * urn:oasis:names:specification:ubl:schema:xsd:OrderCancellation-2 + * for "Order Cancellation". + */ + @Nonnull + @Nonempty + public String getRootElementNamespaceURI () + { + return m_sRootElementNSURI; + } } diff --git a/ph-ubl24/src/test/java/com/helger/ubl24/EUBL24DocumentTypeTest.java b/ph-ubl24/src/test/java/com/helger/ubl24/EUBL24DocumentTypeTest.java new file mode 100644 index 00000000..1c73028f --- /dev/null +++ b/ph-ubl24/src/test/java/com/helger/ubl24/EUBL24DocumentTypeTest.java @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2014-2024 Philip Helger (www.helger.com) + * philip[at]helger[dot]com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.helger.ubl24; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +import com.helger.commons.collection.impl.CommonsHashSet; +import com.helger.commons.collection.impl.ICommonsSet; +import com.helger.commons.io.resource.IReadableResource; +import com.helger.commons.string.StringHelper; + +/** + * Test class for class {@link EUBL23DocumentType}. + * + * @author Philip Helger + */ +public final class EUBL24DocumentTypeTest +{ + @Test + public void testAll () + { + final ICommonsSet > aClasses = new CommonsHashSet <> (); + final ICommonsSet aFilenames = new CommonsHashSet <> (); + for (final EUBL24DocumentType e : EUBL24DocumentType.values ()) + { + assertNotNull (e.getImplementationClass ()); + + assertTrue (e.getAllXSDResources ().size () >= 1); + for (final IReadableResource aRes : e.getAllXSDResources ()) + assertTrue (e.name (), aRes.exists ()); + + assertTrue (StringHelper.hasText (e.getRootElementLocalName ())); + assertTrue (StringHelper.hasText (e.getRootElementNamespaceURI ())); + + assertSame (e, EUBL24DocumentType.valueOf (e.name ())); + assertTrue (aClasses.add (e.getImplementationClass ())); + assertTrue (aFilenames.add (e.getAllXSDResources ().getLastOrNull ().getPath ())); + } + + assertEquals ("OrderCancellation", EUBL24DocumentType.ORDER_CANCELLATION.getRootElementLocalName ()); + assertEquals ("urn:oasis:names:specification:ubl:schema:xsd:OrderCancellation-2", + EUBL24DocumentType.ORDER_CANCELLATION.getRootElementNamespaceURI ()); + } +}