Revision 26305

View differences:

tags/tmp_build/libraries/libExceptions/.cvsignore
1
bin
2
bin-test
3
dist/*
0 4

  
tags/tmp_build/libraries/libExceptions/build.xml
1
<project name="libExceptions" default="create-jar" basedir=".">
2
  	<!-- set global properties for this build -->
3
	<property name="src"  location="src"/>
4
	<property name="build"  location="bin"/>
5
	<property name="src-test"  location="src-test"/>
6
	<property name="build-test"  location="bin-test"/>
7
	<property name="dist"  location="dist"/>
8
	<property name="targetDir" location="dist"/>
9
	<property name="fmapLibs" location="../libFMap/lib" />
10
	<property name="andamiLibs" location="../_fwAndami/lib" />
11
	<property name="remoteServicesLibs" location="../libRemoteServices/lib" />
12
	<property name="jarName" value="org.gvsig.exceptions"/>
13
	<!--<property name="compile-classpath" value="" />-->
14
	<import file="../binaries/ant/utilities.xml"/>
15

  
16
  <target name="init">
17
    <!-- Create the time stamp -->
18
    <tstamp/>
19
	<echo>
20
		Compiling ${ant.project.name}...</echo>
21
  </target>
22

  
23
	<target name="batch-build"
24
				description="compile the sources, create the jar file"
25
				depends="init,compile,create-jar">
26
	</target>
27

  
28
	<target name="compile" description="compile the source">
29
		<!-- Compile the Java code from ${src} to ${build} -->
30
		<mkdir dir="${build}" />
31
		<loadEclipseClasspath project="${basedir}"/>
32
		<gvSIG-javac
33
			classpath="${eclipseClasspath}"
34
		/>
35

  
36
		<!--<javac	srcdir="${src}"
37
				destdir="${build}"
38
				source="1.4"
39
				target="1.4"
40
				debug="${debug}"
41
				debuglevel="${debuglevel}"
42
				classpath="${compile-classpath}"/>-->
43
		<!-- copy any images or resources present in the src dir -->
44
		<copy todir="${build}">
45
			<fileset dir="${src}" excludes="**/*.java" casesensitive="false"/>
46
		</copy>
47
	</target>
48

  
49
	<target name="create-jar" description="Crea el jar de la aplicacion">
50
		<mkdir dir="${dist}" />
51
	  	<jar jarfile="${targetDir}/${jarName}.jar" basedir="${build}"/>
52
		<copy todir="${andamiLibs}">
53
			<fileset dir="${targetDir}" includes="${jarName}.jar" />
54
		</copy>
55
	</target>
56

  
57
	<target name="clean" description="clean up">
58
		<!-- Delete the ${build} and ${dist} directory trees -->
59
		<delete dir="${build}" />
60
		<delete dir="${dist}" />
61
	</target>
62

  
63
	<target name="run-tests" depends="batch-build,compile-tests">
64
		<antcall target="generic-run-tests">
65
			<param name="TestSuite.Name" value="org.gvsig.gui.beans.AllTests"/>
66
		</antcall>
67
	</target>
68

  
69
</project>
0 70

  
tags/tmp_build/libraries/libExceptions/.classpath
1
<?xml version="1.0" encoding="UTF-8"?>
2
<classpath>
3
	<classpathentry kind="src" path="src"/>
4
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
5
	<classpathentry output="bin-test" kind="src" path="src-test"/>
6
	<classpathentry kind="var" path="JUNIT_HOME/junit.jar"/>
7
	<classpathentry kind="lib" path="lib/log4j-1.2.8.jar"/>
8
	<classpathentry kind="output" path="bin"/>
9
</classpath>
0 10

  
tags/tmp_build/libraries/libExceptions/.project
1
<?xml version="1.0" encoding="UTF-8"?>
2
<projectDescription>
3
	<name>libExceptions</name>
4
	<comment></comment>
5
	<projects>
6
	</projects>
7
	<buildSpec>
8
		<buildCommand>
9
			<name>org.eclipse.jdt.core.javabuilder</name>
10
			<arguments>
11
			</arguments>
12
		</buildCommand>
13
		<buildCommand>
14
			<name>de.loskutov.FileSync.FSBuilder</name>
15
			<arguments>
16
			</arguments>
17
		</buildCommand>
18
	</buildSpec>
19
	<natures>
20
		<nature>org.eclipse.jdt.core.javanature</nature>
21
	</natures>
