Example #1
0
  public void func_20007_a(Packet102WindowClick packet102windowclick) {
    if (playerEntity.currentCraftingInventory.windowId == packet102windowclick.window_Id
        && playerEntity.currentCraftingInventory.getCanCraft(playerEntity)) {
      ItemStack itemstack =
          playerEntity.currentCraftingInventory.func_27085_a(
              packet102windowclick.inventorySlot,
              packet102windowclick.mouseClick,
              packet102windowclick.field_27039_f,
              playerEntity);
      if (ItemStack.areItemStacksEqual(packet102windowclick.itemStack, itemstack)) {
        playerEntity.playerNetServerHandler.sendPacket(
            new Packet106Transaction(
                packet102windowclick.window_Id, packet102windowclick.action, true));
        playerEntity.isChangingQuantityOnly = true;
        playerEntity.currentCraftingInventory.updateCraftingMatrix();
        playerEntity.updateHeldItem();
        playerEntity.isChangingQuantityOnly = false;
      } else {
        field_10_k.put(
            Integer.valueOf(playerEntity.currentCraftingInventory.windowId),
            Short.valueOf(packet102windowclick.action));
        playerEntity.playerNetServerHandler.sendPacket(
            new Packet106Transaction(
                packet102windowclick.window_Id, packet102windowclick.action, false));
        playerEntity.currentCraftingInventory.setCanCraft(playerEntity, false);
        ArrayList arraylist = new ArrayList();
        for (int i = 0; i < playerEntity.currentCraftingInventory.inventorySlots.size(); i++) {
          arraylist.add(
              ((Slot) playerEntity.currentCraftingInventory.inventorySlots.get(i)).getStack());
        }

        playerEntity.updateCraftingInventory(playerEntity.currentCraftingInventory, arraylist);
      }
    }
  }
Example #2
0
 /**
  * Helper method used to get default value for wrappers used for primitive types (0 for Integer
  * etc)
  *
  * @since 1.6.1
  */
 public static Object defaultValue(Class<?> cls) {
   if (cls == Integer.TYPE) {
     return Integer.valueOf(0);
   }
   if (cls == Long.TYPE) {
     return Long.valueOf(0L);
   }
   if (cls == Boolean.TYPE) {
     return Boolean.FALSE;
   }
   if (cls == Double.TYPE) {
     return Double.valueOf(0.0);
   }
   if (cls == Float.TYPE) {
     return Float.valueOf(0.0f);
   }
   if (cls == Byte.TYPE) {
     return Byte.valueOf((byte) 0);
   }
   if (cls == Short.TYPE) {
     return Short.valueOf((short) 0);
   }
   if (cls == Character.TYPE) {
     return '\0';
   }
   throw new IllegalArgumentException("Class " + cls.getName() + " is not a primitive type");
 }
Example #3
0
 private BasicProcessImage getModscanProcessImage(int slaveId, Map map, DBCollection coll) {
   BasicProcessImage processImage = new BasicProcessImage(slaveId);
   processImage.setAllowInvalidAddress(true);
   processImage.setInvalidAddressValue(Short.valueOf("0"));
   // Add an image listener.
   processImage.addListener(new BasicProcessImageListener());
   return processImage;
 }
 private static Object decode(Class returnType, String valueStr, TypeResolver resolver) {
   if (returnType.isArray()) {
     int sIndex = valueStr.indexOf("{");
     int eIndex = valueStr.lastIndexOf("}");
     String content = valueStr.substring(sIndex + 1, eIndex).trim();
     StringTokenizer tok = new StringTokenizer(content, ",");
     Object ar =
         java.lang.reflect.Array.newInstance(returnType.getComponentType(), tok.countTokens());
     int j = 0;
     while (tok.hasMoreElements()) {
       java.lang.reflect.Array.set(
           ar, j++, decode(returnType.getComponentType(), tok.nextToken(), resolver));
     }
     return ar;
   } else if (returnType.isEnum()) {
     try {
       String value = valueStr.trim();
       if (value.indexOf('.') > 0) {
         value = valueStr.substring(valueStr.lastIndexOf(".") + 1);
       }
       return returnType.getMethod("valueOf", String.class).invoke(null, value);
     } catch (IllegalAccessException e) {
       e.printStackTrace(); // To change body of catch statement use File | Settings | File
       // Templates.
     } catch (InvocationTargetException e) {
       e.printStackTrace(); // To change body of catch statement use File | Settings | File
       // Templates.
     } catch (NoSuchMethodException e) {
       e.printStackTrace(); // To change body of catch statement use File | Settings | File
       // Templates.
     }
   } else if (String.class.equals(returnType)) {
     return unquote(valueStr);
   } else if (boolean.class.equals(returnType)) {
     return Boolean.valueOf(valueStr);
   } else if (int.class.equals(returnType)) {
     return Integer.valueOf(valueStr);
   } else if (double.class.equals(returnType)) {
     return Double.valueOf(valueStr);
   } else if (long.class.equals(returnType)) {
     return Long.valueOf(valueStr);
   } else if (float.class.equals(returnType)) {
     return Float.valueOf(valueStr);
   } else if (short.class.equals(returnType)) {
     return Short.valueOf(valueStr);
   } else if (char.class.equals(returnType)) {
     return unquote(valueStr).charAt(0);
   } else if (Class.class.equals(returnType)) {
     try {
       String cName = valueStr.trim().replace(".class", "");
       return resolver.resolveType(cName);
     } catch (ClassNotFoundException cnfe) {
       cnfe.printStackTrace();
       return Object.class;
     }
   }
   return null;
 }
