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:es.caib.zkib.jxpath.util.BasicTypeConverter.java

/**
 * Convert null to a primitive type./*from  www . java  2s .  com*/
 * @param toType destination class
 * @return a wrapper
 */
protected Object convertNullToPrimitive(Class toType) {
    if (toType == boolean.class) {
        return Boolean.FALSE;
    }
    if (toType == char.class) {
        return new Character('\0');
    }
    if (toType == byte.class) {
        return new Byte((byte) 0);
    }
    if (toType == short.class) {
        return new Short((short) 0);
    }
    if (toType == int.class) {
        return new Integer(0);
    }
    if (toType == long.class) {
        return new Long(0L);
    }
    if (toType == float.class) {
        return new Float(0.0f);
    }
    if (toType == double.class) {
        return new Double(0.0);
    }
    return null;
}

From source file:com.exadel.flamingo.flex.messaging.amf.io.AMF0Serializer.java

protected Object[] convertPrimitiveArrayToObjectArray(Object array) {
    Class<?> componentType = array.getClass().getComponentType();

    Object[] result = null;//from  w  w  w  .j  a  va  2 s .  c o  m

    if (componentType == null) {
        throw new NullPointerException("componentType is null");
    } else if (componentType == Character.TYPE) {
        char[] carray = (char[]) array;
        result = new Object[carray.length];
        for (int i = 0; i < carray.length; i++) {
            result[i] = new Character(carray[i]);
        }
    } else if (componentType == Byte.TYPE) {
        byte[] barray = (byte[]) array;
        result = new Object[barray.length];
        for (int i = 0; i < barray.length; i++) {
            result[i] = new Byte(barray[i]);
        }
    } else if (componentType == Short.TYPE) {
        short[] sarray = (short[]) array;
        result = new Object[sarray.length];
        for (int i = 0; i < sarray.length; i++) {
            result[i] = new Short(sarray[i]);
        }
    } else if (componentType == Integer.TYPE) {
        int[] iarray = (int[]) array;
        result = new Object[iarray.length];
        for (int i = 0; i < iarray.length; i++) {
            result[i] = Integer.valueOf(iarray[i]);
        }
    } else if (componentType == Long.TYPE) {
        long[] larray = (long[]) array;
        result = new Object[larray.length];
        for (int i = 0; i < larray.length; i++) {
            result[i] = new Long(larray[i]);
        }
    } else if (componentType == Double.TYPE) {
        double[] darray = (double[]) array;
        result = new Object[darray.length];
        for (int i = 0; i < darray.length; i++) {
            result[i] = new Double(darray[i]);
        }
    } else if (componentType == Float.TYPE) {
        float[] farray = (float[]) array;
        result = new Object[farray.length];
        for (int i = 0; i < farray.length; i++) {
            result[i] = new Float(farray[i]);
        }
    } else if (componentType == Boolean.TYPE) {
        boolean[] barray = (boolean[]) array;
        result = new Object[barray.length];
        for (int i = 0; i < barray.length; i++) {
            result[i] = new Boolean(barray[i]);
        }
    } else {
        throw new IllegalArgumentException("unexpected component type: " + componentType.getClass().getName());
    }

    return result;
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccXMsgRspnHandler.CFAccXMsgRspnContactURLRecHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    try {//w ww .j  a  va2 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("ContactURL");

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

        ICFAccSchemaObj schemaObj = xmsgRspnHandler.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");
        }

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

        // Convert string attributes to native Java types

        long natTenantId = Long.parseLong(attrTenantId);

        long natContactURLId = Long.parseLong(attrContactURLId);

        long natContactId = Long.parseLong(attrContactId);

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

        String natName = attrName;

        String natURL = attrURL;

        int natRevision = Integer.parseInt(attrRevision);
        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);
        }
        // Get the parent context
        CFLibXmlCoreContext parentContext = curContext.getPrevContext();
        // Instantiate a buffer for the parsed information
        ICFAccContactURLObj obj = schemaObj.getContactURLTableObj().newInstance();
        CFAccContactURLBuff dataBuff = obj.getContactURLBuff();
        dataBuff.setRequiredTenantId(natTenantId);
        dataBuff.setRequiredContactURLId(natContactURLId);
        dataBuff.setRequiredContactId(natContactId);
        dataBuff.setOptionalURLProtocolId(natURLProtocolId);
        dataBuff.setRequiredName(natName);
        dataBuff.setRequiredURL(natURL);
        dataBuff.setRequiredRevision(natRevision);
        if (createdBy != null) {
            dataBuff.setCreatedByUserId(createdBy);
        }
        if (createdAt != null) {
            dataBuff.setCreatedAt(createdAt);
        }
        if (updatedBy != null) {
            dataBuff.setUpdatedByUserId(updatedBy);
        }
        if (updatedAt != null) {
            dataBuff.setUpdatedAt(updatedAt);
        }
        obj.copyBuffToPKey();
        SortedMap<CFAccContactURLPKey, ICFAccContactURLObj> sortedMap = (SortedMap<CFAccContactURLPKey, ICFAccContactURLObj>) xmsgRspnHandler
                .getSortedMapOfObjects();
        ICFAccContactURLObj realized = (ICFAccContactURLObj) obj.realize();
        xmsgRspnHandler.setLastObjectProcessed(realized);
        if (sortedMap != null) {
            sortedMap.put(realized.getPKey(), realized);
        }
    } catch (RuntimeException e) {
        throw new RuntimeException("Near " + getParser().getLocationInfo() + ": Caught and rethrew "
                + e.getClass().getName() + " - " + e.getMessage(), e);
    } catch (Error e) {
        throw new Error("Near " + getParser().getLocationInfo() + ": Caught and rethrew "
                + e.getClass().getName() + " - " + e.getMessage(), e);
    }
}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskXMsgRqstHandler.CFAsteriskXMsgRqstISOLanguageUpdateHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    CFAsteriskXMsgSchemaMessageFormatter schemaFormatter = null;
    try {/*from   w  w w  .  ja  v a2  s .c o  m*/
        // Common XML Attributes
        String attrId = null;
        String attrRevision = null;
        // ISOLanguage Attributes
        String attrISOCode = null;
        String attrBaseLanguageCode = null;
        String attrISOCountryId = 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("RqstISOLanguageUpdate");

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

        schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter();

        ICFAsteriskSchemaObj 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("ISOCode")) {
                if (attrISOCode != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrISOCode = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("BaseLanguageCode")) {
                if (attrBaseLanguageCode != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrBaseLanguageCode = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("ISOCountryId")) {
                if (attrISOCountryId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrISOCountryId = 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 ((attrId == null) || (attrId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "Id");
        }
        if (attrISOCode == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "ISOCode");
        }
        if (attrBaseLanguageCode == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "BaseLanguageCode");
        }
        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
        CFSecurityISOLanguagePKey pkey = ((ICFAsteriskSchema) schemaObj.getBackingStore())
                .getFactoryISOLanguage().newPKey();

        short natId;
        natId = Short.parseShort(attrId);
        pkey.setRequiredId(natId);
        // Read the instance
        ICFAsteriskISOLanguageObj origBuff = ((ICFAsteriskISOLanguageObj) schemaObj.getISOLanguageTableObj()
                .readISOLanguage(pkey));
        if (origBuff == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getISOLanguageTableObj().readISOLanguage()");
        } else {
            // Edit the instance
            ICFAsteriskISOLanguageEditObj editBuff = (ICFAsteriskISOLanguageEditObj) origBuff.beginEdit();
            CFSecurityISOLanguageBuff dataBuff = editBuff.getISOLanguageBuff();
            // Convert string attributes to native Java types
            // and apply the converted attributes to the editBuff.
            String natISOCode = attrISOCode;

            dataBuff.setRequiredISOCode(natISOCode);

            String natBaseLanguageCode = attrBaseLanguageCode;

            dataBuff.setRequiredBaseLanguageCode(natBaseLanguageCode);

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

            dataBuff.setOptionalISOCountryId(natISOCountryId);

            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 = schemaFormatter.formatRspnXmlPreamble()
                    + "\n" + "\t" + CFAsteriskXMsgISOLanguageMessageFormatter
                            .formatISOLanguageRspnUpdated("\n\t\t\t", origBuff.getISOLanguageBuff())
                    + "\n" + schemaFormatter.formatRspnXmlPostamble();
            ((CFAsteriskXMsgRqstHandler) getParser()).appendResponse(response);
        }
    } catch (RuntimeException e) {
        CFAsteriskXMsgRqstHandler xmsgRqstHandler = ((CFAsteriskXMsgRqstHandler) getParser());
        schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter();
        String response = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFAsteriskXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                + schemaFormatter.formatRspnXmlPostamble();
        xmsgRqstHandler.resetResponse();
        xmsgRqstHandler.appendResponse(response);
        xmsgRqstHandler.setCaughtException(true);
    } catch (Error e) {
        CFAsteriskXMsgRqstHandler xmsgRqstHandler = ((CFAsteriskXMsgRqstHandler) getParser());
        schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter();
        String response = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFAsteriskXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                + schemaFormatter.formatRspnXmlPostamble();
        xmsgRqstHandler.resetResponse();
        xmsgRqstHandler.appendResponse(response);
        xmsgRqstHandler.setCaughtException(true);
    }
}

