Example usage for java.lang Short Short

List of usage examples for java.lang Short Short

Introduction

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

Prototype

@Deprecated(since = "9")
public Short(String s) throws NumberFormatException 

Source Link

Document

Constructs a newly allocated Short object that represents the short value indicated by the String parameter.

Usage

From source file:com.espertech.esper.regression.expr.TestBitWiseOperators.java

private void runBitWiseOperators() {
    sendEvent(FIRST_EVENT, new Byte(FIRST_EVENT), SECOND_EVENT, new Short(SECOND_EVENT), FIRST_EVENT,
            new Integer(THIRD_EVENT), 3L, new Long(FOURTH_EVENT), FITH_EVENT, new Boolean(FITH_EVENT));

    EventBean received = listener.getAndResetLastNewData()[0];
    assertEquals((byte) 1, (received.get("myFirstProperty")));
    assertTrue(((Short) (received.get("mySecondProperty")) & SECOND_EVENT) == SECOND_EVENT);
    assertTrue(((Integer) (received.get("myThirdProperty")) & FIRST_EVENT) == FIRST_EVENT);
    assertEquals(7L, (received.get("myFourthProperty")));
    assertEquals(false, (received.get("myFifthProperty")));
}

From source file:com.workday.autoparse.json.demo.JsonParserTest.java

