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:com.jxt.web.service.AgentInfoServiceImpl.java

@Override
public ApplicationAgentList getApplicationAgentList(ApplicationAgentList.Key applicationAgentListKey,
        String applicationName, long timestamp) {
    if (applicationName == null) {
        throw new NullPointerException("applicationName must not be null");
    }/*  ww  w  .  jav  a2s  .  co  m*/
    if (applicationAgentListKey == null) {
        throw new NullPointerException("applicationAgentListKey must not be null");
    }
    final List<String> agentIdList = this.applicationIndexDao.selectAgentIds(applicationName);
    if (logger.isDebugEnabled()) {
        logger.debug("agentIdList={}", agentIdList);
    }

    if (CollectionUtils.isEmpty(agentIdList)) {
        logger.debug("agentIdList is empty. applicationName={}", applicationName);
        return new ApplicationAgentList(new TreeMap<String, List<AgentInfo>>());
    }

    // key = hostname
    // value= list fo agentinfo
    SortedMap<String, List<AgentInfo>> result = new TreeMap<>();

    List<AgentInfo> agentInfos = this.agentInfoDao.getAgentInfos(agentIdList, timestamp);
    this.agentLifeCycleDao.populateAgentStatuses(agentInfos, timestamp);
    for (AgentInfo agentInfo : agentInfos) {
        if (agentInfo != null) {
            String hostname = applicationAgentListKey.getKey(agentInfo);

            if (result.containsKey(hostname)) {
                result.get(hostname).add(agentInfo);
            } else {
                List<AgentInfo> list = new ArrayList<>();
                list.add(agentInfo);
                result.put(hostname, list);
            }
        }
    }

    for (List<AgentInfo> agentInfoList : result.values()) {
        Collections.sort(agentInfoList, AgentInfo.AGENT_NAME_ASC_COMPARATOR);
    }

    logger.info("getApplicationAgentList={}", result);

    return new ApplicationAgentList(result);
}

From source file:edu.usc.pgroup.louvain.hadoop.ReduceCommunity.java

