Example usage for java.lang InstantiationException setStackTrace

List of usage examples for java.lang InstantiationException setStackTrace

Introduction

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

Prototype

public void setStackTrace(StackTraceElement[] stackTrace) 

Source Link

Document

Sets the stack trace elements that will be returned by #getStackTrace() and printed by #printStackTrace() and related methods.

Usage

From source file:org.kuali.kpme.tklm.leave.accrual.bucket.KPMEAccrualCategoryBucket.java

public void initialize(PrincipalHRAttributesBo currentPrincipalCalendar) throws InstantiationException,
        IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    leaveBalances = new LinkedHashMap<String, List<LeaveBalance>>();
    principalCalendar = currentPrincipalCalendar;
    asOfDate = LocalDate.now();/* ww  w  .j a va 2  s . com*/
    List<AccrualCategory> accrualCategories = HrServiceLocator.getAccrualCategoryService()
            .getActiveAccrualCategoriesForLeavePlan(currentPrincipalCalendar.getLeavePlan(), asOfDate);
    for (AccrualCategory accrualCategory : accrualCategories) {
        List<LeaveBalance> leaveBalances = new ArrayList<LeaveBalance>();
        for (Class<LeaveBalance> leaveBalanceClazz : baseBalanceList) {
            Constructor<?>[] constructors = leaveBalanceClazz.getConstructors();
            //does this array contain default constructors as well??
            Object[] args = new Object[2];
            args[0] = accrualCategory;
            args[1] = principalCalendar;
            Constructor<?> constructor = constructors[0];
            LeaveBalance myLeaveBalance = (LeaveBalance) constructor.newInstance(args);
            leaveBalances.add(myLeaveBalance);
        }
        this.leaveBalances.put(accrualCategory.getLmAccrualCategoryId(), leaveBalances);
    }
    //This list *could* contain leave blocks for accrual categories that have been deactivated, those from another leave plan, etc
    List<LeaveBlock> leaveBlocks = LmServiceLocator.getLeaveBlockService().getLeaveBlocksSinceCarryOver(
            currentPrincipalCalendar.getPrincipalId(), LmServiceLocator.getLeaveBlockService()
                    .getLastCarryOverBlocks(currentPrincipalCalendar.getPrincipalId(), asOfDate),
            LocalDate.now().plusDays(365), true);

    //These maps could also contain such accrual categories within their keyset.
    Map<String, LeaveBlock> carryOverBlocks = LmServiceLocator.getLeaveBlockService()
            .getLastCarryOverBlocks(currentPrincipalCalendar.getPrincipalId(), asOfDate);
    Map<String, List<LeaveBlock>> accrualCategoryMappedLeaveBlocks = mapLeaveBlocksByAccrualCategory(
            leaveBlocks);
    //merge carryOverBlock map with accrualCategoryMappedLeaveBlocks.
    for (Entry<String, LeaveBlock> entry : carryOverBlocks.entrySet()) {
        if (accrualCategoryMappedLeaveBlocks.containsKey(entry.getKey()))
            accrualCategoryMappedLeaveBlocks.get(entry.getKey()).add(entry.getValue());
        else {
            List<LeaveBlock> carryOverList = new ArrayList<LeaveBlock>();
            carryOverList.add(entry.getValue());
            accrualCategoryMappedLeaveBlocks.put(entry.getKey(), carryOverList);
        }
    }
    //add leave blocks, accrual category by accrual category, to bucket.
    for (Entry<String, List<LeaveBlock>> entry : accrualCategoryMappedLeaveBlocks.entrySet()) {
        for (LeaveBlock leaveBlock : entry.getValue()) {
            try {
                addLeaveBlock(leaveBlock);
            } catch (KPMEBalanceException e) {
                InstantiationException ie = new InstantiationException();
                ie.setStackTrace(e.getStackTrace());
                throw ie;
            }
        }
    }
}

From source file:org.kuali.kpme.tklm.leave.accrual.bucket.KPMEAccrualCategoryBucket.java

