Example usage for java.util SortedMap put

List of usage examples for java.util SortedMap put

Introduction

In this page you can find the example usage for java.util SortedMap put.

Prototype

V put(K key, V value);

Source Link

Document

Associates the specified value with the specified key in this map (optional operation).

Usage

From source file:net.sourceforge.msscodefactory.cfensyntax.v2_0.CFEnSyntaxXMsgRspnHandler.CFEnSyntaxXMsgRspnTenantRecHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    try {//from w ww .  j  a  va  2s .  com
        // Common XML Attributes
        String attrId = null;
        String attrRevision = null;
        // Tenant Attributes
        String attrClusterId = null;
        String attrTenantName = 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("Tenant");

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

        ICFEnSyntaxSchemaObj 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("ClusterId")) {
                if (attrClusterId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrClusterId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("TenantName")) {
                if (attrTenantName != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrTenantName = 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 ((attrClusterId == null) || (attrClusterId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "ClusterId");
        }
        if ((attrId == null) || (attrId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "Id");
        }
        if (attrTenantName == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "TenantName");
        }

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

        // Convert string attributes to native Java types

        long natClusterId = Long.parseLong(attrClusterId);

        long natId = Long.parseLong(attrId);

        String natTenantName = attrTenantName;

        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
        ICFEnSyntaxTenantObj obj = schemaObj.getTenantTableObj().newInstance();
        CFEnSyntaxTenantBuff dataBuff = obj.getTenantBuff();
        dataBuff.setRequiredClusterId(natClusterId);
        dataBuff.setRequiredId(natId);
        dataBuff.setRequiredTenantName(natTenantName);
        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<CFEnSyntaxTenantPKey, ICFEnSyntaxTenantObj> sortedMap = (SortedMap<CFEnSyntaxTenantPKey, ICFEnSyntaxTenantObj>) xmsgRspnHandler
                .getSortedMapOfObjects();
        ICFEnSyntaxTenantObj realized = (ICFEnSyntaxTenantObj) 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:br.eti.ranieri.opcoesweb.importacao.offline.ImportadorOffline.java

private void calcularBlackScholes(List<CotacaoBDI> cotacoes, ConfiguracaoImportacao configuracaoImportacao)
        throws Exception {
    if (cotacoes == null)
        return;//  ww  w  . java  2  s.c  o  m

    // Organiza as cotacoes por data e acao. As cotacoes da
    // acao e das opcoes ficam, por enquanto, na mesma lista
    SortedMap<LocalDate, Map<Acao, List<CotacaoBDI>>> diaAcaoOpcoes = new TreeMap<LocalDate, Map<Acao, List<CotacaoBDI>>>();
    for (CotacaoBDI cotacao : cotacoes) {
        LocalDate data = cotacao.getDataPregao();

        Map<Acao, List<CotacaoBDI>> cotacoesPorAcao = new HashMap<Acao, List<CotacaoBDI>>();
        if (diaAcaoOpcoes.containsKey(data)) {
            cotacoesPorAcao = diaAcaoOpcoes.get(data);
        } else {
            diaAcaoOpcoes.put(data, cotacoesPorAcao);
        }

        Acao acao = null;
        if (cotacao.getCodigoNegociacao().startsWith("PETR")) {
            acao = Acao.PETROBRAS;
        } else if (cotacao.getCodigoNegociacao().startsWith("VALE")) {
            acao = Acao.VALE;
        } else {
            log.error("Codigo de negociacao [{}] nao esta " + "vinculada a VALE e nem a PETROBRAS.",
                    cotacao.getCodigoNegociacao());
            continue;
        }

        List<CotacaoBDI> cotacoesAcaoOpcoes = new ArrayList<CotacaoBDI>();
        if (cotacoesPorAcao.containsKey(acao)) {
            cotacoesAcaoOpcoes = cotacoesPorAcao.get(acao);
        } else {
            cotacoesPorAcao.put(acao, cotacoesAcaoOpcoes);
        }

        cotacoesAcaoOpcoes.add(cotacao);
    }

    // Agora separa, para cada dia e para cada acao, as
    // cotacoes da acao, das opcoes que vencem este mes
    // e das opcoes que vencem no proximo mes.
    // 
    // Para cada dia e para cada acao, calcula o Black&Scholes
    // em cada dupla acao e lista de opcoes
    for (LocalDate data : diaAcaoOpcoes.keySet()) {

        Serie serieAtualOpcoes = Serie.getSerieAtualPorData(data);
        Serie proximaSerieOpcoes = Serie.getProximaSeriePorData(data);
        Double selic = taxaSelic.getSelic(data);

        for (Acao acao : diaAcaoOpcoes.get(data).keySet()) {

            CotacaoBDI cotacaoAcao = null;
            List<CotacaoBDI> cotacoesOpcoesSerie1 = new ArrayList<CotacaoBDI>();
            List<CotacaoBDI> cotacoesOpcoesSerie2 = new ArrayList<CotacaoBDI>();

            for (CotacaoBDI cotacao : diaAcaoOpcoes.get(data).get(acao)) {
                if (CodigoBDI.LOTE_PADRAO.equals(cotacao.getCodigoBdi())
                        && TipoMercadoBDI.MERCADO_A_VISTA.equals(cotacao.getTipoMercado())) {
                    if (cotacaoAcao != null)
                        log.error("Sobrescreveu cotacao [{}] com [{}].", cotacaoAcao, cotacao);
                    cotacaoAcao = cotacao;
                } else if (CodigoBDI.OPCOES_DE_COMPRA.equals(cotacao.getCodigoBdi())
                        && TipoMercadoBDI.OPCOES_DE_COMPRA.equals(cotacao.getTipoMercado())) {
                    if (serieAtualOpcoes.isSerieDaOpcao(cotacao.getCodigoNegociacao())) {
                        cotacoesOpcoesSerie1.add(cotacao);
                    } else if (proximaSerieOpcoes.isSerieDaOpcao(cotacao.getCodigoNegociacao())) {
                        cotacoesOpcoesSerie2.add(cotacao);
                    }
                }
            }

            if (cotacaoAcao == null) {
                log.error("Nao foi encontrada cotacao de " + "acao [{}] no dia [{}].", acao.getCodigo(), data);
                continue;
            }
            if (cotacoesOpcoesSerie1.size() == 0) {
                log.error("Nao foram encontradas cotacoes de opcoes "
                        + "de [{}] no dia [{}] para vencer neste mes.", acao.getCodigo(), data);
                continue;
            }
            if (cotacoesOpcoesSerie2.size() == 0) {
                log.error("Nao foram encontradas cotacoes de opcoes "
                        + "de [{}] no dia [{}] para vencer proximo mes.", acao.getCodigo(), data);
                continue;
            }

            CotacaoBDI opcaoTeorica1 = new CotacaoBDI(data, //
                    CodigoBDI.OPCOES_DE_COMPRA, //
                    TipoMercadoBDI.OPCOES_DE_COMPRA, //
                    "Teorica", 0, 0, 0, //
                    cotacaoAcao.getFechamento(), //
                    cotacoesOpcoesSerie1.iterator().next().getDataVencimento());

            CotacaoBDI opcaoTeorica2 = new CotacaoBDI(data, //
                    CodigoBDI.OPCOES_DE_COMPRA, //
                    TipoMercadoBDI.OPCOES_DE_COMPRA, //
                    "Teorica", 0, 0, 0, //
                    cotacaoAcao.getFechamento(), //
                    cotacoesOpcoesSerie2.iterator().next().getDataVencimento());

            Integer opcoesPorDia = configuracaoImportacao.getQuantidadeOpcoesPorAcaoPorDia();

            CotacaoAcaoOpcoes cotacao = blackScholes.calcularIndices(cotacaoAcao, serieAtualOpcoes,
                    cotacoesOpcoesSerie1, opcaoTeorica1, proximaSerieOpcoes, cotacoesOpcoesSerie2,
                    opcaoTeorica2, opcoesPorDia, selic);

            persistencia.incluirCotacaoHistorica(data, acao, cotacao);
        }
    }
}

From source file:hermes.browser.model.PropertySetTableModel.java

public PropertySetTableModel(Object bean, PropertySetConfig propertySet, Set filter)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {

    this.propertySet = propertySet;

    Set iterSet = null;/*from  ww  w .ja va  2s .co  m*/
    SortedMap sortMap = new TreeMap();

    if (propertySet.getProperty() != null) {

        for (Iterator iter = propertySet.getProperty().iterator(); iter.hasNext();) {
            PropertyConfig property = (PropertyConfig) iter.next();

            if (!ignore.contains(property.getName())) {
                Object propertyValue = property.getValue();

                if (propertyValue == null) {
                    propertyValue = "null";
                }

                sortMap.put(property.getName(), propertyValue);
            }
        }

        for (Iterator iter2 = sortMap.entrySet().iterator(); iter2.hasNext();) {
            Map.Entry entry = (Map.Entry) iter2.next();

            Vector row = new Vector();

            row.add(entry.getKey());
            row.add(entry.getValue());

            rows.add(row);
        }
    }

    setBean(bean);
}

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

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    try {//  w ww. j  a  v a  2  s  .  c  o m
        // Common XML Attributes
        String attrId = null;
        String attrRevision = null;
        // TSecGroup Attributes
        String attrTenantId = null;
        String attrTSecGroupId = null;
        String attrName = 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("TSecGroup");

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

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

        // Convert string attributes to native Java types

        long natTenantId = Long.parseLong(attrTenantId);

        int natTSecGroupId = Integer.parseInt(attrTSecGroupId);

        String natName = attrName;

        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
        ICFAccTSecGroupObj obj = schemaObj.getTSecGroupTableObj().newInstance();
        CFAccTSecGroupBuff dataBuff = obj.getTSecGroupBuff();
        dataBuff.setRequiredTenantId(natTenantId);
        dataBuff.setRequiredTSecGroupId(natTSecGroupId);
        dataBuff.setRequiredName(natName);
        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<CFAccTSecGroupPKey, ICFAccTSecGroupObj> sortedMap = (SortedMap<CFAccTSecGroupPKey, ICFAccTSecGroupObj>) xmsgRspnHandler
                .getSortedMapOfObjects();
        ICFAccTSecGroupObj realized = (ICFAccTSecGroupObj) 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_0.CFAstXMsgRspnHandler.CFAstXMsgRspnTSecGroupRecHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    try {// w w w.  j a  va  2  s .  co m
        // Common XML Attributes
        String attrId = null;
        String attrRevision = null;
        // TSecGroup Attributes
        String attrTenantId = null;
        String attrTSecGroupId = null;
        String attrName = 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("TSecGroup");

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

        ICFAstSchemaObj 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("TSecGroupId")) {
                if (attrTSecGroupId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrTSecGroupId = 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 ((attrTenantId == null) || (attrTenantId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "TenantId");
        }
        if ((attrTSecGroupId == null) || (attrTSecGroupId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "TSecGroupId");
        }
        if (attrName == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "Name");
        }

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

        // Convert string attributes to native Java types

        long natTenantId = Long.parseLong(attrTenantId);

        int natTSecGroupId = Integer.parseInt(attrTSecGroupId);

        String natName = attrName;

        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
        ICFAstTSecGroupObj obj = schemaObj.getTSecGroupTableObj().newInstance();
        CFAstTSecGroupBuff dataBuff = obj.getTSecGroupBuff();
        dataBuff.setRequiredTenantId(natTenantId);
        dataBuff.setRequiredTSecGroupId(natTSecGroupId);
        dataBuff.setRequiredName(natName);
        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<CFAstTSecGroupPKey, ICFAstTSecGroupObj> sortedMap = (SortedMap<CFAstTSecGroupPKey, ICFAstTSecGroupObj>) xmsgRspnHandler
                .getSortedMapOfObjects();
        ICFAstTSecGroupObj realized = (ICFAstTSecGroupObj) 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.CFGenKbXMsgRspnISOCountryRecHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    try {/*ww  w.j  a  v a 2  s  .c  o  m*/
        // Common XML Attributes
        String attrId = null;
        String attrRevision = null;
        // ISOCountry Attributes
        String attrISOCode = null;
        String attrName = 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("ISOCountry");

        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("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("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 = xmsgRspnHandler.getCurContext();

        // Convert string attributes to native Java types

        short natId = Short.parseShort(attrId);

        String natISOCode = attrISOCode;

        String natName = attrName;

        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
        ICFGenKbISOCountryObj obj = schemaObj.getISOCountryTableObj().newInstance();
        CFGenKbISOCountryBuff dataBuff = obj.getISOCountryBuff();
        dataBuff.setRequiredId(natId);
        dataBuff.setRequiredISOCode(natISOCode);
        dataBuff.setRequiredName(natName);
        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<CFGenKbISOCountryPKey, ICFGenKbISOCountryObj> sortedMap = (SortedMap<CFGenKbISOCountryPKey, ICFGenKbISOCountryObj>) xmsgRspnHandler
                .getSortedMapOfObjects();
        ICFGenKbISOCountryObj realized = (ICFGenKbISOCountryObj) 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.CFGenKbXMsgRspnSecGroupRecHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    try {//from  ww  w . j a v a 2s.c  om
        // Common XML Attributes
        String attrId = null;
        String attrRevision = null;
        // SecGroup Attributes
        String attrClusterId = null;
        String attrSecGroupId = null;
        String attrName = 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("SecGroup");

        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("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("ClusterId")) {
                if (attrClusterId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrClusterId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("SecGroupId")) {
                if (attrSecGroupId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrSecGroupId = 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 ((attrClusterId == null) || (attrClusterId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "ClusterId");
        }
        if ((attrSecGroupId == null) || (attrSecGroupId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "SecGroupId");
        }
        if (attrName == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "Name");
        }

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

        // Convert string attributes to native Java types

        long natClusterId = Long.parseLong(attrClusterId);

        int natSecGroupId = Integer.parseInt(attrSecGroupId);

        String natName = attrName;

        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
        ICFGenKbSecGroupObj obj = schemaObj.getSecGroupTableObj().newInstance();
        CFGenKbSecGroupBuff dataBuff = obj.getSecGroupBuff();
        dataBuff.setRequiredClusterId(natClusterId);
        dataBuff.setRequiredSecGroupId(natSecGroupId);
        dataBuff.setRequiredName(natName);
        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<CFGenKbSecGroupPKey, ICFGenKbSecGroupObj> sortedMap = (SortedMap<CFGenKbSecGroupPKey, ICFGenKbSecGroupObj>) xmsgRspnHandler
                .getSortedMapOfObjects();
        ICFGenKbSecGroupObj realized = (ICFGenKbSecGroupObj) 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.cffreeswitch.v2_0.CFFswXMsgRspnHandler.CFFswXMsgRspnPbxIvrMenuEntryRecHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    try {//  w w w .j  av a  2 s . c  o m
        // Common XML Attributes
        String attrId = null;
        String attrRevision = null;
        // PbxIvrMenuEntry Attributes
        String attrTenantId = null;
        String attrMenuEntryId = null;
        String attrMenuId = null;
        String attrDigits = null;
        String attrEntryType = null;
        String attrParam = null;
        // Attribute Extraction
        String attrLocalName;
        int numAttrs;
        int idxAttr;
        final String S_ProcName = "startElement";
        final String S_LocalName = "LocalName";

        assert qName.equals("PbxIvrMenuEntry");

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

        ICFFswSchemaObj 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("MenuEntryId")) {
                if (attrMenuEntryId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrMenuEntryId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("MenuId")) {
                if (attrMenuId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrMenuId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("Digits")) {
                if (attrDigits != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrDigits = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("EntryType")) {
                if (attrEntryType != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrEntryType = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("Param")) {
                if (attrParam != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrParam = 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 ((attrMenuEntryId == null) || (attrMenuEntryId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "MenuEntryId");
        }
        if ((attrMenuId == null) || (attrMenuId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "MenuId");
        }
        if (attrDigits == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "Digits");
        }
        if (attrEntryType == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "EntryType");
        }
        if (attrParam == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "Param");
        }

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

        // Convert string attributes to native Java types

        long natTenantId = Long.parseLong(attrTenantId);

        long natMenuEntryId = Long.parseLong(attrMenuEntryId);

        long natMenuId = Long.parseLong(attrMenuId);

        String natDigits = attrDigits;

        String natEntryType = attrEntryType;

        String natParam = attrParam;

        int natRevision = Integer.parseInt(attrRevision);
        // Get the parent context
        CFLibXmlCoreContext parentContext = curContext.getPrevContext();
        // Instantiate a buffer for the parsed information
        ICFFswPbxIvrMenuEntryObj obj = schemaObj.getPbxIvrMenuEntryTableObj().newInstance();
        CFFswPbxIvrMenuEntryBuff dataBuff = obj.getPbxIvrMenuEntryBuff();
        dataBuff.setRequiredTenantId(natTenantId);
        dataBuff.setRequiredMenuEntryId(natMenuEntryId);
        dataBuff.setRequiredMenuId(natMenuId);
        dataBuff.setRequiredDigits(natDigits);
        dataBuff.setRequiredEntryType(natEntryType);
        dataBuff.setRequiredParam(natParam);
        dataBuff.setRequiredRevision(natRevision);
        obj.copyBuffToPKey();
        SortedMap<CFFswPbxIvrMenuEntryPKey, ICFFswPbxIvrMenuEntryObj> sortedMap = (SortedMap<CFFswPbxIvrMenuEntryPKey, ICFFswPbxIvrMenuEntryObj>) xmsgRspnHandler
                .getSortedMapOfObjects();
        ICFFswPbxIvrMenuEntryObj realized = (ICFFswPbxIvrMenuEntryObj) 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:org.jasig.schedassist.portlet.VisibleScheduleTag.java

@Override
public int doStartTagInternal() {
    RenderRequest renderRequest = (RenderRequest) pageContext.getRequest().getAttribute(PORTLET_REQUEST);
    RenderResponse renderResponse = (RenderResponse) pageContext.getRequest().getAttribute(PORTLET_RESPONSE);

    final Date scheduleStart = visibleSchedule.getScheduleStart();
    if (null == scheduleStart) {
        // the visibleSchedule is empty, short circuit
        try {//  w  w w. j  av  a2 s. co m
            StringBuilder noappointments = new StringBuilder();
            noappointments.append("<span class=\"none-available\">");
            noappointments.append(getMessageSource().getMessage("no.available.appointments", null, null));
            noappointments.append("</span>");
            pageContext.getOut().write(noappointments.toString());
        } catch (IOException e) {
            LOG.error("IOException occurred in doStartTag", e);
        }
        // SKIP_BODY means don't print any content from body of tag
        return SKIP_BODY;
    }

    LOG.debug("scheduleStart: " + scheduleStart);
    SortedMap<Date, List<AvailableBlock>> dailySchedules = new TreeMap<Date, List<AvailableBlock>>();
    Date index = DateUtils.truncate(scheduleStart, java.util.Calendar.DATE);
    Date scheduleEnd = visibleSchedule.getScheduleEnd();
    while (index.before(scheduleEnd)) {
        dailySchedules.put(index, new ArrayList<AvailableBlock>());
        index = DateUtils.addDays(index, 1);
    }
    final Date lastMapKey = dailySchedules.lastKey();
    LOG.debug("visibleSchedule spans " + dailySchedules.keySet().size() + " days");

    try {
        SortedMap<AvailableBlock, AvailableStatus> scheduleBlockMap = visibleSchedule.getBlockMap();
        int numberOfEventsToDisplay = 0;
        for (AvailableBlock block : scheduleBlockMap.keySet()) {
            Date eventStartDate = block.getStartTime();
            LOG.debug("event start date: " + eventStartDate);
            Date mapKey = DateUtils.truncate(eventStartDate, java.util.Calendar.DATE);
            if (CommonDateOperations.equalsOrAfter(eventStartDate, scheduleStart)
                    && dailySchedules.containsKey(mapKey)) {
                dailySchedules.get(mapKey).add(block);
                numberOfEventsToDisplay++;
            }
        }
        LOG.debug("number of events to display: " + numberOfEventsToDisplay);
        if (numberOfEventsToDisplay == 0) {
            // no available times in this range!
            StringBuilder noappointments = new StringBuilder();
            noappointments.append("<span class=\"none-available\">");
            noappointments.append(getMessageSource().getMessage("no.available.appointments", null, null));
            noappointments.append("</span>");
            pageContext.getOut().write(noappointments.toString());
        } else {
            int weekNumber = 1;
            Date currentWeekStart = DateUtils.truncate(scheduleStart, java.util.Calendar.DATE);
            Date currentWeekFinish = DateUtils.addDays(currentWeekStart,
                    CommonDateOperations.numberOfDaysUntilSunday(currentWeekStart));
            currentWeekFinish = DateUtils.addMinutes(currentWeekFinish, -1);

            boolean renderAnotherWeek = true;

            while (renderAnotherWeek) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("will render another week using currentWeekStart " + currentWeekStart
                            + " and currentWeekFinish " + currentWeekFinish);
                }
                SortedMap<Date, List<AvailableBlock>> subMap = dailySchedules.subMap(currentWeekStart,
                        currentWeekFinish);
                renderWeek(pageContext.getOut(), weekNumber++, subMap, scheduleBlockMap, renderRequest,
                        renderResponse);

                currentWeekStart = DateUtils.addMinutes(currentWeekFinish, 1);
                currentWeekFinish = DateUtils.addDays(currentWeekStart, 7);
                currentWeekFinish = DateUtils.addMinutes(currentWeekFinish, -1);

                if (LOG.isDebugEnabled()) {
                    LOG.debug("recalculated currentWeekStart " + currentWeekStart + ", currentWeekFinish "
                            + currentWeekFinish);
                }

                if (currentWeekStart.after(lastMapKey)) {
                    renderAnotherWeek = false;
                    LOG.debug("will not render another week");
                }
            }
        }

    } catch (IOException e) {
        LOG.error("IOException occurred in doStartTag", e);
    }
    // SKIP_BODY means don't print any content from body of tag
    return SKIP_BODY;
}

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

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    try {//www .j ava 2s.  c  o  m
        // Common XML Attributes
        String attrId = null;
        String attrRevision = null;
        // TSecGroup Attributes
        String attrTenantId = null;
        String attrTSecGroupId = null;
        String attrName = 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("TSecGroup");

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

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

        // Convert string attributes to native Java types

        long natTenantId = Long.parseLong(attrTenantId);

        int natTSecGroupId = Integer.parseInt(attrTSecGroupId);

        String natName = attrName;

        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
        ICFGenKbTSecGroupObj obj = schemaObj.getTSecGroupTableObj().newInstance();
        CFGenKbTSecGroupBuff dataBuff = obj.getTSecGroupBuff();
        dataBuff.setRequiredTenantId(natTenantId);
        dataBuff.setRequiredTSecGroupId(natTSecGroupId);
        dataBuff.setRequiredName(natName);
        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<CFGenKbTSecGroupPKey, ICFGenKbTSecGroupObj> sortedMap = (SortedMap<CFGenKbTSecGroupPKey, ICFGenKbTSecGroupObj>) xmsgRspnHandler
                .getSortedMapOfObjects();
        ICFGenKbTSecGroupObj realized = (ICFGenKbTSecGroupObj) 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);
    }
}