KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > ddf > EscherSimpleProperty


1
2 /* ====================================================================
3    Copyright 2002-2004 Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16 ==================================================================== */

17         
18 package org.apache.poi.ddf;
19
20 import org.apache.poi.util.LittleEndian;
21 import org.apache.poi.util.HexDump;
22
23 /**
24  * A simple property is of fixed length and as a property number in addition
25  * to a 32-bit value. Properties that can't be stored in only 32-bits are
26  * stored as EscherComplexProperty objects.
27  *
28  * @author Glen Stampoultzis (glens at apache.org)
29  */

30 public class EscherSimpleProperty extends EscherProperty
31 {
32     protected int propertyValue;
33
34     /**
35      * The id is distinct from the actual property number. The id includes the property number the blip id
36      * flag and an indicator whether the property is complex or not.
37      */

38     public EscherSimpleProperty( short id, int propertyValue )
39     {
40         super( id );
41         this.propertyValue = propertyValue;
42     }
43
44     /**
45      * Constructs a new escher property. The three parameters are combined to form a property
46      * id.
47      */

48     public EscherSimpleProperty( short propertyNumber, boolean isComplex, boolean isBlipId, int propertyValue )
49     {
50         super( propertyNumber, isComplex, isBlipId );
51         this.propertyValue = propertyValue;
52     }
53
54     /**
55      * Serialize the simple part of the escher record.
56      *
57      * @return the number of bytes serialized.
58      */

59     public int serializeSimplePart( byte[] data, int offset )
60     {
61         LittleEndian.putShort(data, offset, getId());
62         LittleEndian.putInt(data, offset + 2, propertyValue);
63         return 6;
64     }
65
66     /**
67      * Escher properties consist of a simple fixed length part and a complex variable length part.
68      * The fixed length part is serialized first.
69      */

70     public int serializeComplexPart( byte[] data, int pos )
71     {
72         return 0;
73     }
74
75     /**
76      * @return Return the 32 bit value of this property.
77      */

78     public int getPropertyValue()
79     {
80         return propertyValue;
81     }
82
83     /**
84      * Returns true if one escher property is equal to another.
85      */

86     public boolean equals( Object JavaDoc o )
87     {
88         if ( this == o ) return true;
89         if ( !( o instanceof EscherSimpleProperty ) ) return false;
90
91         final EscherSimpleProperty escherSimpleProperty = (EscherSimpleProperty) o;
92
93         if ( propertyValue != escherSimpleProperty.propertyValue ) return false;
94         if ( getId() != escherSimpleProperty.getId() ) return false;
95
96         return true;
97     }
98
99     /**
100      * Returns a hashcode so that this object can be stored in collections that
101      * require the use of such things.
102      */

103     public int hashCode()
104     {
105         return propertyValue;
106     }
107
108     /**
109      * @return the string representation of this property.
110      */

111     public String JavaDoc toString()
112     {
113         return "propNum: " + getPropertyNumber()
114                 + ", propName: " + EscherProperties.getPropertyName( getPropertyNumber() )
115                 + ", complex: " + isComplex()
116                 + ", blipId: " + isBlipId()
117                 + ", value: " + propertyValue + " (0x" + HexDump.toHex(propertyValue) + ")";
118     }
119
120 }
121
Popular Tags