private void testParse(String fileName) throws Exception {
    TestObject testObject = (TestObject) parser.parseJsonStream(getInputStream(fileName));
    assertNotNull("testObject", testObject);

    assertEquals("testObject.discriminationValue", "testObject", testObject.discriminationValue);
    assertEquals("testObject.superDiscriminationValue", "testObject", testObject.superDiscriminationValue);

    // Basic Types
    assertTrue("testObject.myBoolean", testObject.myBoolean);
    assertEquals("testObject.myByte", (byte) 65, testObject.myByte);
    assertEquals("testObject.myChar", 'c', testObject.myChar);
    assertEquals("testObject.myDouble", 12.34, testObject.myDouble, ERROR);
    assertEquals("testObject.myFloat", 123.45f, testObject.myFloat, ERROR);
    assertEquals("testObject.myInt", 12, testObject.myInt);
    assertEquals("testObject.myLong", 123456, testObject.myLong);
    assertEquals("testObject.myShort", 17, testObject.myShort);

    assertTrue("testObject.myBoxedBoolean", testObject.myBoxedBoolean);
    assertEquals("testObject.myBoxedByte", Byte.valueOf("63"), testObject.myBoxedByte);
    assertEquals("testObject.myBoxedChar", Character.valueOf('d'), testObject.myBoxedChar);
    assertEquals("testObject.myBoxedDouble", Double.valueOf("12.345"), testObject.myBoxedDouble);
    assertEquals("testObject.myBoxedFloat", Float.valueOf("123.456"), testObject.myBoxedFloat);
    assertEquals("testObject.myBoxedInt", Integer.valueOf("123"), testObject.myBoxedInt);
    assertEquals("testObject.myBoxedLong", Long.valueOf(1234567), testObject.myBoxedLong);
    assertEquals("testObject.myBoxedShort", new Short("18"), testObject.myBoxedShort);

    assertEquals("testObject.myString", "hello", testObject.myString);
    assertEquals("testObject.myBigDecimal", new BigDecimal("123456789.0123456789"), testObject.myBigDecimal);
    assertEquals("testObject.myBigInteger", new BigInteger("1234567891011"), testObject.myBigInteger);
    assertEquals("testObject.overriddenThing", 123, testObject.overriddenThing);
    assertNull("testObject.superOverriddenThing", testObject.superOverriddenThing);

    // Maps//www.j  ava 2  s  .  c  o m
    assertNotNull("testObject.myStringMap", testObject.myStringMap);
    assertEquals("testObject.myStringMap.size", 2, testObject.myStringMap.size());
    assertEquals("testObject.myStringMap[key1]", "value1", testObject.myStringMap.get("key1"));
    assertEquals("testObject.myStringMap[key2]", "value2", testObject.myStringMap.get("key2"));

    assertNotNull("testObject.myTestObjectMap", testObject.myTestObjectMap);
    assertEquals("testObject.myTestObjectMap.size", 2, testObject.myTestObjectMap.size());
    assertEquals("testObject.myTestObjectMap[key1]", new SimpleTestObject("post-parse:string 1"),
            testObject.myTestObjectMap.get("key1"));
    assertEquals("testObject.myTestObjectMap[key2]", new SimpleTestObject("post-parse:string 2"),
            testObject.myTestObjectMap.get("key2"));

    assertNotNull("testObject.myInterfaceMap", testObject.myInterfaceMap);
    assertEquals("testObject.myInterfaceMap.size", 2, testObject.myInterfaceMap.size());
    assertEquals("testObject.myInterfaceMap[key1]", new TestObject.InnerTestObject("string 1"),
            testObject.myInterfaceMap.get("key1"));
    assertEquals("testObject.myInterfaceMap[key2]", new TestObject.InnerTestObject("string 2"),
            testObject.myInterfaceMap.get("key2"));

    assertNotNull("testObject.myObjectMap", testObject.myObjectMap);
    assertEquals("testObject.myObjectMap.size", 2, testObject.myTestObjectMap.size());
    assertEquals("testObject.myObjectMap[key1]",
            new SimpleTestObject("post-parse:string 1", "simpleTestObject"),
            testObject.myObjectMap.get("key1"));
    assertEquals("testObject.myObjectMap[key2]", "25", testObject.myObjectMap.get("key2"));

    // Collections
    assertEquals("testObject.myBooleanCollection", CollectionUtils.newHashSet(true, false, true),
            testObject.myBooleanCollection);
    assertEquals("testObject.myByteCollection", CollectionUtils.newHashSet((byte) 63, (byte) 64),
            testObject.myByteCollection);
    assertEquals("testObject.myCharCollection", new LinkedHashSet<>(CollectionUtils.newArrayList('d', 'e')),
            testObject.myCharCollection);
    assertEquals("testObject.myDoubleCollection",
            new LinkedList<>(CollectionUtils.newArrayList(12.345, 13.345)), testObject.myDoubleCollection);
    assertEquals("testObject.myFloatCollection", CollectionUtils.newArrayList(123.456f, 234.56f),
            testObject.myFloatCollection);
    assertEquals("testObject.myIntCollection", CollectionUtils.newArrayList(123, 456),
            testObject.myIntCollection);
    assertEquals("testObject.myLongCollection", CollectionUtils.newArrayList(1234567L, 2345678L),
            testObject.myLongCollection);
    assertEquals("testObject.myShortCollection", CollectionUtils.newArrayList((short) 18, (short) 19),
            testObject.myShortCollection);
    assertEquals("testObject.myStringCollection", CollectionUtils.newArrayList("hello", "there"),
            testObject.myStringCollection);
    assertEquals("testObject.myBigDecimalCollection", CollectionUtils
            .newArrayList(new BigDecimal("123456789.0123456789"), new BigDecimal("23456789.0123456789")),
            testObject.myBigDecimalCollection);
    assertEquals("testObject.myBigIntegerCollection",
            CollectionUtils.newArrayList(new BigInteger("1234567891011"), new BigInteger("234567891011")),
            testObject.myBigIntegerCollection);

    // Custom Objects
    SimpleTestObject singularChild = testObject.mySingularChild;
    assertNotNull("testObject.mySingularChild", singularChild);
    assertEquals("testObject.mySingularChild.myString", "post-parse:a singular child", singularChild.myString);
    assertTrue("testObject.mySingularChildByInterface instanceOf InnerTestObject",
            testObject.mySingularChildByInterface instanceof TestObject.InnerTestObject);
    assertEquals("testObject.mySingularChildByInterface.string", "an object",
            ((TestObject.InnerTestObject) (testObject.mySingularChildByInterface)).string);

    assertEquals("testObject.myInnerObject", new TestObject.InnerTestObject("an InnerTestObject"),
            testObject.myInnerObject);

    List<SimpleTestObject> list = testObject.myList;
    assertNotNull("testObject.myList", list);
    assertEquals("testObject.myList.size()", 2, list.size());
    assertEquals("testObject.myList[0].myString", "post-parse:list child 0", list.get(0).myString);
    assertEquals("testObject.myList[1].myString", "post-parse:list child 1", list.get(1).myString);

    assertNotNull("testObject.myListByInterface", testObject.myListByInterface);
    assertEquals("testObject.myListByInterface", 2, testObject.myListByInterface.size());
    assertTrue("testObject.myListByInterface[0] instanceOf InnerTestObject",
            testObject.myListByInterface.get(0) instanceof TestObject.InnerTestObject);
    assertEquals("testObject.myListByInterface[0]", "object 0",
            ((TestObject.InnerTestObject) (testObject.myListByInterface.get(0))).string);
    assertTrue("testObject.myListByInterface[1] instanceOf InnerTestObject",
            testObject.myListByInterface.get(1) instanceof TestObject.InnerTestObject);
    assertEquals("testObject.myListByInterface[1]", "object 1",
            ((TestObject.InnerTestObject) (testObject.myListByInterface.get(1))).string);

    List<List<Integer>> collectionOfCollections = testObject.myCollectionOfCollections;
    assertNotNull("testObject.collectionOfCollections", collectionOfCollections);
    assertEquals("testObject.collectionOfCollections.size()", 2, collectionOfCollections.size());
    assertEquals("testObject.collectionOfCollection[0]", CollectionUtils.newArrayList(1, 2),
            collectionOfCollections.get(0));
    assertEquals("testObject.collectionOfCollection[1]", CollectionUtils.newArrayList(3, 4),
            collectionOfCollections.get(1));

    List<Set<SimpleTestObject>> collectionOfCollectionUtilsOfTestObjects = testObject.mySetsOfTestObjects;
    assertNotNull("testObject.myCollectionUtilsOfTestObjects", collectionOfCollectionUtilsOfTestObjects);
    assertEquals("testObject.myCollectionUtilsOfTestObjects[0][0]",
            CollectionUtils.newHashSet(new SimpleTestObject("post-parse:set 0 child 0", "simpleTestObject"),
                    new SimpleTestObject("post-parse:set 0 child 1", "simpleTestObject")),
            collectionOfCollectionUtilsOfTestObjects.get(0));
    assertEquals("testObject.myCollectionUtilsOfTestObjects[0][0]",
            CollectionUtils.newHashSet(new SimpleTestObject("post-parse:set 1 child 0", "simpleTestObject"),
                    new SimpleTestObject("post-parse:set 1 child 1", "simpleTestObject")),
            collectionOfCollectionUtilsOfTestObjects.get(1));

    assertEquals("testObject.myUnannotatedObject", new UnannotatedObject("singular unannotated object"),
            testObject.myUnannotatedObject);

    assertEquals("testObject.myUnannotatedObjectCollection",
            CollectionUtils.newArrayList(new UnannotatedObject("unannotated item 0"),
                    new UnannotatedObject("unannotated item 1")),
            testObject.myUnannotatedObjectCollection);

    // JSON Natives
    assertNotNull("testObject.myJsonObject", testObject.myJsonObject);
    assertEquals("testObject.myJsonObject.getString(\"name\")", "value",
            testObject.myJsonObject.getString("name"));

    assertNotNull("testObject.myJsonArray", testObject.myJsonArray);
    assertEquals("testObject.myJsonArray.length()", 2, testObject.myJsonArray.length());
    assertEquals("testObject.myJsonArray[0].(\"name 0\")", "value 0",
            ((JSONObject) testObject.myJsonArray.get(0)).getString("name 0"));
    assertEquals("testObject.myJsonArray[1].(\"name 1\")", "value 1",
            ((JSONObject) testObject.myJsonArray.get(1)).getString("name 1"));

    assertNotNull("testObject.myJsonObjectCollection", testObject.myJsonObjectCollection);
    assertEquals("testObject.myJsonObjectCollection.size()", 2, testObject.myJsonObjectCollection.size());
    assertEquals("testObject.myJsonObjectCollection[0].(\"list name 0\")", "list value 0",
            testObject.myJsonObjectCollection.get(0).getString("list name 0"));
    assertEquals("testObject.myJsonObjectCollection[1].(\"list name 1\")", "list value 1",
            testObject.myJsonObjectCollection.get(1).getString("list name 1"));

    // Setters
    assertEquals("testObject.stringFromSetter", "string for setter", testObject.stringFromSetter);
    assertEquals("testObject.unannotatedObjectFromSetter",
            new UnannotatedObject("unannotated object for setter"), testObject.unannotatedObjectFromSetter);
    assertEquals("testObject.testObjectCollectionFromSetter",
            CollectionUtils.newArrayList(new ParserAnnotatedObject("object for list setter 0", null),
                    new ParserAnnotatedObject("object for list setter 1", null)),
            testObject.testObjectCollectionFromSetter);

    assertNotNull("testObject.integerCollectionsFromSetter", testObject.integerCollectionsFromSetter);
    assertEquals("testObject.integerCollectionsFromSetter.size()", 2,
            testObject.integerCollectionsFromSetter.size());
    assertEquals("testObject.integerCollectionsFromSetter.get(0)", CollectionUtils.newHashSet(1, 2),
            testObject.integerCollectionsFromSetter.get(0));
    assertEquals("testObject.integerCollectionsFromSetter.get(1)", CollectionUtils.newHashSet(3, 4),
            testObject.integerCollectionsFromSetter.get(1));

    // Empty Objects
    assertEquals("testObject.myEmptyObject", new SimpleTestObject(), testObject.myEmptyObject);
    assertNotNull("testObject.myEmptyCollection", testObject.myEmptyCollection);
    assertTrue("testObject.myEmptyCollection.isEmpty()", testObject.myEmptyCollection.isEmpty());

    // Nulls
    assertEquals("testObject.myNullInt", 1, testObject.myNullInt);
    assertNull("testObject.myNullString", testObject.myNullString);
    assertNull("testObject.myNullTestObject", testObject.myNullTestObject);
    assertNull("testObject.myNullCollection", testObject.myNullCollection);
    assertEquals("testObject.myDefaultCollection", Collections.singleton("the one"),
            testObject.myDefaultCollection);
}

From source file:com.sm.query.utils.QueryUtils.java

public static Object getParamArg(Class<?> cl) {
    if (!cl.isPrimitive())
        return null;
    else if (boolean.class.equals(cl))
        return Boolean.FALSE;
    else if (byte.class.equals(cl))
        return new Byte((byte) 0);
    else if (short.class.equals(cl))
        return new Short((short) 0);
    else if (char.class.equals(cl))
        return new Character((char) 0);
    else if (int.class.equals(cl))
        return Integer.valueOf(0);
    else if (long.class.equals(cl))
        return Long.valueOf(0);
    else if (float.class.equals(cl))
        return Float.valueOf(0);
    else if (double.class.equals(cl))
        return Double.valueOf(0);
    else// w w  w .ja va2s .com
        throw new UnsupportedOperationException();
}

From source file:easyJ.common.validate.GenericTypeValidator.java

/**
 * Checks if the value can safely be converted to a short primitive.
 * //from  ww w . j ava 2  s.  c o  m
 * @param value
 *                The value validation is being performed on.
 * @param locale
 *                The locale to use to parse the number (system default if
 *                null)vv
 * @return the converted Short value.
 */
public static Short formatShort(String value, Locale locale) {
    Short result = null;

    if (value != null) {
        NumberFormat formatter = null;
        if (locale != null) {
            formatter = NumberFormat.getNumberInstance(locale);
        } else {
            formatter = NumberFormat.getNumberInstance(Locale.getDefault());
        }
        formatter.setParseIntegerOnly(true);
        ParsePosition pos = new ParsePosition(0);
        Number num = formatter.parse(value, pos);

        // If there was no error and we used the whole string
        if (pos.getErrorIndex() == -1 && pos.getIndex() == value.length()) {
            if (num.doubleValue() >= Short.MIN_VALUE && num.doubleValue() <= Short.MAX_VALUE) {
                result = new Short(num.shortValue());
            }
        }
    }

    return result;
}

From source file:net.sf.json.JSONDynaBean.java

/**
 * DOCUMENT ME!//from  w w w  .  ja  va 2 s.c om
 *
 * @param name DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 */
public Object get(String name) {
    Object value = dynaValues.get(name);

    if (value != null) {
        return value;
    }

    Class type = getDynaProperty(name).getType();

    if (type == null) {
        throw new NullPointerException("Unspecified property type for " + name);
    }

    if (!type.isPrimitive()) {
        return value;
    }

    if (type == Boolean.TYPE) {
        return Boolean.FALSE;
    } else if (type == Byte.TYPE) {
        return new Byte((byte) 0);
    } else if (type == Character.TYPE) {
        return new Character((char) 0);
    } else if (type == Short.TYPE) {
        return new Short((short) 0);
    } else if (type == Integer.TYPE) {
        return new Integer(0);
    } else if (type == Long.TYPE) {
        return new Long(0);
    } else if (type == Float.TYPE) {
        return new Float(0.0);
    } else if (type == Double.TYPE) {
        return new Double(0);
    }

    return null;
}

From source file:com.igorbaiborodine.example.mybatis.customer.TestCustomerService.java

private Address createAddress(int random_) {

    Address address = new Address();
    address.setAddress(random_ + " Test Service Ave.");
    address.setCityId(new Short("1"));
    address.setDistrict("MyBatis-Spring");
    address.setPostalCode("33333");
    address.setPhone("5556666666");

    return address;
}

From source file:de.hub.cs.dbis.lrb.operators.AverageVehicleSpeedBolt.java

@Override
public void execute(Tuple input) {
    this.inputPositionReport.clear();
    this.inputPositionReport.addAll(input.getValues());
    LOGGER.trace(this.inputPositionReport.toString());

    Integer vid = this.inputPositionReport.getVid();
    short minute = this.inputPositionReport.getMinuteNumber();
    int speed = this.inputPositionReport.getSpeed().intValue();
    this.segment.set(this.inputPositionReport);

    assert (minute >= this.currentMinute);

    if (minute > this.currentMinute) {
        // emit all values for last minute
        // (because input tuples are ordered by ts, we can close the last minute safely)
        for (Entry<Integer, Pair<AvgValue, SegmentIdentifier>> entry : this.avgSpeedsMap.entrySet()) {
            Pair<AvgValue, SegmentIdentifier> value = entry.getValue();
            SegmentIdentifier segId = value.getRight();

            // VID, Minute-Number, X-Way, Segment, Direction, Avg(speed)
            this.collector.emit(new AvgVehicleSpeedTuple(entry.getKey(), new Short(this.currentMinute),
                    segId.getXWay(), segId.getSegment(), segId.getDirection(), value.getLeft().getAverage()));
        }/*from  w  w  w . jav a  2s  .  c  om*/

        this.avgSpeedsMap.clear();
        this.currentMinute = minute;
    }

    Pair<AvgValue, SegmentIdentifier> vehicleEntry = this.avgSpeedsMap.get(vid);
    if (vehicleEntry != null && !vehicleEntry.getRight().equals(this.segment)) {
        SegmentIdentifier segId = vehicleEntry.getRight();

        // VID, Minute-Number, X-Way, Segment, Direction, Avg(speed)
        this.collector.emit(new AvgVehicleSpeedTuple(vid, new Short(this.currentMinute), segId.getXWay(),
                segId.getSegment(), segId.getDirection(), vehicleEntry.getLeft().getAverage()));

        // set to null to get new vehicle entry below
        vehicleEntry = null;
    }

    if (vehicleEntry == null) {
        vehicleEntry = new MutablePair<AvgValue, SegmentIdentifier>(new AvgValue(speed), this.segment.copy());
        this.avgSpeedsMap.put(vid, vehicleEntry);
    } else {
        vehicleEntry.getLeft().updateAverage(speed);
    }

    this.collector.ack(input);
}

From source file:org.energyos.espi.common.test.EspiFactory.java

public static UsagePoint newSimpleUsagePoint() {
    UsagePoint usagePoint = new UsagePoint();

    usagePoint.setUUID(UUID.randomUUID());
    usagePoint.setDescription("Electric meter");

    usagePoint.setRoleFlags("role flags".getBytes());
    usagePoint.setStatus(new Short("5"));

    usagePoint.setServiceCategory(new ServiceCategory(ServiceCategory.ELECTRICITY_SERVICE));
    usagePoint.setServiceDeliveryPoint(new ServiceDeliveryPoint());

    return usagePoint;
}

From source file:net.sourceforge.msscodefactory.cfcrm.v2_1.CFCrmXMsgRqstHandler.CFCrmXMsgRqstISOLanguageDeleteByCountryIdxHandler.java

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

        assert qName.equals("RqstISOLanguageDeleteByCountryIdx");

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

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

        // Extract Attributes
        numAttrs = attrs.getLength();
        for (idxAttr = 0; idxAttr < numAttrs; idxAttr++) {
            attrLocalName = attrs.getLocalName(idxAttr);
            if (attrLocalName.equals("Id")) {
                if (attrId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("ISOCountryId")) {
                if (attrISOCountryId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrISOCountryId = 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

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

        Short natISOCountryId;
        natISOCountryId = new Short(Short.parseShort(attrISOCountryId));

        // Delete the objects
        schemaObj.getISOLanguageTableObj().deleteISOLanguageByCountryIdx(natISOCountryId);
        String response = CFCrmXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFCrmXMsgISOLanguageMessageFormatter.formatISOLanguageRspnDeleted() + "\n"
                + CFCrmXMsgSchemaMessageFormatter.formatRspnXmlPostamble();
        ((CFCrmXMsgRqstHandler) getParser()).appendResponse(response);
    } catch (RuntimeException e) {
        String response = CFCrmXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFCrmXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                + CFCrmXMsgSchemaMessageFormatter.formatRspnXmlPostamble();
        CFCrmXMsgRqstHandler xmsgRqstHandler = ((CFCrmXMsgRqstHandler) getParser());
        xmsgRqstHandler.resetResponse();
        xmsgRqstHandler.appendResponse(response);
        xmsgRqstHandler.setCaughtException(true);
    } catch (Error e) {
        String response = CFCrmXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFCrmXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                + CFCrmXMsgSchemaMessageFormatter.formatRspnXmlPostamble();
        CFCrmXMsgRqstHandler xmsgRqstHandler = ((CFCrmXMsgRqstHandler) getParser());
        xmsgRqstHandler.resetResponse();
        xmsgRqstHandler.appendResponse(response);
        xmsgRqstHandler.setCaughtException(true);
    }
}

From source file:net.sourceforge.msscodefactory.cfcrm.v2_0.CFCrmXMsgRqstHandler.CFCrmXMsgRqstAddressDeleteByCountryIdxHandler.java

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

        assert qName.equals("RqstAddressDeleteByCountryIdx");

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

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

        // Extract Attributes
        numAttrs = attrs.getLength();
        for (idxAttr = 0; idxAttr < numAttrs; idxAttr++) {
            attrLocalName = attrs.getLocalName(idxAttr);
            if (attrLocalName.equals("Id")) {
                if (attrId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("CountryId")) {
                if (attrCountryId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrCountryId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("schemaLocation")) {
                // ignored
            } else {
                throw CFLib.getDefaultExceptionFactory().newUnrecognizedAttributeException(getClass(),
                        S_ProcName, getParser().getLocationInfo(), attrLocalName);
            }
        }

        // Ensure that required attributes have values$implRqstTableDeleteByHandlerCheckReqKeyAttrs$

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

        Short natCountryId;
        natCountryId = new Short(Short.parseShort(attrCountryId));

        // Delete the objects
        schemaObj.getAddressTableObj().deleteAddressByCountryIdx(natCountryId);
        String response = CFCrmXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFCrmXMsgAddressMessageFormatter.formatAddressRspnDeleted() + "\n"
                + CFCrmXMsgSchemaMessageFormatter.formatRspnXmlPostamble();
        ((CFCrmXMsgRqstHandler) getParser()).appendResponse(response);
    } catch (RuntimeException e) {
        String response = CFCrmXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFCrmXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                + CFCrmXMsgSchemaMessageFormatter.formatRspnXmlPostamble();
        CFCrmXMsgRqstHandler xmsgRqstHandler = ((CFCrmXMsgRqstHandler) getParser());
        xmsgRqstHandler.resetResponse();
        xmsgRqstHandler.appendResponse(response);
        xmsgRqstHandler.setCaughtException(true);
    } catch (Error e) {
        String response = CFCrmXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFCrmXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                + CFCrmXMsgSchemaMessageFormatter.formatRspnXmlPostamble();
        CFCrmXMsgRqstHandler xmsgRqstHandler = ((CFCrmXMsgRqstHandler) getParser());
        xmsgRqstHandler.resetResponse();
        xmsgRqstHandler.appendResponse(response);
        xmsgRqstHandler.setCaughtException(true);
    }
}