Search in sources :

Example 1 with PCLParticipantIdentifierSchemesType

use of com.helger.xsds.peppol.codelists2.PCLParticipantIdentifierSchemesType in project peppol-commons by phax.

the class MainCreatePredefinedEnumsFromXML_v8x method _handleParticipantIdentifierSchemes.

private static void _handleParticipantIdentifierSchemes(final Document aParticipantSheet) {
    final PCLParticipantIdentifierSchemesType aList = new GenericJAXBMarshaller<>(PCLParticipantIdentifierSchemesType.class, new QName("dummy")).read(aParticipantSheet);
    // Create Java source
    try {
        final JDefinedClass jEnum = CM._package(RESULT_PACKAGE_PREFIX + "pidscheme")._enum("EPredefinedParticipantIdentifierScheme")._implements(IParticipantIdentifierScheme.class);
        jEnum.annotate(CodingStyleguideUnaware.class);
        jEnum.javadoc().add(DO_NOT_EDIT);
        // Add metadata
        jEnum.field(JMod.PUBLIC_STATIC_FINAL, CM.ref(String.class), "CODE_LIST_VERSION", JExpr.lit(aList.getVersion()));
        jEnum.field(JMod.PUBLIC_STATIC_FINAL, CM.INT, "CODE_LIST_ENTRY_COUNT", JExpr.lit(aList.getEntryCount().intValue()));
        // enum constants
        for (final PCLParticipantIdentifierSchemeType aRow : aList.getParticipantIdentifierScheme()) {
            final String sSchemeID = aRow.getSchemeid();
            final String sISO6523 = aRow.getIso6523();
            final String sCountryCode = aRow.getCountry();
            final String sSchemeName = aRow.getSchemeName();
            final String sIssuingAgency = aRow.getIssuingAgency();
            final String sInitialRelease = aRow.getInitialRelease();
            final EPeppolCodeListItemState eState = _getState(aRow.getState());
            final boolean bDeprecated = !eState.isActive();
            final String sDeprecationRelease = aRow.getDeprecationRelease();
            final LocalDate aRemovalDate = aRow.getRemovalDateLocal();
            final String sStructure = aRow.getStructure();
            final String sDisplay = aRow.getDisplay();
            final String sExamples = aRow.getExamples();
            final String sUsage = aRow.getUsage();
            final String sEnumConstName = RegExHelper.getAsIdentifier(sSchemeID);
            final JEnumConstant jEnumConst = jEnum.enumConstant(sEnumConstName);
            jEnumConst.arg(JExpr.lit(sSchemeID));
            jEnumConst.arg(JExpr.lit(sISO6523));
            jEnumConst.arg(JExpr.lit(sCountryCode));
            jEnumConst.arg(JExpr.lit(sSchemeName));
            jEnumConst.arg(sIssuingAgency == null ? JExpr._null() : JExpr.lit(sIssuingAgency));
            jEnumConst.arg(CM.ref(Version.class).staticInvoke("parse").arg(sInitialRelease));
            jEnumConst.arg(CM.ref(EPeppolCodeListItemState.class).enumConstantRef(eState));
            jEnumConst.arg(bDeprecated ? CM.ref(Version.class).staticInvoke("parse").arg(sDeprecationRelease) : JExpr._null());
            jEnumConst.arg(_asExpr(aRemovalDate));
            jEnumConst.javadoc().add("Prefix <code>" + sISO6523 + "</code>, scheme ID <code>" + sSchemeID + "</code><br>");
            if (StringHelper.hasText(sStructure))
                jEnumConst.javadoc().add("\nStructure of the code: " + CodeGenerationHelper.maskHtml(sStructure) + "<br>");
            if (StringHelper.hasText(sDisplay))
                jEnumConst.javadoc().add("\nDisplay requirements: " + CodeGenerationHelper.maskHtml(sDisplay) + "<br>");
            if (StringHelper.hasText(sExamples))
                jEnumConst.javadoc().add("\nExample value: " + CodeGenerationHelper.maskHtml(sExamples) + "<br>");
            if (StringHelper.hasText(sUsage))
                jEnumConst.javadoc().add("\nUsage information: " + CodeGenerationHelper.maskHtml(sUsage) + "<br>");
            jEnumConst.javadoc().addTag(JDocComment.TAG_SINCE).add("code list " + sInitialRelease);
            if (bDeprecated) {
                jEnumConst.annotate(Deprecated.class);
                jEnumConst.javadoc().addDeprecated().add("since " + sDeprecationRelease + " - this item should not be used to issue new identifiers!");
            }
        }
        // fields
        final JFieldVar fSchemeID = jEnum.field(JMod.PRIVATE | JMod.FINAL, String.class, "m_sSchemeID");
        final JFieldVar fISO6523 = jEnum.field(JMod.PRIVATE | JMod.FINAL, String.class, "m_sISO6523");
        final JFieldVar fCountryCode = jEnum.field(JMod.PRIVATE | JMod.FINAL, String.class, "m_sCountryCode");
        final JFieldVar fSchemeName = jEnum.field(JMod.PRIVATE | JMod.FINAL, String.class, "m_sSchemeName");
        final JFieldVar fIssuingAgency = jEnum.field(JMod.PRIVATE | JMod.FINAL, String.class, "m_sIssuingAgency");
        final JFieldVar fInitialRelease = jEnum.field(JMod.PRIVATE | JMod.FINAL, Version.class, "m_aInitialRelease");
        final JFieldVar fState = jEnum.field(JMod.PRIVATE | JMod.FINAL, EPeppolCodeListItemState.class, "m_eState");
        final JFieldVar fDeprecationRelease = jEnum.field(JMod.PRIVATE | JMod.FINAL, Version.class, "m_aDeprecationRelease");
        final JFieldVar fRemovalDate = jEnum.field(JMod.PRIVATE | JMod.FINAL, LocalDate.class, "m_aRemovalDate");
        // Constructor
        final JMethod jCtor = jEnum.constructor(0);
        final JVar jSchemeID = jCtor.param(JMod.FINAL, String.class, "sSchemeID");
        jSchemeID.annotate(Nonnull.class);
        jSchemeID.annotate(Nonempty.class);
        final JVar jISO6523 = jCtor.param(JMod.FINAL, String.class, "sISO6523");
        jISO6523.annotate(Nonnull.class);
        jISO6523.annotate(Nonempty.class);
        final JVar jCountryCode = jCtor.param(JMod.FINAL, String.class, "sCountryCode");
        jCountryCode.annotate(Nonnull.class);
        jCountryCode.annotate(Nonempty.class);
        final JVar jSchemeName = jCtor.param(JMod.FINAL, String.class, "sSchemeName");
        jSchemeName.annotate(Nonnull.class);
        jSchemeName.annotate(Nonempty.class);
        final JVar jIssuingAgency = jCtor.param(JMod.FINAL, String.class, "sIssuingAgency");
        jIssuingAgency.annotate(Nullable.class);
        final JVar jInitialRelease = jCtor.param(JMod.FINAL, Version.class, "aInitialRelease");
        jInitialRelease.annotate(Nonnull.class);
        final JVar jState = jCtor.param(JMod.FINAL, EPeppolCodeListItemState.class, "eState");
        jState.annotate(Nonnull.class);
        final JVar jDeprecationRelease = jCtor.param(JMod.FINAL, Version.class, "aDeprecationRelease");
        jDeprecationRelease.annotate(Nullable.class);
        final JVar jRemovalDate = jCtor.param(JMod.FINAL, LocalDate.class, "aRemovalDate");
        jRemovalDate.annotate(Nullable.class);
        jCtor.body().assign(fSchemeID, jSchemeID).assign(fISO6523, jISO6523).assign(fCountryCode, jCountryCode).assign(fSchemeName, jSchemeName).assign(fIssuingAgency, jIssuingAgency).assign(fInitialRelease, jInitialRelease).assign(fState, jState).assign(fDeprecationRelease, jDeprecationRelease).assign(fRemovalDate, jRemovalDate);
        // public String getSchemeID ()
        JMethod m = jEnum.method(JMod.PUBLIC, String.class, "getSchemeID");
        m.annotate(Nonnull.class);
        m.annotate(Nonempty.class);
        m.body()._return(fSchemeID);
        // public String getISO6523Code ()
        m = jEnum.method(JMod.PUBLIC, String.class, "getISO6523Code");
        m.annotate(Nonnull.class);
        m.annotate(Nonempty.class);
        m.body()._return(fISO6523);
        // public String getCountryCode ()
        m = jEnum.method(JMod.PUBLIC, String.class, "getCountryCode");
        m.annotate(Nonnull.class);
        m.annotate(Nonempty.class);
        m.body()._return(fCountryCode);
        // public String getSchemeName ()
        m = jEnum.method(JMod.PUBLIC, String.class, "getSchemeName");
        m.annotate(Nonnull.class);
        m.annotate(Nonempty.class);
        m.body()._return(fSchemeName);
        // public String getSchemeAgency ()
        m = jEnum.method(JMod.PUBLIC, String.class, "getSchemeAgency");
        m.annotate(Nullable.class);
        m.body()._return(fIssuingAgency);
        // public Version getInitialRelease ()
        m = jEnum.method(JMod.PUBLIC, Version.class, "getInitialRelease");
        m.annotate(Nonnull.class);
        m.body()._return(fInitialRelease);
        // public EPeppolCodeListItemState getState ()
        m = jEnum.method(JMod.PUBLIC, EPeppolCodeListItemState.class, "getState");
        m.annotate(Nonnull.class);
        m.body()._return(fState);
        // public Version getDeprecationRelease ()
        m = jEnum.method(JMod.PUBLIC, Version.class, "getDeprecationRelease");
        m.annotate(Nullable.class);
        m.body()._return(fDeprecationRelease);
        // public LocalDate getRemovalDate ()
        m = jEnum.method(JMod.PUBLIC, LocalDate.class, "getRemovalDate");
        m.annotate(Nullable.class);
        m.body()._return(fRemovalDate);
    } catch (final Exception ex) {
        LOGGER.warn("Failed to create source", ex);
    }
}
Also used : JDefinedClass(com.helger.jcodemodel.JDefinedClass) QName(javax.xml.namespace.QName) LocalDate(java.time.LocalDate) JCodeModelException(com.helger.jcodemodel.JCodeModelException) EPeppolCodeListItemState(com.helger.peppolid.peppol.EPeppolCodeListItemState) JEnumConstant(com.helger.jcodemodel.JEnumConstant) Version(com.helger.commons.version.Version) JFieldVar(com.helger.jcodemodel.JFieldVar) PCLParticipantIdentifierSchemeType(com.helger.xsds.peppol.codelists2.PCLParticipantIdentifierSchemeType) JMethod(com.helger.jcodemodel.JMethod) PCLParticipantIdentifierSchemesType(com.helger.xsds.peppol.codelists2.PCLParticipantIdentifierSchemesType) JVar(com.helger.jcodemodel.JVar)

Aggregations

Version (com.helger.commons.version.Version)1 JCodeModelException (com.helger.jcodemodel.JCodeModelException)1 JDefinedClass (com.helger.jcodemodel.JDefinedClass)1 JEnumConstant (com.helger.jcodemodel.JEnumConstant)1 JFieldVar (com.helger.jcodemodel.JFieldVar)1 JMethod (com.helger.jcodemodel.JMethod)1 JVar (com.helger.jcodemodel.JVar)1 EPeppolCodeListItemState (com.helger.peppolid.peppol.EPeppolCodeListItemState)1 PCLParticipantIdentifierSchemeType (com.helger.xsds.peppol.codelists2.PCLParticipantIdentifierSchemeType)1 PCLParticipantIdentifierSchemesType (com.helger.xsds.peppol.codelists2.PCLParticipantIdentifierSchemesType)1 LocalDate (java.time.LocalDate)1 QName (javax.xml.namespace.QName)1