Revision 34368

View differences:

tags/v2_0_0_Build_2023/libraries/libIverUtiles/resources-test/log4j.xml
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
3

  
4
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
5

  
6
	<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
7
		<layout class="org.apache.log4j.PatternLayout">
8
			<param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{2}.%M()]\n  %m%n" />
9
		</layout>
10
	</appender>
11

  
12
	<category name="org.gvsig.tools">
13
		<priority value="DEBUG" />
14
	</category>
15

  
16
	<category name="org.gvsig.utils">
17
		<priority value="DEBUG" />
18
	</category>
19

  
20
	<root>
21
		<priority value="INFO" />
22
		<appender-ref ref="CONSOLE" />
23
	</root>
24
</log4j:configuration>
tags/v2_0_0_Build_2023/libraries/libIverUtiles/src/org/gvsig/tools/IverUtilesLibrary.java
1
package org.gvsig.tools;
2

  
3
import org.gvsig.tools.library.AbstractLibrary;
4
import org.gvsig.tools.library.LibraryException;
5

  
6
public class IverUtilesLibrary extends AbstractLibrary {
7

  
8
	public IverUtilesLibrary() {
9
		super(IverUtilesLibrary.class, TYPE.API);
10
	}
11

  
12
	@Override
13
	protected void doInitialize() throws LibraryException {
14
		// Nothing to do
15
	}
16

  
17
	@Override
18
	protected void doPostInitialize() throws LibraryException {
19
		// nothing to do
20
	}
21
}
0 22

  
tags/v2_0_0_Build_2023/libraries/libIverUtiles/src/org/gvsig/tools/backup/DefaultBackupGeneratorFactory.java
1
package org.gvsig.tools.backup;
2

  
3
/* gvSIG. Geographic Information System of the Valencian Government
4
 *
5
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
6
 * of the Valencian Government (CIT)
7
 * 
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 * 
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *  
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
21
 * MA  02110-1301, USA.
22
 * 
23
 */
24

  
25
/**
26
 * <p>Factory that gets a {@link DefaultBackupGenerator DefaultBackupGenerator} as a particular version of
27
 *  backup generator.</p>
28
 *
29
 * @author Jose Ignacio Yarza (jiyarza@opensistemas.com)
30
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
31
 */
32
public class DefaultBackupGeneratorFactory extends BackupGeneratorFactory {
33
	/*
34
	 * (non-Javadoc)
35
	 * @see com.iver.utiles.backup.BackupGeneratorFactory#getBackupGenerator()
36
	 */
37
	public BackupGenerator getBackupGenerator() {		
38
		return new DefaultBackupGenerator();
39
	}
40
}
tags/v2_0_0_Build_2023/libraries/libIverUtiles/src/org/gvsig/tools/backup/BackupGenerator.java
1
package org.gvsig.tools.backup;
2

  
3
/* gvSIG. Geographic Information System of the Valencian Government
4
 *
5
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
6
 * of the Valencian Government (CIT)
7
 * 
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 * 
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *  
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
21
 * MA  02110-1301, USA.
22
 * 
23
 */
24

  
25
import java.io.File;
26

  
27
import org.gvsig.tools.backup.exceptions.BackupException;
28

  
29

  
30
/**
31
 * <p>A tagging interface that all file backups must implement.</p>
32
 *
33
 * @author Jose Ignacio Yarza (jiyarza@opensistemas.com)
34
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
35
 */
36
public interface BackupGenerator {
37
	/**
38
	 * <p>Performs a backup of <code>source</code>.</p>
39
	 * 
40
	 * @param source the source file
41
	 */
42
	public void backup(File source) throws BackupException;
43
}
tags/v2_0_0_Build_2023/libraries/libIverUtiles/src/org/gvsig/tools/backup/DefaultBackupGenerator.java
1
package org.gvsig.tools.backup;
2

  
3
/* gvSIG. Geographic Information System of the Valencian Government
4
 *
5
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
6
 * of the Valencian Government (CIT)
7
 * 
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 * 
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *  
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
21
 * MA  02110-1301, USA.
22
 * 
23
 */ 
24

  
25
import java.io.File;
26
import java.io.FileInputStream;
27
import java.io.FileOutputStream;
28
import java.nio.channels.FileChannel;
29

  
30
import org.gvsig.tools.backup.exceptions.BackupException;
31

  
32

  
33
/**
34
 * <p>Performs a backup of a file, into another file at the same path (directory), with the file extension 
35
 *  changed to <i>.bak</i>.</p>
36
 *
37
 * @author Jose Ignacio Yarza (jiyarza@opensistemas.com)
38
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
39
 */