Example #5
0
  public static List readWatchableObjects(DataInputStream par0DataInputStream) throws IOException {
    ArrayList arraylist = null;

    for (byte byte0 = par0DataInputStream.readByte();
        byte0 != 127;
        byte0 = par0DataInputStream.readByte()) {
      if (arraylist == null) {
        arraylist = new ArrayList();
      }

      int i = (byte0 & 0xe0) >> 5;
      int j = byte0 & 0x1f;
      WatchableObject watchableobject = null;

      switch (i) {
        case 0:
          watchableobject = new WatchableObject(i, j, Byte.valueOf(par0DataInputStream.readByte()));
          break;

        case 1:
          watchableobject =
              new WatchableObject(i, j, Short.valueOf(par0DataInputStream.readShort()));
          break;

        case 2:
          watchableobject =
              new WatchableObject(i, j, Integer.valueOf(par0DataInputStream.readInt()));
          break;

        case 3:
          watchableobject =
              new WatchableObject(i, j, Float.valueOf(par0DataInputStream.readFloat()));
          break;

        case 4:
          watchableobject = new WatchableObject(i, j, Packet.readString(par0DataInputStream, 64));
          break;

        case 5:
          short word0 = par0DataInputStream.readShort();
          byte byte1 = par0DataInputStream.readByte();
          short word1 = par0DataInputStream.readShort();
          watchableobject = new WatchableObject(i, j, new ItemStack(word0, byte1, word1));
          break;

        case 6:
          int k = par0DataInputStream.readInt();
          int l = par0DataInputStream.readInt();
          int i1 = par0DataInputStream.readInt();
          watchableobject = new WatchableObject(i, j, new ChunkCoordinates(k, l, i1));
          break;
      }

      arraylist.add(watchableobject);
    }

    return arraylist;
  }
Example #6
0
 public static Number toWrapper(int i) {
   if (i >= Byte.MIN_VALUE && i <= Byte.MAX_VALUE) {
     return Byte.valueOf((byte) i);
   } else if (i >= Short.MIN_VALUE && i <= Short.MAX_VALUE) {
     return Short.valueOf((short) i);
   } else {
     return Integer.valueOf(i);
   }
 }
Example #7
0
  /**
   * @param fieldName 字段名
   * @param fieldValue 字段值
   * @param o 对象 @Description 根据字段名给对象的字段赋值
   */
  private static void setFieldValueByName(String fieldName, Object fieldValue, Object o)
      throws Exception {
    //        if (fieldName.equals("id") || fieldName.equals("operatorId")) {
    //            return;
    //        }
    Field field = getFieldByName(fieldName, o.getClass());
    if (field != null) {
      field.setAccessible(true);
      // 获取字段类型
      Class<?> fieldType = field.getType();

      // 根据字段类型给字段赋值
      if (String.class == fieldType) {
        field.set(o, String.valueOf(fieldValue));
      } else if (Integer.TYPE == fieldType || Integer.class == fieldType) {
        field.set(o, Integer.valueOf(fieldValue.toString()));
      } else if (Long.TYPE == fieldType || Long.class == fieldType) {
        field.set(o, Long.valueOf(fieldValue.toString()));
      } else if (Float.TYPE == fieldType || Float.class == fieldType) {
        field.set(o, Float.valueOf(fieldValue.toString()));
      } else if (Short.TYPE == fieldType || Short.class == fieldType) {
        field.set(o, Short.valueOf(fieldValue.toString()));
      } else if (Double.TYPE == fieldType || Double.class == fieldType) {
        field.set(o, Double.valueOf(fieldValue.toString()));
      } else if (Character.TYPE == fieldType) {
        if ((fieldValue != null) && (fieldValue.toString().length() > 0)) {
          field.set(o, Character.valueOf(fieldValue.toString().charAt(0)));
        }
      } else if (Date.class == fieldType) {
        String dateStr = fieldValue.toString();
        //                String[] split = dateStr.split("/");
        //                StringBuilder sb = new StringBuilder();
        //                int i = 0;
        //                for (String str : split) {
        //                    if (i == split.length - 1) {
        //                        sb.append("20" + str);
        //                        continue;
        //                    }
        //                    sb.append(str).append("/");
        //                    i++;
        //                }
        //                dateStr = sb.toString();
        SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy HH:mm");
        Date parseDate = formatter.parse(dateStr);
        // Date parseDate = DateUtils.parseDate(fieldValue.toString(), new String[] { "MM/dd/yyyy
        // HH:mm:ss" });
        field.set(o, parseDate);
      } else if (BigDecimal.class == fieldType) {
        field.set(o, new BigDecimal(fieldValue.toString()));
      } else {
        field.set(o, fieldValue);
      }
    } else {
      throw new ExcelException(o.getClass().getSimpleName() + "类不存在字段名" + fieldName);
    }
  }
  // load
  // loads the provided program into memory
  public static void load(Scanner in) {

    int i = 0;
    String code;
    while (in.hasNext()) {
      code = in.next();
      writeMemory((short) i, (byte) (0xFF & Short.valueOf(code, 16)));
      i++;
    }
  }
 /** {@inheritDoc} */
 @SuppressWarnings({"SuspiciousMethodCalls"})
 public boolean retainAll(Collection<?> collection) {
   boolean modified = false;
   TShortIterator iter = iterator();
   while (iter.hasNext()) {
     if (!collection.contains(Short.valueOf(iter.next()))) {
       iter.remove();
       modified = true;
     }
   }
   return modified;
 }
 @Override
 public <T> T next(InstanceType<T> instanceType, FixtureContract fixture) {
   try {
     if (instanceType.isCompatibleWith(Integer.class)) {
       return (T) Integer.valueOf(this.getNextRandom().intValue());
     } else if (instanceType.isCompatibleWith(Short.class)) {
       return (T) Short.valueOf(getNextRandom().shortValue());
     } else if (instanceType.isCompatibleWith(Long.class)) {
       return (T) getNextRandom();
     } else if (instanceType.isCompatibleWith(Byte.class)) {
       return (T) Byte.valueOf(getNextRandom().byteValue());
     } else if (instanceType.isCompatibleWith(Character.class)) {
       return (T)
           Character.valueOf(new String(new byte[] {getNextRandom().byteValue()}).charAt(0));
     }
     return (T) this.getNextRandom();
   } catch (Exception e) {
     throw new ObjectCreationException(instanceType, e);
   }
 }