From source file:net.sourceforge.msscodefactory.cffreeswitch.v2_4.CFFreeSwitchXMsgRqstHandler.CFFreeSwitchXMsgRqstISOLanguageUpdateHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    CFFreeSwitchXMsgSchemaMessageFormatter schemaFormatter = null;
    try {//  www  . j  a v a2s .  c  o  m
        // Common XML Attributes
        String attrId = null;
        String attrRevision = null;
        // ISOLanguage Attributes
        String attrISOCode = null;
        String attrBaseLanguageCode = null;
        String attrISOCountryId = 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("RqstISOLanguageUpdate");

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

        schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter();

        ICFFreeSwitchSchemaObj 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("ISOCode")) {
                if (attrISOCode != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrISOCode = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("BaseLanguageCode")) {
                if (attrBaseLanguageCode != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrBaseLanguageCode = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("ISOCountryId")) {
                if (attrISOCountryId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrISOCountryId = 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 ((attrId == null) || (attrId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "Id");
        }
        if (attrISOCode == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "ISOCode");
        }
        if (attrBaseLanguageCode == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "BaseLanguageCode");
        }
        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
        CFSecurityISOLanguagePKey pkey = ((ICFFreeSwitchSchema) schemaObj.getBackingStore())
                .getFactoryISOLanguage().newPKey();

        short natId;
        natId = Short.parseShort(attrId);
        pkey.setRequiredId(natId);
        // Read the instance
        ICFFreeSwitchISOLanguageObj origBuff = ((ICFFreeSwitchISOLanguageObj) schemaObj.getISOLanguageTableObj()
                .readISOLanguage(pkey));
        if (origBuff == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getISOLanguageTableObj().readISOLanguage()");
        } else {
            // Edit the instance
            ICFFreeSwitchISOLanguageEditObj editBuff = (ICFFreeSwitchISOLanguageEditObj) origBuff.beginEdit();
            CFSecurityISOLanguageBuff dataBuff = editBuff.getISOLanguageBuff();
            // Convert string attributes to native Java types
            // and apply the converted attributes to the editBuff.
            String natISOCode = attrISOCode;

            dataBuff.setRequiredISOCode(natISOCode);

            String natBaseLanguageCode = attrBaseLanguageCode;

            dataBuff.setRequiredBaseLanguageCode(natBaseLanguageCode);

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

            dataBuff.setOptionalISOCountryId(natISOCountryId);

            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 = schemaFormatter.formatRspnXmlPreamble()
                    + "\n" + "\t" + CFFreeSwitchXMsgISOLanguageMessageFormatter
                            .formatISOLanguageRspnUpdated("\n\t\t\t", origBuff.getISOLanguageBuff())
                    + "\n" + schemaFormatter.formatRspnXmlPostamble();
            ((CFFreeSwitchXMsgRqstHandler) getParser()).appendResponse(response);
        }
    } catch (RuntimeException e) {
        CFFreeSwitchXMsgRqstHandler xmsgRqstHandler = ((CFFreeSwitchXMsgRqstHandler) getParser());
        schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter();
        String response = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFFreeSwitchXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                + schemaFormatter.formatRspnXmlPostamble();
        xmsgRqstHandler.resetResponse();
        xmsgRqstHandler.appendResponse(response);
        xmsgRqstHandler.setCaughtException(true);
    } catch (Error e) {
        CFFreeSwitchXMsgRqstHandler xmsgRqstHandler = ((CFFreeSwitchXMsgRqstHandler) getParser());
        schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter();
        String response = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFFreeSwitchXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                + schemaFormatter.formatRspnXmlPostamble();
        xmsgRqstHandler.resetResponse();
        xmsgRqstHandler.appendResponse(response);
        xmsgRqstHandler.setCaughtException(true);
    }
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccXMsgRspnHandler.CFAccXMsgRspnContactURLLockedHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    try {/*  www  .j a  v a2s. co  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("RspnContactURLLocked");

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

        ICFAccSchemaObj schemaObj = xmsgRspnHandler.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");
        }

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

        // Convert string attributes to native Java types

        long natTenantId = Long.parseLong(attrTenantId);

        long natContactURLId = Long.parseLong(attrContactURLId);

        long natContactId = Long.parseLong(attrContactId);

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

        String natName = attrName;

        String natURL = attrURL;

        int natRevision = Integer.parseInt(attrRevision);
        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);
        }
        // Instantiate a buffer for the parsed information
        ICFAccContactURLObj obj = schemaObj.getContactURLTableObj().newInstance();
        CFAccContactURLBuff dataBuff = obj.getContactURLBuff();
        dataBuff.setRequiredTenantId(natTenantId);
        dataBuff.setRequiredContactURLId(natContactURLId);
        dataBuff.setRequiredContactId(natContactId);
        dataBuff.setOptionalURLProtocolId(natURLProtocolId);
        dataBuff.setRequiredName(natName);
        dataBuff.setRequiredURL(natURL);
        dataBuff.setRequiredRevision(natRevision);
        if (createdBy != null) {
            dataBuff.setCreatedByUserId(createdBy);
        }
        if (createdAt != null) {
            dataBuff.setCreatedAt(createdAt);
        }
        if (updatedBy != null) {
            dataBuff.setUpdatedByUserId(updatedBy);
        }
        if (updatedAt != null) {
            dataBuff.setUpdatedAt(updatedAt);
        }
        obj.copyBuffToPKey();
        ICFAccContactURLObj realized = (ICFAccContactURLObj) obj.realize();
        xmsgRspnHandler.setLastObjectProcessed(realized);
    } catch (RuntimeException e) {
        throw new RuntimeException("Near " + getParser().getLocationInfo() + ": Caught and rethrew "
                + e.getClass().getName() + " - " + e.getMessage(), e);
    } catch (Error e) {
        throw new Error("Near " + getParser().getLocationInfo() + ": Caught and rethrew "
                + e.getClass().getName() + " - " + e.getMessage(), e);
    }
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccXMsgRspnHandler.CFAccXMsgRspnContactURLCreatedHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    try {/*  w ww .  j a v a2  s  .c om*/
        // 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("RspnContactURLCreated");

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

        ICFAccSchemaObj schemaObj = xmsgRspnHandler.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");
        }

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

        // Convert string attributes to native Java types

        long natTenantId = Long.parseLong(attrTenantId);

        long natContactURLId = Long.parseLong(attrContactURLId);

        long natContactId = Long.parseLong(attrContactId);

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

        String natName = attrName;

        String natURL = attrURL;

        int natRevision = Integer.parseInt(attrRevision);
        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);
        }
        // Instantiate a buffer for the parsed information
        ICFAccContactURLObj obj = schemaObj.getContactURLTableObj().newInstance();
        CFAccContactURLBuff dataBuff = obj.getContactURLBuff();
        dataBuff.setRequiredTenantId(natTenantId);
        dataBuff.setRequiredContactURLId(natContactURLId);
        dataBuff.setRequiredContactId(natContactId);
        dataBuff.setOptionalURLProtocolId(natURLProtocolId);
        dataBuff.setRequiredName(natName);
        dataBuff.setRequiredURL(natURL);
        dataBuff.setRequiredRevision(natRevision);
        if (createdBy != null) {
            dataBuff.setCreatedByUserId(createdBy);
        }
        if (createdAt != null) {
            dataBuff.setCreatedAt(createdAt);
        }
        if (updatedBy != null) {
            dataBuff.setUpdatedByUserId(updatedBy);
        }
        if (updatedAt != null) {
            dataBuff.setUpdatedAt(updatedAt);
        }
        obj.copyBuffToPKey();
        ICFAccContactURLObj realized = (ICFAccContactURLObj) obj.realize();
        xmsgRspnHandler.setLastObjectProcessed(realized);
    } catch (RuntimeException e) {
        throw new RuntimeException("Near " + getParser().getLocationInfo() + ": Caught and rethrew "
                + e.getClass().getName() + " - " + e.getMessage(), e);
    } catch (Error e) {
        throw new Error("Near " + getParser().getLocationInfo() + ": Caught and rethrew "
                + e.getClass().getName() + " - " + e.getMessage(), e);
    }
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccXMsgRspnHandler.CFAccXMsgRspnContactURLUpdatedHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    try {/* w w w . j  ava2s  .c om*/
        // 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("RspnContactURLUpdated");

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

        ICFAccSchemaObj schemaObj = xmsgRspnHandler.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");
        }

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

        // Convert string attributes to native Java types

        long natTenantId = Long.parseLong(attrTenantId);

        long natContactURLId = Long.parseLong(attrContactURLId);

        long natContactId = Long.parseLong(attrContactId);

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

        String natName = attrName;

        String natURL = attrURL;

        int natRevision = Integer.parseInt(attrRevision);
        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);
        }
        // Instantiate a buffer for the parsed information
        ICFAccContactURLObj obj = schemaObj.getContactURLTableObj().newInstance();
        CFAccContactURLBuff dataBuff = obj.getContactURLBuff();
        dataBuff.setRequiredTenantId(natTenantId);
        dataBuff.setRequiredContactURLId(natContactURLId);
        dataBuff.setRequiredContactId(natContactId);
        dataBuff.setOptionalURLProtocolId(natURLProtocolId);
        dataBuff.setRequiredName(natName);
        dataBuff.setRequiredURL(natURL);
        dataBuff.setRequiredRevision(natRevision);
        if (createdBy != null) {
            dataBuff.setCreatedByUserId(createdBy);
        }
        if (createdAt != null) {
            dataBuff.setCreatedAt(createdAt);
        }
        if (updatedBy != null) {
            dataBuff.setUpdatedByUserId(updatedBy);
        }
        if (updatedAt != null) {
            dataBuff.setUpdatedAt(updatedAt);
        }
        obj.copyBuffToPKey();
        ICFAccContactURLObj realized = (ICFAccContactURLObj) obj.realize();
        xmsgRspnHandler.setLastObjectProcessed(realized);
    } catch (RuntimeException e) {
        throw new RuntimeException("Near " + getParser().getLocationInfo() + ": Caught and rethrew "
                + e.getClass().getName() + " - " + e.getMessage(), e);
    } catch (Error e) {
        throw new Error("Near " + getParser().getLocationInfo() + ": Caught and rethrew "
                + e.getClass().getName() + " - " + e.getMessage(), e);
    }
}