private Graph reconstructGraph(Iterable<BytesWritable> values) throws Exception {

    Iterator<BytesWritable> it = values.iterator();

    SortedMap<Integer, GraphMessage> map = new TreeMap<Integer, GraphMessage>();

    //Load data//from  w  w w  . j  a  v  a  2s.c  o  m
    while (it.hasNext()) {
        BytesWritable bytesWritable = it.next();
        ByteArrayInputStream inputStream = new ByteArrayInputStream(bytesWritable.getBytes());

        try {
            ObjectInputStream objectInputStream = new ObjectInputStream(inputStream);
            GraphMessage msg = (GraphMessage) objectInputStream.readObject();
            map.put(msg.getCurrentPartition(), msg);
        } catch (IOException e) {
            e.printStackTrace();
            throw new Exception(e);
        }

    }

    // Renumber

    int gap = 0;
    int degreeGap = 0;
    Path pt = new Path(outpath + File.separator + "Map-Partition-Sizes");
    FileSystem fs = FileSystem.get(new Configuration());

    if (fs.exists(pt)) {
        fs.delete(pt, true);

    }

    BufferedWriter br = new BufferedWriter(new OutputStreamWriter(fs.create(pt, true)));

    PrintWriter out = new PrintWriter(br);

    for (int i = 0; i < map.keySet().size(); i++) {

        GraphMessage msg = map.get(i);
        long currentDegreelen = msg.getDegrees()[msg.getDegrees().length - 1];
        if (i != 0) {
            for (int j = 0; j < msg.getLinks().length; j++) {
                msg.getLinks()[j] += gap;
            }

            for (int j = 0; j < msg.getRemoteMap().length; j++) {
                msg.getRemoteMap()[j].source += gap;
            }

            for (int j = 0; j < msg.getN2c().length; j++) {
                msg.getN2c()[j] += gap;
            }

            for (int j = 0; j < msg.getDegrees().length; j++) {
                msg.getDegrees()[j] += degreeGap;

            }

        }

        out.println("" + i + "," + msg.getNb_nodes());
        gap += msg.getNb_nodes();
        degreeGap += currentDegreelen;
    }

    out.flush();
    out.close();
    //Integrate

    Graph graph = new Graph();

    for (int i = 0; i < map.keySet().size(); i++) {
        GraphMessage msg = map.get(i);

        Collections.addAll(graph.getDegrees().getList(), msg.getDegrees());
        Collections.addAll(graph.getLinks().getList(), msg.getLinks());
        Collections.addAll(graph.getWeights().getList(), msg.getWeights());

        graph.setNb_links(graph.getNb_links() + msg.getNb_links());
        graph.setNb_nodes((int) (graph.getNb_nodes() + msg.getNb_nodes()));
        graph.setTotal_weight(graph.getTotal_weight() + msg.getTotal_weight());

    }

    //Merge local done.

    Map<Integer, Vector<Integer>> remoteEdges = new HashMap<Integer, Vector<Integer>>();
    Map<Integer, Vector<Float>> remoteWeighs = new HashMap<Integer, Vector<Float>>();

    for (int i = 0; i < map.keySet().size(); i++) {
        Map<HashMap.SimpleEntry<Integer, Integer>, Float> m = new HashMap<AbstractMap.SimpleEntry<Integer, Integer>, Float>();

        GraphMessage msg = map.get(i);
        for (int j = 0; j < msg.getRemoteMap().length; j++) {

            RemoteMap remoteMap = msg.getRemoteMap()[j];

            int sink = remoteMap.sink;
            int sinkPart = remoteMap.sinkPart;

            int target = map.get(sinkPart).getN2c()[sink];

            HashMap.SimpleEntry<Integer, Integer> key = new HashMap.SimpleEntry<Integer, Integer>(
                    remoteMap.source, target);
            if (m.containsKey(key)) {
                m.put(key, m.get(key) + 1.0f);
            } else {
                m.put(key, 1.0f);
            }
        }

        graph.setNb_links(graph.getNb_links() + m.size());

        Iterator<HashMap.SimpleEntry<Integer, Integer>> itr = m.keySet().iterator();

        while (itr.hasNext()) {

            HashMap.SimpleEntry<Integer, Integer> key = itr.next();
            float w = m.get(key);

            if (remoteEdges.containsKey(key.getKey())) {

                remoteEdges.get(key.getKey()).getList().add(key.getValue());

                if (remoteWeighs.containsKey(key.getKey())) {
                    remoteWeighs.get(key.getKey()).getList().add(w);
                }

            } else {
                Vector<Integer> list = new Vector<Integer>();
                list.getList().add(key.getValue());
                remoteEdges.put(key.getKey(), list);

                Vector<Float> wList = new Vector<Float>();
                wList.getList().add(w);
                remoteWeighs.put(key.getKey(), wList);
            }

        }

    }

    graph.addRemoteEdges(remoteEdges, remoteWeighs);

    //Merge Remote Done

    return graph;

}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccRam.CFAccRamTagTable.java