Example #11
0
 @SuppressWarnings("UnnecessaryBoxing")
 private static Object box(final Object value) {
   Object newBoxedValue;
   if (value instanceof Integer) {
     newBoxedValue = Integer.valueOf(((Integer) value).intValue());
   } else if (value instanceof Byte) {
     newBoxedValue = Byte.valueOf(((Byte) value).byteValue());
   } else if (value instanceof Short) {
     newBoxedValue = Short.valueOf(((Short) value).shortValue());
   } else if (value instanceof Long) {
     newBoxedValue = Long.valueOf(((Long) value).longValue());
   } else if (value instanceof Boolean) {
     newBoxedValue = Boolean.valueOf(((Boolean) value).booleanValue());
   } else if (value instanceof Character) {
     newBoxedValue = Character.valueOf(((Character) value).charValue());
   } else {
     return new Object();
   }
   return newBoxedValue;
 }
  public void handleWindowClick(Packet102WindowClick par1Packet102WindowClick) {
    if (playerEntity.craftingInventory.windowId == par1Packet102WindowClick.window_Id
        && playerEntity.craftingInventory.isPlayerNotUsingContainer(playerEntity)) {
      ItemStack itemstack =
          playerEntity.craftingInventory.slotClick(
              par1Packet102WindowClick.inventorySlot,
              par1Packet102WindowClick.mouseClick,
              par1Packet102WindowClick.holdingShift,
              playerEntity);

      if (ItemStack.areItemStacksEqual(par1Packet102WindowClick.itemStack, itemstack)) {
        playerEntity.serverForThisPlayer.sendPacketToPlayer(
            new Packet106Transaction(
                par1Packet102WindowClick.window_Id, par1Packet102WindowClick.action, true));
        playerEntity.playerInventoryBeingManipulated = true;
        playerEntity.craftingInventory.updateCraftingResults();
        playerEntity.sendInventoryToPlayer();
        playerEntity.playerInventoryBeingManipulated = false;
      } else {
        field_72586_s.addKey(
            playerEntity.craftingInventory.windowId,
            Short.valueOf(par1Packet102WindowClick.action));
        playerEntity.serverForThisPlayer.sendPacketToPlayer(
            new Packet106Transaction(
                par1Packet102WindowClick.window_Id, par1Packet102WindowClick.action, false));
        playerEntity.craftingInventory.setPlayerIsPresent(playerEntity, false);
        ArrayList arraylist = new ArrayList();

        for (int i = 0; i < playerEntity.craftingInventory.inventorySlots.size(); i++) {
          arraylist.add(((Slot) playerEntity.craftingInventory.inventorySlots.get(i)).getStack());
        }

        playerEntity.sendContainerAndContentsToPlayer(playerEntity.craftingInventory, arraylist);
      }
    }
  }