private void adjustBalances(CalendarEntry calendarEntry, DateTime rolloverDate, Set<String> assignmentKeys)
        throws KPMEBalanceException {

    //fetch calendar entries in this sequence belonging to the current leave year.
    String dateString = TKUtils.formatDate(LocalDate.now());
    List<CalendarEntry> calendarEntries = HrServiceLocator.getCalendarEntryService()
            .getAllCalendarEntriesForCalendarIdAndYear(calendarEntry.getHrCalendarId(),
                    dateString.substring(6, 10));

    //calendar change into a different leave calendar year
    if (rolloverDate != null) {

        //clear all balances.
        clearLeaveBalances();//w w w .  j a  v  a 2s. com

        //reset the asOfDate this bucket will go off of, as well as those of the leave balances
        adjustAsOfDates(calendarEntry, calendarEntries);

        //TODO: if in current calendar year, use current date + planning months for extent of fetch.
        List<LeaveBlock> leaveBlocks = LmServiceLocator.getLeaveBlockService().getLeaveBlocksSinceCarryOver(
                principalCalendar.getPrincipalId(),
                LmServiceLocator.getLeaveBlockService().getLastCarryOverBlocks(
                        principalCalendar.getPrincipalId(), rolloverDate.minusDays(1).toLocalDate()),
                rolloverDate.plusDays(365).toLocalDate(), true);

        //retrieve (if any) last carryover blocks given the new asOfDate
        Map<String, LeaveBlock> carryOverBlocks = LmServiceLocator.getLeaveBlockService()
                .getLastCarryOverBlocks(principalCalendar.getPrincipalId(), asOfDate);

        //method taken from leave summary service - map general leave block fetch by accrual category
        Map<String, List<LeaveBlock>> accrualCategoryMappedLeaveBlocks = mapLeaveBlocksByAccrualCategory(
                leaveBlocks);

        //merge carryOverBlock map with accrualCategoryMappedLeaveBlocks.
        for (Entry<String, LeaveBlock> entry : carryOverBlocks.entrySet()) {
            //TODO: modify CarryOverLeaveBalance to identify and make use of CARRY_OVER type leave block
            if (accrualCategoryMappedLeaveBlocks.containsKey(entry.getKey()))
                accrualCategoryMappedLeaveBlocks.get(entry.getKey()).add(entry.getValue());
            else {
                List<LeaveBlock> carryOverList = new ArrayList<LeaveBlock>();
                carryOverList.add(entry.getValue());
                accrualCategoryMappedLeaveBlocks.put(entry.getKey(), carryOverList);
            }

        }
        //add leave blocks, accrual category by accrual category, to this bucket.
        for (Entry<String, List<LeaveBlock>> entry : accrualCategoryMappedLeaveBlocks.entrySet()) {
            for (LeaveBlock leaveBlock : entry.getValue()) {
                try {
                    addLeaveBlock(leaveBlock);
                } catch (KPMEBalanceException e) {
                    InstantiationException ie = new InstantiationException();
                    ie.setStackTrace(e.getStackTrace());
                    ie.printStackTrace();
                }
            }
        }
    } else {
        //Calendar change within the same leave year.

        List<String> assignmentKeyList = new ArrayList<String>();
        assignmentKeyList.addAll(assignmentKeys);

        List<LeaveBlock> leaveBlocks = new ArrayList<LeaveBlock>();

        //determine which leave blocks are affected by the calendar change, remove them, and re-add them under the new asOfDate
        if (calendarEntry.getEndPeriodFullDateTime()
                .isBefore(viewingCalendarEntry.getEndPeriodFullDateTime().getMillis())) {
            //need to remove leave blocks from otherLeaveCalendarDocument begin date to thisLeaveCalendarDocument end date
            leaveBlocks = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(
                    principalCalendar.getPrincipalId(),
                    calendarEntry.getBeginPeriodFullDateTime().toLocalDate(),
                    viewingCalendarEntry.getEndPeriodFullDateTime().toLocalDate());
            //leaveBlocks = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForLeaveCalendar(principalCalendar.getPrincipalId(), LocalDate.fromDateFields(calendarEntry.getBeginPeriodDateTime()), LocalDate.fromDateFields(viewingCalendarEntry.getEndPeriodDateTime()), assignmentKeyList);
        } else {
            //need to remove leave blocks from thisLeaveCalendarDocument begin date to otherLeaveCalendarDocument end date
            leaveBlocks = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(
                    principalCalendar.getPrincipalId(),
                    viewingCalendarEntry.getBeginPeriodFullDateTime().toLocalDate(),
                    calendarEntry.getEndPeriodFullDateTime().toLocalDate());
            //leaveBlocks = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForLeaveCalendar(principalCalendar.getPrincipalId(), LocalDate.fromDateFields(viewingCalendarEntry.getBeginPeriodDateTime()), LocalDate.fromDateFields(calendarEntry.getEndPeriodDateTime()), assignmentKeyList);
        }
        //remove affected leave blocks
        for (LeaveBlock block : leaveBlocks) {
            removeLeaveBlock(block);
        }

        //update this bucket and its leave balances with new relative date information
        LocalDate newAsOfDate = null;
        DateTime currentLeavePlanStartDate = HrServiceLocator.getLeavePlanService()
                .getFirstDayOfLeavePlan(principalCalendar.getLeavePlan(), LocalDate.now());
        if (calendarEntry.getEndPeriodFullDateTime().isBefore(currentLeavePlanStartDate)) {
            //require balances as of the final day of the leave calendar year.
            DateTime calendarEntryLeavePlanRolloverDate = HrServiceLocator.getLeavePlanService()
                    .getRolloverDayOfLeavePlan(principalCalendar.getLeavePlan(),
                            calendarEntry.getEndPeriodFullDateTime().toLocalDate());
            newAsOfDate = LocalDate.fromDateFields(calendarEntryLeavePlanRolloverDate.toDate()).minusDays(1);
        } else {
            Interval interval = new Interval(calendarEntry.getBeginPeriodFullDateTime(),
                    calendarEntry.getEndPeriodFullDateTime());
            if (interval.contains(LocalDate.now().toDate().getTime())) {
                newAsOfDate = LocalDate.now();
            } else if (calendarEntry.getBeginPeriodFullDateTime().toLocalDate().isBefore(LocalDate.now()))
                newAsOfDate = calendarEntry.getEndPeriodFullDateTime().toLocalDate().minusDays(1);
            else // if it's in the calendar interval above, the equals case is taken care of, begin date must be after today
                newAsOfDate = calendarEntry.getBeginPeriodFullDateTime().toLocalDate().minusDays(1);
        }

        asOfDate = newAsOfDate;

        for (Entry<String, List<LeaveBalance>> leaveBalance : leaveBalances.entrySet()) {
            for (LeaveBalance balance : leaveBalance.getValue()) {
                balance.calendarPeriodBeginDate = calendarEntry.getBeginPeriodFullDateTime().toLocalDate();
                balance.calendarPeriodEndDate = calendarEntry.getEndPeriodFullDateTime().toLocalDate();
                balance.asOfDate = newAsOfDate;
            }
        }
        //re-add the affected leave blocks under the new date / calendar information
        for (LeaveBlock block : leaveBlocks) {
            addLeaveBlock(block);
        }
    }
}

From source file:org.nuxeo.opensocial.servlet.GuiceContextListener.java

private Module getModuleInstance(String moduleName) throws InstantiationException {
    try {/*  w w  w  .ja va 2 s .  com*/
        return (Module) Class.forName(moduleName).newInstance();
    } catch (IllegalAccessException e) {
        InstantiationException ie = new InstantiationException("IllegalAccessException: " + e.getMessage());
        ie.setStackTrace(e.getStackTrace());
        throw ie;
    } catch (ClassNotFoundException e) {
        InstantiationException ie = new InstantiationException("ClassNotFoundException: " + e.getMessage());
        ie.setStackTrace(e.getStackTrace());
        throw ie;
    }
}