From source file:net.sourceforge.msscodefactory.cfcore.v2_0.CFGenKbXMsgRspnHandler.CFGenKbXMsgRspnTextFormatterRecHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    try {//from  w  ww  .j a  v  a2s  . 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
        // TextFormatter Attributes
        // Attribute Extraction
        String attrLocalName;
        int numAttrs;
        int idxAttr;
        final String S_ProcName = "startElement";
        final String S_LocalName = "LocalName";

        assert qName.equals("TextFormatter");

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

        ICFGenKbSchemaObj schemaObj = xmsgRspnHandler.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");
        }

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

        // Convert string attributes to native Java types

        long natTenantId = Long.parseLong(attrTenantId);

        long natCartridgeId = Long.parseLong(attrCartridgeId);

        int natItemId = Integer.parseInt(attrItemId);

        short natRuleTypeId = Short.parseShort(attrRuleTypeId);

        String natName = attrName;

        short natToolSetId = Short.parseShort(attrToolSetId);

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

        short natGenDefId = Short.parseShort(attrGenDefId);

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

        int natRevision = Integer.parseInt(attrRevision);
        // Get the parent context
        CFLibXmlCoreContext parentContext = curContext.getPrevContext();
        // Instantiate a buffer for the parsed information
        ICFGenKbTextFormatterObj obj = schemaObj.getTextFormatterTableObj().newInstance();
        CFGenKbTextFormatterBuff dataBuff = obj.getTextFormatterBuff();
        dataBuff.setRequiredTenantId(natTenantId);
        dataBuff.setRequiredCartridgeId(natCartridgeId);
        dataBuff.setRequiredItemId(natItemId);
        dataBuff.setRequiredRuleTypeId(natRuleTypeId);
        dataBuff.setRequiredName(natName);
        dataBuff.setRequiredToolSetId(natToolSetId);
        dataBuff.setOptionalScopeDefId(natScopeDefId);
        dataBuff.setRequiredGenDefId(natGenDefId);
        dataBuff.setOptionalGelExecutableId(natGelExecutableId);
        dataBuff.setRequiredRevision(natRevision);
        obj.copyBuffToPKey();
        SortedMap<CFGenKbGenItemPKey, ICFGenKbGenItemObj> sortedMap = (SortedMap<CFGenKbGenItemPKey, ICFGenKbGenItemObj>) xmsgRspnHandler
                .getSortedMapOfObjects();
        ICFGenKbTextFormatterObj realized = (ICFGenKbTextFormatterObj) obj.realize();
        xmsgRspnHandler.setLastObjectProcessed(realized);
        if (sortedMap != null) {
            sortedMap.put(realized.getPKey(), realized);
        }
    } catch (RuntimeException e) {
        throw new RuntimeException("Near " + getParser().getLocationInfo() + ": Caught and rethrew "
                + e.getClass().getName() + " - " + e.getMessage(), e);
    } catch (Error e) {
        throw new Error("Near " + getParser().getLocationInfo() + ": Caught and rethrew "
                + e.getClass().getName() + " - " + e.getMessage(), e);
    }
}