public void createTag(CFAccAuthorization Authorization, CFAccTagBuff Buff) {
    CFAccTagPKey pkey = schema.getFactoryTag().newPKey();
    pkey.setRequiredTenantId(Buff.getRequiredTenantId());
    pkey.setRequiredId(((CFAccRamTenantTable) schema.getTableTenant()).nextTagIdGen(Authorization,
            Buff.getRequiredTenantId()));
    Buff.setRequiredTenantId(pkey.getRequiredTenantId());
    Buff.setRequiredId(pkey.getRequiredId());
    CFAccTagByTenantIdxKey keyTenantIdx = schema.getFactoryTag().newTenantIdxKey();
    keyTenantIdx.setRequiredTenantId(Buff.getRequiredTenantId());

    CFAccTagByNameIdxKey keyNameIdx = schema.getFactoryTag().newNameIdxKey();
    keyNameIdx.setRequiredTenantId(Buff.getRequiredTenantId());
    keyNameIdx.setRequiredName(Buff.getRequiredName());

    // Validate unique indexes

    if (dictByPKey.containsKey(pkey)) {
        throw CFLib.getDefaultExceptionFactory().newPrimaryKeyNotNewException(getClass(), "createTag", pkey);
    }// w ww.  j av a2  s .c om

    if (dictByNameIdx.containsKey(keyNameIdx)) {
        throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), "createTag",
                "TagNameIdx", keyNameIdx);
    }

    // Validate foreign keys

    {
        boolean allNull = true;
        allNull = false;
        if (!allNull) {
            if (null == schema.getTableTenant().readDerivedByIdIdx(Authorization, Buff.getRequiredTenantId())) {
                throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "createTag",
                        "Container", "TagTenant", "Tenant", null);
            }
        }
    }

    // Proceed with adding the new record

    dictByPKey.put(pkey, Buff);

    SortedMap<CFAccTagPKey, CFAccTagBuff> subdictTenantIdx;
    if (dictByTenantIdx.containsKey(keyTenantIdx)) {
        subdictTenantIdx = dictByTenantIdx.get(keyTenantIdx);
    } else {
        subdictTenantIdx = new TreeMap<CFAccTagPKey, CFAccTagBuff>();
        dictByTenantIdx.put(keyTenantIdx, subdictTenantIdx);
    }
    subdictTenantIdx.put(pkey, Buff);

    dictByNameIdx.put(keyNameIdx, Buff);

}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccRam.CFAccRamDomainBaseTable.java

public void createDomainBase(CFAccAuthorization Authorization, CFAccDomainBaseBuff Buff) {
    CFAccDomainBasePKey pkey = schema.getFactoryDomainBase().newPKey();
    pkey.setClassCode(Buff.getClassCode());
    pkey.setRequiredTenantId(Buff.getRequiredTenantId());
    pkey.setRequiredId(((CFAccRamTenantTable) schema.getTableTenant()).nextDomainIdGen(Authorization,
            Buff.getRequiredTenantId()));
    Buff.setRequiredTenantId(pkey.getRequiredTenantId());
    Buff.setRequiredId(pkey.getRequiredId());
    CFAccDomainBaseByTenantIdxKey keyTenantIdx = schema.getFactoryDomainBase().newTenantIdxKey();
    keyTenantIdx.setRequiredTenantId(Buff.getRequiredTenantId());

    // Validate unique indexes

    if (dictByPKey.containsKey(pkey)) {
        throw CFLib.getDefaultExceptionFactory().newPrimaryKeyNotNewException(getClass(), "createDomainBase",
                pkey);/*  w ww  .j a va2  s . c  om*/
    }

    // Validate foreign keys

    {
        boolean allNull = true;
        allNull = false;
        if (!allNull) {
            if (null == schema.getTableTenant().readDerivedByIdIdx(Authorization, Buff.getRequiredTenantId())) {
                throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                        "createDomainBase", "Owner", "Tenant", "Tenant", null);
            }
        }
    }

    // Proceed with adding the new record

    dictByPKey.put(pkey, Buff);

    SortedMap<CFAccDomainBasePKey, CFAccDomainBaseBuff> subdictTenantIdx;
    if (dictByTenantIdx.containsKey(keyTenantIdx)) {
        subdictTenantIdx = dictByTenantIdx.get(keyTenantIdx);
    } else {
        subdictTenantIdx = new TreeMap<CFAccDomainBasePKey, CFAccDomainBaseBuff>();
        dictByTenantIdx.put(keyTenantIdx, subdictTenantIdx);
    }
    subdictTenantIdx.put(pkey, Buff);

}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstRam.CFAstRamDomainBaseTable.java

