Statistics
| Revision:

root / trunk / libraries / libGPE / src / org / gvsig / gpe / utils / TypedObjectStack.java @ 12418

History | View | Annotate | Download (3.42 KB)

1
package org.gvsig.gpe.utils;
2

    
3
import java.util.Stack;
4

    
5
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
6
 *
7
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
22
 *
23
 * For more information, contact:
24
 *
25
 *  Generalitat Valenciana
26
 *   Conselleria d'Infraestructures i Transport
27
 *   Av. Blasco Ib??ez, 50
28
 *   46010 VALENCIA
29
 *   SPAIN
30
 *
31
 *      +34 963862235
32
 *   gvsig@gva.es
33
 *      www.gvsig.gva.es
34
 *
35
 *    or
36
 *
37
 *   IVER T.I. S.A
38
 *   Salamanca 50
39
 *   46005 Valencia
40
 *   Spain
41
 *
42
 *   +34 963163400
43
 *   dac@iver.es
44
 */
45
/* CVS MESSAGES:
46
 *
47
 * $Id: TypedObjectStack.java 12418 2007-06-29 12:19:48Z jorpiell $
48
 * $Log$
49
 * Revision 1.1  2007-06-29 12:19:14  jorpiell
50
 * The schema validation is made independently of the concrete writer
51
 *
52
 *
53
 */
54
/**
55
 * This class implements a object stack. Every object
56
 * is composed by an object name and an XML schema
57
 * element name. It is used on writing process to save
58
 * the state information
59
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
60
 * @author Carlos S?nchez Peri??n (sanchez_carper@gva.es)
61
 */
62
public class TypedObjectStack {
63
        private Stack stack = null;
64
        
65
        public TypedObjectStack(){
66
                this.stack = new Stack();
67
        }
68
        
69
        /**
70
         * Retrieve the las element from the top of the 
71
         * stack
72
         * @return
73
         * The las stack element
74
         */
75
        public TypedObject pop(){
76
                if (stack.size() > 0){
77
                        return (TypedObject)stack.pop();
78
                }
79
                return null;
80
        }
81
        
82
        /**
83
         * Add a new element to the stack
84
         * @param typedObject
85
         * Object to add
86
         */
87
        public void push(TypedObject typedObject){
88
                stack.push(typedObject);
89
        }
90
        
91
        /**
92
         * Add a new element to the stack
93
         * @param name
94
         * Element name
95
         * @param type
96
         * XML schema element type
97
         * @param isRemoved
98
         * If the elemnt has to be removed
99
         */
100
        public void push(String name, String type, boolean isRemoved){
101
                stack.push(new TypedObject(name,type,isRemoved));
102
        }
103
        
104
        /**
105
         * @return the stack size
106
         */
107
        public int size(){
108
                return stack.size();
109
        }        
110
        
111
        /**
112
         * @return the last stack element without retrieve it
113
         */
114
        public TypedObject lastElement(){
115
                if (stack.size() > 0){
116
                        return (TypedObject)stack.lastElement();
117
                }
118
                return null;
119
        }
120
        
121
        /**
122
         * This class implements a pair of element name
123
         * ald XML schema element type.
124
         * @author Jorge Piera Llodr? (jorge.piera@iver.es)
125
         */
126
        public class TypedObject{
127
                private String name = null;
128
                private String type = null;
129
                private boolean isRemoved = false;
130
                
131
                TypedObject(String name, String type, boolean isRemoved) {
132
                        this.name = name;
133
                        this.type = type;
134
                        this.isRemoved = isRemoved;
135
                }
136

    
137
                /**
138
                 * @return the name
139
                 */
140
                public String getName() {
141
                        return name;
142
                }
143

    
144
                /**
145
                 * @return the type
146
                 */
147
                public String getType() {
148
                        return type;
149
                }
150

    
151
                /**
152
                 * @return the isRemoved
153
                 */
154
                public boolean isRemoved() {
155
                        return isRemoved;
156
                }
157
        }
158

    
159
}