22
</projectDescription>
0 23

  
tags/tmp_build/libraries/libExceptions/src-test/org/gvsig/exceptions/ListBaseExceptionTest.java
1
package org.gvsig.exceptions;
2

  
3
import junit.framework.TestCase;
4

  
5
public class ListBaseExceptionTest extends TestCase {
6

  
7
	protected void setUp() throws Exception {
8
		super.setUp();
9
	}
10

  
11
	protected void tearDown() throws Exception {
12
		super.tearDown();
13
	}
14

  
15
	public void testSimple(){
16

  
17
	}
18

  
19
}
0 20

  
tags/tmp_build/libraries/libExceptions/src-test/org/gvsig/exceptions/BaseExceptionTest.java
1
package org.gvsig.exceptions;
2

  
3
import junit.framework.TestCase;
4

  
5
public class BaseExceptionTest extends TestCase {
6

  
7
	protected void setUp() throws Exception {
8
		super.setUp();
9
	}
10

  
11
	protected void tearDown() throws Exception {
12
		super.tearDown();
13
	}
14
	
15
	public void testSimple(){
16
		try {
17
			throw new NullPointerException("Excepcion de puntero nulo");
18
		} catch (NullPointerException e){
19
			DriverException de = new DriverException("SimpleDriver", e);
20
			assertEquals("Error in the driver SimpleDriver",de.getMessage());
21
			assertEquals("Error in the driver SimpleDriver\nExcepcion de puntero nulo\n",de.getMessageStack());
22
		}
23
	}
24

  
25
	public void testSimpleLocalized(){
26
		class MyTranslator implements IExceptionTranslator {
27
			public String getText(String clave) {
28
				return clave.toUpperCase();
29
			}
30
		}
31
		BaseException.setTranslator(new MyTranslator());
32
		try {
33
			throw new NullPointerException("Excepcion de puntero nulo");
34
		} catch (NullPointerException e){
35
			DriverException de = new DriverException("SimpleDriver", e);
36
			assertEquals("ERROR_IN_THE_DRIVER_%(DRIVERNAME)S",de.getLocalizedMessage());
37
			assertEquals("ERROR_IN_THE_DRIVER_%(DRIVERNAME)S\nExcepcion de puntero nulo\n",de.getLocalizedMessageStack());
38
		}
39
		BaseException.setTranslator(null);
40
	}
41

  
42
	public void testSimple2(){
43
		try {
44
			throw new NullPointerException("Excepcion de puntero nulo");
45
		} catch (NullPointerException e){
46
			BadDateException de = new BadDateException("SimpleDriver", e);
47
			assertEquals("Driver SimpleDriver: Formato de fecha incorrecto",de.getMessage());
48
			assertEquals("Driver SimpleDriver: Formato de fecha incorrecto\nExcepcion de puntero nulo\n",de.getMessageStack());
49
		}
50
	}
51

  
52
	public void testSimpleLocalized2(){
53
		class MyTranslator implements IExceptionTranslator {
54
			public String getText(String clave) {
55
				return clave.toUpperCase();
56
			}
57
		}
58
		BaseException.setTranslator(new MyTranslator());
59
		try {
60
			throw new NullPointerException("Excepcion de puntero nulo");
61
		} catch (NullPointerException e){
62
			BadDateException de = new BadDateException("SimpleDriver", e);
63
			assertEquals("DRIVER_%(DRIVERNAME)S_FORMATO_DE_FECHA_INCORRECTO",de.getLocalizedMessage());
64
			assertEquals("DRIVER_%(DRIVERNAME)S_FORMATO_DE_FECHA_INCORRECTO\nExcepcion de puntero nulo\n",de.getLocalizedMessageStack());
65
		}
66
		BaseException.setTranslator(null);
67
	}
68

  
69
	public void testTranslatorWithoutInterface() {
70
		class MyTranslator {
71
			public String getTest(String clave) {
72
				return clave.toUpperCase();
73
			}
74
		}
75
		BaseException.setTranslator(new MyTranslator());
76
		try {
77
			throw new NullPointerException("Excepcion de puntero nulo");
78
		} catch (NullPointerException e){
79
			BadDateException de = new BadDateException("SimpleDriver", e);
80
			assertEquals("DRIVER_%(DRIVERNAME)S_FORMATO_DE_FECHA_INCORRECTO",de.getLocalizedMessage());
81
			assertEquals("DRIVER_%(DRIVERNAME)S_FORMATO_DE_FECHA_INCORRECTO\nExcepcion de puntero nulo\n",de.getLocalizedMessageStack());
82
		}
83
		BaseException.setTranslator(null);
84
		
85
	}
86

  
87
	class BadDateException extends DriverException {
88
		private static final long serialVersionUID = -8985920349210629998L;
89
		
90
		public BadDateException(String driverName, Throwable cause){
91
			super(driverName, cause);
92
			messageKey="Driver_%(driverName)s_Formato_de_fecha_incorrecto";
93
			formatString="Driver %(driverName)s: Formato de fecha incorrecto";
94
			code = serialVersionUID;
95
		}
96
	}
97
}
0 98

  
tags/tmp_build/libraries/libExceptions/src-test/org/gvsig/exceptions/DriverException.java
1
package org.gvsig.exceptions;
2

  
3
import java.util.HashMap;
4
import java.util.Map;
5

  
6
public class DriverException extends BaseException {
7
	
8
	private static final long serialVersionUID = -8985920349210629999L;
9
	private String driverName;
10
	
11
	public DriverException() {
12
		init();
13
	}
14
	
15
	public DriverException(String driverName) {
16
		init();
17
		this.driverName = driverName;
18
	}
19
	
20
	public DriverException(String driverName, Throwable cause) {
21
		init();
22
		this.driverName = driverName;
23
		initCause(cause);
24
	}
25

  
26
	public void init() {
27
		messageKey="Error_in_the_driver_%(driverName)s";
28
		formatString="Error in the driver %(driverName)s";
29
		code = serialVersionUID;
30
	}
31

  
32
	
33
	public String getDriverName() {
34
		return driverName;
35
	}
36
	
37
	public void setDriverName(String driverName) {
38
		this.driverName = driverName;
39
	}
40
	
41
	protected Map values() {
42
		HashMap values = new HashMap();
43
		values.put("driverName",this.driverName);
44
		return values;
45
	}
46
}
0 47

  
tags/tmp_build/libraries/libExceptions/src-test/org/gvsig/exceptions/AllTests.java
1
package org.gvsig.exceptions;
2

  
3
import junit.framework.Test;
4
import junit.framework.TestSuite;
5

  
6
public class AllTests {
7

  
8
	public static Test suite() {
9
		TestSuite suite = new TestSuite("Test for org.gvsig.exceptions");
10
		//$JUnit-BEGIN$
11
		suite.addTestSuite(ListBaseExceptionTest.class);
12
		suite.addTestSuite(BaseExceptionTest.class);
13
		//$JUnit-END$
14
		return suite;
15
	}
16

  
17
}
0 18

  
tags/tmp_build/libraries/libExceptions/src/org/gvsig/exceptions/IExceptionTranslator.java
1
package org.gvsig.exceptions;
2

  
3
/**
4
 * 
5
 * @author Equipo de desarrollo de gvSIG
6
 *
7
 */