Example #13
0
 private Object createObject(
     Node node, String name, String classPackage, String type, String value, boolean setProperty) {
   Bean parentBean = null;
   if (beansStack.size() > 0) parentBean = (Bean) beansStack.peek();
   Object object = null;
   // param is either an XSD type or a bean,
   // check if it can be converted to an XSD type
   XSDatatype dt = null;
   try {
     dt = DatatypeFactory.getTypeByName(type);
   } catch (DatatypeException dte) {
     // the type is not a valid XSD data type
   }
   // convert null value to default
   if ((dt != null) && (value == null)) {
     Class objType = dt.getJavaObjectType();
     if (objType == String.class) value = "";
     else if ((objType == java.math.BigInteger.class)
         || (objType == Long.class)
         || (objType == Integer.class)
         || (objType == Short.class)
         || (objType == Byte.class)) value = "0";
     else if ((objType == java.math.BigDecimal.class)
         || (objType == Double.class)
         || (objType == Float.class)) value = "0.0";
     else if (objType == Boolean.class) value = "false";
     else if (objType == java.util.Date.class) value = DateUtils.getCurrentDate();
     else if (objType == java.util.Calendar.class) value = DateUtils.getCurrentDateTime();
   }
   //  check whether the type was converted to an XSD datatype
   if ((dt != null) && dt.isValid(value, null)) {
     // create and return an XSD Java object (e.g. String, Integer, Boolean, etc)
     object = dt.createJavaObject(value, null);
     if (object instanceof java.util.Calendar) {
       // check that the object is truly a Calendar
       // because DatatypeFactory converts xsd:date
       // types to GregorianCalendar instead of Date.
       if (type.equals("date")) {
         java.text.DateFormat df = new java.text.SimpleDateFormat("yyyy-MM-dd");
         try {
           object = df.parse(value);
         } catch (java.text.ParseException pe) {
           object = new java.util.Date();
         }
       }
     }
   } else {
     // Create a bean object
     if (topLevelBean == null) topLevelBean = parentBean;
     object = pushBeanOnStack(classPackage, type);
     // Check fields to see if this property is the 'value' for the object
     Field[] fields = object.getClass().getDeclaredFields();
     for (int i = 0; i < fields.length; i++) {
       if (fields[i].isAnnotationPresent(ObjectXmlAsValue.class)) {
         try {
           StringBuffer fieldName = new StringBuffer(fields[i].getName());
           char c = fieldName.charAt(0);
           if (c >= 'a' && c <= 'z') {
             c += 'A' - 'a';
           }
           fieldName.setCharAt(0, c);
           fieldName.insert(0, "set");
           Method method =
               object
                   .getClass()
                   .getMethod(fieldName.toString(), new Class[] {fields[i].getType()});
           method.invoke(object, value);
           break;
         } catch (Exception e) {
           System.err.println(e.getMessage());
         }
       }
     }
     NamedNodeMap nodeAttrs = node.getAttributes();
     // iterate attributes and set field values for property attributes
     for (int i = 0; i < nodeAttrs.getLength(); i++) {
       String nodePrefix = nodeAttrs.item(i).getPrefix();
       if (nodePrefix.equals(nsPrefix)) {
         String nodeName = nodeAttrs.item(i).getLocalName();
         String nodeValue = nodeAttrs.item(i).getNodeValue();
         try {
           Field field = object.getClass().getDeclaredField(nodeName);
           if (field.isAnnotationPresent(ObjectXmlAsAttribute.class)) {
             StringBuffer fieldName = new StringBuffer(field.getName());
             char c = fieldName.charAt(0);
             if (c >= 'a' && c <= 'z') {
               c += 'A' - 'a';
             }
             fieldName.setCharAt(0, c);
             fieldName.insert(0, "set");
             Method method =
                 object.getClass().getMethod(fieldName.toString(), new Class[] {field.getType()});
             if (field.getType() == String.class) method.invoke(object, nodeValue);
             else if (field.getType() == Boolean.TYPE)
               method.invoke(object, StringUtils.strToBool(nodeValue, "true"));
             else if (field.getType() == Byte.TYPE)
               method.invoke(object, Byte.valueOf(nodeValue).byteValue());
             else if (field.getType() == Character.TYPE)
               method.invoke(object, Character.valueOf(nodeValue.charAt(0)));
             else if (field.getType() == Double.TYPE)
               method.invoke(object, Double.valueOf(nodeValue).doubleValue());
             else if (field.getType() == Float.TYPE)
               method.invoke(object, Float.valueOf(nodeValue).floatValue());
             else if (field.getType() == Integer.TYPE)
               method.invoke(object, Integer.valueOf(nodeValue).intValue());
             else if (field.getType() == Long.TYPE)
               method.invoke(object, Long.valueOf(nodeValue).longValue());
             else if (field.getType() == Short.TYPE)
               method.invoke(object, Short.valueOf(nodeValue).shortValue());
           }
         } catch (Exception e) {
           System.err.println(e.getMessage());
         }
       }
     }
   }
   if ((parentBean != null) && (setProperty)) {
     parentBean.setProperty(name, object);
   }
   return object;
 }
Example #14
0
 public static Object wrapAsObject(short i) {
   return Short.valueOf(i);
 }