public void createDomainBase(CFAstAuthorization Authorization, CFAstDomainBaseBuff Buff) {
    CFAstDomainBasePKey pkey = schema.getFactoryDomainBase().newPKey();
    pkey.setClassCode(Buff.getClassCode());
    pkey.setRequiredTenantId(Buff.getRequiredTenantId());
    pkey.setRequiredId(((CFAstRamTenantTable) schema.getTableTenant()).nextDomainIdGen(Authorization,
            Buff.getRequiredTenantId()));
    Buff.setRequiredTenantId(pkey.getRequiredTenantId());
    Buff.setRequiredId(pkey.getRequiredId());
    CFAstDomainBaseByTenantIdxKey keyTenantIdx = schema.getFactoryDomainBase().newTenantIdxKey();
    keyTenantIdx.setRequiredTenantId(Buff.getRequiredTenantId());

    // Validate unique indexes

    if (dictByPKey.containsKey(pkey)) {
        throw CFLib.getDefaultExceptionFactory().newPrimaryKeyNotNewException(getClass(), "createDomainBase",
                pkey);/*from w w  w .ja v  a2  s.c o  m*/
    }

    // Validate foreign keys

    {
        boolean allNull = true;
        allNull = false;
        if (!allNull) {
            if (null == schema.getTableTenant().readDerivedByIdIdx(Authorization, Buff.getRequiredTenantId())) {
                throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                        "createDomainBase", "Owner", "Tenant", "Tenant", null);
            }
        }
    }

    // Proceed with adding the new record

    dictByPKey.put(pkey, Buff);

    SortedMap<CFAstDomainBasePKey, CFAstDomainBaseBuff> subdictTenantIdx;
    if (dictByTenantIdx.containsKey(keyTenantIdx)) {
        subdictTenantIdx = dictByTenantIdx.get(keyTenantIdx);
    } else {
        subdictTenantIdx = new TreeMap<CFAstDomainBasePKey, CFAstDomainBaseBuff>();
        dictByTenantIdx.put(keyTenantIdx, subdictTenantIdx);
    }
    subdictTenantIdx.put(pkey, Buff);

}

From source file:net.sourceforge.fenixedu.presentationTier.Action.administrativeOffice.student.RegistrationDA.java

public ActionForward viewAttends(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request,
        HttpServletResponse response) {//w  ww .  j a  va2s .  c o  m
    RenderUtils.invalidateViewState();

    final Registration registration = getAndSetRegistration(request);
    request.setAttribute("registration", registration);

    if (registration != null) {
        final SortedMap<ExecutionSemester, SortedSet<Attends>> attendsMap = new TreeMap<ExecutionSemester, SortedSet<Attends>>();
        for (final Attends attends : registration.getAssociatedAttendsSet()) {
            final ExecutionSemester executionSemester = attends.getExecutionPeriod();
            SortedSet<Attends> attendsSet = attendsMap.get(executionSemester);
            if (attendsSet == null) {
                attendsSet = new TreeSet<Attends>(Attends.ATTENDS_COMPARATOR);
                attendsMap.put(executionSemester, attendsSet);
            }
            attendsSet.add(attends);
        }
        request.setAttribute("attendsMap", attendsMap);
    }

    return mapping.findForward("viewAttends");
}

From source file:net.sourceforge.msscodefactory.cfgcash.v2_0.CFGCashRam.CFGCashRamURLProtocolTable.java