40
public class DefaultBackupGenerator implements BackupGenerator {
41
	/*
42
	 * (non-Javadoc)
43
	 * @see com.iver.utiles.backup.BackupGenerator#backup(java.io.File)
44
	 */
45
	public void backup(File source) throws BackupException {
46
		try {
47
			int index = source.getAbsolutePath().lastIndexOf(".");
48

  
49
			if (index == -1)
50
				return;
51

  
52
			File dest = new File(source.getAbsolutePath().substring(0, index) + ".bak");
53

  
54
	        // Create channel on the source
55
	        FileChannel srcChannel = new FileInputStream(source).getChannel();
56

  
57
	        // Create channel on the destination
58
	        FileChannel dstChannel = new FileOutputStream(dest).getChannel();
59

  
60
	        // Copy file contents from source to destination
61
	        dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
62

  
63
	        // Close the channels
64
	        srcChannel.close();
65
	        dstChannel.close();
66
	    } catch (Exception ex) {
67
	    	throw new BackupException(ex.getMessage(), ex, source);
68
	    }
69
	}
70
}
tags/v2_0_0_Build_2023/libraries/libIverUtiles/src/org/gvsig/tools/backup/exceptions/BackupException.java
1
package org.gvsig.tools.backup.exceptions;
2

  
3
/* gvSIG. Geographic Information System of the Valencian Government
4
 *
5
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
6
 * of the Valencian Government (CIT)
7
 * 
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 * 
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *  
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
21
 * MA  02110-1301, USA.
22
 * 
23
 */
24

  
25
import java.io.File;
26

  
27
/**
28
 * <p>Exception to report that a backup process has failed.</p>
29
 *
30
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
31
 */
32
public class BackupException extends Exception {
33
	private static final long serialVersionUID = -2846421984617208883L;
34

  
35
	/**
36
	 * <p>The source file to be backup.</p>
37
	 */
38
	protected File source;
39

  
40
	/**
41
	 * <p>Constructs a new backup exception with the specified detail message and cause.</p>
42
	 * 
43
	 * @param message the detail message (which is saved for later retrieval by the <code>getMessage()</code> method).
44
	 * @param cause the cause (which is saved for later retrieval by the <code>getCause()</code> method). (A <code>null</code>
45
	 *  value is permitted, and indicates that the cause is nonexistent or unknown.)
46
	 * @param source the file from that was going to be done a backup
47
	 * 
48
	 * @see Exception#Exception(String, Throwable)
49
	 */
50
	public BackupException(String message, Throwable cause, File source) {
51
		super(message, cause);
52
		this.source = source;
53
	}
54

  
55
	/**
56
	 * <p>Gets the source file to be backup.</p> 
57
	 * 
58
	 * @return the source file
59
	 */
60
	public File getSource() {
61
		return source;
62
	}
63
}
tags/v2_0_0_Build_2023/libraries/libIverUtiles/src/org/gvsig/tools/backup/BackupGeneratorFactory.java
1
package org.gvsig.tools.backup;
2

  
3
/* gvSIG. Geographic Information System of the Valencian Government
4
 *
5
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
6
 * of the Valencian Government (CIT)
7
 * 
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 * 
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *  
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
21
 * MA  02110-1301, USA.
22
 * 
23
 */
24
 
25
/**
26
 * <p>Generic factory that creates a {@link BackupGenerator BackupGenerator} that performs a particular
27
 *  kind of backup.</p>
28
 *
29
 * @author Jose Ignacio Yarza (jiyarza@opensistemas.com)
30
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
31
 */
32
public abstract class BackupGeneratorFactory {
33
	/**
34
	 * <p>Gets an instance of a backup generator that performs a particular kind of backup.</p>
35
	 * 
36
	 * @return an instance of a backup generator that performs a particular kind of backup
37
	 */
38
	public abstract BackupGenerator getBackupGenerator();
39
}
tags/v2_0_0_Build_2023/libraries/libIverUtiles/src/org/gvsig/utils/DateTime.java
1

  
2
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
3
*
4
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
5
*
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
*
20
* For more information, contact:
21
*
22
*  Generalitat Valenciana
23
*   Conselleria d'Infraestructures i Transport
24
*   Av. Blasco Ib??ez, 50
25
*   46010 VALENCIA
26
*   SPAIN
27
*
28
*      +34 963862235
29
*   gvsig@gva.es
30
*      www.gvsig.gva.es
31
*
32
*    or
33
*
34
*   IVER T.I. S.A
35
*   Salamanca 50
36
*   46005 Valencia
37
*   Spain
38
*
39
*   +34 963163400
40
*   dac@iver.es
41
*/
42
package org.gvsig.utils;
43
import java.util.Calendar;
44
import java.util.Date;
45
import java.util.GregorianCalendar;
46
import java.util.Locale;
47

  
48
/**
49
 * This class contains static methods to manage Dates. It was principally 
50
 * created because of some problems doing the "String do DateTime" 
51
 * and the "DateTime to String" conversions.  
52
 * 
53
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
54
 */