From source file:net.sourceforge.msscodefactory.cfcore.v2_0.CFGenKbXMsgRspnHandler.CFGenKbXMsgRspnTimeFormatterRecHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    try {//from  www  . ja v  a  2s .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
        // TimeFormatter Attributes
        // Attribute Extraction
        String attrLocalName;
        int numAttrs;
        int idxAttr;
        final String S_ProcName = "startElement";
        final String S_LocalName = "LocalName";

        assert qName.equals("TimeFormatter");

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

        ICFGenKbSchemaObj schemaObj = xmsgRspnHandler.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");
        }

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

        // Convert string attributes to native Java types

        long natTenantId = Long.parseLong(attrTenantId);

        long natCartridgeId = Long.parseLong(attrCartridgeId);

        int natItemId = Integer.parseInt(attrItemId);

        short natRuleTypeId = Short.parseShort(attrRuleTypeId);

        String natName = attrName;

        short natToolSetId = Short.parseShort(attrToolSetId);

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

        short natGenDefId = Short.parseShort(attrGenDefId);

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

        int natRevision = Integer.parseInt(attrRevision);
        // Get the parent context
        CFLibXmlCoreContext parentContext = curContext.getPrevContext();
        // Instantiate a buffer for the parsed information
        ICFGenKbTimeFormatterObj obj = schemaObj.getTimeFormatterTableObj().newInstance();
        CFGenKbTimeFormatterBuff dataBuff = obj.getTimeFormatterBuff();
        dataBuff.setRequiredTenantId(natTenantId);
        dataBuff.setRequiredCartridgeId(natCartridgeId);
        dataBuff.setRequiredItemId(natItemId);
        dataBuff.setRequiredRuleTypeId(natRuleTypeId);
        dataBuff.setRequiredName(natName);
        dataBuff.setRequiredToolSetId(natToolSetId);
        dataBuff.setOptionalScopeDefId(natScopeDefId);
        dataBuff.setRequiredGenDefId(natGenDefId);
        dataBuff.setOptionalGelExecutableId(natGelExecutableId);
        dataBuff.setRequiredRevision(natRevision);
        obj.copyBuffToPKey();
        SortedMap<CFGenKbGenItemPKey, ICFGenKbGenItemObj> sortedMap = (SortedMap<CFGenKbGenItemPKey, ICFGenKbGenItemObj>) xmsgRspnHandler
                .getSortedMapOfObjects();
        ICFGenKbTimeFormatterObj realized = (ICFGenKbTimeFormatterObj) obj.realize();
        xmsgRspnHandler.setLastObjectProcessed(realized);
        if (sortedMap != null) {
            sortedMap.put(realized.getPKey(), realized);
        }
    } catch (RuntimeException e) {
        throw new RuntimeException("Near " + getParser().getLocationInfo() + ": Caught and rethrew "
                + e.getClass().getName() + " - " + e.getMessage(), e);
    } catch (Error e) {
        throw new Error("Near " + getParser().getLocationInfo() + ": Caught and rethrew "
                + e.getClass().getName() + " - " + e.getMessage(), e);
    }
}