public void createURLProtocol(CFGCashAuthorization Authorization, CFGCashURLProtocolBuff Buff) {
    CFGCashURLProtocolPKey pkey = schema.getFactoryURLProtocol().newPKey();
    pkey.setRequiredURLProtocolId(Buff.getRequiredURLProtocolId());
    Buff.setRequiredURLProtocolId(pkey.getRequiredURLProtocolId());
    CFGCashURLProtocolByUNameIdxKey keyUNameIdx = schema.getFactoryURLProtocol().newUNameIdxKey();
    keyUNameIdx.setRequiredName(Buff.getRequiredName());

    CFGCashURLProtocolByIsSecureIdxKey keyIsSecureIdx = schema.getFactoryURLProtocol().newIsSecureIdxKey();
    keyIsSecureIdx.setRequiredIsSecure(Buff.getRequiredIsSecure());

    // Validate unique indexes

    if (dictByPKey.containsKey(pkey)) {
        throw CFLib.getDefaultExceptionFactory().newPrimaryKeyNotNewException(getClass(), "createURLProtocol",
                pkey);//ww w .j av a  2 s  .  co m
    }

    if (dictByUNameIdx.containsKey(keyUNameIdx)) {
        throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                "createURLProtocol", "URLProtocolUNameIdx", keyUNameIdx);
    }

    // Validate foreign keys

    // Proceed with adding the new record

    dictByPKey.put(pkey, Buff);

    dictByUNameIdx.put(keyUNameIdx, Buff);

    SortedMap<CFGCashURLProtocolPKey, CFGCashURLProtocolBuff> subdictIsSecureIdx;
    if (dictByIsSecureIdx.containsKey(keyIsSecureIdx)) {
        subdictIsSecureIdx = dictByIsSecureIdx.get(keyIsSecureIdx);
    } else {
        subdictIsSecureIdx = new TreeMap<CFGCashURLProtocolPKey, CFGCashURLProtocolBuff>();
        dictByIsSecureIdx.put(keyIsSecureIdx, subdictIsSecureIdx);
    }
    subdictIsSecureIdx.put(pkey, Buff);

}

From source file:com.bitplan.pdfindex.Pdfindexer.java

/**
 * create the index/*  www . j a v  a 2 s.  com*/
 * @throws Exception -if a problem occurs
 */
protected void doIndex() throws Exception {
    List<DocumentSource> sources = null;
    if ((this.getSource() != null) || (this.getSourceFileList() != null) || this.arguments.size() > 0) {
        sources = createIndex();
        if (this.extract) {
            for (DocumentSource source : sources) {
                PDDocument pdfdoc = source.getDocument();
                if (source.file != null) {
                    PDFTextStripper stripper = new PDFTextStripper();
                    String path = source.file.getPath();
                    String textpath = FilenameUtils.getPath(path) + FilenameUtils.getBaseName(path) + ".txt";
                    System.out.println("extracting text to " + textpath);
                    PrintWriter textWriter = new PrintWriter(new File(textpath));
                    stripper.writeText(pdfdoc, textWriter);
                    textWriter.close();
                }
            }
        }
    }
    // create the main html output
    PrintWriter output = getOutput();
    List<String> words = getSearchWords();
    SortedMap<String, SearchResult> searchResults = new TreeMap<String, SearchResult>();
    for (String word : words) {
        TopDocs topDocs = searchIndex(word, "content", getMaxHits());
        searchResults.put(word, new SearchResult(searcher, topDocs));
    }
    String html = this.getIndexAsHtml(searchResults);
    output.print(html);
    output.flush();
    output.close();
}