8
public interface IExceptionTranslator {
9
	
10
	/** 
11
	 *  @param key The key of the message error.
12
	 *  @return The translated error message
13
	 *  corresponding to the key that it
14
	 *  obtains as parameter.
15
	 */
16
	public String getText(String key);
17
}
0 18

  
tags/tmp_build/libraries/libExceptions/src/org/gvsig/exceptions/IBaseException.java
1
package org.gvsig.exceptions;
2

  
3
import java.util.Iterator;
4

  
5
/**
6
 * 
7
 * 
8
 * @author Equipo de desarrollo de gvSIG
9
 *
10
 */
11
public interface IBaseException {
12
	
13
	/** 
14
	 *  Returns the message that describes the exception.
15
	 *  
16
	 *  @return The message.
17
	 */
18
	public String getMessage();
19

  
20
	/** 
21
	 *  Returns the message that describes the exception, with indentation.
22
	 *  
23
	 *  @param indent Quantity of blanks to insert
24
	 *         at the start of the message.
25
	 *  @return The message with indentation.
26
	 */
27
	public String getMessage(int indent);
28

  
29
	/** 
30
	 *  Returns the translated message that describes the exception.
31
	 *  
32
	 *  @return The translated message with indentation.
33
	 */
34
	public String getLocalizedMessage();
35
	
36
	/** 
37
	 *  Returns the translated message that
38
	 *  describes the exception with indentation.
39
	 *
40
	 *  @param translator Instance of a class that fulfills
41
	 *         the IExceptionTranslator interface.
42
	 *         His method "getText" takes charge returning
43
	 *         the expression, correspondent to the key that
44
	 *         delivers him, translated into the configured language.
45
	 *  @param indent Quantity of blanks to insert
46
	 *         at the start of the message.
47
	 *  @return The translated message with indentation.
48
	 */
49
	public String getLocalizedMessage(IExceptionTranslator translator, int indent);
50
	
51
	/** 
52
	 *  Crosses the exceptions chained through cause to conform
53
	 *  the message.
54
	 *  
55
	 *  @return The compound message with all the messages
56
	 *          of the stack of exceptions.
57
	 */
58
	public String getMessageStack();
59

  
60
	/** 
61
	 *  Crosses the exceptions chained through cause to conform
62
	 *  the compound message with indentation.
63
	 *  
64
	 *  @param indent Quantity of blanks to insert
65
	 *         at the start of the messages.
66
	 *  @return The compound message with all the messages
67
	 *          of the stack of exceptions.
68

  
69
	 */
70
	public String getMessageStack(int indent);
71

  
72
	/** 
73
	 *  Crosses the exceptions chained through cause
74
	 *  to conform the compound message in the corresponding language.
75
	 *  
76
	 *  @return The translated compound message.
77
	 *    
78
	 */
79
	public String getLocalizedMessageStack();
80

  
81
	/** 
82
	 *  Crosses the exceptions chained through cause
83
	 *  to conform the compound message in the corresponding language.
84
	 *  
85
	 *  @param translator Instance of a class that fulfills
86
	 *         the IExceptionTranslator interface.
87
	 *         His method "getText" takes charge returning
88
	 *         the expression, correspondent to the key that
89
	 *         delivers him, translated into the configured language.
90
	 *  @param indent Quantity of blanks to insert
91
	 *         at the start of the messages.
92
	 *  @return The translated message with indentation.
93
	 *  
94
	 */
95
	public String getLocalizedMessageStack(IExceptionTranslator translator, int indent);
96
	
97
	
98
	/** 
99
	 *  @return The exception's code.
100
	 */
101
	public long getCode();
102
	
103
	/** 
104
	 *  @return The format string.
105
	 */
106
	public String getFormatString();
107
	
108
	/** 
109
	 *  @return The message key associated to the exception.
110
	 */
111
	public String getMessageKey();
112
	
113
	/** 
114
	 *  @return A iterator for the chained exceptions.
115
	 */
116
	public Iterator iterator();
117
	
118
}
0 119

  
tags/tmp_build/libraries/libExceptions/src/org/gvsig/exceptions/BaseExceptionIterator.java
1
package org.gvsig.exceptions;
2

  
3
import java.util.Iterator;
4

  
5
class BaseExceptionIterator implements Iterator {
6
	
7
	Exception exception;
8
	
9
	BaseExceptionIterator(BaseException exception){
10
		this.exception = exception;
11
	}
12
	/** 
13
	 *  @return true if the iteration has more elements.
14
	 */
15
	public boolean hasNext() {
16
		return this.exception != null;
17
	}
18
	
19
	/** 
20
	 *  @return The next element in the iteration.
21
	 */
22
	public Object next() {
23
		Exception exception;
24
		exception = this.exception;
25
		this.exception = (Exception) exception.getCause();
26
		return exception;
27
	}
28
	
29
	/** 
30
	 *  @throws "UnsupportedOperationException" because
31
	 *  the remove operation will not be supported
32
	 *  by this Iterator.
33
	 */
34
	public void remove() {
35
		throw new UnsupportedOperationException();
36
	}
37
}
0 38

  
tags/tmp_build/libraries/libExceptions/src/org/gvsig/exceptions/ListBaseException.java
1
package org.gvsig.exceptions;
2

  
3
import java.util.ArrayList;
4
import java.util.Collection;
5
import java.util.Iterator;
6
import java.util.List;
7
import java.util.ListIterator;
8

  
9
/**
10
 * @author Equipo de desarrollo de gvSIG
11
 *
12
 */