Example #15
0
  /**
   * This is the main controller logic for item selection servlet. This determines whether to show a
   * list of items for a WorkOrder, add a item, edit a item's detail information, or delete a item.
   * The product_action parameter is past to this servlet to determine what action to perform. The
   * product_action parameter is a button defined by JSPs related to product presentation screens.
   *
   * <p>The default action is to show all product related to a parent WorkOrder.
   *
   * @param req HttpServlet request
   * @param resp HttpServlet response
   */
  public void doPost(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    WorkOrderDetailRemote workorderdetEJBean = null;

    securityChecks(req, resp);

    // Get the current session
    HttpSession session = req.getSession(false);
    if (session == null) return;

    String sTmp = "";

    // Get a new business logic EJB (custInfoEJBean)
    USFEnv.getLog().writeDebug("getting buslogic EJB", this, null);
    try {
      workorderdetEJBean = workorderdetHome.create();
      USFEnv.getLog().writeDebug("EJBean Created", this, null);
    } catch (CreateException e) {
      String errorMsg = "Critical Exception in ItemsServlet";
      USFEnv.getLog().writeCrit(errorMsg + " failed EJB creation", this, e);
      errorJSP(req, resp, errorMsg);
      return;
    } catch (RemoteException e) {
      String errorMsg = "Critical Exception in ItemsServlet";
      USFEnv.getLog().writeCrit(errorMsg + " failed EJB connect", this, e);
      errorJSP(req, resp, errorMsg);
      return;
    } catch (Exception e) {
      String errorMsg = "Critical Exception no EJB created";
      USFEnv.getLog().writeCrit(errorMsg + " failed EJB creation", this, e);
      errorJSP(req, resp, errorMsg);
      return;
    }

    try {

      // Button user pressed in the itemselection.jsp
      String sJSPAction = req.getParameter("product_action");
      USFEnv.getLog().writeWarn("product_action from JSP: " + sJSPAction, this, null);

      short year = Short.valueOf((String) session.getValue("Iyear")).shortValue();
      long customerId = Long.valueOf((String) session.getValue("rcustId")).longValue();
      long applicationId = Long.valueOf((String) session.getValue("rappid")).longValue();
      long workorderId = 0;
      long bkId = 0;
      long billkeyId = 0;
      long bsId = 0;
      long wodId = 0;
      String editflag = "";
      String bsNm = "";

      java.sql.Date strtDate = null;
      java.sql.Date endDate = null;
      String prodError = "";

      // Check to make sure session does have an WorkOrder ID
      if (session.getValue("WorkOrderId") != null) {
        // If Yes get the parent WorkOrder ID from session
        workorderId = Long.valueOf((String) session.getValue("WorkOrderId")).longValue();
      }

      // Button Action from JSP is empty then show the Default page of the
      // Product Listing.
      if (USFUtil.isBlank(sJSPAction)) {
        USFEnv.getLog().writeDebug("Display product list for FRN.", this, null);
        // list items for parent Work Order Number

        Vector billingsystems = null;

        WrkOrdrDets workorderdets = new WrkOrdrDets();

        billingsystems = workorderdets.getBillingSystems();

        req.setAttribute("BillingSystems", billingsystems);

        for (int s = 0; s < billingsystems.size(); s++)
          USFEnv.getLog()
              .writeDebug("INSIDE BILLING SYSTEMS " + billingsystems.elementAt(s), this, null);

        listProducts(workorderId, workorderdetEJBean, session, req, resp);
        return;
      }

      // Button action from JSP is to Add a new Item
      else if (sJSPAction.equals("add")) {
        // Remove the Product Object from session
        session.removeValue("prodObj");

        editflag = "addnew";
        req.setAttribute("editflag", editflag);

        // Read the Item and the Billing System for adding the New
        // Item.
        String formProdBsId = (String) req.getParameter("formProdId");
        String formProdId = formProdBsId.substring(0, formProdBsId.indexOf("|"));
        String formProdName = formProdBsId.substring(formProdBsId.indexOf("|") + 1);
        long rscId = (new Long(formProdId).longValue());
        // bsId = (new Long( formBsId ).longValue()) ;
        String billSystem = formProdName.substring(0, formProdName.indexOf("-"));
        String itemName = formProdName.substring(formProdName.indexOf("-") + 1);

        BlgSys blgSys = new BlgSys();
        bsId = blgSys.getBsId(billSystem);

        // Create db connection for EJB
        workorderdetEJBean.connect();

        // Get the WorkOrder Object.
        WorkOrder woObj = workorderdetEJBean.getWorkOrderInfo(workorderId);

        // Get the list of Billing Keys for the Billing System.
        String[] blgKeys = workorderdetEJBean.getBillingKeys(customerId, bsId);

        // Release db connection for EJB
        workorderdetEJBean.release();

        // If no Billing Keys for the Billing System selected then redirect
        // to the List Items screen and show the error Message.
        if (blgKeys == null) {
          BlgSys blgsys = new BlgSys();
          Hashtable bSysList = (Hashtable) blgsys.searchBlgSys();
          //	Hashtable bSysList = (Hashtable) USFEnv.getBillSystems();

          // Set the JSP error message
          req.setAttribute("errorMsg", "No BTNs for Billing System " + billSystem);

          // list products for parent WorkOrder Number
          listProducts(workorderId, workorderdetEJBean, session, req, resp);
          return;
        }

        req.setAttribute("prodcredit", "N");
        req.setAttribute("bsystem", String.valueOf(bsId));
        req.setAttribute("bkList", blgKeys);
        req.setAttribute("prodId", formProdId);
        String wid = String.valueOf(workorderId);

        session.putValue("workorderId", wid);

        req.setAttribute("billingsystem", billSystem);

        req.setAttribute("itemname", itemName);

        // Include the JSP to Edit Product
        includeJSP(req, resp, ITEM_JSP_PATH, "editItem");
        return;
      }

      // Button action from JSP is to Edit a Product
      else if (sJSPAction.equals("edit")) {
        String bsysid = req.getParameter("bsId");
        session.putValue("bysysidforedit", bsysid);

        wodId = (new Long((String) req.getParameter("wodId"))).longValue();
        // bkId = (new Long( (String) req.getParameter("bkId"))).longValue() ;

        session.putValue("workorderdetid", String.valueOf(wodId));

        bsId = (new Long((String) req.getParameter("bsId"))).longValue();

        BlgSys blgSys = new BlgSys();
        bsNm = blgSys.getBsName(bsId);

        // Create db connection for EJB
        workorderdetEJBean.connect();

        // WorkOrder woObj = workorderdetEJBean.getWorkOrderInfo(workorderId);

        // Get the WorkOrder Number Object
        WrkOrdrDets wodets_obj = new WrkOrdrDets();
        wodets_obj = workorderdetEJBean.getProductInfo(wodId);

        // Get the List of Billing Keys for the Billing System.
        String[] blgKeys = workorderdetEJBean.getBillingKeys(customerId, bsId);

        // Check if the Item has any Credits. If any credits then Billing
        // Key is not Editable else Editable.
        if (workorderdetEJBean.hasCredits(wodId)) {
          req.setAttribute("prodcredit", "Y");
        } else {
          req.setAttribute("prodcredit", "N");
        }

        // Release db connection for EJB
        workorderdetEJBean.release();

        // If Item Object is not null (which generally is the case) then
        // set the Attributes for the JSP.
        if (wodets_obj != null) {
          // Put the Item Object in session
          editflag = "edit";
          session.putValue("wodets", wodets_obj);
          req.setAttribute("editflag", editflag);

          // Set the attributes for the Billing System, Billing Key List,
          req.setAttribute("bkList", blgKeys);
          req.setAttribute("bsname", bsNm);

          // Include the JSP to Edit the Item.
          includeJSP(req, resp, ITEM_JSP_PATH, "editItem");
          return;
        }

        // If Item Object is null (which generally should not Occur) show
        // the Default page of Item List for the WorkOrder Number
        else {
          // Set the JSP error message
          req.setAttribute(
              "errorMsg", "Product Key - " + wodId + " Information not available in the Data Base");

          // list items for parent WorkOrder Number
          listProducts(workorderId, workorderdetEJBean, session, req, resp);
          return;
        }

      }

      // Button action from JSP is to Delete an Item
      else if (sJSPAction.equals("delete")) {
        String formWodId = req.getParameter("wodId");

        wodId = (new Long((String) req.getParameter("wodId"))).longValue();

        // Create db connection for EJB
        workorderdetEJBean.connect();

        // Delete the Item
        if (workorderdetEJBean.deleteProduct(wodId)) {
          req.setAttribute("errorMsg", "Product Key - " + wodId + " Deleted");
        } else {
          req.setAttribute(
              "errorMsg",
              "Deletion Failed. Product Key - " + wodId + " is associated with amounts.");
        }
        // Release db connection for EJB
        workorderdetEJBean.release();

        // Show the Item List screen
        listProducts(workorderId, workorderdetEJBean, session, req, resp);
        return;

      }

      // Button action from JSP is to Save a Product. This includes Insertion
      // of New Product or Updation of an Existing Product.

      else if (sJSPAction.equals("save")) {
        boolean save = false;
        boolean newProd = false;
        // long qty=0;

        // Read the Billing System Id
        String formBsId = (String) req.getParameter("bs_id");

        String bsysid = (String) req.getParameter("bsysid");
        /*
        String trans_type = (String) req.getParameter("trans_type");

        //String quantity = (String) req.getParameter("qty");
        String quantity="";
        if (!(req.getParameter("qty").equals("")))
        {
        	quantity=(String) req.getParameter("qty");

        	qty = (new Long(quantity).longValue());
        } */
        String prod_stat = (String) req.getParameter("prod_stat");

        double nrcg_dscnt =
            (new Double((String) req.getParameter("NonRecurringDiscount"))).doubleValue();

        double rcg_dscnt =
            (new Double((String) req.getParameter("RecurringDiscount"))).doubleValue();

        String start_month = (String) req.getParameter("strt_month");
        String start_day = (String) req.getParameter("strt_day");
        String start_year = (String) req.getParameter("strt_year");
        String end_month = (String) req.getParameter("end_month");
        String end_day = (String) req.getParameter("end_day");
        String end_year = (String) req.getParameter("end_year");

        String start_date = start_month + "-" + start_day + "-" + start_year;

        String end_date = end_month + "-" + end_day + "-" + end_year;

        long wrkordrid = (new Long((String) session.getValue("WorkOrderId"))).longValue();

        String for_editing = req.getParameter("for_editing");
        String for_new = req.getParameter("for_new");

        String formBkId = (String) req.getParameter("bk_id");

        String formBKId = formBkId.substring(0, formBkId.indexOf("|"));

        String formBTN = formBkId.substring(formBkId.indexOf("|") + 1);

        billkeyId = (new Long(formBKId)).longValue();

        try {
          bsId = (new Long((String) req.getParameter("bs_id"))).longValue();
        } catch (Exception e) {
          USFEnv.getLog().writeDebug("Exception is " + e, this, null);
        }

        RHCCBlgKeys blgkeys = new RHCCBlgKeys();

        if (for_editing.equals("editing")) {
          blgkeys.setRbkId(billkeyId);
          blgkeys.setRbkKeys(formBTN);
          blgkeys.setBsId(new Long(bsysid).longValue());
        }

        if (for_new.equals("new")) {
          blgkeys.setRbkId(billkeyId);
          blgkeys.setRbkKeys(formBTN);
          blgkeys.setBsId(bsId);
        }

        int index = 0;

        WrkOrdrDets wod_obj = new WrkOrdrDets();

        // wod_obj.setTxTyp(trans_type);
        // wod_obj.setQty(qty);
        wod_obj.setNonRcrgDscnt(nrcg_dscnt);
        wod_obj.setRcrgDscnt(rcg_dscnt);
        wod_obj.setRBKID(billkeyId);
        wod_obj.setWodStat(prod_stat);
        wod_obj.setWOID(wrkordrid);

        if (!(start_date.equals(""))) {
          strtDate =
              new java.sql.Date((new SimpleDateFormat("MM-dd-yyyy")).parse(start_date).getTime());
          wod_obj.setStrtDat(strtDate);
        }
        // Else if the Start Date is null update the Item Object Date to
        // null
        else {
          wod_obj.setStrtDat(null);
        }

        // If Item Service End Date is not null read the date and update
        // the Item Object with the date
        if (!(end_date.equals(""))) {
          endDate =
              new java.sql.Date((new SimpleDateFormat("MM-dd-yyyy")).parse(end_date).getTime());
          wod_obj.setEndDat(endDate);
        }
        // Else if the End Date is null update the Item Object Date to null
        else {
          wod_obj.setEndDat(null);
        }

        // Check if the Start Date is after the End Date or equals End Date
        if ((strtDate != null) && (endDate != null) && (strtDate.after(endDate))) {
          prodError = "Product Service Start Date is after Product Service End Date. \n";
          index = 1;
        } else if ((strtDate != null) && (endDate != null) && (strtDate.equals(endDate))) {
          prodError = "Product Service Start Date equals Product Service End Date. \n";
        }

        workorderdetEJBean.connect();

        if (for_editing.equals("editing")) {
          long workorderdetID = (new Long((String) session.getValue("workorderdetid"))).longValue();
          wod_obj.setWODID(workorderdetID);

          if (index == 0) {
            save = workorderdetEJBean.saveProduct(wod_obj);
          }

          if (save) {
            prodError =
                prodError + "<BR> Product Key - " + wod_obj.getWODID() + " Information updated";
            req.setAttribute("error", prodError);
          } else {
            prodError = prodError + "<BR> Failed to update Product Information";
            req.setAttribute("error", prodError);
          }
        }

        if (for_new.equals("new")) {
          if (index == 0) {
            int prodId = Integer.parseInt(req.getParameter("prod_Id"));
            wod_obj.setProd_id(prodId);
            save = workorderdetEJBean.saveProduct(wod_obj);
          }

          if (save) {
            prodError =
                prodError + "<BR> Product Key - " + wod_obj.getWODID() + " Information Saved";
            req.setAttribute("error", prodError);
          } else {
            prodError = prodError + "<BR> Failed to Save Product Information";
            req.setAttribute("error", prodError);
          }
        }

        workorderdetEJBean.release();

        listProducts(wrkordrid, workorderdetEJBean, session, req, resp);
      }

    } // End of try block
    catch (Exception e) {
      if (workorderdetEJBean != null) {
        // calling bean release method
        try {
          workorderdetEJBean.release();
        } catch (Exception ex) {
          USFEnv.getLog().writeCrit(" Exception in calling release() method ", this, e);
        }
      }
      String errorMsg = "Processing Exception in Items Servlet: ";
      USFEnv.getLog().writeCrit(errorMsg, this, e);
      errorJSP(req, resp, errorMsg);
    } // End of catch block
  } // end of doPost()
