Example usage for java.lang Short Short

List of usage examples for java.lang Short Short

Introduction

In this page you can find the example usage for java.lang Short Short.

Prototype

@Deprecated(since = "9")
public Short(String s) throws NumberFormatException 

Source Link

Document

Constructs a newly allocated Short object that represents the short value indicated by the String parameter.

Usage

From source file:net.sourceforge.msscodefactory.cfcore.v2_0.CFGenKbXMsgRqstHandler.CFGenKbXMsgRqstInt64FormatterUpdateHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    try {/*from w w  w.j ava2 s  . c  o  m*/
        // Common XML Attributes
        String attrId = null;
        String attrRevision = null;
        // GenItem Attributes
        String attrTenantId = null;
        String attrCartridgeId = null;
        String attrItemId = null;
        String attrRuleTypeId = null;
        String attrName = null;
        String attrToolSetId = null;
        String attrScopeDefId = null;
        String attrGenDefId = null;
        String attrGelExecutableId = null;
        // GenBind Attributes
        // GenFormatter Attributes
        // Int64Formatter Attributes
        // Attribute Extraction
        String attrLocalName;
        int numAttrs;
        int idxAttr;
        final String S_ProcName = "startElement";
        final String S_LocalName = "LocalName";

        assert qName.equals("RqstInt64FormatterUpdate");

        CFGenKbXMsgRqstHandler xmsgRqstHandler = (CFGenKbXMsgRqstHandler) getParser();
        if (xmsgRqstHandler == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser()");
        }

        ICFGenKbSchemaObj schemaObj = xmsgRqstHandler.getSchemaObj();
        if (schemaObj == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser().getSchemaObj()");
        }

        // Extract Attributes
        numAttrs = attrs.getLength();
        for (idxAttr = 0; idxAttr < numAttrs; idxAttr++) {
            attrLocalName = attrs.getLocalName(idxAttr);
            if (attrLocalName.equals("Id")) {
                if (attrId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("Revision")) {
                if (attrRevision != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrRevision = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("TenantId")) {
                if (attrTenantId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrTenantId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("CartridgeId")) {
                if (attrCartridgeId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrCartridgeId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("ItemId")) {
                if (attrItemId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrItemId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("RuleTypeId")) {
                if (attrRuleTypeId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrRuleTypeId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("Name")) {
                if (attrName != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrName = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("ToolSetId")) {
                if (attrToolSetId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrToolSetId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("ScopeDefId")) {
                if (attrScopeDefId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrScopeDefId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("GenDefId")) {
                if (attrGenDefId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrGenDefId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("GelExecutableId")) {
                if (attrGelExecutableId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrGelExecutableId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("schemaLocation")) {
                // ignored
            } else {
                throw CFLib.getDefaultExceptionFactory().newUnrecognizedAttributeException(getClass(),
                        S_ProcName, getParser().getLocationInfo(), attrLocalName);
            }
        }

        // Ensure that required attributes have values
        if ((attrTenantId == null) || (attrTenantId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "TenantId");
        }
        if ((attrCartridgeId == null) || (attrCartridgeId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "CartridgeId");
        }
        if ((attrItemId == null) || (attrItemId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "ItemId");
        }
        if ((attrRuleTypeId == null) || (attrRuleTypeId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "RuleTypeId");
        }
        if (attrName == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "Name");
        }
        if ((attrToolSetId == null) || (attrToolSetId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "ToolSetId");
        }
        if ((attrGenDefId == null) || (attrGenDefId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "GenDefId");
        }
        if ((attrRevision == null) || (attrRevision.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "Revision");
        }

        // Save named attributes to context
        CFLibXmlCoreContext curContext = getParser().getCurContext();

        // Instantiate a PKey buffer for the parsed information
        CFGenKbGenItemPKey pkey = schemaObj.getBackingStore().getFactoryGenItem().newPKey();

        long natTenantId;
        natTenantId = Long.parseLong(attrTenantId);
        pkey.setRequiredTenantId(natTenantId);
        long natCartridgeId;
        natCartridgeId = Long.parseLong(attrCartridgeId);
        pkey.setRequiredCartridgeId(natCartridgeId);
        int natItemId;
        natItemId = Integer.parseInt(attrItemId);
        pkey.setRequiredItemId(natItemId);
        // Read the instance
        ICFGenKbInt64FormatterObj origBuff = schemaObj.getInt64FormatterTableObj().readInt64Formatter(pkey);
        if (origBuff == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getInt64FormatterTableObj().readInt64Formatter()");
        } else {
            // Edit the instance
            ICFGenKbInt64FormatterEditObj editBuff = (ICFGenKbInt64FormatterEditObj) origBuff.beginEdit();
            CFGenKbInt64FormatterBuff dataBuff = editBuff.getInt64FormatterBuff();
            // Convert string attributes to native Java types
            // and apply the converted attributes to the editBuff.
            short natRuleTypeId = Short.parseShort(attrRuleTypeId);

            dataBuff.setRequiredRuleTypeId(natRuleTypeId);

            String natName = attrName;

            dataBuff.setRequiredName(natName);

            short natToolSetId = Short.parseShort(attrToolSetId);

            dataBuff.setRequiredToolSetId(natToolSetId);

            Short natScopeDefId;
            if ((attrScopeDefId == null) || (attrScopeDefId.length() <= 0)) {
                natScopeDefId = null;
            } else {
                natScopeDefId = new Short(Short.parseShort(attrScopeDefId));
            }

            dataBuff.setOptionalScopeDefId(natScopeDefId);

            short natGenDefId = Short.parseShort(attrGenDefId);

            dataBuff.setRequiredGenDefId(natGenDefId);

            Integer natGelExecutableId;
            if ((attrGelExecutableId == null) || (attrGelExecutableId.length() <= 0)) {
                natGelExecutableId = null;
            } else {
                natGelExecutableId = new Integer(Integer.parseInt(attrGelExecutableId));
            }

            dataBuff.setOptionalGelExecutableId(natGelExecutableId);

            int natRevision = Integer.parseInt(attrRevision);
            dataBuff.setRequiredRevision(natRevision);
            //   Attempt the update
            editBuff.update();
            editBuff.endEdit();
            String response = CFGenKbXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                    + CFGenKbXMsgInt64FormatterMessageFormatter.formatInt64FormatterRspnUpdated("\n\t\t\t",
                            origBuff.getInt64FormatterBuff())
                    + "\n" + CFGenKbXMsgSchemaMessageFormatter.formatRspnXmlPostamble();
            ((CFGenKbXMsgRqstHandler) getParser()).appendResponse(response);
        }
    } catch (RuntimeException e) {
        String response = CFGenKbXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFGenKbXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                + CFGenKbXMsgSchemaMessageFormatter.formatRspnXmlPostamble();
        CFGenKbXMsgRqstHandler xmsgRqstHandler = ((CFGenKbXMsgRqstHandler) getParser());
        xmsgRqstHandler.resetResponse();
        xmsgRqstHandler.appendResponse(response);
        xmsgRqstHandler.setCaughtException(true);
    } catch (Error e) {
        String response = CFGenKbXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFGenKbXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                + CFGenKbXMsgSchemaMessageFormatter.formatRspnXmlPostamble();
        CFGenKbXMsgRqstHandler xmsgRqstHandler = ((CFGenKbXMsgRqstHandler) getParser());
        xmsgRqstHandler.resetResponse();
        xmsgRqstHandler.appendResponse(response);
        xmsgRqstHandler.setCaughtException(true);
    }
}

From source file:net.sourceforge.msscodefactory.cfcore.v2_0.CFGenKbXMsgRqstHandler.CFGenKbXMsgRqstDoubleFormatterUpdateHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    try {// w ww .  j  av  a  2  s . c  o  m
        // Common XML Attributes
        String attrId = null;
        String attrRevision = null;
        // GenItem Attributes
        String attrTenantId = null;
        String attrCartridgeId = null;
        String attrItemId = null;
        String attrRuleTypeId = null;
        String attrName = null;
        String attrToolSetId = null;
        String attrScopeDefId = null;
        String attrGenDefId = null;
        String attrGelExecutableId = null;
        // GenBind Attributes
        // GenFormatter Attributes
        // DoubleFormatter Attributes
        // Attribute Extraction
        String attrLocalName;
        int numAttrs;
        int idxAttr;
        final String S_ProcName = "startElement";
        final String S_LocalName = "LocalName";

        assert qName.equals("RqstDoubleFormatterUpdate");

        CFGenKbXMsgRqstHandler xmsgRqstHandler = (CFGenKbXMsgRqstHandler) getParser();
        if (xmsgRqstHandler == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser()");
        }

        ICFGenKbSchemaObj schemaObj = xmsgRqstHandler.getSchemaObj();
        if (schemaObj == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser().getSchemaObj()");
        }

        // Extract Attributes
        numAttrs = attrs.getLength();
        for (idxAttr = 0; idxAttr < numAttrs; idxAttr++) {
            attrLocalName = attrs.getLocalName(idxAttr);
            if (attrLocalName.equals("Id")) {
                if (attrId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("Revision")) {
                if (attrRevision != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrRevision = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("TenantId")) {
                if (attrTenantId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrTenantId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("CartridgeId")) {
                if (attrCartridgeId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrCartridgeId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("ItemId")) {
                if (attrItemId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrItemId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("RuleTypeId")) {
                if (attrRuleTypeId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrRuleTypeId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("Name")) {
                if (attrName != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrName = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("ToolSetId")) {
                if (attrToolSetId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrToolSetId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("ScopeDefId")) {
                if (attrScopeDefId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrScopeDefId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("GenDefId")) {
                if (attrGenDefId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrGenDefId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("GelExecutableId")) {
                if (attrGelExecutableId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrGelExecutableId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("schemaLocation")) {
                // ignored
            } else {
                throw CFLib.getDefaultExceptionFactory().newUnrecognizedAttributeException(getClass(),
                        S_ProcName, getParser().getLocationInfo(), attrLocalName);
            }
        }

        // Ensure that required attributes have values
        if ((attrTenantId == null) || (attrTenantId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "TenantId");
        }
        if ((attrCartridgeId == null) || (attrCartridgeId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "CartridgeId");
        }
        if ((attrItemId == null) || (attrItemId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "ItemId");
        }
        if ((attrRuleTypeId == null) || (attrRuleTypeId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "RuleTypeId");
        }
        if (attrName == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "Name");
        }
        if ((attrToolSetId == null) || (attrToolSetId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "ToolSetId");
        }
        if ((attrGenDefId == null) || (attrGenDefId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "GenDefId");
        }
        if ((attrRevision == null) || (attrRevision.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "Revision");
        }

        // Save named attributes to context
        CFLibXmlCoreContext curContext = getParser().getCurContext();

        // Instantiate a PKey buffer for the parsed information
        CFGenKbGenItemPKey pkey = schemaObj.getBackingStore().getFactoryGenItem().newPKey();

        long natTenantId;
        natTenantId = Long.parseLong(attrTenantId);
        pkey.setRequiredTenantId(natTenantId);
        long natCartridgeId;
        natCartridgeId = Long.parseLong(attrCartridgeId);
        pkey.setRequiredCartridgeId(natCartridgeId);
        int natItemId;
        natItemId = Integer.parseInt(attrItemId);
        pkey.setRequiredItemId(natItemId);
        // Read the instance
        ICFGenKbDoubleFormatterObj origBuff = schemaObj.getDoubleFormatterTableObj().readDoubleFormatter(pkey);
        if (origBuff == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getDoubleFormatterTableObj().readDoubleFormatter()");
        } else {
            // Edit the instance
            ICFGenKbDoubleFormatterEditObj editBuff = (ICFGenKbDoubleFormatterEditObj) origBuff.beginEdit();
            CFGenKbDoubleFormatterBuff dataBuff = editBuff.getDoubleFormatterBuff();
            // Convert string attributes to native Java types
            // and apply the converted attributes to the editBuff.
            short natRuleTypeId = Short.parseShort(attrRuleTypeId);

            dataBuff.setRequiredRuleTypeId(natRuleTypeId);

            String natName = attrName;

            dataBuff.setRequiredName(natName);

            short natToolSetId = Short.parseShort(attrToolSetId);

            dataBuff.setRequiredToolSetId(natToolSetId);

            Short natScopeDefId;
            if ((attrScopeDefId == null) || (attrScopeDefId.length() <= 0)) {
                natScopeDefId = null;
            } else {
                natScopeDefId = new Short(Short.parseShort(attrScopeDefId));
            }

            dataBuff.setOptionalScopeDefId(natScopeDefId);

            short natGenDefId = Short.parseShort(attrGenDefId);

            dataBuff.setRequiredGenDefId(natGenDefId);

            Integer natGelExecutableId;
            if ((attrGelExecutableId == null) || (attrGelExecutableId.length() <= 0)) {
                natGelExecutableId = null;
            } else {
                natGelExecutableId = new Integer(Integer.parseInt(attrGelExecutableId));
            }

            dataBuff.setOptionalGelExecutableId(natGelExecutableId);

            int natRevision = Integer.parseInt(attrRevision);
            dataBuff.setRequiredRevision(natRevision);
            //   Attempt the update
            editBuff.update();
            editBuff.endEdit();
            String response = CFGenKbXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                    + CFGenKbXMsgDoubleFormatterMessageFormatter.formatDoubleFormatterRspnUpdated("\n\t\t\t",
                            origBuff.getDoubleFormatterBuff())
                    + "\n" + CFGenKbXMsgSchemaMessageFormatter.formatRspnXmlPostamble();
            ((CFGenKbXMsgRqstHandler) getParser()).appendResponse(response);
        }
    } catch (RuntimeException e) {
        String response = CFGenKbXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFGenKbXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                + CFGenKbXMsgSchemaMessageFormatter.formatRspnXmlPostamble();
        CFGenKbXMsgRqstHandler xmsgRqstHandler = ((CFGenKbXMsgRqstHandler) getParser());
        xmsgRqstHandler.resetResponse();
        xmsgRqstHandler.appendResponse(response);
        xmsgRqstHandler.setCaughtException(true);
    } catch (Error e) {
        String response = CFGenKbXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFGenKbXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                + CFGenKbXMsgSchemaMessageFormatter.formatRspnXmlPostamble();
        CFGenKbXMsgRqstHandler xmsgRqstHandler = ((CFGenKbXMsgRqstHandler) getParser());
        xmsgRqstHandler.resetResponse();
        xmsgRqstHandler.appendResponse(response);
        xmsgRqstHandler.setCaughtException(true);
    }
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccXMsgRqstHandler.CFAccXMsgRqstContactCreateHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    try {//from   w w  w  .  java  2  s .  co m
        // Common XML Attributes
        String attrId = null;
        String attrRevision = null;
        // Contact Attributes
        String attrTenantId = null;
        String attrContactId = null;
        String attrContactListId = null;
        String attrISOTimezoneId = null;
        String attrFullName = null;
        String attrLastName = null;
        String attrFirstName = null;
        String attrCustom = null;
        String attrCustom2 = null;
        String attrCustom3 = null;
        String attrCreatedAt = null;
        String attrCreatedBy = null;
        String attrUpdatedAt = null;
        String attrUpdatedBy = null;
        // Attribute Extraction
        String attrLocalName;
        int numAttrs;
        int idxAttr;
        final String S_ProcName = "startElement";
        final String S_LocalName = "LocalName";

        assert qName.equals("RqstContactCreate");

        CFAccXMsgRqstHandler xmsgRqstHandler = (CFAccXMsgRqstHandler) getParser();
        if (xmsgRqstHandler == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser()");
        }

        ICFAccSchemaObj schemaObj = xmsgRqstHandler.getSchemaObj();
        if (schemaObj == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser().getSchemaObj()");
        }

        // Instantiate an edit buffer for the parsed information
        ICFAccContactEditObj editBuff = (ICFAccContactEditObj) schemaObj.getContactTableObj().newInstance()
                .beginEdit();
        CFAccContactBuff dataBuff = editBuff.getContactBuff();
        // Extract Attributes
        numAttrs = attrs.getLength();
        for (idxAttr = 0; idxAttr < numAttrs; idxAttr++) {
            attrLocalName = attrs.getLocalName(idxAttr);
            if (attrLocalName.equals("Id")) {
                if (attrId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("schemaLocation")) {
                // ignored
            } else if (attrLocalName.equals("Revision")) {
                if (attrRevision != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrRevision = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("CreatedAt")) {
                if (attrCreatedAt != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrCreatedAt = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("CreatedBy")) {
                if (attrCreatedBy != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrCreatedBy = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("UpdatedAt")) {
                if (attrUpdatedAt != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrUpdatedAt = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("UpdatedBy")) {
                if (attrUpdatedBy != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrUpdatedBy = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("TenantId")) {
                if (attrTenantId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrTenantId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("ContactId")) {
                if (attrContactId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrContactId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("ContactListId")) {
                if (attrContactListId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrContactListId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("ISOTimezoneId")) {
                if (attrISOTimezoneId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrISOTimezoneId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("FullName")) {
                if (attrFullName != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrFullName = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("LastName")) {
                if (attrLastName != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrLastName = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("FirstName")) {
                if (attrFirstName != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrFirstName = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("Custom")) {
                if (attrCustom != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrCustom = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("Custom2")) {
                if (attrCustom2 != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrCustom2 = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("Custom3")) {
                if (attrCustom3 != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrCustom3 = attrs.getValue(idxAttr);
            } else {
                throw CFLib.getDefaultExceptionFactory().newUnrecognizedAttributeException(getClass(),
                        S_ProcName, getParser().getLocationInfo(), attrLocalName);
            }
        }

        // Ensure that required attributes have values
        if ((attrTenantId == null) || (attrTenantId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "TenantId");
        }
        if ((attrContactId == null) || (attrContactId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "ContactId");
        }
        if ((attrContactListId == null) || (attrContactListId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "ContactListId");
        }
        if (attrFullName == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "FullName");
        }

        // Save named attributes to context
        CFLibXmlCoreContext curContext = getParser().getCurContext();

        // Convert string attributes to native Java types
        // and apply the converted attributes to the editBuff.
        long natTenantId = Long.parseLong(attrTenantId);

        dataBuff.setRequiredTenantId(natTenantId);

        long natContactListId = Long.parseLong(attrContactListId);

        dataBuff.setRequiredContactListId(natContactListId);

        Short natISOTimezoneId;
        if ((attrISOTimezoneId == null) || (attrISOTimezoneId.length() <= 0)) {
            natISOTimezoneId = null;
        } else {
            natISOTimezoneId = new Short(Short.parseShort(attrISOTimezoneId));
        }

        dataBuff.setOptionalISOTimezoneId(natISOTimezoneId);

        String natFullName = attrFullName;

        dataBuff.setRequiredFullName(natFullName);

        String natLastName = attrLastName;

        dataBuff.setOptionalLastName(natLastName);

        String natFirstName = attrFirstName;

        dataBuff.setOptionalFirstName(natFirstName);

        String natCustom = attrCustom;

        dataBuff.setOptionalCustom(natCustom);

        String natCustom2 = attrCustom2;

        dataBuff.setOptionalCustom2(natCustom2);

        String natCustom3 = attrCustom3;

        dataBuff.setOptionalCustom3(natCustom3);

        UUID createdBy = null;
        if (attrCreatedBy != null) {
            createdBy = UUID.fromString(attrCreatedBy);
        }
        Calendar createdAt = null;
        if (attrCreatedAt != null) {
            createdAt = CFLibXmlUtil.parseTimestamp(attrCreatedAt);
        }
        UUID updatedBy = null;
        if (attrUpdatedBy != null) {
            updatedBy = UUID.fromString(attrUpdatedBy);
        }
        Calendar updatedAt = null;
        if (attrUpdatedAt != null) {
            updatedAt = CFLibXmlUtil.parseTimestamp(attrUpdatedAt);
        }
        if (createdBy != null) {
            dataBuff.setCreatedByUserId(createdBy);
        }
        if (createdAt != null) {
            dataBuff.setCreatedAt(createdAt);
        }
        if (updatedBy != null) {
            dataBuff.setUpdatedByUserId(updatedBy);
        }
        if (updatedAt != null) {
            dataBuff.setUpdatedAt(updatedAt);
        }
        //   Attempt the create
        editBuff.copyBuffToPKey(); // Allow for predefined ids
        ICFAccContactObj created = (ICFAccContactObj) editBuff.create();
        editBuff.endEdit();
        String response = CFAccXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFAccXMsgContactMessageFormatter.formatContactRspnCreated("\n\t\t\t",
                        created.getContactBuff())
                + "\n" + CFAccXMsgSchemaMessageFormatter.formatRspnXmlPostamble();
        ((CFAccXMsgRqstHandler) getParser()).appendResponse(response);
    } catch (RuntimeException e) {
        String response = CFAccXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFAccXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                + CFAccXMsgSchemaMessageFormatter.formatRspnXmlPostamble();
        CFAccXMsgRqstHandler xmsgRqstHandler = ((CFAccXMsgRqstHandler) getParser());
        xmsgRqstHandler.resetResponse();
        xmsgRqstHandler.appendResponse(response);
        xmsgRqstHandler.setCaughtException(true);
    } catch (Error e) {
        String response = CFAccXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFAccXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                + CFAccXMsgSchemaMessageFormatter.formatRspnXmlPostamble();
        CFAccXMsgRqstHandler xmsgRqstHandler = ((CFAccXMsgRqstHandler) getParser());
        xmsgRqstHandler.resetResponse();
        xmsgRqstHandler.appendResponse(response);
        xmsgRqstHandler.setCaughtException(true);
    }
}

From source file:es.caib.zkib.jxpath.util.BasicTypeConverter.java

/**
 * Allocate a number of a given type and value.
 * @param type destination class//w ww . j ava2s . co  m
 * @param value double
 * @return Number
 */
protected Number allocateNumber(Class type, double value) {
    type = TypeUtils.wrapPrimitive(type);
    if (type == Byte.class) {
        return new Byte((byte) value);
    }
    if (type == Short.class) {
        return new Short((short) value);
    }
    if (type == Integer.class) {
        return new Integer((int) value);
    }
    if (type == Long.class) {
        return new Long((long) value);
    }
    if (type == Float.class) {
        return new Float((float) value);
    }
    if (type == Double.class) {
        return new Double(value);
    }
    if (type == BigInteger.class) {
        return BigInteger.valueOf((long) value);
    }
    if (type == BigDecimal.class) {
        return new BigDecimal(value);
    }
    String classname = type.getName();
    Class initialValueType = null;
    if ("java.util.concurrent.atomic.AtomicInteger".equals(classname)) {
        initialValueType = int.class;
    }
    if ("java.util.concurrent.atomic.AtomicLong".equals(classname)) {
        initialValueType = long.class;
    }
    if (initialValueType != null) {
        try {
            return (Number) type.getConstructor(new Class[] { initialValueType })
                    .newInstance(new Object[] { allocateNumber(initialValueType, value) });
        } catch (Exception e) {
            throw new JXPathTypeConversionException(classname, e);
        }
    }
    return null;
}

From source file:net.sourceforge.msscodefactory.cfcore.v2_0.CFGenKbXMsgRqstHandler.CFGenKbXMsgRqstGenTruncCreateHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    try {//from w  ww  . j  a v a2  s .  c  o  m
        // Common XML Attributes
        String attrId = null;
        String attrRevision = null;
        // GenItem Attributes
        String attrTenantId = null;
        String attrCartridgeId = null;
        String attrItemId = null;
        String attrRuleTypeId = null;
        String attrName = null;
        String attrToolSetId = null;
        String attrScopeDefId = null;
        String attrGenDefId = null;
        String attrGelExecutableId = null;
        // GenRule Attributes
        String attrBody = null;
        // GenTrunc Attributes
        String attrTruncateAt = null;
        // Attribute Extraction
        String attrLocalName;
        int numAttrs;
        int idxAttr;
        final String S_ProcName = "startElement";
        final String S_LocalName = "LocalName";

        assert qName.equals("RqstGenTruncCreate");

        CFGenKbXMsgRqstHandler xmsgRqstHandler = (CFGenKbXMsgRqstHandler) getParser();
        if (xmsgRqstHandler == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser()");
        }

        ICFGenKbSchemaObj schemaObj = xmsgRqstHandler.getSchemaObj();
        if (schemaObj == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser().getSchemaObj()");
        }

        // Instantiate an edit buffer for the parsed information
        ICFGenKbGenTruncEditObj editBuff = (ICFGenKbGenTruncEditObj) schemaObj.getGenTruncTableObj()
                .newInstance().beginEdit();
        CFGenKbGenTruncBuff dataBuff = editBuff.getGenTruncBuff();
        // Extract Attributes
        numAttrs = attrs.getLength();
        for (idxAttr = 0; idxAttr < numAttrs; idxAttr++) {
            attrLocalName = attrs.getLocalName(idxAttr);
            if (attrLocalName.equals("Id")) {
                if (attrId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("schemaLocation")) {
                // ignored
            } else if (attrLocalName.equals("Revision")) {
                if (attrRevision != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrRevision = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("TenantId")) {
                if (attrTenantId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrTenantId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("CartridgeId")) {
                if (attrCartridgeId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrCartridgeId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("ItemId")) {
                if (attrItemId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrItemId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("RuleTypeId")) {
                if (attrRuleTypeId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrRuleTypeId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("Name")) {
                if (attrName != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrName = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("ToolSetId")) {
                if (attrToolSetId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrToolSetId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("ScopeDefId")) {
                if (attrScopeDefId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrScopeDefId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("GenDefId")) {
                if (attrGenDefId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrGenDefId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("GelExecutableId")) {
                if (attrGelExecutableId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrGelExecutableId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("Body")) {
                if (attrBody != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrBody = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("TruncateAt")) {
                if (attrTruncateAt != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrTruncateAt = attrs.getValue(idxAttr);
            } else {
                throw CFLib.getDefaultExceptionFactory().newUnrecognizedAttributeException(getClass(),
                        S_ProcName, getParser().getLocationInfo(), attrLocalName);
            }
        }

        // Ensure that required attributes have values
        if ((attrTenantId == null) || (attrTenantId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "TenantId");
        }
        if ((attrCartridgeId == null) || (attrCartridgeId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "CartridgeId");
        }
        if ((attrItemId == null) || (attrItemId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "ItemId");
        }
        if ((attrRuleTypeId == null) || (attrRuleTypeId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "RuleTypeId");
        }
        if (attrName == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "Name");
        }
        if ((attrToolSetId == null) || (attrToolSetId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "ToolSetId");
        }
        if ((attrGenDefId == null) || (attrGenDefId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "GenDefId");
        }
        if (attrBody == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "Body");
        }
        if ((attrTruncateAt == null) || (attrTruncateAt.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "TruncateAt");
        }

        // Save named attributes to context
        CFLibXmlCoreContext curContext = getParser().getCurContext();

        // Convert string attributes to native Java types
        // and apply the converted attributes to the editBuff.
        long natTenantId = Long.parseLong(attrTenantId);

        dataBuff.setRequiredTenantId(natTenantId);

        long natCartridgeId = Long.parseLong(attrCartridgeId);

        dataBuff.setRequiredCartridgeId(natCartridgeId);

        short natRuleTypeId = Short.parseShort(attrRuleTypeId);

        dataBuff.setRequiredRuleTypeId(natRuleTypeId);

        String natName = attrName;

        dataBuff.setRequiredName(natName);

        short natToolSetId = Short.parseShort(attrToolSetId);

        dataBuff.setRequiredToolSetId(natToolSetId);

        Short natScopeDefId;
        if ((attrScopeDefId == null) || (attrScopeDefId.length() <= 0)) {
            natScopeDefId = null;
        } else {
            natScopeDefId = new Short(Short.parseShort(attrScopeDefId));
        }

        dataBuff.setOptionalScopeDefId(natScopeDefId);

        short natGenDefId = Short.parseShort(attrGenDefId);

        dataBuff.setRequiredGenDefId(natGenDefId);

        Integer natGelExecutableId;
        if ((attrGelExecutableId == null) || (attrGelExecutableId.length() <= 0)) {
            natGelExecutableId = null;
        } else {
            natGelExecutableId = new Integer(Integer.parseInt(attrGelExecutableId));
        }

        dataBuff.setOptionalGelExecutableId(natGelExecutableId);

        String natBody = attrBody;

        dataBuff.setRequiredBody(natBody);

        int natTruncateAt = Integer.parseInt(attrTruncateAt);

        dataBuff.setRequiredTruncateAt(natTruncateAt);

        //   Attempt the create
        editBuff.copyBuffToPKey(); // Allow for predefined ids
        ICFGenKbGenTruncObj created = (ICFGenKbGenTruncObj) editBuff.create();
        editBuff.endEdit();
        String response = CFGenKbXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFGenKbXMsgGenTruncMessageFormatter.formatGenTruncRspnCreated("\n\t\t\t",
                        created.getGenTruncBuff())
                + "\n" + CFGenKbXMsgSchemaMessageFormatter.formatRspnXmlPostamble();
        ((CFGenKbXMsgRqstHandler) getParser()).appendResponse(response);
    } catch (RuntimeException e) {
        String response = CFGenKbXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFGenKbXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                + CFGenKbXMsgSchemaMessageFormatter.formatRspnXmlPostamble();
        CFGenKbXMsgRqstHandler xmsgRqstHandler = ((CFGenKbXMsgRqstHandler) getParser());
        xmsgRqstHandler.resetResponse();
        xmsgRqstHandler.appendResponse(response);
        xmsgRqstHandler.setCaughtException(true);
    } catch (Error e) {
        String response = CFGenKbXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFGenKbXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                + CFGenKbXMsgSchemaMessageFormatter.formatRspnXmlPostamble();
        CFGenKbXMsgRqstHandler xmsgRqstHandler = ((CFGenKbXMsgRqstHandler) getParser());
        xmsgRqstHandler.resetResponse();
        xmsgRqstHandler.appendResponse(response);
        xmsgRqstHandler.setCaughtException(true);
    }
}

From source file:com.espertech.esper.regression.expr.TestCaseExpr.java

public void testCaseSyntax2StringsNBranches() {
    // Test of the various coercion user cases.
    String caseExpr = "select case intPrimitive" + " when 1 then Boolean.toString(boolPrimitive) "
            + " when 2 then Boolean.toString(boolBoxed) " + " when 3 then Integer.toString(intPrimitive) "
            + " when 4 then Integer.toString(intBoxed)" + " when 5 then Long.toString(longPrimitive) "
            + " when 6 then Long.toString(longBoxed) " + " when 7 then Character.toString(charPrimitive) "
            + " when 8 then Character.toString(charBoxed) " + " when 9 then Short.toString(shortPrimitive) "
            + " when 10 then Short.toString(shortBoxed) " + " when 11 then Byte.toString(bytePrimitive) "
            + " when 12 then Byte.toString(byteBoxed) " + " when 13 then Float.toString(floatPrimitive) "
            + " when 14 then Float.toString(floatBoxed) " + " when 15 then Double.toString(doublePrimitive) "
            + " when 16 then Double.toString(doubleBoxed) " + " when 17 then theString "
            + " else 'x' end as p1 " + " from " + SupportBean.class.getName() + ".win:length(1)";

    EPStatement selectTestCase = epService.getEPAdministrator().createEPL(caseExpr);
    selectTestCase.addListener(testListener);
    assertEquals(String.class, selectTestCase.getEventType().getPropertyType("p1"));

    sendSupportBeanEvent(true, new Boolean(false), 1, new Integer(0), 0L, new Long(0L), '0', new Character('a'),
            (short) 0, new Short((short) 0), (byte) 0, new Byte((byte) 0), 0.0f, new Float((float) 0), 0.0,
            new Double(0.0), null, SupportEnum.ENUM_VALUE_1);
    EventBean theEvent = testListener.getAndResetLastNewData()[0];
    assertEquals("true", theEvent.get("p1"));

    sendSupportBeanEvent(true, new Boolean(false), 2, new Integer(0), 0L, new Long(0L), '0', new Character('a'),
            (short) 0, new Short((short) 0), (byte) 0, new Byte((byte) 0), 0.0f, new Float((float) 0), 0.0,
            new Double(0.0), null, SupportEnum.ENUM_VALUE_1);
    theEvent = testListener.getAndResetLastNewData()[0];
    assertEquals("false", theEvent.get("p1"));

    sendSupportBeanEvent(true, new Boolean(false), 3, new Integer(0), 0L, new Long(0L), '0', new Character('a'),
            (short) 0, new Short((short) 0), (byte) 0, new Byte((byte) 0), 0.0f, new Float((float) 0), 0.0,
            new Double(0.0), null, SupportEnum.ENUM_VALUE_1);
    theEvent = testListener.getAndResetLastNewData()[0];
    assertEquals("3", theEvent.get("p1"));

    sendSupportBeanEvent(true, new Boolean(false), 4, new Integer(4), 0L, new Long(0L), '0', new Character('a'),
            (short) 0, new Short((short) 0), (byte) 0, new Byte((byte) 0), 0.0f, new Float((float) 0), 0.0,
            new Double(0.0), null, SupportEnum.ENUM_VALUE_1);
    theEvent = testListener.getAndResetLastNewData()[0];
    assertEquals("4", theEvent.get("p1"));

    sendSupportBeanEvent(true, new Boolean(false), 5, new Integer(0), 5L, new Long(0L), '0', new Character('a'),
            (short) 0, new Short((short) 0), (byte) 0, new Byte((byte) 0), 0.0f, new Float((float) 0), 0.0,
            new Double(0.0), null, SupportEnum.ENUM_VALUE_1);
    theEvent = testListener.getAndResetLastNewData()[0];
    assertEquals("5", theEvent.get("p1"));

    sendSupportBeanEvent(true, new Boolean(false), 6, new Integer(0), 0L, new Long(6L), '0', new Character('a'),
            (short) 0, new Short((short) 0), (byte) 0, new Byte((byte) 0), 0.0f, new Float((float) 0), 0.0,
            new Double(0.0), null, SupportEnum.ENUM_VALUE_1);
    theEvent = testListener.getAndResetLastNewData()[0];
    assertEquals("6", theEvent.get("p1"));

    sendSupportBeanEvent(true, new Boolean(false), 7, new Integer(0), 0L, new Long(0L), 'A', new Character('a'),
            (short) 0, new Short((short) 0), (byte) 0, new Byte((byte) 0), 0.0f, new Float((float) 0), 0.0,
            new Double(0.0), null, SupportEnum.ENUM_VALUE_1);
    theEvent = testListener.getAndResetLastNewData()[0];
    assertEquals("A", theEvent.get("p1"));

    sendSupportBeanEvent(true, new Boolean(false), 8, new Integer(0), 0L, new Long(0L), 'A', new Character('a'),
            (short) 0, new Short((short) 0), (byte) 0, new Byte((byte) 0), 0.0f, new Float((float) 0), 0.0,
            new Double(0.0), null, SupportEnum.ENUM_VALUE_1);
    theEvent = testListener.getAndResetLastNewData()[0];
    assertEquals("a", theEvent.get("p1"));

    sendSupportBeanEvent(true, new Boolean(false), 9, new Integer(0), 0L, new Long(0L), 'A', new Character('a'),
            (short) 9, new Short((short) 0), (byte) 0, new Byte((byte) 0), 0.0f, new Float((float) 0), 0.0,
            new Double(0.0), null, SupportEnum.ENUM_VALUE_1);
    theEvent = testListener.getAndResetLastNewData()[0];
    assertEquals("9", theEvent.get("p1"));

    sendSupportBeanEvent(true, new Boolean(false), 10, new Integer(0), 0L, new Long(0L), 'A',
            new Character('a'), (short) 9, new Short((short) 10), (byte) 11, new Byte((byte) 12), 13.0f,
            new Float((float) 14), 15.0, new Double(16.0), "testCoercion", SupportEnum.ENUM_VALUE_1);
    theEvent = testListener.getAndResetLastNewData()[0];
    assertEquals("10", theEvent.get("p1"));

    sendSupportBeanEvent(true, new Boolean(false), 11, new Integer(0), 0L, new Long(0L), 'A',
            new Character('a'), (short) 9, new Short((short) 10), (byte) 11, new Byte((byte) 12), 13.0f,
            new Float((float) 14), 15.0, new Double(16.0), "testCoercion", SupportEnum.ENUM_VALUE_1);
    theEvent = testListener.getAndResetLastNewData()[0];
    assertEquals("11", theEvent.get("p1"));

    sendSupportBeanEvent(true, new Boolean(false), 12, new Integer(0), 0L, new Long(0L), 'A',
            new Character('a'), (short) 9, new Short((short) 10), (byte) 11, new Byte((byte) 12), 13.0f,
            new Float((float) 14), 15.0, new Double(16.0), "testCoercion", SupportEnum.ENUM_VALUE_1);
    theEvent = testListener.getAndResetLastNewData()[0];
    assertEquals("12", theEvent.get("p1"));

    sendSupportBeanEvent(true, new Boolean(false), 13, new Integer(0), 0L, new Long(0L), 'A',
            new Character('a'), (short) 9, new Short((short) 10), (byte) 11, new Byte((byte) 12), 13.0f,
            new Float((float) 14), 15.0, new Double(16.0), "testCoercion", SupportEnum.ENUM_VALUE_1);
    theEvent = testListener.getAndResetLastNewData()[0];
    assertEquals("13.0", theEvent.get("p1"));

    sendSupportBeanEvent(true, new Boolean(false), 14, new Integer(0), 0L, new Long(0L), 'A',
            new Character('a'), (short) 9, new Short((short) 10), (byte) 11, new Byte((byte) 12), 13.0f,
            new Float((float) 14), 15.0, new Double(16.0), "testCoercion", SupportEnum.ENUM_VALUE_1);
    theEvent = testListener.getAndResetLastNewData()[0];
    assertEquals("14.0", theEvent.get("p1"));

    sendSupportBeanEvent(true, new Boolean(false), 15, new Integer(0), 0L, new Long(0L), 'A',
            new Character('a'), (short) 9, new Short((short) 10), (byte) 11, new Byte((byte) 12), 13.0f,
            new Float((float) 14), 15.0, new Double(16.0), "testCoercion", SupportEnum.ENUM_VALUE_1);
    theEvent = testListener.getAndResetLastNewData()[0];
    assertEquals("15.0", theEvent.get("p1"));

    sendSupportBeanEvent(true, new Boolean(false), 16, new Integer(0), 0L, new Long(0L), 'A',
            new Character('a'), (short) 9, new Short((short) 10), (byte) 11, new Byte((byte) 12), 13.0f,
            new Float((float) 14), 15.0, new Double(16.0), "testCoercion", SupportEnum.ENUM_VALUE_1);
    theEvent = testListener.getAndResetLastNewData()[0];
    assertEquals("16.0", theEvent.get("p1"));

    sendSupportBeanEvent(true, new Boolean(false), 17, new Integer(0), 0L, new Long(0L), 'A',
            new Character('a'), (short) 9, new Short((short) 10), (byte) 11, new Byte((byte) 12), 13.0f,
            new Float((float) 14), 15.0, new Double(16.0), "testCoercion", SupportEnum.ENUM_VALUE_1);
    theEvent = testListener.getAndResetLastNewData()[0];
    assertEquals("testCoercion", theEvent.get("p1"));

    sendSupportBeanEvent(true, new Boolean(false), -1, new Integer(0), 0L, new Long(0L), 'A',
            new Character('a'), (short) 9, new Short((short) 10), (byte) 11, new Byte((byte) 12), 13.0f,
            new Float((float) 14), 15.0, new Double(16.0), "testCoercion", SupportEnum.ENUM_VALUE_1);
    theEvent = testListener.getAndResetLastNewData()[0];
    assertEquals("x", theEvent.get("p1"));
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccXMsgRqstHandler.CFAccXMsgRqstContactURLUpdateHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    try {//from   ww w  . jav a 2 s .c  o m
        // Common XML Attributes
        String attrId = null;
        String attrRevision = null;
        // ContactURL Attributes
        String attrTenantId = null;
        String attrContactURLId = null;
        String attrContactId = null;
        String attrURLProtocolId = null;
        String attrName = null;
        String attrURL = null;
        String attrCreatedAt = null;
        String attrCreatedBy = null;
        String attrUpdatedAt = null;
        String attrUpdatedBy = null;
        // Attribute Extraction
        String attrLocalName;
        int numAttrs;
        int idxAttr;
        final String S_ProcName = "startElement";
        final String S_LocalName = "LocalName";

        assert qName.equals("RqstContactURLUpdate");

        CFAccXMsgRqstHandler xmsgRqstHandler = (CFAccXMsgRqstHandler) getParser();
        if (xmsgRqstHandler == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser()");
        }

        ICFAccSchemaObj schemaObj = xmsgRqstHandler.getSchemaObj();
        if (schemaObj == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser().getSchemaObj()");
        }

        // Extract Attributes
        numAttrs = attrs.getLength();
        for (idxAttr = 0; idxAttr < numAttrs; idxAttr++) {
            attrLocalName = attrs.getLocalName(idxAttr);
            if (attrLocalName.equals("Id")) {
                if (attrId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("Revision")) {
                if (attrRevision != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrRevision = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("CreatedAt")) {
                if (attrCreatedAt != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrCreatedAt = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("CreatedBy")) {
                if (attrCreatedBy != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrCreatedBy = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("UpdatedAt")) {
                if (attrUpdatedAt != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrUpdatedAt = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("UpdatedBy")) {
                if (attrUpdatedBy != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrUpdatedBy = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("TenantId")) {
                if (attrTenantId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrTenantId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("ContactURLId")) {
                if (attrContactURLId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrContactURLId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("ContactId")) {
                if (attrContactId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrContactId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("URLProtocolId")) {
                if (attrURLProtocolId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrURLProtocolId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("Name")) {
                if (attrName != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrName = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("URL")) {
                if (attrURL != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrURL = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("schemaLocation")) {
                // ignored
            } else {
                throw CFLib.getDefaultExceptionFactory().newUnrecognizedAttributeException(getClass(),
                        S_ProcName, getParser().getLocationInfo(), attrLocalName);
            }
        }

        // Ensure that required attributes have values
        if ((attrTenantId == null) || (attrTenantId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "TenantId");
        }
        if ((attrContactURLId == null) || (attrContactURLId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "ContactURLId");
        }
        if ((attrContactId == null) || (attrContactId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "ContactId");
        }
        if (attrName == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "Name");
        }
        if (attrURL == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "URL");
        }
        if ((attrRevision == null) || (attrRevision.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "Revision");
        }
        if ((attrCreatedAt == null) || (attrCreatedAt.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "CreatedAt");
        }
        if ((attrCreatedBy == null) || (attrCreatedBy.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "CreatedBy");
        }
        if ((attrUpdatedAt == null) || (attrUpdatedAt.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "UpdatedAt");
        }
        if ((attrUpdatedBy == null) || (attrUpdatedBy.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "UpdatedBy");
        }

        // Save named attributes to context
        CFLibXmlCoreContext curContext = getParser().getCurContext();

        // Instantiate a PKey buffer for the parsed information
        CFAccContactURLPKey pkey = schemaObj.getBackingStore().getFactoryContactURL().newPKey();

        long natTenantId;
        natTenantId = Long.parseLong(attrTenantId);
        pkey.setRequiredTenantId(natTenantId);
        long natContactURLId;
        natContactURLId = Long.parseLong(attrContactURLId);
        pkey.setRequiredContactURLId(natContactURLId);
        // Read the instance
        ICFAccContactURLObj origBuff = schemaObj.getContactURLTableObj().readContactURL(pkey);
        if (origBuff == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getContactURLTableObj().readContactURL()");
        } else {
            // Edit the instance
            ICFAccContactURLEditObj editBuff = (ICFAccContactURLEditObj) origBuff.beginEdit();
            CFAccContactURLBuff dataBuff = editBuff.getContactURLBuff();
            // Convert string attributes to native Java types
            // and apply the converted attributes to the editBuff.
            long natContactId = Long.parseLong(attrContactId);

            dataBuff.setRequiredContactId(natContactId);

            Short natURLProtocolId;
            if ((attrURLProtocolId == null) || (attrURLProtocolId.length() <= 0)) {
                natURLProtocolId = null;
            } else {
                natURLProtocolId = new Short(Short.parseShort(attrURLProtocolId));
            }

            dataBuff.setOptionalURLProtocolId(natURLProtocolId);

            String natName = attrName;

            dataBuff.setRequiredName(natName);

            String natURL = attrURL;

            dataBuff.setRequiredURL(natURL);

            int natRevision = Integer.parseInt(attrRevision);
            dataBuff.setRequiredRevision(natRevision);
            UUID createdBy = null;
            if (attrCreatedBy != null) {
                createdBy = UUID.fromString(attrCreatedBy);
            }
            Calendar createdAt = null;
            if (attrCreatedAt != null) {
                createdAt = CFLibXmlUtil.parseTimestamp(attrCreatedAt);
            }
            UUID updatedBy = null;
            if (attrUpdatedBy != null) {
                updatedBy = UUID.fromString(attrUpdatedBy);
            }
            Calendar updatedAt = null;
            if (attrUpdatedAt != null) {
                updatedAt = CFLibXmlUtil.parseTimestamp(attrUpdatedAt);
            }
            if (createdBy != null) {
                dataBuff.setCreatedByUserId(createdBy);
            }
            if (createdAt != null) {
                dataBuff.setCreatedAt(createdAt);
            }
            if (updatedBy != null) {
                dataBuff.setUpdatedByUserId(updatedBy);
            }
            if (updatedAt != null) {
                dataBuff.setUpdatedAt(updatedAt);
            }
            //   Attempt the update
            editBuff.update();
            editBuff.endEdit();
            String response = CFAccXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                    + CFAccXMsgContactURLMessageFormatter.formatContactURLRspnUpdated("\n\t\t\t",
                            origBuff.getContactURLBuff())
                    + "\n" + CFAccXMsgSchemaMessageFormatter.formatRspnXmlPostamble();
            ((CFAccXMsgRqstHandler) getParser()).appendResponse(response);
        }
    } catch (RuntimeException e) {
        String response = CFAccXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFAccXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                + CFAccXMsgSchemaMessageFormatter.formatRspnXmlPostamble();
        CFAccXMsgRqstHandler xmsgRqstHandler = ((CFAccXMsgRqstHandler) getParser());
        xmsgRqstHandler.resetResponse();
        xmsgRqstHandler.appendResponse(response);
        xmsgRqstHandler.setCaughtException(true);
    } catch (Error e) {
        String response = CFAccXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFAccXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                + CFAccXMsgSchemaMessageFormatter.formatRspnXmlPostamble();
        CFAccXMsgRqstHandler xmsgRqstHandler = ((CFAccXMsgRqstHandler) getParser());
        xmsgRqstHandler.resetResponse();
        xmsgRqstHandler.appendResponse(response);
        xmsgRqstHandler.setCaughtException(true);
    }
}

From source file:net.sourceforge.msscodefactory.cfcore.v2_0.CFGenKbXMsgRqstHandler.CFGenKbXMsgRqstGenRuleUpdateHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    try {/*from w  w  w  .j  ava2 s .  c  o  m*/
        // Common XML Attributes
        String attrId = null;
        String attrRevision = null;
        // GenItem Attributes
        String attrTenantId = null;
        String attrCartridgeId = null;
        String attrItemId = null;
        String attrRuleTypeId = null;
        String attrName = null;
        String attrToolSetId = null;
        String attrScopeDefId = null;
        String attrGenDefId = null;
        String attrGelExecutableId = null;
        // GenRule Attributes
        String attrBody = null;
        // Attribute Extraction
        String attrLocalName;
        int numAttrs;
        int idxAttr;
        final String S_ProcName = "startElement";
        final String S_LocalName = "LocalName";

        assert qName.equals("RqstGenRuleUpdate");

        CFGenKbXMsgRqstHandler xmsgRqstHandler = (CFGenKbXMsgRqstHandler) getParser();
        if (xmsgRqstHandler == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser()");
        }

        ICFGenKbSchemaObj schemaObj = xmsgRqstHandler.getSchemaObj();
        if (schemaObj == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser().getSchemaObj()");
        }

        // Extract Attributes
        numAttrs = attrs.getLength();
        for (idxAttr = 0; idxAttr < numAttrs; idxAttr++) {
            attrLocalName = attrs.getLocalName(idxAttr);
            if (attrLocalName.equals("Id")) {
                if (attrId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("Revision")) {
                if (attrRevision != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrRevision = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("TenantId")) {
                if (attrTenantId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrTenantId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("CartridgeId")) {
                if (attrCartridgeId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrCartridgeId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("ItemId")) {
                if (attrItemId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrItemId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("RuleTypeId")) {
                if (attrRuleTypeId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrRuleTypeId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("Name")) {
                if (attrName != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrName = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("ToolSetId")) {
                if (attrToolSetId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrToolSetId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("ScopeDefId")) {
                if (attrScopeDefId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrScopeDefId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("GenDefId")) {
                if (attrGenDefId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrGenDefId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("GelExecutableId")) {
                if (attrGelExecutableId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrGelExecutableId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("Body")) {
                if (attrBody != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrBody = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("schemaLocation")) {
                // ignored
            } else {
                throw CFLib.getDefaultExceptionFactory().newUnrecognizedAttributeException(getClass(),
                        S_ProcName, getParser().getLocationInfo(), attrLocalName);
            }
        }

        // Ensure that required attributes have values
        if ((attrTenantId == null) || (attrTenantId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "TenantId");
        }
        if ((attrCartridgeId == null) || (attrCartridgeId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "CartridgeId");
        }
        if ((attrItemId == null) || (attrItemId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "ItemId");
        }
        if ((attrRuleTypeId == null) || (attrRuleTypeId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "RuleTypeId");
        }
        if (attrName == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "Name");
        }
        if ((attrToolSetId == null) || (attrToolSetId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "ToolSetId");
        }
        if ((attrGenDefId == null) || (attrGenDefId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "GenDefId");
        }
        if ((attrRevision == null) || (attrRevision.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "Revision");
        }
        if (attrBody == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "Body");
        }

        // Save named attributes to context
        CFLibXmlCoreContext curContext = getParser().getCurContext();

        // Instantiate a PKey buffer for the parsed information
        CFGenKbGenItemPKey pkey = schemaObj.getBackingStore().getFactoryGenItem().newPKey();

        long natTenantId;
        natTenantId = Long.parseLong(attrTenantId);
        pkey.setRequiredTenantId(natTenantId);
        long natCartridgeId;
        natCartridgeId = Long.parseLong(attrCartridgeId);
        pkey.setRequiredCartridgeId(natCartridgeId);
        int natItemId;
        natItemId = Integer.parseInt(attrItemId);
        pkey.setRequiredItemId(natItemId);
        // Read the instance
        ICFGenKbGenRuleObj origBuff = schemaObj.getGenRuleTableObj().readGenRule(pkey);
        if (origBuff == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getGenRuleTableObj().readGenRule()");
        } else {
            // Edit the instance
            ICFGenKbGenRuleEditObj editBuff = (ICFGenKbGenRuleEditObj) origBuff.beginEdit();
            CFGenKbGenRuleBuff dataBuff = editBuff.getGenRuleBuff();
            // Convert string attributes to native Java types
            // and apply the converted attributes to the editBuff.
            short natRuleTypeId = Short.parseShort(attrRuleTypeId);

            dataBuff.setRequiredRuleTypeId(natRuleTypeId);

            String natName = attrName;

            dataBuff.setRequiredName(natName);

            short natToolSetId = Short.parseShort(attrToolSetId);

            dataBuff.setRequiredToolSetId(natToolSetId);

            Short natScopeDefId;
            if ((attrScopeDefId == null) || (attrScopeDefId.length() <= 0)) {
                natScopeDefId = null;
            } else {
                natScopeDefId = new Short(Short.parseShort(attrScopeDefId));
            }

            dataBuff.setOptionalScopeDefId(natScopeDefId);

            short natGenDefId = Short.parseShort(attrGenDefId);

            dataBuff.setRequiredGenDefId(natGenDefId);

            Integer natGelExecutableId;
            if ((attrGelExecutableId == null) || (attrGelExecutableId.length() <= 0)) {
                natGelExecutableId = null;
            } else {
                natGelExecutableId = new Integer(Integer.parseInt(attrGelExecutableId));
            }

            dataBuff.setOptionalGelExecutableId(natGelExecutableId);

            int natRevision = Integer.parseInt(attrRevision);
            dataBuff.setRequiredRevision(natRevision);
            String natBody = attrBody;

            dataBuff.setRequiredBody(natBody);

            //   Attempt the update
            editBuff.update();
            editBuff.endEdit();
            String response = CFGenKbXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                    + CFGenKbXMsgGenRuleMessageFormatter.formatGenRuleRspnUpdated("\n\t\t\t",
                            origBuff.getGenRuleBuff())
                    + "\n" + CFGenKbXMsgSchemaMessageFormatter.formatRspnXmlPostamble();
            ((CFGenKbXMsgRqstHandler) getParser()).appendResponse(response);
        }
    } catch (RuntimeException e) {
        String response = CFGenKbXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFGenKbXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                + CFGenKbXMsgSchemaMessageFormatter.formatRspnXmlPostamble();
        CFGenKbXMsgRqstHandler xmsgRqstHandler = ((CFGenKbXMsgRqstHandler) getParser());
        xmsgRqstHandler.resetResponse();
        xmsgRqstHandler.appendResponse(response);
        xmsgRqstHandler.setCaughtException(true);
    } catch (Error e) {
        String response = CFGenKbXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFGenKbXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                + CFGenKbXMsgSchemaMessageFormatter.formatRspnXmlPostamble();
        CFGenKbXMsgRqstHandler xmsgRqstHandler = ((CFGenKbXMsgRqstHandler) getParser());
        xmsgRqstHandler.resetResponse();
        xmsgRqstHandler.appendResponse(response);
        xmsgRqstHandler.setCaughtException(true);
    }
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccXMsgRqstHandler.CFAccXMsgRqstAddressCreateHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    try {/*from   ww w. j a va 2 s  .c o  m*/
        // Common XML Attributes
        String attrId = null;
        String attrRevision = null;
        // Address Attributes
        String attrTenantId = null;
        String attrAddressId = null;
        String attrContactId = null;
        String attrDescription = null;
        String attrAddrLine1 = null;
        String attrAddrLine2 = null;
        String attrCity = null;
        String attrState = null;
        String attrCountryId = null;
        String attrZip = null;
        String attrCreatedAt = null;
        String attrCreatedBy = null;
        String attrUpdatedAt = null;
        String attrUpdatedBy = null;
        // Attribute Extraction
        String attrLocalName;
        int numAttrs;
        int idxAttr;
        final String S_ProcName = "startElement";
        final String S_LocalName = "LocalName";

        assert qName.equals("RqstAddressCreate");

        CFAccXMsgRqstHandler xmsgRqstHandler = (CFAccXMsgRqstHandler) getParser();
        if (xmsgRqstHandler == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser()");
        }

        ICFAccSchemaObj schemaObj = xmsgRqstHandler.getSchemaObj();
        if (schemaObj == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser().getSchemaObj()");
        }

        // Instantiate an edit buffer for the parsed information
        ICFAccAddressEditObj editBuff = (ICFAccAddressEditObj) schemaObj.getAddressTableObj().newInstance()
                .beginEdit();
        CFAccAddressBuff dataBuff = editBuff.getAddressBuff();
        // Extract Attributes
        numAttrs = attrs.getLength();
        for (idxAttr = 0; idxAttr < numAttrs; idxAttr++) {
            attrLocalName = attrs.getLocalName(idxAttr);
            if (attrLocalName.equals("Id")) {
                if (attrId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("schemaLocation")) {
                // ignored
            } else if (attrLocalName.equals("Revision")) {
                if (attrRevision != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrRevision = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("CreatedAt")) {
                if (attrCreatedAt != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrCreatedAt = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("CreatedBy")) {
                if (attrCreatedBy != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrCreatedBy = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("UpdatedAt")) {
                if (attrUpdatedAt != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrUpdatedAt = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("UpdatedBy")) {
                if (attrUpdatedBy != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrUpdatedBy = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("TenantId")) {
                if (attrTenantId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrTenantId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("AddressId")) {
                if (attrAddressId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrAddressId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("ContactId")) {
                if (attrContactId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrContactId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("Description")) {
                if (attrDescription != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrDescription = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("AddrLine1")) {
                if (attrAddrLine1 != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrAddrLine1 = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("AddrLine2")) {
                if (attrAddrLine2 != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrAddrLine2 = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("City")) {
                if (attrCity != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrCity = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("State")) {
                if (attrState != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrState = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("CountryId")) {
                if (attrCountryId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrCountryId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("Zip")) {
                if (attrZip != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrZip = attrs.getValue(idxAttr);
            } else {
                throw CFLib.getDefaultExceptionFactory().newUnrecognizedAttributeException(getClass(),
                        S_ProcName, getParser().getLocationInfo(), attrLocalName);
            }
        }

        // Ensure that required attributes have values
        if ((attrTenantId == null) || (attrTenantId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "TenantId");
        }
        if ((attrAddressId == null) || (attrAddressId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "AddressId");
        }
        if ((attrContactId == null) || (attrContactId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "ContactId");
        }
        if (attrDescription == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "Description");
        }

        // Save named attributes to context
        CFLibXmlCoreContext curContext = getParser().getCurContext();

        // Convert string attributes to native Java types
        // and apply the converted attributes to the editBuff.
        long natTenantId = Long.parseLong(attrTenantId);

        dataBuff.setRequiredTenantId(natTenantId);

        long natContactId = Long.parseLong(attrContactId);

        dataBuff.setRequiredContactId(natContactId);

        String natDescription = attrDescription;

        dataBuff.setRequiredDescription(natDescription);

        String natAddrLine1 = attrAddrLine1;

        dataBuff.setOptionalAddrLine1(natAddrLine1);

        String natAddrLine2 = attrAddrLine2;

        dataBuff.setOptionalAddrLine2(natAddrLine2);

        String natCity = attrCity;

        dataBuff.setOptionalCity(natCity);

        String natState = attrState;

        dataBuff.setOptionalState(natState);

        Short natCountryId;
        if ((attrCountryId == null) || (attrCountryId.length() <= 0)) {
            natCountryId = null;
        } else {
            natCountryId = new Short(Short.parseShort(attrCountryId));
        }

        dataBuff.setOptionalCountryId(natCountryId);

        String natZip = attrZip;

        dataBuff.setOptionalZip(natZip);

        UUID createdBy = null;
        if (attrCreatedBy != null) {
            createdBy = UUID.fromString(attrCreatedBy);
        }
        Calendar createdAt = null;
        if (attrCreatedAt != null) {
            createdAt = CFLibXmlUtil.parseTimestamp(attrCreatedAt);
        }
        UUID updatedBy = null;
        if (attrUpdatedBy != null) {
            updatedBy = UUID.fromString(attrUpdatedBy);
        }
        Calendar updatedAt = null;
        if (attrUpdatedAt != null) {
            updatedAt = CFLibXmlUtil.parseTimestamp(attrUpdatedAt);
        }
        if (createdBy != null) {
            dataBuff.setCreatedByUserId(createdBy);
        }
        if (createdAt != null) {
            dataBuff.setCreatedAt(createdAt);
        }
        if (updatedBy != null) {
            dataBuff.setUpdatedByUserId(updatedBy);
        }
        if (updatedAt != null) {
            dataBuff.setUpdatedAt(updatedAt);
        }
        //   Attempt the create
        editBuff.copyBuffToPKey(); // Allow for predefined ids
        ICFAccAddressObj created = (ICFAccAddressObj) editBuff.create();
        editBuff.endEdit();
        String response = CFAccXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFAccXMsgAddressMessageFormatter.formatAddressRspnCreated("\n\t\t\t",
                        created.getAddressBuff())
                + "\n" + CFAccXMsgSchemaMessageFormatter.formatRspnXmlPostamble();
        ((CFAccXMsgRqstHandler) getParser()).appendResponse(response);
    } catch (RuntimeException e) {
        String response = CFAccXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFAccXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                + CFAccXMsgSchemaMessageFormatter.formatRspnXmlPostamble();
        CFAccXMsgRqstHandler xmsgRqstHandler = ((CFAccXMsgRqstHandler) getParser());
        xmsgRqstHandler.resetResponse();
        xmsgRqstHandler.appendResponse(response);
        xmsgRqstHandler.setCaughtException(true);
    } catch (Error e) {
        String response = CFAccXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFAccXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                + CFAccXMsgSchemaMessageFormatter.formatRspnXmlPostamble();
        CFAccXMsgRqstHandler xmsgRqstHandler = ((CFAccXMsgRqstHandler) getParser());
        xmsgRqstHandler.resetResponse();
        xmsgRqstHandler.appendResponse(response);
        xmsgRqstHandler.setCaughtException(true);
    }
}

From source file:com.appglu.impl.CrudTemplateTest.java

@Test
public void writeAllDataTypes() throws ParseException {
    mockServer.expect(requestTo("http://localhost/appglu/v1/tables/data_types"))
            .andExpect(method(HttpMethod.POST)).andExpect(header("Content-Type", jsonMediaType.toString()))
            .andExpect(content().string(compactedJson("data/crud_write_all_data_types")))
            .andRespond(withStatus(HttpStatus.CREATED).body(compactedJson("data/crud_create_response"))
                    .headers(responseHeaders));

    Row row = new Row();

    String string = new String("a very long string for test");

    row.put("boolean", true);
    row.put("short", new Short((short) 1));
    row.put("byte", new Byte((byte) 2));
    row.put("byteArray", string.getBytes());
    row.put("float", new Float(1.5f));
    row.put("double", new Double(7.5d));
    row.put("integer", new Integer(10));
    row.put("long", new Long(21474836475L));
    row.put("bigInteger", new BigInteger("9223372036854775807123"));
    row.put("string", string);

    Date datetime = DateUtils.parseDate("2010-01-15T12:10:00+0000");
    row.putDatetime("datetime", datetime);

    Date time = DateUtils.parseDate("1970-01-01T12:10:00+0000");
    row.putTime("time", time);

    Date date = DateUtils.parseDate("2010-01-15T00:00:00+0000");
    row.putDate("date", date);

    Object id = crudOperations.create("data_types", row);
    Assert.assertEquals(8, id);/*w w w  .  ja v  a  2s. c  o  m*/

    mockServer.verify();
}