13
public abstract class ListBaseException extends BaseException implements List{
14
	private List exceptions = new ArrayList();
15
	
16
	/* (non-Javadoc)
17
	 * @see java.util.Collection#size()
18
	 */
19
	public int size() {
20
		return this.exceptions.size();
21
	}
22

  
23
	/* (non-Javadoc)
24
	 * @see java.util.Collection#isEmpty()
25
	 */
26
	public boolean isEmpty() {
27
		return this.exceptions.isEmpty();
28
	}
29

  
30
	/* (non-Javadoc)
31
	 * @see java.util.Collection#contains(java.lang.Object)
32
	 */
33
	public boolean contains(Object arg0) {
34
		return this.exceptions.contains(arg0);
35
	}
36

  
37
	/* (non-Javadoc)
38
	 * @see java.util.Collection#toArray()
39
	 */
40
	public Object[] toArray() {
41
		return this.exceptions.toArray();
42
	}
43

  
44
	/**
45
	 * @param arg0
46
	 * @return
47
	 */
48
	public Object[] toArray(Object[] arg0) {
49
		return this.exceptions.toArray(arg0);
50
	}
51

  
52
	/**
53
	 * @param arg0
54
	 * @return
55
	 */
56
	public boolean add(Object arg0) {
57
		return this.exceptions.add(arg0);
58
	}
59

  
60
	/* (non-Javadoc)
61
	 * @see java.util.Collection#remove(java.lang.Object)
62
	 */
63
	public boolean remove(Object arg0) {
64
		return this.exceptions.remove(arg0);
65
	}
66

  
67
	/**
68
	 * @param arg0
69
	 * @return
70
	 */
71
	public boolean containsAll(Collection arg0) {
72
		return this.exceptions.contains(arg0);
73
	}
74

  
75
	/**
76
	 * @param arg0
77
	 * @return
78
	 */
79
	public boolean addAll(Collection arg0) {
80
		return this.exceptions.addAll(arg0);
81
	}
82

  
83
	/**
84
	 * @param arg0
85
	 * @param arg1
86
	 * @return
87
	 */
88
	public boolean addAll(int arg0, Collection arg1) {
89
		return this.exceptions.addAll(arg0, arg1);
90
	}
91

  
92
	/**
93
	 * @param arg0
94
	 * @return
95
	 */
96
	public boolean removeAll(Collection arg0) {
97
		return this.exceptions.removeAll(arg0);
98
	}
99

  
100
	/**
101
	 * @param arg0
102
	 * @return
103
	 */
104
	public boolean retainAll(Collection arg0) {
105
		return this.exceptions.retainAll(arg0);
106
	}
107

  
108
	/* (non-Javadoc)
109
	 * @see java.util.Collection#clear()
110
	 */
111
	public void clear() {
112
		this.exceptions.clear();
113
	}
114

  
115
	/* (non-Javadoc)
116
	 * @see java.util.List#get(int)
117
	 */
118
	public Object get(int arg0) {
119
		return this.exceptions.get(arg0);
120
	}
121

  
122
	/**
123
	 * @param arg0
124
	 * @param arg1
125
	 * @return
126
	 */
127
	public Object set(int arg0, Object arg1) {
128
		return this.exceptions.set(arg0, arg1);
129
	}
130

  
131
	/**
132
	 * @param arg0
133
	 * @param arg1
134
	 */
135
	public void add(int arg0, Object arg1) {
136
		this.exceptions.add(arg0, arg1);
137
	}
138

  
139
	/* (non-Javadoc)
140
	 * @see java.util.List#remove(int)
141
	 */
142
	public Object remove(int arg0) {
143
		return this.exceptions.remove(arg0);
144
	}
145

  
146
	/* (non-Javadoc)
147
	 * @see java.util.List#indexOf(java.lang.Object)
148
	 */
149
	public int indexOf(Object arg0) {
150
		return this.exceptions.indexOf(arg0);
151
	}
152

  
153
	/* (non-Javadoc)
154
	 * @see java.util.List#lastIndexOf(java.lang.Object)
155
	 */
156
	public int lastIndexOf(Object arg0) {
157
		return this.exceptions.lastIndexOf(arg0);
158
	}
159

  
160
	/* (non-Javadoc)
161
	 * @see java.util.List#listIterator()
162
	 */
163
	public ListIterator listIterator() {
164
		return this.exceptions.listIterator();
165
	}
166

  
167
	/* (non-Javadoc)
168
	 * @see java.util.List#listIterator(int)
169
	 */
170
	public ListIterator listIterator(int arg0) {
171
		return this.exceptions.listIterator(arg0);
172
	}
173

  
174
	/* (non-Javadoc)
175
	 * @see java.util.List#subList(int, int)
176
	 */
177
	public List subList(int arg0, int arg1) {
178
		return this.exceptions.subList(arg0, arg1);
179
	}
180
	
181
	/* (non-Javadoc)
182
	 * @see java.lang.Throwable#getMessage()
183
	 */
184
	public String getMessage() {
185
		String msg = super.getMessage();
186
		Exception bex;
187
		Iterator iter=this.exceptions.iterator();
188
		while (iter.hasNext()) {
189
			bex = (Exception) iter.next();
190
			msg = msg + "\n  " + bex.getMessage();
191
		}
192
		return msg;
193
	}
194
	
195
	/* (non-Javadoc)
196
	 * @see org.gvsig.exceptions.IBaseException#getLocalizedMessage(org.gvsig.exceptions.IExceptionTranslator, int)
197
	 */
198
	public String getLocalizedMessage(IExceptionTranslator exceptionTranslator, int indent) {
199
		String msg = super.getLocalizedMessage(exceptionTranslator, indent);
200
		Exception bex;
201
		Iterator iter=this.exceptions.iterator();
202
		while (iter.hasNext()) {
203
			bex = (Exception) iter.next();
204
			if( bex instanceof BaseException ) {
205
				msg = msg + "\n  " + ((BaseException)bex).getLocalizedMessage(exceptionTranslator, indent);				
206
			} else {
207
				msg = msg + "\n  " + bex.getLocalizedMessage();
208
			}
209
		}
210
		return BaseException.insertBlanksAtStart(msg,indent);
211
	}
212

  
213
}
0 214

  
tags/tmp_build/libraries/libExceptions/src/org/gvsig/exceptions/BaseException.java
1
package org.gvsig.exceptions;
2

  
3
import java.lang.reflect.Method;
4
import java.util.Iterator;
5
import java.util.Map;
6

  
7
import org.apache.log4j.Logger;
8

  
9
/**
10
 *
11
 * Esta clase esta pensada para actuar como clase base para
12
 * las excepciones que se lanzan dentro del proyecto de gvSIG.
13
 *
14
 * A?ade la implementacion necesaria para disponer de mensajes
15
 * de error internacionalizables, a traves del metodo
16
 * getLocalizedMessage, asi como una serie de metodos que nos
17
 * permiten obtener los mesanes de error de la cadena de excepciones
18
 * enlazadas a traves de su "causa", asi como utilidades que
19
 * permitan recorrer de forma comoda esta cadena de excepciones
20
 * por medio de un Iterador.
21
 *
22
 * @author Equipo de desarrollo de gvSIG.
23
 *
24
 */