Example #16
0
  /** Read a {@link Writable}, {@link String}, primitive type, or an array of the preceding. */
  @SuppressWarnings("unchecked")
  public static Object readObject(DataInput in, ObjectWritable objectWritable, Configuration conf)
      throws IOException {
    String className = UTF8.readString(in);
    Class<?> declaredClass = PRIMITIVE_NAMES.get(className);
    if (declaredClass == null) {
      declaredClass = loadClass(conf, className);
    }

    Object instance;

    if (declaredClass.isPrimitive()) { // primitive types

      if (declaredClass == Boolean.TYPE) { // boolean
        instance = Boolean.valueOf(in.readBoolean());
      } else if (declaredClass == Character.TYPE) { // char
        instance = Character.valueOf(in.readChar());
      } else if (declaredClass == Byte.TYPE) { // byte
        instance = Byte.valueOf(in.readByte());
      } else if (declaredClass == Short.TYPE) { // short
        instance = Short.valueOf(in.readShort());
      } else if (declaredClass == Integer.TYPE) { // int
        instance = Integer.valueOf(in.readInt());
      } else if (declaredClass == Long.TYPE) { // long
        instance = Long.valueOf(in.readLong());
      } else if (declaredClass == Float.TYPE) { // float
        instance = Float.valueOf(in.readFloat());
      } else if (declaredClass == Double.TYPE) { // double
        instance = Double.valueOf(in.readDouble());
      } else if (declaredClass == Void.TYPE) { // void
        instance = null;
      } else {
        throw new IllegalArgumentException("Not a primitive: " + declaredClass);
      }

    } else if (declaredClass.isArray()) { // array
      int length = in.readInt();
      instance = Array.newInstance(declaredClass.getComponentType(), length);
      for (int i = 0; i < length; i++) {
        Array.set(instance, i, readObject(in, conf));
      }

    } else if (declaredClass == String.class) { // String
      instance = UTF8.readString(in);
    } else if (declaredClass.isEnum()) { // enum
      instance = Enum.valueOf((Class<? extends Enum>) declaredClass, UTF8.readString(in));
    } else { // Writable
      Class instanceClass = null;
      String str = UTF8.readString(in);
      instanceClass = loadClass(conf, str);

      Writable writable = WritableFactories.newInstance(instanceClass, conf);
      writable.readFields(in);
      instance = writable;

      if (instanceClass == NullInstance.class) { // null
        declaredClass = ((NullInstance) instance).declaredClass;
        instance = null;
      }
    }

    if (objectWritable != null) { // store values
      objectWritable.declaredClass = declaredClass;
      objectWritable.instance = instance;
    }

    return instance;
  }
 /**
  * Wraps a value
  *
  * @param k value in the underlying map
  * @return an Object representation of the value
  */
 protected Short wrapValue(short k) {
   return Short.valueOf(k);
 }