55
public class DateTime {
56

  
57
/**
58
 * returns the current date
59
 * 
60
 * 
61
 * @return java.util.Date
62
 */
63
    public static Date getCurrentDate() {        
64
        Calendar cal = new GregorianCalendar();
65
 
66
        return cal.getTime();
67
    } 
68

  
69
/**
70
 * It trnasforms one date in one String
71
 * 
72
 * 
73
 * @return A String
74
 * @param dtK Date
75
 * @param sFormat Date format. Example: "Y-m-d H:i:s.Z";
76
 */
77
    public static String dateToString(Date dtK, String sFormat) {        
78
        String sDate;
79
        int nYear;
80
        int nMonth;
81
        int nDay;
82
        int nHour;
83
        int nMinute;
84
        int nSecond;
85
        int nMS;
86
        Calendar clnK;
87
        String sf;
88
        int jc;
89
        clnK = Calendar.getInstance(Locale.US);
90
        clnK.setTime(dtK);
91
        nYear = clnK.get(Calendar.YEAR);
92
        nMonth = 1 + clnK.get(Calendar.MONTH);
93
        nDay = clnK.get(Calendar.DAY_OF_MONTH);
94
        nHour = clnK.get(Calendar.HOUR_OF_DAY);
95
        nMinute = clnK.get(Calendar.MINUTE);
96
        nSecond = clnK.get(Calendar.SECOND);
97
        nMS = clnK.get(Calendar.MILLISECOND);
98
        sDate = "";
99
        for (jc = 0; jc < sFormat.length(); jc++) {
100
            switch (sFormat.charAt(jc)) {
101
                case 'Y':
102
                    sDate += nYear;
103
                    break;
104
                case 'm':
105
                    sf = "" + nMonth;
106
                    if (nMonth < 10) {
107
                        sf = "0" + sf;
108
                    }
109
                    sDate += sf;
110
                    break;
111
                case 'd':
112
                    sf = "" + nDay;
113
                    if (nDay < 10) {
114
                        sf = "0" + sf;
115
                    }
116
                    sDate += sf;
117
                    break;
118
                case 'H':
119
                    sf = "" + nHour;
120
                    if (nHour < 10) {
121
                        sf = "0" + sf;
122
                    }
123
                    sDate += sf;
124
                    break;
125
                case 'i':
126
                    sf = "" + nMinute;
127
                    if (nMinute < 10) {
128
                        sf = "0" + sf;
129
                    }
130
                    sDate += sf;
131
                    break;
132
                case 's':
133
                    sf = "" + nSecond;
134
                    if (nSecond < 10) {
135
                        sf = "0" + sf;
136
                    }
137
                    sDate += sf;
138
                    break;
139
                case 'Z':
140
                    sf = "" + nMS;
141
                    if (nMS < 10) {
142
                        sf = "0" + sf;
143
                    }
144
                    sDate += sf;
145
                    break;
146
                default:
147
                    sDate += sFormat.substring(jc, jc + 1);
148
            }
149
        }
150
        return sDate;
151
    } 
152
   
153
/**
154
 * It transfoms one String in one Date
155
 * 
156
 * 
157
 * @return Date
158
 * @param sDate String
159
 */
160
    public static Date stringToDate(String sDate) {        
161
        Date dtRes;
162
        Calendar clnK;
163
        int nYear;
164
        int nMonth;
165
        int nDay;
166
        int nHour;
167
        int nMinute;
168
        int nSecond;
169
        int nMS;
170
        String sf;
171
        for (; sDate.length() < 23;)
172
            sDate += "0";
173
        sf = sDate.substring(0, 4);
174
        nYear = Integer.parseInt(sf);
175
        sf = sDate.substring(5, 7);
176
        nMonth = Integer.parseInt(sf) - 1;
177
        sf = sDate.substring(8, 10);
178
        nDay = Integer.parseInt(sf);
179
        sf = sDate.substring(11, 13);
180
        nHour = Integer.parseInt(sf);
181
        sf = sDate.substring(14, 16);
182
        nMinute = Integer.parseInt(sf);
183
        sf = sDate.substring(17, 19);
184
        nSecond = Integer.parseInt(sf);
185
        sf = sDate.substring(20, 23);
186
        nMS = Integer.parseInt(sf);
187
        clnK = Calendar.getInstance(Locale.US);
188
        clnK.set(nYear, nMonth, nDay, nHour, nMinute, nSecond);
189
        clnK.set(Calendar.MILLISECOND, nMS);
190
        dtRes = new Date();
191
        dtRes = clnK.getTime();
192
        //	    sf=dateToString(dtRes,"Y-m-d H:i:s.Z");
193
        return dtRes;
194
    } 
195
 }
0 196

  
tags/v2_0_0_Build_2023/libraries/libIverUtiles/src/org/gvsig/utils/IPersistence.java
1
/*
2
 * Created on 10-nov-2005
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21
 *
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
package org.gvsig.utils;
45

  
46
/**
47
 * <p>Any object that needs store its data to restore it after, should implement <code>IPersistence</code>.</p>
48
 *
49
 * <p>The process of persisting (for instance in a file) the information of an object using XML is named <i>Marshall</i>,
50
 *  whereas the inverse process in named <i>Unmarshall</i>.</p>
51
 *
52
 * <p>It's necessary specify the name of the class that will be persisted or restored.</p>
53
 *
54
 * @author fjp
55
 */