25
public abstract class BaseException extends Exception implements IBaseException {
26
	private final static String BLANKS ="                                                                                                     ";
27
	private static IExceptionTranslator translator= null;
28
	private static Logger logger = null;
29

  
30

  
31
	protected String messageKey;
32

  
33
	protected String formatString;
34

  
35
	/**
36
	 * Unique code of error.
37
	 */
38
	protected long code;
39

  
40
	/**
41
	 * Returns the format string received in the parameter
42
	 * with its keys replaced with the corresponding values of the map.
43
	 *
44
	 * @param formatString
45
	 * @param values map
46
	 * @return string formatted
47
	 */
48
	private String format(String formatString, Map values) {
49
		String key;
50
		String ret = formatString;
51
		if(formatString == null){
52
			Logger lLogger=getLogger();
53
			lLogger.error(this.getClass().getName()+": formatString is null.");
54
			if (values != null){
55
				Iterator keys = values.keySet().iterator();
56
				ret = "values = { ";
57
				while (keys.hasNext()){
58
					key = (String) keys.next();
59
					ret = ret.concat(key+": "+ (String)values.get(key)+"; ");
60
				}
61
				ret = ret.concat(" }");
62
			}
63
			
64
			return ret;
65
		}
66
		if (values != null){
67
			Iterator keys = values.keySet().iterator();
68
			while (keys.hasNext()){
69
				key = (String) keys.next();
70
				ret = ret.replaceAll("%\\("+key+"\\)", (String)values.get(key));
71
			}
72
		}
73
		return ret;
74
	}
75
	protected Logger getLogger() {
76
		if(logger==null){
77
			logger = Logger.getLogger(BaseException.class.getName());
78
		}
79
		return logger;
80
	}
81

  
82
	/* (non-Javadoc)
83
	 * @see java.lang.Throwable#getMessage()
84
	 */
85
	public String getMessage() {
86
		return format(this.formatString, values());
87
	}
88

  
89
	/* (non-Javadoc)
90
	 * @see org.gvsig.exceptions.IBaseException#getMessage(int)
91
	 */
92
	public String getMessage(int indent) {
93
		return insertBlanksAtStart(format(formatString, values()),indent);
94
	}
95

  
96
	/* (non-Javadoc)
97
	 * @see java.lang.Throwable#getLocalizedMessage()
98
	 */
99
	public String getLocalizedMessage() {
100
		return getLocalizedMessage(translator,0);
101
	}
102

  
103
	/* (non-Javadoc)
104
	 * @see org.gvsig.exceptions.IBaseException#getLocalizedMessage(org.gvsig.exceptions.IExceptionTranslator, int)
105
	 */
106
	public String getLocalizedMessage(IExceptionTranslator translator, int indent){
107

  
108
		String fmt;
109
		if (translator == null){
110
			translator = BaseException.translator;
111
		}
112
		if (translator == null){
113
			fmt = getFormatString();
114
		} else {
115
			fmt = getMessageKey();
116
			if (fmt == null){
117
				fmt = getFormatString();
118
			} else {
119
				fmt = translator.getText(fmt);
120
			}
121
		}
122
		return insertBlanksAtStart(format(fmt,values()),indent);
123
	}
124

  
125
	/* (non-Javadoc)
126
	 * @see org.gvsig.exceptions.IBaseException#getMessageStack()
127
	 */
128
	public String getMessageStack() {
129
		return getMessageStack(0);
130
	}
131

  
132
	/* (non-Javadoc)
133
	 * @see org.gvsig.exceptions.IBaseException#getMessageStack(int)
134
	 */
135
	public String getMessageStack(int indent) {
136
		Iterator iter = this.iterator();
137
		String msg="";
138
		String msg1;
139
		Exception ex;
140
		int i = 1;
141
		while (iter.hasNext()){
142
			ex = ((Exception)iter.next());
143
			if ( ex instanceof BaseException ) {
144
				BaseException bex = (BaseException) ex;
145
				msg1 = bex.getMessage(indent*i);
146
			} else {
147
				msg1 = insertBlanksAtStart(ex.getMessage(),indent*i);
148
			}
149
			if(msg1!=null && !msg1.equals("")){
150
				if( msg.equals("")) {
151
					msg = msg1 ;					
152
				} else {
153
					msg = msg + "\n" + msg1 ;
154
				}
155
			}
156
			i++;
157
		}
158
		return msg;
159
	}
160

  
161

  
162
	/* (non-Javadoc)
163
	 * @see org.gvsig.exceptions.IBaseException#getLocalizedMessageStack()
164
	 */
165
	public String getLocalizedMessageStack() {
166
		return getLocalizedMessageStack(BaseException.translator,0);
167
	}
168

  
169
	/* (non-Javadoc)
170
	 * @see org.gvsig.exceptions.IBaseException#getLocalizedMessageStack(org.gvsig.exceptions.IExceptionTranslator, int)
171
	 */
172
	public String getLocalizedMessageStack(IExceptionTranslator translator, int indent) {
173
		Iterator iter = this.iterator();
174
		String msg="";
175
		Exception ex;
176
		while (iter.hasNext()){
177
			ex = ((Exception)iter.next());
178
			if ( ex instanceof BaseException ) {
179
				BaseException bex = (BaseException) ex;
180
				if( msg.equals("") ) {
181
					msg = bex.getLocalizedMessage(translator,indent);
182
				} else {
183
					msg = msg + "\n" + bex.getLocalizedMessage(translator,indent).trim();
184
				}
185
			} else {
186
				if( msg.equals("") ) {
187
					msg = ex.getLocalizedMessage();			
188
				} else {
189
					msg = msg + "\n" + ex.getLocalizedMessage();
190
				}
191
			}
192
		}
193
		return msg;
194
	}
195

  
196
	/**
197
	 * Inserts blanks at the start of a string.
198
	 *
199
	 * @param str A string.
200
	 * @param len Quantity of blanks to insert at the start of str.
201
	 * @return A string compund by the quantity of blanks that
202
	 *         len indicates and str.
203
	 */
204
	static String insertBlanksAtStart(String str, int len){
205
		try {
206
			return BLANKS.substring(0,len)+str;
207
		} catch (IndexOutOfBoundsException e) {
208
			return BLANKS + str;
209
		}
210
	}
211

  
212
	/* (non-Javadoc)
213
	 * @see org.gvsig.exceptions.IBaseException#getCode()
214
	 */
215
	public long getCode() {
216
		return this.code;
217
	}
218

  
219
	/**
220
	 * Sets the exception's code.
221
	 */
222
	public void setCode(long code) {
223
		this.code = code;
224
	}
225

  
226
	/* (non-Javadoc)
227
	 * @see org.gvsig.exceptions.IBaseException#getFormatString()
228
	 */
229
	public String getFormatString() {
230
		return this.formatString;
231
	}
232

  
233
	/**
234
	 * Sets the format string.
235
	 *
236
	 * @param formatString
237
	 */
238
	public void setFormatString(String formatString) {
239
		this.formatString = formatString;
240
	}
241

  
242
	/* (non-Javadoc)
243
	 * @see org.gvsig.exceptions.IBaseException#getMessageKey()
244
	 */
245
	public String getMessageKey() {
246
		return this.messageKey;
247
	}
248

  
249
	/**
250
	 * Sets the property messageKey.
251
	 *
252
	 * @param messageKey
253
	 */
254
	public void setMessageKey(String messageKey) {
255
		this.messageKey = messageKey;
256
	}
257

  
258
	/* (non-Javadoc)
259
	 * @see org.gvsig.exceptions.IBaseException#iterator()
260
	 */
261
	public Iterator iterator() {
262
		return new BaseExceptionIterator(this);
263
	}
264

  
265
	/**
266
	 * @return A map that serves to replace in the format string
267
	 * the keys with the corresponding values.
268
	 */
269
	abstract protected Map values();
270

  
271
	/**
272
	 * Sets the property translator.
273
	 * @param translator It(He,She) is used to translate
274
	 *        the messages associated with the exceptions.
275
	 */
276
	public static void setTranslator(IExceptionTranslator translator){
277
		BaseException.translator = translator;
278
	}
279

  
280
	public static void setTranslator(Object translator){
281
		BaseException.translator = new TranslatorWraper(translator);
282
	}
283

  
284
	public String toString(){
285
		return format(this.formatString, values());
286
	}
287

  
288
}
289

  
290
class TranslatorWraper implements IExceptionTranslator {
291

  
292
	private Object translator = null;
293
	private Method method = null;
294

  
295
	public TranslatorWraper(Object translator) {
296
		Class theClass = translator.getClass();
297
		String s = "";
298

  
299
		this.translator = translator;
300
		try {
301
			method = theClass.getMethod("getText",new Class[] { s.getClass() });
302
		} catch (Exception e) {
303
			throw new RuntimeException("El objeto translator suministrado no tiene el metodo getText apropiado.", e);
304
		}
305

  
306
	}
307

  
308
	public String getText(String key) {
309
		try {
310
			return (String)(method.invoke(translator,new String[] { key }));
311
		} catch (Exception e) {
312
			return key;
313
		}
314
	}
315

  
316
}
0 317

  
tags/tmp_build/libraries/libExceptions/pom.xml
1
<project xmlns="http://maven.apache.org/POM/4.0.0"
2
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4
	<modelVersion>4.0.0</modelVersion>
