Example usage for java.lang Short parseShort

List of usage examples for java.lang Short parseShort

Introduction

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

Prototype

public static short parseShort(String s) throws NumberFormatException 

Source Link

Document

Parses the string argument as a signed decimal short .

Usage

From source file:net.sourceforge.msscodefactory.cfcrm.v2_1.CFCrmSaxLoader.CFCrmSaxLoaderServiceHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    try {/*from w ww.ja v  a2s.c o  m*/
        // Common XML Attributes
        String attrId = null;
        // Service Attributes
        String attrHostPort = null;
        String attrServiceType = null;
        // Service References
        ICFCrmClusterObj refCluster = null;
        ICFCrmHostNodeObj refHost = null;
        ICFCrmServiceTypeObj refServiceType = null;
        // Attribute Extraction
        String attrLocalName;
        int numAttrs;
        int idxAttr;
        final String S_ProcName = "startElement";
        final String S_LocalName = "LocalName";

        assert qName.equals("Service");

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

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

        // Instantiate an edit buffer for the parsed information
        ICFCrmServiceEditObj editBuff = (ICFCrmServiceEditObj) schemaObj.getServiceTableObj().newInstance()
                .beginEdit();

        // 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("HostPort")) {
                if (attrHostPort != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrHostPort = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("ServiceType")) {
                if (attrServiceType != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrServiceType = 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 ((attrHostPort == null) || (attrHostPort.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "HostPort");
        }

        // Save named attributes to context
        CFLibXmlCoreContext curContext = getParser().getCurContext();
        curContext.putNamedValue("Id", attrId);
        curContext.putNamedValue("HostPort", attrHostPort);
        curContext.putNamedValue("ServiceType", attrServiceType);

        // Convert string attributes to native Java types
        // and apply the converted attributes to the editBuff.

        Integer natId;
        if ((attrId != null) && (attrId.length() > 0)) {
            natId = new Integer(Integer.parseInt(attrId));
        } else {
            natId = null;
        }
        short natHostPort = Short.parseShort(attrHostPort);
        editBuff.setRequiredHostPort(natHostPort);

        // Get the scope/container object

        CFLibXmlCoreContext parentContext = curContext.getPrevContext();
        Object scopeObj;
        if (parentContext != null) {
            scopeObj = parentContext.getNamedValue("Object");
        } else {
            scopeObj = null;
        }

        // Resolve and apply optional Container reference

        if (scopeObj == null) {
            refHost = null;
            editBuff.setOptionalContainerHost(refHost);
            refCluster = editBuff.getRequiredOwnerCluster();
        } else if (scopeObj instanceof ICFCrmHostNodeObj) {
            refHost = (ICFCrmHostNodeObj) scopeObj;
            editBuff.setOptionalContainerHost(refHost);
            refCluster = editBuff.getRequiredOwnerCluster();
        } else {
            throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName,
                    "scopeObj", scopeObj, "ICFCrmHostNodeObj");
        }

        // Resolve and apply Owner reference

        if (refCluster == null) {
            if (scopeObj instanceof ICFCrmClusterObj) {
                refCluster = (ICFCrmClusterObj) scopeObj;
                editBuff.setRequiredOwnerCluster(refCluster);
            } else {
                throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                        "Owner<Cluster>");
            }
        }

        // Lookup refServiceType by key name value attr
        if ((attrServiceType != null) && (attrServiceType.length() > 0)) {
            refServiceType = schemaObj.getServiceTypeTableObj().readServiceTypeByUDescrIdx(attrServiceType);
            if (refServiceType == null) {
                throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                        "Resolve ServiceType reference named \"" + attrServiceType + "\" to table ServiceType");
            }
        } else {
            refServiceType = null;
        }
        editBuff.setOptionalParentServiceType(refServiceType);

        ICFCrmServiceObj origService;
        ICFCrmServiceEditObj editService = editBuff;
        origService = (ICFCrmServiceObj) editService.create();
        editService.endEdit();

        curContext.putNamedValue("Object", origService);
    } 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.cfensyntax.v2_2.CFEnSyntaxXMsgRqstHandler.CFEnSyntaxXMsgRqstISOCountryLanguageReadByLanguageIdxHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    try {/*  ww w. ja  v a2 s.  c  o  m*/
        // Common XML Attributes
        String attrId = null;
        String attrISOLanguageId = null;
        // Attribute Extraction
        String attrLocalName;
        int numAttrs;
        int idxAttr;
        final String S_ProcName = "startElement";
        final String S_LocalName = "LocalName";

        assert qName.equals("RqstISOCountryLanguageReadByLanguageIdx");

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

        ICFEnSyntaxSchemaObj 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("ISOLanguageId")) {
                if (attrISOLanguageId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrISOLanguageId = 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 ((attrISOLanguageId == null) || (attrISOLanguageId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "ISOLanguageId");
        }

        // Save named attributes to context
        CFLibXmlCoreContext curContext = getParser().getCurContext();
        // Convert string attributes to native Java types
        // and apply the converted attributes to the editBuff.

        short natISOLanguageId;
        natISOLanguageId = Short.parseShort(attrISOLanguageId);

        // Read the objects
        List<ICFEnSyntaxISOCountryLanguageObj> list = schemaObj.getISOCountryLanguageTableObj()
                .readISOCountryLanguageByLanguageIdx(natISOLanguageId);
        String responseOpening = CFEnSyntaxXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFEnSyntaxXMsgISOCountryLanguageMessageFormatter.formatISOCountryLanguageRspnListOpenTag();
        xmsgRqstHandler.appendResponse(responseOpening);
        Iterator<ICFEnSyntaxISOCountryLanguageObj> iter = list.iterator();
        ICFEnSyntaxISOCountryLanguageObj cur;
        String subxml;
        while (iter.hasNext()) {
            cur = iter.next();
            subxml = CFEnSyntaxXMsgISOCountryLanguageMessageFormatter
                    .formatISOCountryLanguageRspnDerivedRec("\n\t\t", cur.getISOCountryLanguageBuff());
            xmsgRqstHandler.appendResponse(subxml);
        }
        String responseClosing = "\n" + "\t"
                + CFEnSyntaxXMsgISOCountryLanguageMessageFormatter.formatISOCountryLanguageRspnListCloseTag()
                + CFEnSyntaxXMsgSchemaMessageFormatter.formatRspnXmlPostamble();
        xmsgRqstHandler.appendResponse(responseClosing);
    } catch (RuntimeException e) {
        String response = CFEnSyntaxXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFEnSyntaxXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                + CFEnSyntaxXMsgSchemaMessageFormatter.formatRspnXmlPostamble();
        CFEnSyntaxXMsgRqstHandler xmsgRqstHandler = ((CFEnSyntaxXMsgRqstHandler) getParser());
        xmsgRqstHandler.resetResponse();
        xmsgRqstHandler.appendResponse(response);
        xmsgRqstHandler.setCaughtException(true);
    } catch (Error e) {
        String response = CFEnSyntaxXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFEnSyntaxXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                + CFEnSyntaxXMsgSchemaMessageFormatter.formatRspnXmlPostamble();
        CFEnSyntaxXMsgRqstHandler xmsgRqstHandler = ((CFEnSyntaxXMsgRqstHandler) getParser());
        xmsgRqstHandler.resetResponse();
        xmsgRqstHandler.appendResponse(response);
        xmsgRqstHandler.setCaughtException(true);
    }
}

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

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    CFFreeSwitchXMsgSchemaMessageFormatter schemaFormatter = null;
    try {/*from www.  ja  v a2  s . c o m*/
        // Common XML Attributes
        String attrId = null;
        String attrTZHourOffset = null;
        String attrTZMinOffset = null;
        // Attribute Extraction
        String attrLocalName;
        int numAttrs;
        int idxAttr;
        final String S_ProcName = "startElement";
        final String S_LocalName = "LocalName";

        assert qName.equals("RqstISOTimezoneReadByOffsetIdx");

        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("TZHourOffset")) {
                if (attrTZHourOffset != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrTZHourOffset = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("TZMinOffset")) {
                if (attrTZMinOffset != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrTZMinOffset = 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 ((attrTZHourOffset == null) || (attrTZHourOffset.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "TZHourOffset");
        }
        if ((attrTZMinOffset == null) || (attrTZMinOffset.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "TZMinOffset");
        }

        // Save named attributes to context
        CFLibXmlCoreContext curContext = getParser().getCurContext();
        // Convert string attributes to native Java types
        // and apply the converted attributes to the editBuff.

        short natTZHourOffset;
        natTZHourOffset = Short.parseShort(attrTZHourOffset);

        short natTZMinOffset;
        natTZMinOffset = Short.parseShort(attrTZMinOffset);

        // Read the objects
        List<ICFSecurityISOTimezoneObj> list = schemaObj.getISOTimezoneTableObj()
                .readISOTimezoneByOffsetIdx(natTZHourOffset, natTZMinOffset);
        String responseOpening = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFFreeSwitchXMsgISOTimezoneMessageFormatter.formatISOTimezoneRspnListOpenTag();
        xmsgRqstHandler.appendResponse(responseOpening);
        Iterator<ICFSecurityISOTimezoneObj> iter = list.iterator();
        ICFSecurityISOTimezoneObj cur;
        String subxml;
        while (iter.hasNext()) {
            cur = iter.next();
            subxml = CFFreeSwitchXMsgISOTimezoneMessageFormatter.formatISOTimezoneRspnDerivedRec("\n\t\t",
                    cur.getISOTimezoneBuff());
            xmsgRqstHandler.appendResponse(subxml);
        }
        String responseClosing = "\n" + "\t"
                + CFFreeSwitchXMsgISOTimezoneMessageFormatter.formatISOTimezoneRspnListCloseTag()
                + schemaFormatter.formatRspnXmlPostamble();
        xmsgRqstHandler.appendResponse(responseClosing);
    } 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.cfinternet.v2_0.CFInternetSaxLoader.CFInternetSaxLoaderAuditActionHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    try {/*w  w  w. j av a2 s.  c o m*/
        // Common XML Attributes
        String attrId = null;
        // Primary Key Attributes for Constant Enum support
        String attrAuditActionId = null;
        // AuditAction Attributes
        String attrDescription = null;
        // AuditAction References
        // Attribute Extraction
        String attrLocalName;
        int numAttrs;
        int idxAttr;
        final String S_ProcName = "startElement";
        final String S_LocalName = "LocalName";

        assert qName.equals("AuditAction");

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

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

        // Instantiate an edit buffer for the parsed information
        ICFInternetAuditActionEditObj editBuff = (ICFInternetAuditActionEditObj) schemaObj
                .getAuditActionTableObj().newInstance().beginEdit();

        // 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("AuditActionId")) {
                if (attrAuditActionId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrAuditActionId = 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("schemaLocation")) {
                // ignored
            } else {
                throw CFLib.getDefaultExceptionFactory().newUnrecognizedAttributeException(getClass(),
                        S_ProcName, getParser().getLocationInfo(), attrLocalName);
            }
        }

        // Ensure that required attributes have values
        if ((attrAuditActionId == null) || (attrAuditActionId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "AuditActionId");
        }
        if (attrDescription == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "Description");
        }

        // Save named attributes to context
        CFLibXmlCoreContext curContext = getParser().getCurContext();
        curContext.putNamedValue("Id", attrId);
        curContext.putNamedValue("Description", attrDescription);

        // Convert string attributes to native Java types
        // and apply the converted attributes to the editBuff.

        short natAuditActionId;
        natAuditActionId = Short.parseShort(attrAuditActionId);
        editBuff.getPKey().setRequiredAuditActionId(natAuditActionId);
        editBuff.getAuditActionBuff().setRequiredAuditActionId(natAuditActionId);

        String natDescription = attrDescription;
        editBuff.setRequiredDescription(natDescription);

        // Get the scope/container object

        CFLibXmlCoreContext parentContext = curContext.getPrevContext();
        Object scopeObj;
        if (parentContext != null) {
            scopeObj = parentContext.getNamedValue("Object");
        } else {
            scopeObj = null;
        }

        CFInternetSaxLoader.LoaderBehaviourEnum loaderBehaviour = saxLoader.getAuditActionLoaderBehaviour();
        ICFInternetAuditActionEditObj editAuditAction = null;
        ICFInternetAuditActionObj origAuditAction = schemaObj.getAuditActionTableObj()
                .readAuditActionByUDescrIdx(editBuff.getRequiredDescription());
        editBuff.getPKey().setRequiredAuditActionId(natAuditActionId);
        editBuff.getAuditActionBuff().setRequiredAuditActionId(natAuditActionId);
        if (origAuditAction == null) {
            editAuditAction = editBuff;
        } else {
            switch (loaderBehaviour) {
            case Insert:
                break;
            case Update:
                editAuditAction = (ICFInternetAuditActionEditObj) origAuditAction.beginEdit();
                editAuditAction.setRequiredDescription(editBuff.getRequiredDescription());
                break;
            case Replace:
                editAuditAction = (ICFInternetAuditActionEditObj) origAuditAction.beginEdit();
                editAuditAction.delete();
                editAuditAction.endEdit();
                origAuditAction = null;
                editAuditAction = editBuff;
                break;
            }
        }

        if (editAuditAction != null) {
            if (origAuditAction != null) {
                editAuditAction.update();
            } else {
                origAuditAction = (ICFInternetAuditActionObj) editAuditAction.create();
            }
            editAuditAction.endEdit();
        }

        curContext.putNamedValue("Object", origAuditAction);
    } 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.CFAsteriskXMsgRspnHandler.CFAsteriskXMsgRspnAuditActionRecHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    try {/*  w w  w.  j  a  v  a  2  s. c o m*/
        // Common XML Attributes
        String attrId = null;
        String attrRevision = null;
        // AuditAction Attributes
        String attrAuditActionId = null;
        String attrDescription = null;
        // Attribute Extraction
        String attrLocalName;
        int numAttrs;
        int idxAttr;
        final String S_ProcName = "startElement";
        final String S_LocalName = "LocalName";

        assert qName.equals("AuditAction");

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

        ICFAsteriskSchemaObj 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("AuditActionId")) {
                if (attrAuditActionId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrAuditActionId = 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("schemaLocation")) {
                // ignored
            } else {
                throw CFLib.getDefaultExceptionFactory().newUnrecognizedAttributeException(getClass(),
                        S_ProcName, getParser().getLocationInfo(), attrLocalName);
            }
        }

        // Ensure that required attributes have values
        if ((attrAuditActionId == null) || (attrAuditActionId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "AuditActionId");
        }
        if (attrDescription == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "Description");
        }

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

        // Convert string attributes to native Java types

        short natAuditActionId = Short.parseShort(attrAuditActionId);

        String natDescription = attrDescription;

        int natRevision = Integer.parseInt(attrRevision);
        // Get the parent context
        CFLibXmlCoreContext parentContext = curContext.getPrevContext();
        // Instantiate a buffer for the parsed information
        ICFAsteriskAuditActionObj obj = (ICFAsteriskAuditActionObj) (schemaObj.getAuditActionTableObj()
                .newInstance());
        CFSecurityAuditActionBuff dataBuff = obj.getAuditActionBuff();
        dataBuff.setRequiredAuditActionId(natAuditActionId);
        dataBuff.setRequiredDescription(natDescription);
        dataBuff.setRequiredRevision(natRevision);
        obj.copyBuffToPKey();
        @SuppressWarnings("unchecked")
        List<ICFSecurityAuditActionObj> list = (List<ICFSecurityAuditActionObj>) xmsgRspnHandler
                .getListOfObjects();
        ICFSecurityAuditActionObj realized = (ICFSecurityAuditActionObj) obj.realize();
        xmsgRspnHandler.setLastObjectProcessed(realized);
        if (list != null) {
            list.add(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.agkn.field_stripe.stripe.XMLFieldStripeReader.java

/**
 * Parses the specified non-<code>null</code> string value into the appropriate
 * type based on the {@link IField field's} {@link IField#getType() type}.
 *///from   w ww .  j a  v a 2 s .  co m
private Object parseValue(final String stringValue) {
    switch (fieldType) {
    case BYTE:
        return Byte.parseByte(stringValue);
    case SHORT:
        return Short.parseShort(stringValue);
    case INT:
        return Integer.parseInt(stringValue);
    case LONG:
        return Long.parseLong(stringValue);
    case FLOAT:
        return Float.parseFloat(stringValue);
    case DOUBLE:
        return Double.parseDouble(stringValue);
    case BOOLEAN:
        return Boolean.parseBoolean(stringValue);
    case STRING:
        return StringEscapeUtils.unescapeXml(stringValue);

    default:
        throw new DeveloperException("Unknown field type in field \"" + field.getName() + ".");
    }
}

From source file:net.sourceforge.msscodefactory.cfcrm.v2_0.CFCrmSaxLoader.CFCrmSaxLoaderISOCountryHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    try {/*ww  w  .ja v  a 2 s  .c  om*/
        // Common XML Attributes
        String attrId = null;
        // Primary Key Attributes for Constant Enum support
        // ISOCountry Attributes
        String attrISOCode = null;
        String attrName = null;
        // ISOCountry References
        // Attribute Extraction
        String attrLocalName;
        int numAttrs;
        int idxAttr;
        final String S_ProcName = "startElement";
        final String S_LocalName = "LocalName";

        assert qName.equals("ISOCountry");

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

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

        // Instantiate an edit buffer for the parsed information
        ICFCrmISOCountryEditObj editBuff = (ICFCrmISOCountryEditObj) schemaObj.getISOCountryTableObj()
                .newInstance().beginEdit();

        // 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("ISOCode")) {
                if (attrISOCode != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrISOCode = 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("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 (attrName == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "Name");
        }

        // Save named attributes to context
        CFLibXmlCoreContext curContext = getParser().getCurContext();
        curContext.putNamedValue("Id", attrId);
        curContext.putNamedValue("ISOCode", attrISOCode);
        curContext.putNamedValue("Name", attrName);

        // Convert string attributes to native Java types
        // and apply the converted attributes to the editBuff.

        short natId;
        natId = Short.parseShort(attrId);
        editBuff.getPKey().setRequiredId(natId);
        editBuff.getISOCountryBuff().setRequiredId(natId);

        String natISOCode = attrISOCode;
        editBuff.setRequiredISOCode(natISOCode);

        String natName = attrName;
        editBuff.setRequiredName(natName);

        // Get the scope/container object

        CFLibXmlCoreContext parentContext = curContext.getPrevContext();
        Object scopeObj;
        if (parentContext != null) {
            scopeObj = parentContext.getNamedValue("Object");
        } else {
            scopeObj = null;
        }

        CFCrmSaxLoader.LoaderBehaviourEnum loaderBehaviour = saxLoader.getISOCountryLoaderBehaviour();
        ICFCrmISOCountryEditObj editISOCountry = null;
        ICFCrmISOCountryObj origISOCountry = schemaObj.getISOCountryTableObj()
                .readISOCountryByISOCodeIdx(editBuff.getRequiredISOCode());
        editBuff.getPKey().setRequiredId(natId);
        editBuff.getISOCountryBuff().setRequiredId(natId);
        if (origISOCountry == null) {
            editISOCountry = editBuff;
        } else {
            switch (loaderBehaviour) {
            case Insert:
                break;
            case Update:
                editISOCountry = (ICFCrmISOCountryEditObj) origISOCountry.beginEdit();
                editISOCountry.setRequiredISOCode(editBuff.getRequiredISOCode());
                editISOCountry.setRequiredName(editBuff.getRequiredName());
                break;
            case Replace:
                editISOCountry = (ICFCrmISOCountryEditObj) origISOCountry.beginEdit();
                editISOCountry.delete();
                editISOCountry.endEdit();
                origISOCountry = null;
                editISOCountry = editBuff;
                break;
            }
        }

        if (editISOCountry != null) {
            if (origISOCountry != null) {
                editISOCountry.update();
            } else {
                origISOCountry = (ICFCrmISOCountryObj) editISOCountry.create();
            }
            editISOCountry.endEdit();
        }

        curContext.putNamedValue("Object", origISOCountry);
    } 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.cffreeswitch.v2_4.CFFreeSwitchXMsgRspnHandler.CFFreeSwitchXMsgRspnAuditActionRecHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    try {/*ww w .  jav a  2s.c om*/
        // Common XML Attributes
        String attrId = null;
        String attrRevision = null;
        // AuditAction Attributes
        String attrAuditActionId = null;
        String attrDescription = null;
        // Attribute Extraction
        String attrLocalName;
        int numAttrs;
        int idxAttr;
        final String S_ProcName = "startElement";
        final String S_LocalName = "LocalName";

        assert qName.equals("AuditAction");

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

        ICFFreeSwitchSchemaObj 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("AuditActionId")) {
                if (attrAuditActionId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrAuditActionId = 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("schemaLocation")) {
                // ignored
            } else {
                throw CFLib.getDefaultExceptionFactory().newUnrecognizedAttributeException(getClass(),
                        S_ProcName, getParser().getLocationInfo(), attrLocalName);
            }
        }

        // Ensure that required attributes have values
        if ((attrAuditActionId == null) || (attrAuditActionId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "AuditActionId");
        }
        if (attrDescription == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "Description");
        }

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

        // Convert string attributes to native Java types

        short natAuditActionId = Short.parseShort(attrAuditActionId);

        String natDescription = attrDescription;

        int natRevision = Integer.parseInt(attrRevision);
        // Get the parent context
        CFLibXmlCoreContext parentContext = curContext.getPrevContext();
        // Instantiate a buffer for the parsed information
        ICFFreeSwitchAuditActionObj obj = (ICFFreeSwitchAuditActionObj) (schemaObj.getAuditActionTableObj()
                .newInstance());
        CFSecurityAuditActionBuff dataBuff = obj.getAuditActionBuff();
        dataBuff.setRequiredAuditActionId(natAuditActionId);
        dataBuff.setRequiredDescription(natDescription);
        dataBuff.setRequiredRevision(natRevision);
        obj.copyBuffToPKey();
        @SuppressWarnings("unchecked")
        List<ICFSecurityAuditActionObj> list = (List<ICFSecurityAuditActionObj>) xmsgRspnHandler
                .getListOfObjects();
        ICFSecurityAuditActionObj realized = (ICFSecurityAuditActionObj) obj.realize();
        xmsgRspnHandler.setLastObjectProcessed(realized);
        if (list != null) {
            list.add(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.CFGenKbXMsgRqstHandler.CFGenKbXMsgRqstISOTimezoneDeleteByOffsetIdxHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    try {/*from   w w  w  .  j av a  2  s  . c o m*/
        // Common XML Attributes
        String attrId = null;
        String attrTZHourOffset = null;
        String attrTZMinOffset = null;
        // Attribute Extraction
        String attrLocalName;
        int numAttrs;
        int idxAttr;
        final String S_ProcName = "startElement";
        final String S_LocalName = "LocalName";

        assert qName.equals("RqstISOTimezoneDeleteByOffsetIdx");

        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("TZHourOffset")) {
                if (attrTZHourOffset != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrTZHourOffset = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("TZMinOffset")) {
                if (attrTZMinOffset != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrTZMinOffset = 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$implRqstTableDeleteByHandlerCheckReqKeyAttrs$

        // Save named attributes to context
        CFLibXmlCoreContext curContext = getParser().getCurContext();
        // Convert string attributes to native Java types

        short natTZHourOffset;
        natTZHourOffset = Short.parseShort(attrTZHourOffset);

        short natTZMinOffset;
        natTZMinOffset = Short.parseShort(attrTZMinOffset);

        // Delete the objects
        schemaObj.getISOTimezoneTableObj().deleteISOTimezoneByOffsetIdx(natTZHourOffset, natTZMinOffset);
        String response = CFGenKbXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFGenKbXMsgISOTimezoneMessageFormatter.formatISOTimezoneRspnDeleted() + "\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:fr.cedrik.util.ExtendedProperties.java

public short getShort(String key) {
    return Short.parseShort(getProperty(key));
}