From source file:net.sourceforge.msscodefactory.cfgcash.v2_0.CFGCashXMsgRspnHandler.CFGCashXMsgRspnAddressRecHandler.java

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

        assert qName.equals("Address");

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

        ICFGCashSchemaObj 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("AddressId")) {
                if (attrAddressId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrAddressId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("ContactId")) {
                if (attrContactId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrContactId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("Description")) {
                if (attrDescription != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrDescription = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("AddrLine1")) {
                if (attrAddrLine1 != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrAddrLine1 = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("AddrLine2")) {
                if (attrAddrLine2 != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrAddrLine2 = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("City")) {
                if (attrCity != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrCity = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("State")) {
                if (attrState != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrState = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("CountryId")) {
                if (attrCountryId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrCountryId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("Zip")) {
                if (attrZip != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrZip = attrs.getValue(idxAttr);
            } else 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 ((attrAddressId == null) || (attrAddressId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "AddressId");
        }
        if ((attrContactId == null) || (attrContactId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "ContactId");
        }
        if (attrDescription == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "Description");
        }

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

        // Convert string attributes to native Java types

        long natTenantId = Long.parseLong(attrTenantId);

        long natAddressId = Long.parseLong(attrAddressId);

        long natContactId = Long.parseLong(attrContactId);

        String natDescription = attrDescription;

        String natAddrLine1 = attrAddrLine1;

        String natAddrLine2 = attrAddrLine2;

        String natCity = attrCity;

        String natState = attrState;

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

        String natZip = attrZip;

        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
        ICFGCashAddressObj obj = schemaObj.getAddressTableObj().newInstance();
        CFGCashAddressBuff dataBuff = obj.getAddressBuff();
        dataBuff.setRequiredTenantId(natTenantId);
        dataBuff.setRequiredAddressId(natAddressId);
        dataBuff.setRequiredContactId(natContactId);
        dataBuff.setRequiredDescription(natDescription);
        dataBuff.setOptionalAddrLine1(natAddrLine1);
        dataBuff.setOptionalAddrLine2(natAddrLine2);
        dataBuff.setOptionalCity(natCity);
        dataBuff.setOptionalState(natState);
        dataBuff.setOptionalCountryId(natCountryId);
        dataBuff.setOptionalZip(natZip);
        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<CFGCashAddressPKey, ICFGCashAddressObj> sortedMap = (SortedMap<CFGCashAddressPKey, ICFGCashAddressObj>) xmsgRspnHandler
                .getSortedMapOfObjects();
        ICFGCashAddressObj realized = (ICFGCashAddressObj) 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.cfgcash.v2_0.CFGCashXMsgRspnHandler.CFGCashXMsgRspnContactRecHandler.java

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

        assert qName.equals("Contact");

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

        ICFGCashSchemaObj 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("ContactId")) {
                if (attrContactId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrContactId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("ContactListId")) {
                if (attrContactListId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrContactListId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("ISOTimezoneId")) {
                if (attrISOTimezoneId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrISOTimezoneId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("FullName")) {
                if (attrFullName != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrFullName = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("LastName")) {
                if (attrLastName != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrLastName = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("FirstName")) {
                if (attrFirstName != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrFirstName = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("Custom")) {
                if (attrCustom != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrCustom = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("Custom2")) {
                if (attrCustom2 != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrCustom2 = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("Custom3")) {
                if (attrCustom3 != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrCustom3 = attrs.getValue(idxAttr);
            } else 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 ((attrContactId == null) || (attrContactId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "ContactId");
        }
        if ((attrContactListId == null) || (attrContactListId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "ContactListId");
        }
        if (attrFullName == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "FullName");
        }

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

        // Convert string attributes to native Java types

        long natTenantId = Long.parseLong(attrTenantId);

        long natContactId = Long.parseLong(attrContactId);

        long natContactListId = Long.parseLong(attrContactListId);

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

        String natFullName = attrFullName;

        String natLastName = attrLastName;

        String natFirstName = attrFirstName;

        String natCustom = attrCustom;

        String natCustom2 = attrCustom2;

        String natCustom3 = attrCustom3;

        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
        ICFGCashContactObj obj = schemaObj.getContactTableObj().newInstance();
        CFGCashContactBuff dataBuff = obj.getContactBuff();
        dataBuff.setRequiredTenantId(natTenantId);
        dataBuff.setRequiredContactId(natContactId);
        dataBuff.setRequiredContactListId(natContactListId);
        dataBuff.setOptionalISOTimezoneId(natISOTimezoneId);
        dataBuff.setRequiredFullName(natFullName);
        dataBuff.setOptionalLastName(natLastName);
        dataBuff.setOptionalFirstName(natFirstName);
        dataBuff.setOptionalCustom(natCustom);
        dataBuff.setOptionalCustom2(natCustom2);
        dataBuff.setOptionalCustom3(natCustom3);
        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<CFGCashContactPKey, ICFGCashContactObj> sortedMap = (SortedMap<CFGCashContactPKey, ICFGCashContactObj>) xmsgRspnHandler
                .getSortedMapOfObjects();
        ICFGCashContactObj realized = (ICFGCashContactObj) 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);
    }
}