56
public interface IPersistence {
57
	/**
58
	 * <p>Gets the class name of the object.</p>
59
	 *
60
	 * @return the class name of the object
61
	 */
62
    String getClassName();
63

  
64
    /**
65
     * <p>Returns an XML entity with all necessary information of the object to <i>marshall</i>.</p>
66
     *
67
     * @return the XML entity with all necessary information of the object
68
     */
69
    XMLEntity getXMLEntity() throws XMLException;
70

  
71
    /**
72
     * <p>Sets an XML entity with all necessary information of the object.</p>
73
     *
74
     * @param xml the XML entity with all necessary information of the object
75
     */
76
    void setXMLEntity(XMLEntity xml) throws XMLException;
77
}
0 78

  
tags/v2_0_0_Build_2023/libraries/libIverUtiles/src/org/gvsig/utils/XMLEntity.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package org.gvsig.utils;
42

  
43
import java.io.IOException;
44
import java.io.StringReader;
45
import java.io.StringWriter;
46
import java.util.Iterator;
47
import java.util.NoSuchElementException;
48
import java.util.Vector;
49

  
50
import org.exolab.castor.xml.MarshalException;
51
import org.exolab.castor.xml.Marshaller;
52
import org.exolab.castor.xml.ValidationException;
53
import org.gvsig.utils.xmlEntity.generate.Property;
54
import org.gvsig.utils.xmlEntity.generate.XmlTag;
55

  
56

  
57
/**
58
 * Adaptador de las llamadas a sus m?todos sobre los generados por castor para
59
 * generar despu?s los XML.
60
 *
61
 * @author Vicente Caballero Navarro
62
 */