Example #18
0
 public static String format(short value, String format) {
   return NumberUtils.format(Short.valueOf(value), format);
 }
Example #19
0
  /**
   * Primary Constructor
   *
   * @param parmObjTypes The object instances of the classes containing command line parsing
   *     annotations. Non-null. Non-empty.
   * @param args
   * @param prefix
   */
  public JCommanderModule(Collection<Class<?>> parmObjTypes, String[] args, String prefix) {
    checkNotNull(parmObjTypes);
    checkNotNull(args);
    checkNotNull(prefix);
    checkArgument(!parmObjTypes.isEmpty());
    checkArgument(args.length != 0);

    this.parmObjTypes.addAll(parmObjTypes);
    this.args = args;
    this.prefix = prefix;

    /*
     * Populate the binding functions
     */

    bindingFxns.put(
        int.class,
        (name, val) ->
            bindConstant().annotatedWith(named((String) name)).to(Integer.valueOf((int) val)));
    bindingFxns.put(
        byte.class,
        (name, val) ->
            bindConstant().annotatedWith(named((String) name)).to(Byte.valueOf((byte) val)));
    bindingFxns.put(
        long.class,
        (name, val) ->
            bindConstant().annotatedWith(named((String) name)).to(Long.valueOf((long) val)));
    bindingFxns.put(
        short.class,
        (name, val) ->
            bindConstant().annotatedWith(named((String) name)).to(Short.valueOf((short) val)));
    bindingFxns.put(
        float.class,
        (name, val) ->
            bindConstant().annotatedWith(named((String) name)).to(Float.valueOf((float) val)));
    bindingFxns.put(
        double.class,
        (name, val) ->
            bindConstant().annotatedWith(named((String) name)).to(Double.valueOf((double) val)));
    bindingFxns.put(
        char.class,
        (name, val) ->
            bindConstant().annotatedWith(named((String) name)).to(Character.valueOf((char) val)));
    bindingFxns.put(
        boolean.class,
        (name, val) ->
            bindConstant().annotatedWith(named((String) name)).to(Boolean.valueOf((boolean) val)));

    bindingFxns.put(
        Integer.class,
        (name, val) -> bindConstant().annotatedWith(named((String) name)).to((Integer) val));
    bindingFxns.put(
        Byte.class,
        (name, val) -> bindConstant().annotatedWith(named((String) name)).to((Byte) val));
    bindingFxns.put(
        Long.class,
        (name, val) -> bindConstant().annotatedWith(named((String) name)).to((Long) val));
    bindingFxns.put(
        Short.class,
        (name, val) -> bindConstant().annotatedWith(named((String) name)).to((Short) val));
    bindingFxns.put(
        Float.class,
        (name, val) -> bindConstant().annotatedWith(named((String) name)).to((Float) val));
    bindingFxns.put(
        Double.class,
        (name, val) -> bindConstant().annotatedWith(named((String) name)).to((Double) val));
    bindingFxns.put(
        Character.class,
        (name, val) -> bindConstant().annotatedWith(named((String) name)).to((Character) val));
    bindingFxns.put(
        Boolean.class,
        (name, val) -> bindConstant().annotatedWith(named((String) name)).to((Boolean) val));
    bindingFxns.put(
        String.class,
        (name, val) -> bindConstant().annotatedWith(named((String) name)).to((String) val));

    bindingFxns.put(
        File.class,
        (name, val) ->
            bindConstant().annotatedWith(named((String) name)).to(((File) val).getAbsolutePath()));
    bindingFxns.put(
        Path.class,
        (name, val) ->
            bindConstant().annotatedWith(named((String) name)).to(((Path) val).toString()));
    bindingFxns.put(
        URL.class,
        (name, val) ->
            bindConstant().annotatedWith(named((String) name)).to(((URL) val).getFile()));

    bindingFxns.put(
        LocalDate.class,
        (name, val) ->
            bindConstant().annotatedWith(named((String) name)).to(((LocalDate) val).toString()));
    bindingFxns.put(
        LocalDateTime.class,
        (name, val) ->
            bindConstant()
                .annotatedWith(named((String) name))
                .to(((LocalDateTime) val).toString()));
    bindingFxns.put(
        LocalTime.class,
        (name, val) ->
            bindConstant().annotatedWith(named((String) name)).to(((LocalTime) val).toString()));

    bindingFxnsForGenerics.put(
        new TypeLiteral<List<String>>() {},
        (name, val) ->
            bind(new TypeLiteral<List<String>>() {})
                .annotatedWith(named((String) name))
                .toInstance((List<String>) val));
    bindingFxnsForGenerics.put(
        new TypeLiteral<Set<String>>() {},
        (name, val) ->
            bind(new TypeLiteral<Set<String>>() {})
                .annotatedWith(named((String) name))
                .toInstance((Set<String>) val));
  }
Example #20
0
 public static Short asShort(Object value) {
   if (value == null) return null;
   if (value instanceof Number) return ((Number) value).shortValue();
   return Short.valueOf(value.toString());
 }