5
	<groupId>org.gvsig</groupId>
6
	<artifactId>libExceptions</artifactId>
7
	<packaging>jar</packaging>
8
	<version>1.9-SNAPSHOT</version>
9
	<name>libExceptions</name>
10
	<url>http://maven.apache.org</url>
11
	<parent>
12
		<groupId>org.gvsig</groupId>
13
		<artifactId>gvsig-library-base-pom</artifactId>
14
		<version>1.0-SNAPSHOT</version>
15
	</parent>
16
	<dependencies>
17
	</dependencies>
18
	<build>
19
		<sourceDirectory>src</sourceDirectory>
20
		<testSourceDirectory>src-test</testSourceDirectory>
21
	</build>
22
</project>
0 23

  
tags/tmp_build/libraries/libDwg/doc/gpl.txt
1
		    GNU GENERAL PUBLIC LICENSE
2
		       Version 2, June 1991
3

  
4
 Copyright (C) 1989, 1991 Free Software Foundation, Inc.
5
                       59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
6
 Everyone is permitted to copy and distribute verbatim copies
7
 of this license document, but changing it is not allowed.
8

  
9
			    Preamble
10

  
11
  The licenses for most software are designed to take away your
12
freedom to share and change it.  By contrast, the GNU General Public
13
License is intended to guarantee your freedom to share and change free
14
software--to make sure the software is free for all its users.  This
15
General Public License applies to most of the Free Software
16
Foundation's software and to any other program whose authors commit to
17
using it.  (Some other Free Software Foundation software is covered by
18
the GNU Library General Public License instead.)  You can apply it to
19
your programs, too.
20

  
21
  When we speak of free software, we are referring to freedom, not
22
price.  Our General Public Licenses are designed to make sure that you
23
have the freedom to distribute copies of free software (and charge for
24
this service if you wish), that you receive source code or can get it
25
if you want it, that you can change the software or use pieces of it
26
in new free programs; and that you know you can do these things.
27

  
28
  To protect your rights, we need to make restrictions that forbid
29
anyone to deny you these rights or to ask you to surrender the rights.
30
These restrictions translate to certain responsibilities for you if you
31
distribute copies of the software, or if you modify it.
32

  
33
  For example, if you distribute copies of such a program, whether
34
gratis or for a fee, you must give the recipients all the rights that
35
you have.  You must make sure that they, too, receive or can get the
36
source code.  And you must show them these terms so they know their
37
rights.
38

  
39
  We protect your rights with two steps: (1) copyright the software, and
40
(2) offer you this license which gives you legal permission to copy,
41
distribute and/or modify the software.
42

  
43
  Also, for each author's protection and ours, we want to make certain
44
that everyone understands that there is no warranty for this free
45
software.  If the software is modified by someone else and passed on, we
46
want its recipients to know that what they have is not the original, so
47
that any problems introduced by others will not reflect on the original
48
authors' reputations.
49

  
50
  Finally, any free program is threatened constantly by software
51
patents.  We wish to avoid the danger that redistributors of a free
52
program will individually obtain patent licenses, in effect making the
53
program proprietary.  To prevent this, we have made it clear that any
54
patent must be licensed for everyone's free use or not licensed at all.
55

  
56
  The precise terms and conditions for copying, distribution and
57
modification follow.
58

59
		    GNU GENERAL PUBLIC LICENSE
60
   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61

  
62
  0. This License applies to any program or other work which contains
63
a notice placed by the copyright holder saying it may be distributed
64
under the terms of this General Public License.  The "Program", below,
65
refers to any such program or work, and a "work based on the Program"
66
means either the Program or any derivative work under copyright law:
67
that is to say, a work containing the Program or a portion of it,
68
either verbatim or with modifications and/or translated into another
69
language.  (Hereinafter, translation is included without limitation in
70
the term "modification".)  Each licensee is addressed as "you".
71

  
72
Activities other than copying, distribution and modification are not
73
covered by this License; they are outside its scope.  The act of
74
running the Program is not restricted, and the output from the Program
75
is covered only if its contents constitute a work based on the
76
Program (independent of having been made by running the Program).
77
Whether that is true depends on what the Program does.
78

  
79
  1. You may copy and distribute verbatim copies of the Program's
80
source code as you receive it, in any medium, provided that you
81
conspicuously and appropriately publish on each copy an appropriate
82
copyright notice and disclaimer of warranty; keep intact all the
83
notices that refer to this License and to the absence of any warranty;
84
and give any other recipients of the Program a copy of this License
85
along with the Program.
86

  
87
You may charge a fee for the physical act of transferring a copy, and
88
you may at your option offer warranty protection in exchange for a fee.
89

  
90
  2. You may modify your copy or copies of the Program or any portion
91
of it, thus forming a work based on the Program, and copy and
92
distribute such modifications or work under the terms of Section 1
93
above, provided that you also meet all of these conditions:
94

  
95
    a) You must cause the modified files to carry prominent notices
96
    stating that you changed the files and the date of any change.
97

  
98
    b) You must cause any work that you distribute or publish, that in
99
    whole or in part contains or is derived from the Program or any
100
    part thereof, to be licensed as a whole at no charge to all third
101
    parties under the terms of this License.
102

  
103
    c) If the modified program normally reads commands interactively
104
    when run, you must cause it, when started running for such
105
    interactive use in the most ordinary way, to print or display an
106
    announcement including an appropriate copyright notice and a
107
    notice that there is no warranty (or else, saying that you provide
108
    a warranty) and that users may redistribute the program under
109
    these conditions, and telling the user how to view a copy of this
110
    License.  (Exception: if the Program itself is interactive but
111
    does not normally print such an announcement, your work based on
112
    the Program is not required to print an announcement.)
113

114
These requirements apply to the modified work as a whole.  If
115
identifiable sections of that work are not derived from the Program,
116
and can be reasonably considered independent and separate works in
117
themselves, then this License, and its terms, do not apply to those
118
sections when you distribute them as separate works.  But when you
119
distribute the same sections as part of a whole which is a work based
120
on the Program, the distribution of the whole must be on the terms of
121
this License, whose permissions for other licensees extend to the
122
entire whole, and thus to each and every part regardless of who wrote it.
123

  
124
Thus, it is not the intent of this section to claim rights or contest
125
your rights to work written entirely by you; rather, the intent is to
126
exercise the right to control the distribution of derivative or
127
collective works based on the Program.
128

  
129
In addition, mere aggregation of another work not based on the Program
130
with the Program (or with a work based on the Program) on a volume of
131
a storage or distribution medium does not bring the other work under
132
the scope of this License.
133

  
134
  3. You may copy and distribute the Program (or a work based on it,
135
under Section 2) in object code or executable form under the terms of
136
Sections 1 and 2 above provided that you also do one of the following:
137

  
138
    a) Accompany it with the complete corresponding machine-readable
139
    source code, which must be distributed under the terms of Sections
140
    1 and 2 above on a medium customarily used for software interchange; or,
141

  
142
    b) Accompany it with a written offer, valid for at least three
143
    years, to give any third party, for a charge no more than your