63
public class XMLEntity {
64
	private Vector whiteAttrList;
65
	private XmlTag xmltag;
66

  
67
	/**
68
	 * Crea un nuevo XMLEntity.
69
	 *
70
	 * @param tag
71
	 *            DOCUMENT ME!
72
	 */
73
	public XMLEntity(XmlTag tag) {
74
		xmltag = tag;
75
	}
76

  
77
	/**
78
	 * Crea un nuevo XMLEntity.
79
	 */
80
	public XMLEntity() {
81
		xmltag = new XmlTag();
82
	}
83

  
84
	/**
85
	 * A?ade una propiedad con un String como clave y un String como valor.
86
	 *
87
	 * @param key
88
	 *            clave.
89
	 * @param value
90
	 *            valor.
91
	 * @param matters, if false this property will not take effect to the
92
	 * result of toHashCode() method
93
	 * @see toHashCode()
94
	 */
95
	public void putProperty(String key, String value, boolean matters) {
96
		if ((key == null)) {
97
			return;
98
		}
99

  
100
		Property p = new Property();
101
		p.setKey(key);
102
		p.setValue(value);
103
		putProperty(p, matters);
104
	}
105

  
106
	public void putProperty(String key, String value) {
107
		putProperty(key, value, true);
108
	}
109
	/**
110
	 * A?ade una propiedad con un String como clave y un Object como valor.
111
	 *
112
	 * @param key
113
	 *            clave.
114
	 * @param value
115
	 *            valor.
116
	 * @param matters, if false this property will not take effect to the
117
	 * result of toHashCode() method
118
	 * @see toHashCode()
119
	 */
120
	public void putProperty(String key, Object value, boolean matters) {
121
		String ret = "";
122

  
123
		if (key == null) {
124
			return;
125
		}
126

  
127
		Class valueClass = value.getClass();
128

  
129
		if (valueClass.isArray()) {
130
			Class compType = valueClass.getComponentType();
131

  
132
			if (compType == byte.class) {
133
				byte[] array = (byte[]) value;
134

  
135
				if (!(array.length == 0)) {
136
					ret += ("" + array[0]).replaceAll("[,]", "\\\\,");
137

  
138
					for (int i = 1; i < array.length; i++) {
139
						ret += (" ," + ("" + array[i]).replaceAll("[,]",
140
								"\\\\,"));
141
					}
142
				}
143
			} else if (compType == short.class) {
144
				short[] array = (short[]) value;
145

  
146
				if (!(array.length == 0)) {
147
					ret += ("" + array[0]).replaceAll("[,]", "\\\\,");
148

  
149
					for (int i = 1; i < array.length; i++) {
150
						ret += (" ," + ("" + array[i]).replaceAll("[,]",
151
								"\\\\,"));
152
					}
153
				}
154
			} else if (compType == int.class) {
155
				int[] array = (int[]) value;
156

  
157
				if (!(array.length == 0)) {
158
					ret += ("" + array[0]).replaceAll("[,]", "\\\\,");
159

  
160
					for (int i = 1; i < array.length; i++) {
161
						ret += (" ," + ("" + array[i]).replaceAll("[,]",
162
								"\\\\,"));
163
					}
164
				}
165
			} else if (compType == long.class) {
166
				long[] array = (long[]) value;
167

  
168
				if (!(array.length == 0)) {
169
					ret += ("" + array[0]).replaceAll("[,]", "\\\\,");
170

  
171
					for (int i = 1; i < array.length; i++) {
172
						ret += (" ," + ("" + array[i]).replaceAll("[,]",
173
								"\\\\,"));
174
					}
175
				}
176
			} else if (compType == float.class) {
177
				float[] array = (float[]) value;
178

  
179
				if (!(array.length == 0)) {
180
					ret += ("" + array[0]).replaceAll("[,]", "\\\\,");
181

  
182
					for (int i = 1; i < array.length; i++) {
183
						ret += (" ," + ("" + array[i]).replaceAll("[,]",
184
								"\\\\,"));
185
					}
186
				}
187
			} else if (compType == double.class) {
188
				double[] array = (double[]) value;
189

  
190
				if (!(array.length == 0)) {
191
					ret += ("" + array[0]).replaceAll("[,]", "\\\\,");
192

  
193
					for (int i = 1; i < array.length; i++) {
194
						ret += (" ," + ("" + array[i]).replaceAll("[,]",
195
								"\\\\,"));
196
					}
197
				}
198
			} else if (compType == boolean.class) {
199
				boolean[] array = (boolean[]) value;
200

  
201
				if (!(array.length == 0)) {
202
					ret += ("" + array[0]).replaceAll("[,]", "\\\\,");
203

  
204
					for (int i = 1; i < array.length; i++) {
205
						ret += (" ," + ("" + array[i]).replaceAll("[,]",
206
								"\\\\,"));
207
					}
208
				}
209
			} else if (compType == String.class) {
210
				String[] array = (String[]) value;
211

  
212
				if (!(array.length == 0)) {
213
					if (array[0] == null) {
214
						array[0] = "null";
215
					}
216

  
217
					ret += array[0].replaceAll("[,]", "\\\\,");
218

  
219
					for (int i = 1; i < array.length; i++) {
220
						if (array[i] == null) {
221
							array[i] = "null";
222
						}
223

  
224
						array[i] = array[i].replaceAll("[,]", "\\\\,");
225
						ret += (" ," + array[i]);
226
					}
227
				}
228
			} else {
229
				Object[] array = (Object[]) value;
230

  
231
				if (!(array.length == 0)) {
232
					ret += ("" + array[0]).replaceAll("[,]", "\\\\,");
233

  
234
					for (int i = 1; i < array.length; i++) {
235
						array[i] = ("" + array[i]).replaceAll("[,]", "\\\\,");
236
						ret += (" ," + array[i]);
237
					}
238
				}
239
			}
240
		} else {
241
			ret = value.toString();
242
		}
243

  
244
		Property p = new Property();
245
		p.setKey(key);
246
		p.setValue(ret);
247
		putProperty(p, matters);
248
	}
249

  
250
	/**
251
	 * A?ade una propiedad con un String como clave y un double como valor.
252
	 * La propiedad a?adida afecta al valor calculado por toHashCode()
253
	 *
254
	 * @param key
255
	 *            clave.
256
	 * @param value
257
	 *            valor.
258
	 * @see toHashCode()
259
	 */
260
	public void putProperty(String key, Object value) {
261
		putProperty(key, value, true);
262
	}
263

  
264
	/**
265
	 * A?ade una propiedad con un String como clave y un entero como valor.
266
	 *
267
	 * @param key
268
	 *            clave.
269
	 * @param value
270
	 *            valor.
271
	 * @param matters, if false this property will not take effect to the
272
	 * result of toHashCode() method
273
	 * @see toHashCode()
274
	 */
275
	public void putProperty(String key, int value, boolean matters) {
276
		if (key == null) {
277
			return;
278
		}
279

  
280
		Property p = new Property();
281
		p.setKey(key);
282
		p.setValue(new Integer(value).toString());
283
		putProperty(p, matters);
284
	}
285

  
286
	/**
287
	 * A?ade una propiedad con un String como clave y un double como valor.
288
	 * La propiedad a?adida afecta al valor calculado por toHashCode()
289
	 *
290
	 * @param key
291
	 *            clave.
292
	 * @param value
293
	 *            valor.
294
	 * @see toHashCode()
295
	 */
296
	public void putProperty(String key, int value) {
297
		putProperty(key, value, true);
298
	}
299

  
300
	/**
301
	 * A?ade una propiedad con un String como clave y un long como valor.
302
	 *
303
	 * @param key
304
	 *            clave.
305
	 * @param value
306
	 *            valor.
307
	 * @param matters, if false this property will not take effect to the
308
	 * result of toHashCode() method
309
	 * @see toHashCode()
310
	 */
311
	public void putProperty(String key, long value, boolean matters) {
312
		if (key == null) {
313
			return;
314
		}
315

  
316
		Property p = new Property();
317
		p.setKey(key);
318
		p.setValue(new Long(value).toString());
319
		putProperty(p, matters);
320
	}
321

  
322
	/**
323
	 * A?ade una propiedad con un String como clave y un double como valor.
324
	 * La propiedad a?adida afecta al valor calculado por toHashCode()
325
	 *
326
	 * @param key
327
	 *            clave.
328
	 * @param value
329
	 *            valor.
330
	 * @see toHashCode()
331
	 */
332
	public void putProperty(String key, long value) {
333
		putProperty(key, value, true);
334

  
335
	}
336

  
337
	/**
338
	 * A?ade una propiedad con un String como clave y un boolean como valor.
339
	 *
340
	 * @param key
341
	 *            clave.
342
	 * @param value
343
	 *            valor.
344
	 * @param matters, if false this property will not take effect to the
345
	 * result of toHashCode() method
346
	 * @see toHashCode()
347
	 */
348
	public void putProperty(String key, boolean value, boolean matters) {
349
		if (key == null) {
350
			return;
351
		}
352

  
353
		Property p = new Property();
354
		p.setKey(key);
355
		p.setValue(new Boolean(value).toString());
356
		putProperty(p, matters);
357
	}
358

  
359
	/**
360
	 * A?ade una propiedad con un String como clave y un double como valor.
361
	 * La propiedad a?adida afecta al valor calculado por toHashCode()
362
	 *
363
	 * @param key
364
	 *            clave.
365
	 * @param value
366
	 *            valor.
367
	 * @see toHashCode()
368
	 */
369
	public void putProperty(String key, boolean value) {
370
		putProperty(key, value, true);
371
	}
372

  
373

  
374
	/**
375
	 * A?ade una propiedad con un String como clave y un float como valor.
376
	 *
377
	 * @param key
378
	 *            clave.
379
	 * @param value
380
	 *            valor.
381
	 * @param matters, if false this property will not take effect to the
382
	 * result of toHashCode() method
383
	 * @see toHashCode()
384
	 */
385
	public void putProperty(String key, float value, boolean matters) {
386
		if (key == null) {
387
			return;
388
		}
389

  
390
		Property p = new Property();
391
		p.setKey(key);
392
		p.setValue(new Float(value).toString());
393
		putProperty(p, matters);
394
	}
395

  
396
	/**
397
	 * A?ade una propiedad con un String como clave y un double como valor.
398
	 * La propiedad a?adida afecta al valor calculado por toHashCode()
399
	 *
400
	 * @param key
401
	 *            clave.
402
	 * @param value
403
	 *            valor.
404
	 * @see toHashCode()
405
	 */
406
	public void putProperty(String key, float value) {
407
		putProperty(key, value, true);
408
	}
409

  
410
	/**
411
	 * A?ade una propiedad con un String como clave y un double como valor.
412
	 *
413
	 * @param key
414
	 *            clave.
415
	 * @param value
416
	 *            valor.
417
	 * @param matters, if false this property will not take effect to the
418
	 * result of toHashCode() method
419
	 * @see toHashCode()
420
	 */
421
	public void putProperty(String key, double value, boolean matters) {
422
		if (key == null) {
423
			return;
424
		}
425

  
426
		Property p = new Property();
427
		p.setKey(key);
428
		p.setValue(new Double(value).toString());
429
		putProperty(p, matters);
430
	}
431

  
432
	/**
433
	 * A?ade una propiedad con un String como clave y un double como valor.
434
	 * La propiedad a?adida afecta al valor calculado por toHashCode()
435
	 *
436
	 * @param key
437
	 *            clave.
438
	 * @param value
439
	 *            valor.
440
	 * @see toHashCode()
441
	 */
442
	public void putProperty(String key, double value) {
443
		putProperty(key, value, true);
444
	}
445
	/**
446
	 * Devuelve el String que corresponda a la clave que se pasa como par?metro.
447
	 *
448
	 * @param key
449
	 *            clave
450
	 *
451
	 * @return valor.
452
	 *
453
	 * @throws NotExistInXMLEntity
454
	 *             Lanza esta excepci?n si no se encuentra ning?n elemento con
455
	 *             esa clave.
456
	 */
457
	public String getStringProperty(String key) {
458
		Property[] properties = xmltag.getProperty();
459
		String res = null;
460
		boolean exists = false;
461

  
462
		for (int i = 0; i < properties.length; i++) {
463
			if (properties[i].getKey().compareTo(key) == 0) {
464
				res = properties[i].getValue();
465
				exists = true;
466
			}
467
		}
468

  
469
		if (exists) {
470
			return res;
471
		}
472

  
473
		throw new NotExistInXMLEntity();
474
	}
475

  
476
	/**
477
	 * Devuelve el double que corresponda a la clave que se pasa como par?metro.
478
	 *
479
	 * @param key
480
	 *            clave
481
	 *
482
	 * @return valor.
483
	 *
484
	 * @throws NotExistInXMLEntity
485
	 *             Lanza esta excepci?n si no se encuentra ning?n elemento con
486
	 *             esa clave.
487
	 */
488
	public double getDoubleProperty(String key) {
489
		Property[] properties = xmltag.getProperty();
490
		double res = 0;
491
		boolean exists = false;
492

  
493
		for (int i = 0; i < properties.length; i++) {
494
			if (properties[i].getKey().compareTo(key) == 0) {
495
				res = Double.parseDouble(properties[i].getValue());
496
				exists = true;
497
			}
498
		}
499

  
500
		if (exists) {
501
			return res;
502
		}
503

  
504
		throw new NotExistInXMLEntity();
505
	}
506

  
507
	/**
508
	 * Devuelve el array de doubles que corresponda a la clave que se pasa como
509
	 * par?metro.
510
	 *
511
	 * @param key
512
	 *            clave
513
	 *
514
	 * @return valor.
515
	 *
516
	 * @throws NotExistInXMLEntity
517
	 *             Lanza esta excepci?n si no se encuentra ning?n elemento con
518
	 *             esa clave.
519
	 */
520
	public double[] getDoubleArrayProperty(String key) {
521
		Property[] properties = xmltag.getProperty();
522
		String value = null;
523
		boolean exists = false;
524

  
525
		for (int i = 0; i < properties.length; i++) {
526
			if (properties[i].getKey().compareTo(key) == 0) {
527
				value = properties[i].getValue();
528
				exists = true;
529
			}
530
		}
531

  
532
		if (!exists) {
533
			throw new NotExistInXMLEntity();
534
		}
535

  
536
		if (value.compareTo("") == 0) {
537
			return new double[0];
538
		}
539

  
540
		String[] aux = (String[]) value.split(" ,");
541
		double[] ret = new double[aux.length];
542

  
543
		for (int i = 0; i < aux.length; i++) {
544
			ret[i] = Double.parseDouble(aux[i].replaceAll("\\\\,", ","));
545
		}
546

  
547
		return ret;
548
	}
549

  
550
	/**
551
	 * Devuelve el Object que corresponda a la clave que se pasa como par?metro.
552
	 *
553
	 * @param key
554
	 *            clave
555
	 *
556
	 * @return valor.
557
	 *
558
	 * @throws NotExistInXMLEntity
559
	 *             Lanza esta excepci?n si no se encuentra ning?n elemento con
560
	 *             esa clave.
561
	 */
562
	public Object getObjectProperty(String key) {
563
		Property[] properties = xmltag.getProperty();
564
		Object res = null;
565
		boolean exists = false;
566

  
567
		for (int i = 0; i < properties.length; i++) {
568
			if (properties[i].getKey().compareTo(key) == 0) {
569
				res = properties[i].getValue();
570
				exists = true;
571
			}
572
		}
573

  
574
		if (exists) {
575
			return res;
576
		}
577

  
578
		throw new NotExistInXMLEntity();
579
	}
580

  
581
	/**
582
	 * Devuelve el array de float que corresponda a la clave que se pasa como
583
	 * par?metro.
584
	 *
585
	 * @param key
586
	 *            clave
587
	 *
588
	 * @return valor.
589
	 *
590
	 * @throws NotExistInXMLEntity
591
	 *             Lanza esta excepci?n si no se encuentra ning?n elemento con
592
	 *             esa clave.
593
	 */
594
	public float[] getFloatArrayProperty(String key) {
595
		Property[] properties = xmltag.getProperty();
596
		String value = null;
597
		boolean exists = false;
598

  
599
		for (int i = 0; i < properties.length; i++) {
600
			if (properties[i].getKey().compareTo(key) == 0) {
601
				value = properties[i].getValue();
602
				exists = true;
603
			}
604
		}
605

  
606
		if (!exists) {
607
			throw new NotExistInXMLEntity();
608
		}
609

  
610
		if (value.compareTo("") == 0) {
611
			return new float[0];
612
		}
613

  
614
		String[] aux = (String[]) value.split(" ,");
615
		float[] ret = new float[aux.length];
616

  
617
		for (int i = 0; i < aux.length; i++) {
618
			ret[i] = Float.parseFloat(aux[i].replaceAll("\\\\,", ","));
619
		}
620

  
621
		return ret;
622
	}
623

  
624
	/**
625
	 * Devuelve el array de long que corresponda a la clave que se pasa como
626
	 * par?metro.
627
	 *
628
	 * @param key
629
	 *            clave
630
	 *
631
	 * @return valor.
632
	 *
633
	 * @throws NotExistInXMLEntity
634
	 *             Lanza esta excepci?n si no se encuentra ning?n elemento con
635
	 *             esa clave.
636
	 */
637
	public long[] getLongArrayProperty(String key) {
638
		Property[] properties = xmltag.getProperty();
639
		String value = null;
640
		boolean exists = false;
641

  
642
		for (int i = 0; i < properties.length; i++) {
643
			if (properties[i].getKey().compareTo(key) == 0) {
644
				value = properties[i].getValue();
645
				exists = true;
646
			}
647
		}
648

  
649
		if (!exists) {
650
			throw new NotExistInXMLEntity();
651
		}
652

  
653
		if (value.compareTo("") == 0) {
654
			return new long[0];
655
		}
656

  
657
		String[] aux = (String[]) value.split(" ,");
658
		long[] ret = new long[aux.length];
659

  
660
		for (int i = 0; i < aux.length; i++) {
661
			ret[i] = Long.parseLong(aux[i].replaceAll("\\\\,", ","));
662
		}
663

  
664
		return ret;
665
	}
666

  
667
	/**
668
	 * Devuelve el array de bytes que corresponda a la clave que se pasa como
669
	 * par?metro.
670
	 *
671
	 * @param key
672
	 *            clave
673
	 *
674
	 * @return valor.
675
	 *
676
	 * @throws NotExistInXMLEntity
677
	 *             Lanza esta excepci?n si no se encuentra ning?n elemento con
678
	 *             esa clave.
679
	 */
680
	public byte[] getByteArrayProperty(String key) {
681
		Property[] properties = xmltag.getProperty();
682
		String value = null;
683
		boolean exists = false;
684

  
685
		for (int i = 0; i < properties.length; i++) {
686
			if (properties[i].getKey().compareTo(key) == 0) {
687
				value = properties[i].getValue();
688
				exists = true;
689
			}
690
		}
691

  
692
		if (!exists) {
693
			throw new NotExistInXMLEntity();
694
		}
695

  
696
		if (value.compareTo("") == 0) {
697
			return new byte[0];
698
		}
699

  
700
		String[] aux = (String[]) value.split(" ,");
701
		byte[] ret = new byte[aux.length];
702

  
703
		for (int i = 0; i < aux.length; i++) {
704
			ret[i] = Byte.parseByte(aux[i].replaceAll("\\\\,", ","));
705
		}
706

  
707
		return ret;
708
	}
709

  
710
	/**
711
	 * Devuelve el array de enteros que corresponda a la clave que se pasa como
712
	 * par?metro.
713
	 *
714
	 * @param key
715
	 *            clave
716
	 *
717
	 * @return valor.
718
	 *
719
	 * @throws NotExistInXMLEntity
720
	 *             Lanza esta excepci?n si no se encuentra ning?n elemento con
721
	 *             esa clave.
722
	 */
723
	public int[] getIntArrayProperty(String key) {
724
		Property[] properties = xmltag.getProperty();
725
		String value = null;
726
		boolean exists = false;
727

  
728
		for (int i = 0; i < properties.length; i++) {
729
			if (properties[i].getKey().compareTo(key) == 0) {
730
				value = properties[i].getValue();
731
				exists = true;
732
			}
733
		}
734

  
735
		if (!exists) {
736
			throw new NotExistInXMLEntity();
737
		}
738

  
739
		if (value.compareTo("") == 0) {
740
			return new int[0];
741
		}
742

  
743
		String[] aux = (String[]) value.split(" ,");
744
		int[] ret = new int[aux.length];
745

  
746
		for (int i = 0; i < aux.length; i++) {
747
			ret[i] = Integer.parseInt(aux[i].replaceAll("\\\\,", ","));
748
		}
749

  
750
		return ret;
751
	}
752

  
753
	/**
754
	 * Devuelve el array de boolean que corresponda a la clave que se pasa como
755
	 * par?metro.
756
	 *
757
	 * @param key
758
	 *            clave
759
	 *
760
	 * @return valor.
761
	 *
762
	 * @throws NotExistInXMLEntity
763
	 *             Lanza esta excepci?n si no se encuentra ning?n elemento con
764
	 *             esa clave.
765
	 */
766
	public boolean[] getBooleanArrayProperty(String key) {
767
		Property[] properties = xmltag.getProperty();
768
		String value = null;
769
		boolean exists = false;
770

  
771
		for (int i = 0; i < properties.length; i++) {
772
			if (properties[i].getKey().compareTo(key) == 0) {
773
				value = properties[i].getValue();
774
				exists = true;
775
			}
776
		}
777

  
778
		if (!exists) {
779
			throw new NotExistInXMLEntity();
780
		}
781

  
782
		if (value.compareTo("") == 0) {
783
			return new boolean[0];
784
		}
785

  
786
		String[] aux = (String[]) value.split(" ,");
787
		boolean[] ret = new boolean[aux.length];
788

  
789
		for (int i = 0; i < aux.length; i++) {
790
			ret[i] = Boolean.valueOf(aux[i].replaceAll("\\\\,", ","))
791
					.booleanValue();
792
		}
793

  
794
		return ret;
795
	}
796

  
797
	/**
798
	 * Devuelve el array de String que corresponda a la clave que se pasa como
799
	 * par?metro.
800
	 *
801
	 * @param key
802
	 *            clave
803
	 *
804
	 * @return valor.
805
	 *
806
	 * @throws NotExistInXMLEntity
807
	 *             Lanza esta excepci?n si no se encuentra ning?n elemento con
808
	 *             esa clave.
809
	 */
810
	public String[] getStringArrayProperty(String key) {
811
		// /String value = (String) properties.get(key);
812
		Property[] properties = xmltag.getProperty();
813
		String value = null;
814
		boolean exists = false;
815

  
816
		for (int i = 0; i < properties.length; i++) {
817
			if (properties[i].getKey().compareTo(key) == 0) {
818
				value = properties[i].getValue();
819
				exists = true;
820
			}
821
		}
822

  
823
		if (!exists) {
824
			throw new NotExistInXMLEntity();
825
		}
826

  
827
		if (value.compareTo("") == 0) {
828
			return new String[0];
829
		}
830

  
831
		String[] aux = (String[]) value.split(" ,");
832

  
833
		for (int i = 0; i < aux.length; i++) {
834
			aux[i] = aux[i].replaceAll("\\\\,", ",");
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff