001: /* ====================================================================
002: Licensed to the Apache Software Foundation (ASF) under one or more
003: contributor license agreements. See the NOTICE file distributed with
004: this work for additional information regarding copyright ownership.
005: The ASF licenses this file to You under the Apache License, Version 2.0
006: (the "License"); you may not use this file except in compliance with
007: the License. You may obtain a copy of the License at
008:
009: http://www.apache.org/licenses/LICENSE-2.0
010:
011: Unless required by applicable law or agreed to in writing, software
012: distributed under the License is distributed on an "AS IS" BASIS,
013: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: See the License for the specific language governing permissions and
015: limitations under the License.
016: ==================================================================== */
017:
018: package org.apache.poi.ddf;
019:
020: import org.apache.poi.util.LittleEndian;
021: import org.apache.poi.util.HexDump;
022:
023: /**
024: * A simple property is of fixed length and as a property number in addition
025: * to a 32-bit value. Properties that can't be stored in only 32-bits are
026: * stored as EscherComplexProperty objects.
027: *
028: * @author Glen Stampoultzis (glens at apache.org)
029: */
030: public class EscherSimpleProperty extends EscherProperty {
031: protected int propertyValue;
032:
033: /**
034: * The id is distinct from the actual property number. The id includes the property number the blip id
035: * flag and an indicator whether the property is complex or not.
036: */
037: public EscherSimpleProperty(short id, int propertyValue) {
038: super (id);
039: this .propertyValue = propertyValue;
040: }
041:
042: /**
043: * Constructs a new escher property. The three parameters are combined to form a property
044: * id.
045: */
046: public EscherSimpleProperty(short propertyNumber,
047: boolean isComplex, boolean isBlipId, int propertyValue) {
048: super (propertyNumber, isComplex, isBlipId);
049: this .propertyValue = propertyValue;
050: }
051:
052: /**
053: * Serialize the simple part of the escher record.
054: *
055: * @return the number of bytes serialized.
056: */
057: public int serializeSimplePart(byte[] data, int offset) {
058: LittleEndian.putShort(data, offset, getId());
059: LittleEndian.putInt(data, offset + 2, propertyValue);
060: return 6;
061: }
062:
063: /**
064: * Escher properties consist of a simple fixed length part and a complex variable length part.
065: * The fixed length part is serialized first.
066: */
067: public int serializeComplexPart(byte[] data, int pos) {
068: return 0;
069: }
070:
071: /**
072: * @return Return the 32 bit value of this property.
073: */
074: public int getPropertyValue() {
075: return propertyValue;
076: }
077:
078: /**
079: * Returns true if one escher property is equal to another.
080: */
081: public boolean equals(Object o) {
082: if (this == o)
083: return true;
084: if (!(o instanceof EscherSimpleProperty))
085: return false;
086:
087: final EscherSimpleProperty escherSimpleProperty = (EscherSimpleProperty) o;
088:
089: if (propertyValue != escherSimpleProperty.propertyValue)
090: return false;
091: if (getId() != escherSimpleProperty.getId())
092: return false;
093:
094: return true;
095: }
096:
097: /**
098: * Returns a hashcode so that this object can be stored in collections that
099: * require the use of such things.
100: */
101: public int hashCode() {
102: return propertyValue;
103: }
104:
105: /**
106: * @return the string representation of this property.
107: */
108: public String toString() {
109: return "propNum: " + getPropertyNumber() + ", RAW: 0x"
110: + HexDump.toHex(getId()) + ", propName: "
111: + EscherProperties.getPropertyName(getPropertyNumber())
112: + ", complex: " + isComplex() + ", blipId: "
113: + isBlipId() + ", value: " + propertyValue + " (0x"
114: + HexDump.toHex(propertyValue) + ")";
115: }
116:
117: }
|