144
    cost of physically performing source distribution, a complete
145
    machine-readable copy of the corresponding source code, to be
146
    distributed under the terms of Sections 1 and 2 above on a medium
147
    customarily used for software interchange; or,
148

  
149
    c) Accompany it with the information you received as to the offer
150
    to distribute corresponding source code.  (This alternative is
151
    allowed only for noncommercial distribution and only if you
152
    received the program in object code or executable form with such
153
    an offer, in accord with Subsection b above.)
154

  
155
The source code for a work means the preferred form of the work for
156
making modifications to it.  For an executable work, complete source
157
code means all the source code for all modules it contains, plus any
158
associated interface definition files, plus the scripts used to
159
control compilation and installation of the executable.  However, as a
160
special exception, the source code distributed need not include
161
anything that is normally distributed (in either source or binary
162
form) with the major components (compiler, kernel, and so on) of the
163
operating system on which the executable runs, unless that component
164
itself accompanies the executable.
165

  
166
If distribution of executable or object code is made by offering
167
access to copy from a designated place, then offering equivalent
168
access to copy the source code from the same place counts as
169
distribution of the source code, even though third parties are not
170
compelled to copy the source along with the object code.
171

172
  4. You may not copy, modify, sublicense, or distribute the Program
173
except as expressly provided under this License.  Any attempt
174
otherwise to copy, modify, sublicense or distribute the Program is
175
void, and will automatically terminate your rights under this License.
176
However, parties who have received copies, or rights, from you under
177
this License will not have their licenses terminated so long as such
178
parties remain in full compliance.
179

  
180
  5. You are not required to accept this License, since you have not
181
signed it.  However, nothing else grants you permission to modify or
182
distribute the Program or its derivative works.  These actions are
183
prohibited by law if you do not accept this License.  Therefore, by
184
modifying or distributing the Program (or any work based on the
185
Program), you indicate your acceptance of this License to do so, and
186
all its terms and conditions for copying, distributing or modifying
187
the Program or works based on it.
188

  
189
  6. Each time you redistribute the Program (or any work based on the
190
Program), the recipient automatically receives a license from the
191
original licensor to copy, distribute or modify the Program subject to
192
these terms and conditions.  You may not impose any further
193
restrictions on the recipients' exercise of the rights granted herein.
194
You are not responsible for enforcing compliance by third parties to
195
this License.
196

  
197
  7. If, as a consequence of a court judgment or allegation of patent
198
infringement or for any other reason (not limited to patent issues),
199
conditions are imposed on you (whether by court order, agreement or
200
otherwise) that contradict the conditions of this License, they do not
201
excuse you from the conditions of this License.  If you cannot
202
distribute so as to satisfy simultaneously your obligations under this
203
License and any other pertinent obligations, then as a consequence you
204
may not distribute the Program at all.  For example, if a patent
205
license would not permit royalty-free redistribution of the Program by
206
all those who receive copies directly or indirectly through you, then
207
the only way you could satisfy both it and this License would be to
208
refrain entirely from distribution of the Program.
209

  
210
If any portion of this section is held invalid or unenforceable under
211
any particular circumstance, the balance of the section is intended to
212
apply and the section as a whole is intended to apply in other
213
circumstances.
214

  
215
It is not the purpose of this section to induce you to infringe any
216
patents or other property right claims or to contest validity of any
217
such claims; this section has the sole purpose of protecting the
218
integrity of the free software distribution system, which is
219
implemented by public license practices.  Many people have made
220
generous contributions to the wide range of software distributed
221
through that system in reliance on consistent application of that
222
system; it is up to the author/donor to decide if he or she is willing
223
to distribute software through any other system and a licensee cannot
224
impose that choice.
225

  
226
This section is intended to make thoroughly clear what is believed to
227
be a consequence of the rest of this License.
228

229
  8. If the distribution and/or use of the Program is restricted in
230
certain countries either by patents or by copyrighted interfaces, the
231
original copyright holder who places the Program under this License
232
may add an explicit geographical distribution limitation excluding
233
those countries, so that distribution is permitted only in or among
234
countries not thus excluded.  In such case, this License incorporates
235
the limitation as if written in the body of this License.
236

  
237
  9. The Free Software Foundation may publish revised and/or new versions
238
of the General Public License from time to time.  Such new versions will
239
be similar in spirit to the present version, but may differ in detail to
240
address new problems or concerns.
241

  
242
Each version is given a distinguishing version number.  If the Program
243
specifies a version number of this License which applies to it and "any
244
later version", you have the option of following the terms and conditions
245
either of that version or of any later version published by the Free
246
Software Foundation.  If the Program does not specify a version number of
247
this License, you may choose any version ever published by the Free Software
248
Foundation.
249

  
250
  10. If you wish to incorporate parts of the Program into other free
251
programs whose distribution conditions are different, write to the author
252
to ask for permission.  For software which is copyrighted by the Free
253
Software Foundation, write to the Free Software Foundation; we sometimes
254
make exceptions for this.  Our decision will be guided by the two goals
255
of preserving the free status of all derivatives of our free software and
256
of promoting the sharing and reuse of software generally.
257

  
258
			    NO WARRANTY
259

  
260
  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
262
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
266
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
267
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268
REPAIR OR CORRECTION.
269

  
270
  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278
POSSIBILITY OF SUCH DAMAGES.
279

  
280
		     END OF TERMS AND CONDITIONS
281

282
	    How to Apply These Terms to Your New Programs
283

  
284
  If you develop a new program, and you want it to be of the greatest
285
possible use to the public, the best way to achieve this is to make it
286
free software which everyone can redistribute and change under these terms.
287

  
288
  To do so, attach the following notices to the program.  It is safest
289
to attach them to the start of each source file to most effectively
290
convey the exclusion of warranty; and each file should have at least
291
the "copyright" line and a pointer to where the full notice is found.
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff