Skip to content

Commit

Permalink
API extension for #65
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed Sep 17, 2024
1 parent b21b6ba commit 7fec640
Show file tree
Hide file tree
Showing 8 changed files with 222 additions and 0 deletions.
30 changes: 30 additions & 0 deletions ph-ubl20/src/main/java/com/helger/ubl20/EUBL20DocumentType.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -84,11 +86,15 @@ public enum EUBL20DocumentType

private final Class <?> m_aImplClass;
private final ICommonsList <ClassPathResource> m_aXSDs;
private final String m_sRootElementLocalName;
private final String m_sRootElementNSURI;

EUBL20DocumentType (@Nonnull final Class <?> aClass, @Nonnull final ICommonsList <ClassPathResource> 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
Expand All @@ -104,4 +110,28 @@ public ICommonsList <ClassPathResource> getAllXSDResources ()
{
return m_aXSDs.getClone ();
}

/**
* @return The local element name of the root element of this document type.
* E.g. <code>OrderCancellation</code> 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.
* <code>urn:oasis:names:specification:ubl:schema:xsd:OrderCancellation-2</code>
* for "Order Cancellation".
*/
@Nonnull
@Nonempty
public String getRootElementNamespaceURI ()
{
return m_sRootElementNSURI;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand All @@ -34,13 +38,26 @@ public final class EUBL20DocumentTypeTest
@Test
public void testAll ()
{
final ICommonsSet <Class <?>> aClasses = new CommonsHashSet <> ();
final ICommonsSet <String> 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 ());
}
}
30 changes: 30 additions & 0 deletions ph-ubl22/src/main/java/com/helger/ubl22/EUBL22DocumentType.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -195,11 +197,15 @@ public enum EUBL22DocumentType

private final Class <?> m_aImplClass;
private final ICommonsList <ClassPathResource> m_aXSDs;
private final String m_sRootElementLocalName;
private final String m_sRootElementNSURI;

EUBL22DocumentType (@Nonnull final Class <?> aClass, @Nonnull final ICommonsList <ClassPathResource> 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
Expand All @@ -215,4 +221,28 @@ public ICommonsList <ClassPathResource> getAllXSDResources ()
{
return m_aXSDs.getClone ();
}

/**
* @return The local element name of the root element of this document type.
* E.g. <code>OrderCancellation</code> 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.
* <code>urn:oasis:names:specification:ubl:schema:xsd:OrderCancellation-2</code>
* for "Order Cancellation".
*/
@Nonnull
@Nonempty
public String getRootElementNamespaceURI ()
{
return m_sRootElementNSURI;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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}.
Expand All @@ -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 ());
}
}
30 changes: 30 additions & 0 deletions ph-ubl23/src/main/java/com/helger/ubl23/EUBL23DocumentType.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -210,11 +212,15 @@ public enum EUBL23DocumentType

private final Class <?> m_aImplClass;
private final ICommonsList <ClassPathResource> m_aXSDs;
private final String m_sRootElementLocalName;
private final String m_sRootElementNSURI;

EUBL23DocumentType (@Nonnull final Class <?> aClass, @Nonnull final ICommonsList <ClassPathResource> 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
Expand All @@ -230,4 +236,28 @@ public ICommonsList <ClassPathResource> getAllXSDResources ()
{
return m_aXSDs.getClone ();
}

/**
* @return The local element name of the root element of this document type.
* E.g. <code>OrderCancellation</code> 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.
* <code>urn:oasis:names:specification:ubl:schema:xsd:OrderCancellation-2</code>
* for "Order Cancellation".
*/
@Nonnull
@Nonempty
public String getRootElementNamespaceURI ()
{
return m_sRootElementNSURI;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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}.
Expand All @@ -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 ());
}
}
30 changes: 30 additions & 0 deletions ph-ubl24/src/main/java/com/helger/ubl24/EUBL24DocumentType.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -206,11 +208,15 @@ public enum EUBL24DocumentType

private final Class <?> m_aImplClass;
private final ICommonsList <ClassPathResource> m_aXSDs;
private final String m_sRootElementLocalName;
private final String m_sRootElementNSURI;

EUBL24DocumentType (@Nonnull final Class <?> aClass, @Nonnull final ICommonsList <ClassPathResource> 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
Expand All @@ -226,4 +232,28 @@ public ICommonsList <ClassPathResource> getAllXSDResources ()
{
return m_aXSDs.getClone ();
}

/**
* @return The local element name of the root element of this document type.
* E.g. <code>OrderCancellation</code> 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.
* <code>urn:oasis:names:specification:ubl:schema:xsd:OrderCancellation-2</code>
* for "Order Cancellation".
*/
@Nonnull
@Nonempty
public String getRootElementNamespaceURI ()
{
return m_sRootElementNSURI;
}
}
Loading

0 comments on commit 7fec640

Please sign in to comment.