Revision 43828
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/messages/NotificationManager.java | ||
---|---|---|
87 | 87 |
* @see com.iver.mdiApp.Notification#addError(java.lang.String) |
88 | 88 |
*/ |
89 | 89 |
public static synchronized void addError(final String err, Throwable e) { |
90 |
logger.error(err, e); |
|
91 |
dispatchError(err, e); |
|
90 |
logger.error(err, e); |
|
91 |
try { |
|
92 |
dispatchError(err, e); |
|
93 |
} catch(Exception ex) { |
|
94 |
|
|
95 |
} |
|
92 | 96 |
} |
93 | 97 |
|
94 | 98 |
public static synchronized void dispatchError(final String err, Throwable e) { |
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/project/Project.java | ||
---|---|---|
180 | 180 |
public void saveState(File out) throws PersistenceException; |
181 | 181 |
|
182 | 182 |
public void saveState(OutputStream out) throws PersistenceException; |
183 |
|
|
184 |
public void saveState(OutputStream out, File rootFolder) throws PersistenceException; |
|
183 | 185 |
|
184 | 186 |
public void loadState(InputStream in); |
185 | 187 |
|
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/project/DefaultProject.java | ||
---|---|---|
30 | 30 |
import java.io.FileInputStream; |
31 | 31 |
import java.io.FileNotFoundException; |
32 | 32 |
import java.io.FileOutputStream; |
33 |
import java.io.IOException; |
|
33 | 34 |
import java.io.InputStream; |
34 | 35 |
import java.io.OutputStream; |
35 | 36 |
import java.io.Serializable; |
... | ... | |
44 | 45 |
import java.util.List; |
45 | 46 |
import java.util.Map; |
46 | 47 |
import java.util.Set; |
48 |
import java.util.zip.ZipException; |
|
49 |
import java.util.zip.ZipFile; |
|
47 | 50 |
|
48 | 51 |
import org.cresques.cts.IProjection; |
49 | 52 |
|
... | ... | |
69 | 72 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
70 | 73 |
import org.gvsig.tools.ToolsLocator; |
71 | 74 |
import org.gvsig.tools.dynobject.DynStruct; |
72 |
import org.gvsig.tools.exception.ListBaseException; |
|
73 | 75 |
import org.gvsig.tools.observer.ObservableHelper; |
74 | 76 |
import org.gvsig.tools.observer.Observer; |
75 | 77 |
import org.gvsig.tools.persistence.PersistenceManager; |
... | ... | |
542 | 544 |
} catch (FileNotFoundException e) { |
543 | 545 |
throw new PersistenceException(e); |
544 | 546 |
} |
547 |
if( !isValidZIP(out) ) { |
|
548 |
throw new PersistenceException(new ZipException()); |
|
549 |
} |
|
545 | 550 |
this.fname = out; |
546 | 551 |
notifyObservers(ProjectNotification.AFTER_SAVE_TO_FILE, out); |
547 | 552 |
} |
548 | 553 |
|
554 |
boolean isValidZIP(final File file) { |
|
555 |
ZipFile zipfile = null; |
|
556 |
try { |
|
557 |
zipfile = new ZipFile(file); |
|
558 |
return true; |
|
559 |
} catch (IOException e) { |
|
560 |
return false; |
|
561 |
} finally { |
|
562 |
try { |
|
563 |
if (zipfile != null) { |
|
564 |
zipfile.close(); |
|
565 |
zipfile = null; |
|
566 |
} |
|
567 |
} catch (IOException e) { |
|
568 |
} |
|
569 |
} |
|
570 |
} |
|
571 |
|
|
549 | 572 |
public File getFile() { |
550 | 573 |
return this.fname; |
551 | 574 |
} |
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/extension/ProjectExtension.java | ||
---|---|---|
37 | 37 |
import java.util.Set; |
38 | 38 |
import java.util.prefs.Preferences; |
39 | 39 |
import java.util.zip.ZipEntry; |
40 |
import java.util.zip.ZipException; |
|
41 |
import java.util.zip.ZipFile; |
|
40 | 42 |
import java.util.zip.ZipOutputStream; |
41 | 43 |
import javax.imageio.ImageIO; |
42 | 44 |
|
... | ... | |
446 | 448 |
return writeProject(file, p, true); |
447 | 449 |
} |
448 | 450 |
|
449 |
/** |
|
450 |
* Escribe el proyecto en XML. Pero permite decidir si se pide confirmaci?n |
|
451 |
* para sobreescribir |
|
452 |
* |
|
453 |
* @param file |
|
454 |
* Fichero. |
|
455 |
* @param p |
|
456 |
* Proyecto. |
|
457 |
* @param askConfirmation |
|
458 |
* boolean |
|
459 |
*/ |
|
460 |
public boolean writeProject(File file, Project p, boolean askConfirmation) { |
|
461 |
if (askConfirmation && file.exists()) { |
|
462 |
int resp = JOptionPane.showConfirmDialog((Component) PluginServices |
|
463 |
.getMainFrame(), PluginServices.getText(this, |
|
464 |
"fichero_ya_existe_seguro_desea_guardarlo"), PluginServices |
|
465 |
.getText(this, "guardar"), JOptionPane.YES_NO_OPTION); |
|
466 |
if (resp != JOptionPane.YES_OPTION) { |
|
467 |
return false; |
|
468 |
} |
|
469 |
} |
|
470 |
NotificationManager.addInfo(PluginServices.getText(this, |
|
471 |
"writing_project") + ": " + file.getName()); |
|
451 |
/** |
|
452 |
* Escribe el proyecto en disco. |
|
453 |
* Pero permite decidir si se pide confirmaci?n para sobreescribir |
|
454 |
* |
|
455 |
* @param file Fichero. |
|
456 |
* @param p Proyecto. |
|
457 |
* @param askConfirmation boolean |
|
458 |
* @return |
|
459 |
*/ |
|
460 |
public boolean writeProject(File file, Project p, boolean askConfirmation) { |
|
461 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
|
462 |
ApplicationManager application = ApplicationLocator.getManager(); |
|
463 |
if (askConfirmation && file.exists()) { |
|
464 |
int resp = application.confirmDialog( |
|
465 |
i18n.getTranslation("fichero_ya_existe_seguro_desea_guardarlo"), |
|
466 |
i18n.getTranslation("guardar"), |
|
467 |
JOptionPane.YES_NO_OPTION, |
|
468 |
JOptionPane.QUESTION_MESSAGE, |
|
469 |
"Overwrite_project_file" |
|
470 |
); |
|
471 |
if (resp != JOptionPane.YES_OPTION) { |
|
472 |
return false; |
|
473 |
} |
|
474 |
} |
|
475 |
FileOutputStream fout=null; |
|
476 |
ZipOutputStream zout=null; |
|
477 |
LOG.info("Writing project '"+ file.getAbsolutePath()+"'."); |
|
478 |
try { |
|
479 |
fireBeforeSavingFileEvent(new SaveEvent(this,SaveEvent.BEFORE_SAVING, file)); |
|
472 | 480 |
|
473 |
// write it out as XML |
|
474 |
try { |
|
475 |
fireBeforeSavingFileEvent(new SaveEvent(this, |
|
476 |
SaveEvent.BEFORE_SAVING, file)); |
|
477 |
|
|
478 |
FileOutputStream fout = new FileOutputStream(file); |
|
479 |
ZipOutputStream zout = new ZipOutputStream(fout); |
|
480 |
p.saveState(zout); |
|
481 |
|
|
481 |
fout = new FileOutputStream(file); |
|
482 |
zout = new ZipOutputStream(fout); |
|
483 |
p.saveState(zout, file.getParentFile()); |
|
484 |
|
|
482 | 485 |
zout.putNextEntry(new ZipEntry("preview.jpg")); |
483 | 486 |
BufferedImage img = ApplicationLocator.getManager().getUIManager().getImagePreview(); |
484 | 487 |
img = scale(img, 0.40); |
485 | 488 |
try { |
486 | 489 |
ImageIO.write(img, "jpg", zout); |
487 | 490 |
} catch (IOException ex) { |
488 |
LOG.warn("Can't save preview image'.",ex); |
|
491 |
LOG.warn("Can't save preview image'.", ex);
|
|
489 | 492 |
} |
490 |
|
|
493 |
fireAfterSavingFileEvent(new SaveEvent(this, SaveEvent.AFTER_SAVING, file)); |
|
491 | 494 |
IOUtils.closeQuietly(zout); |
492 | 495 |
IOUtils.closeQuietly(fout); |
496 |
|
|
497 |
if( !isValidZIP(file) ) { |
|
498 |
throw new ZipException("Invalid project file '"+file.getAbsolutePath()+"'"); |
|
499 |
} |
|
493 | 500 |
|
494 |
fireAfterSavingFileEvent(new SaveEvent(this,
|
|
495 |
SaveEvent.AFTER_SAVING, file));
|
|
501 |
PluginServices.getMainFrame().setTitle(file.getName());
|
|
502 |
setPath(file.toString());
|
|
496 | 503 |
|
497 |
PluginServices.getMainFrame().setTitle(file.getName()); |
|
498 |
setPath(file.toString()); |
|
504 |
} catch (Exception e) { |
|
505 |
application.messageDialog( |
|
506 |
i18n.getTranslation("_Problems_saving_the_project_XnlX_It_is_possible_that_this_was_not_saved_properly_and_can_not_be_loaded_again"), |
|
507 |
null, |
|
508 |
i18n.getTranslation("guardar"), |
|
509 |
JOptionPane.ERROR_MESSAGE, |
|
510 |
"Problems_saving_the_project" |
|
511 |
); |
|
512 |
LOG.warn("Error writing project '"+file.getAbsolutePath()+"'.", e); |
|
513 |
return false; |
|
514 |
} finally { |
|
515 |
IOUtils.closeQuietly(zout); |
|
516 |
IOUtils.closeQuietly(fout); |
|
517 |
} |
|
518 |
|
|
519 |
LOG.warn("Wrote project '"+file.getAbsolutePath()+"'."); |
|
520 |
return true; |
|
521 |
} |
|
499 | 522 |
|
500 |
} catch (PersistenceException e) { |
|
501 |
String messagestack = e.getLocalizedMessageStack(); |
|
502 |
NotificationManager.addError( |
|
503 |
PluginServices.getText(this, "error_writing_project") |
|
504 |
+ ": " + file.getName() + "\n" + messagestack, e); |
|
505 |
return false; |
|
506 |
} catch (Exception e) { |
|
507 |
NotificationManager.addError( |
|
508 |
PluginServices.getText(this, "error_writing_project") |
|
509 |
+ ": " + file.getName(), e); |
|
510 |
return false; |
|
511 |
} |
|
512 |
NotificationManager.addInfo(PluginServices.getText(this, |
|
513 |
"wrote_project") + ": " + file.getName()); |
|
514 |
return true; |
|
515 |
} |
|
523 |
boolean isValidZIP(final File file) { |
|
524 |
ZipFile zipfile = null; |
|
525 |
try { |
|
526 |
zipfile = new ZipFile(file); |
|
527 |
return true; |
|
528 |
} catch (IOException e) { |
|
529 |
return false; |
|
530 |
} finally { |
|
531 |
try { |
|
532 |
if (zipfile != null) { |
|
533 |
zipfile.close(); |
|
534 |
zipfile = null; |
|
535 |
} |
|
536 |
} catch (IOException e) { |
|
537 |
} |
|
538 |
} |
|
539 |
} |
|
516 | 540 |
|
517 | 541 |
private BufferedImage scale(BufferedImage before, double factor) { |
518 | 542 |
int w = (int) (before.getWidth()*factor); |
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/resources-plugin/i18n/text.properties | ||
---|---|---|
1287 | 1287 |
_Change_view_projection=CRS Vista |
1288 | 1288 |
_Change_view_projection_to_projection_of_the_selected_item_in_the_list=Cambia la proyecci\u00f3n de la Vista a la proyecci\u00f3n del item seleccionado en la lista. |
1289 | 1289 |
_precision_comparing_decimal_numbers=Precisi\u00f3n de comparaci\u00f3n de n\u00fameros decimales |
1290 |
_default_expression_evaluator=Evaluador de expresiones por defecto |
|
1290 |
_default_expression_evaluator=Evaluador de expresiones por defecto |
|
1291 |
_Problems_saving_the_project_XnlX_It_is_possible_that_this_was_not_saved_properly_and_can_not_be_loaded_again=Problemas guardando el proyecto.\nEs posible que este no se haya guardado correctamente y no se pueda volver a cargar. |
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/resources-plugin/i18n/text_en.properties | ||
---|---|---|
1206 | 1206 |
_Change_view_projection=CRS View |
1207 | 1207 |
_Change_view_projection_to_projection_of_the_selected_item_in_the_list=Change View projection to the projection of the selected item in the list |
1208 | 1208 |
_precision_comparing_decimal_numbers=Precision comparing decimal numbers |
1209 |
_default_expression_evaluator=Default expression evaluator |
|
1209 |
_default_expression_evaluator=Default expression evaluator |
|
1210 |
_Problems_saving_the_project_XnlX_It_is_possible_that_this_was_not_saved_properly_and_can_not_be_loaded_again=Problems saving the project.\nIt is possible that this was not saved properly and can not be loaded again. |
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.library/org.gvsig.temporarystorage/org.gvsig.temporarystorage.lib/org.gvsig.temporarystorage.lib.api/src/main/resources/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.gvsig.temporarystorage.TemporaryStorageManagerLibrary |
|
1 |
org.gvsig.temporarystorage.TemporaryStorageLibrary |
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.library/org.gvsig.temporarystorage/org.gvsig.temporarystorage.lib/org.gvsig.temporarystorage.lib.api/src/main/java/org/gvsig/temporarystorage/TemporaryStorageLocator.java | ||
---|---|---|
36 | 36 |
return LOCATOR_NAME; |
37 | 37 |
} |
38 | 38 |
|
39 |
public static TemporaryStorageManager getManager() throws LocatorException { |
|
39 |
public static TemporaryStorageManager getTemporaryStorageManager() throws LocatorException {
|
|
40 | 40 |
return (TemporaryStorageManager) getInstance().get(MANAGER_NAME); |
41 | 41 |
} |
42 | 42 |
|
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.library/org.gvsig.temporarystorage/org.gvsig.temporarystorage.lib/org.gvsig.temporarystorage.lib.impl/src/main/resources/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.gvsig.temporarystorage.impl.TemporaryStorageManagerImplLibrary |
|
1 |
org.gvsig.temporarystorage.impl.TemporaryStorageImplLibrary |
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.library/org.gvsig.temporarystorage/org.gvsig.temporarystorage.lib/org.gvsig.temporarystorage.lib.impl/src/main/java/org/gvsig/temporarystorage/impl/TemporaryStorageManagerImplLibrary.java | ||
---|---|---|
1 |
package org.gvsig.temporarystorage.impl; |
|
2 |
|
|
3 |
|
|
4 |
import org.gvsig.temporarystorage.TemporaryStorageLibrary; |
|
5 |
import org.gvsig.temporarystorage.TemporaryStorageLocator; |
|
6 |
import org.gvsig.tools.library.AbstractLibrary; |
|
7 |
import org.gvsig.tools.library.LibraryException; |
|
8 |
|
|
9 |
public class TemporaryStorageManagerImplLibrary extends AbstractLibrary { |
|
10 |
|
|
11 |
@Override |
|
12 |
public void doRegistration() { |
|
13 |
registerAsImplementationOf(TemporaryStorageLibrary.class); |
|
14 |
} |
|
15 |
|
|
16 |
@Override |
|
17 |
protected void doInitialize() throws LibraryException { |
|
18 |
TemporaryStorageLocator.registerManager(DefaultTemporaryStorageManager.class); |
|
19 |
} |
|
20 |
|
|
21 |
@Override |
|
22 |
protected void doPostInitialize() throws LibraryException { |
|
23 |
|
|
24 |
} |
|
25 |
} |
|
26 |
|
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.library/org.gvsig.temporarystorage/org.gvsig.temporarystorage.lib/org.gvsig.temporarystorage.lib.impl/src/main/java/org/gvsig/temporarystorage/impl/TemporaryStorageImplLibrary.java | ||
---|---|---|
1 |
package org.gvsig.temporarystorage.impl; |
|
2 |
|
|
3 |
|
|
4 |
import org.gvsig.temporarystorage.TemporaryStorageLibrary; |
|
5 |
import org.gvsig.temporarystorage.TemporaryStorageLocator; |
|
6 |
import org.gvsig.tools.library.AbstractLibrary; |
|
7 |
import org.gvsig.tools.library.LibraryException; |
|
8 |
|
|
9 |
public class TemporaryStorageImplLibrary extends AbstractLibrary { |
|
10 |
|
|
11 |
@Override |
|
12 |
public void doRegistration() { |
|
13 |
registerAsImplementationOf(TemporaryStorageLibrary.class); |
|
14 |
} |
|
15 |
|
|
16 |
@Override |
|
17 |
protected void doInitialize() throws LibraryException { |
|
18 |
TemporaryStorageLocator.registerManager(DefaultTemporaryStorageManager.class); |
|
19 |
} |
|
20 |
|
|
21 |
@Override |
|
22 |
protected void doPostInitialize() throws LibraryException { |
|
23 |
|
|
24 |
} |
|
25 |
} |
|
26 |
|
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/DefaultExpressionEvaluatorManager.java | ||
---|---|---|
10 | 10 |
import org.gvsig.expressionevaluator.MutableSymbolTable; |
11 | 11 |
import org.gvsig.expressionevaluator.SymbolTable; |
12 | 12 |
import org.gvsig.fmap.dal.EvaluatorFactory; |
13 |
import org.gvsig.integration.DefaultEvaluatorFactory; |
|
14 |
import org.gvsig.integration.DefaultExpressionEvaluator; |
|
13 |
import org.gvsig.expressionevaluator.integration.DefaultEvaluatorFactory;
|
|
14 |
import org.gvsig.expressionevaluator.integration.DefaultExpressionEvaluator;
|
|
15 | 15 |
|
16 | 16 |
|
17 | 17 |
public class DefaultExpressionEvaluatorManager implements ExpressionEvaluatorManager { |
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/DefaultSymbolTable.java | ||
---|---|---|
11 | 11 |
|
12 | 12 |
public class DefaultSymbolTable implements MutableSymbolTable { |
13 | 13 |
|
14 |
private SymbolTable symbolTable;
|
|
15 |
private final Map<String,Object> vars;
|
|
16 |
private final Map<String,Function> functions;
|
|
14 |
private SymbolTable delegatedSymbolTable;
|
|
15 |
private Map<String,Object> vars; |
|
16 |
private Map<String,Function> functions; |
|
17 | 17 |
|
18 |
public DefaultSymbolTable(SymbolTable symbolTable) {
|
|
19 |
this.symbolTable = symbolTable;
|
|
18 |
public DefaultSymbolTable(SymbolTable delegatedSymbolTable) {
|
|
19 |
this.delegatedSymbolTable = delegatedSymbolTable;
|
|
20 | 20 |
this.vars = new HashMap<>(); |
21 | 21 |
this.functions = new HashMap<>(); |
22 | 22 |
} |
... | ... | |
24 | 24 |
public DefaultSymbolTable() { |
25 | 25 |
this(null); |
26 | 26 |
} |
27 |
|
|
28 |
@Override |
|
29 |
public MutableSymbolTable clone() throws CloneNotSupportedException { |
|
30 |
DefaultSymbolTable other = (DefaultSymbolTable) super.clone(); |
|
31 |
if( this.delegatedSymbolTable!=null ) { |
|
32 |
other.delegatedSymbolTable = this.delegatedSymbolTable.clone(); |
|
33 |
} |
|
34 |
other.vars = new HashMap<>(vars); |
|
35 |
other.functions = new HashMap<>(functions); |
|
36 |
return other; |
|
37 |
} |
|
27 | 38 |
|
28 | 39 |
@Override |
29 | 40 |
public void addVar(String name, Object value) { |
... | ... | |
38 | 49 |
@Override |
39 | 50 |
public Function function(String name) { |
40 | 51 |
Function fn = this.functions.get(name); |
41 |
if( fn == null && this.symbolTable != null ) {
|
|
42 |
fn = this.symbolTable.function(name);
|
|
52 |
if( fn == null && this.delegatedSymbolTable != null ) {
|
|
53 |
fn = this.delegatedSymbolTable.function(name);
|
|
43 | 54 |
} |
44 | 55 |
return fn; |
45 | 56 |
} |
... | ... | |
48 | 59 |
public boolean exists(String name) { |
49 | 60 |
boolean e = this.vars.containsKey(name); |
50 | 61 |
if( !e ) { |
51 |
e = this.symbolTable.exists(name);
|
|
62 |
e = this.delegatedSymbolTable.exists(name);
|
|
52 | 63 |
} |
53 | 64 |
return e; |
54 | 65 |
} |
... | ... | |
58 | 69 |
if( this.vars.containsKey(name) ) { |
59 | 70 |
return this.vars.get(name); |
60 | 71 |
} |
61 |
return this.symbolTable.value(name);
|
|
72 |
return this.delegatedSymbolTable.value(name);
|
|
62 | 73 |
} |
63 | 74 |
|
64 | 75 |
@Override |
65 | 76 |
public void setSymbolTable(SymbolTable symbolTable) { |
66 |
this.symbolTable = symbolTable;
|
|
77 |
this.delegatedSymbolTable = symbolTable;
|
|
67 | 78 |
} |
68 | 79 |
|
69 | 80 |
@Override |
70 | 81 |
public SymbolTable getSymbolTable() { |
71 |
return this.symbolTable;
|
|
82 |
return this.delegatedSymbolTable;
|
|
72 | 83 |
} |
73 | 84 |
|
74 | 85 |
@Override |
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/DefaultToken.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import org.gvsig.expressionevaluator.LexicalAnalyzer.Token; |
4 | 4 |
|
5 |
|
|
6 | 5 |
public class DefaultToken implements Token { |
7 | 6 |
|
8 | 7 |
private int type; |
9 |
String literal; |
|
8 |
private String literal;
|
|
10 | 9 |
private Object value; |
11 | 10 |
|
12 | 11 |
public DefaultToken() { |
13 | 12 |
} |
14 | 13 |
|
14 |
@Override |
|
15 |
public Token clone() throws CloneNotSupportedException { |
|
16 |
// We will assume that the properties of the class are immutable, so |
|
17 |
// it would suffice to call the super class. |
|
18 |
DefaultToken other = (DefaultToken) super.clone(); |
|
19 |
return other; |
|
20 |
} |
|
21 |
|
|
22 |
|
|
23 |
@Override |
|
15 | 24 |
public void set(int type, String literal) { |
16 | 25 |
this.set(type, literal, literal); |
17 | 26 |
} |
18 | 27 |
|
28 |
@Override |
|
19 | 29 |
public void set(int type, String literal, Object value) { |
20 | 30 |
this.literal = literal; |
21 | 31 |
this.type = type; |
22 | 32 |
this.value = value; |
23 | 33 |
} |
24 | 34 |
|
35 |
@Override |
|
25 | 36 |
public int getType() { |
26 | 37 |
return type; |
27 | 38 |
} |
28 | 39 |
|
40 |
@Override |
|
29 | 41 |
public Object getValue() { |
30 | 42 |
return value; |
31 | 43 |
} |
32 | 44 |
|
45 |
@Override |
|
33 | 46 |
public String getLiteral() { |
34 | 47 |
return literal; |
35 | 48 |
} |
36 | 49 |
|
50 |
public void setLiteral(String literal) { |
|
51 |
this.literal = literal; |
|
52 |
} |
|
53 |
|
|
37 | 54 |
} |
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/DefaultCodeBuilder.java | ||
---|---|---|
153 | 153 |
return this.args.size(); |
154 | 154 |
} |
155 | 155 |
|
156 |
@Override |
|
157 | 156 |
public void add(Code arg) { |
158 | 157 |
this.args.add(arg); |
159 | 158 |
} |
... | ... | |
266 | 265 |
} |
267 | 266 |
|
268 | 267 |
@Override |
268 |
public CodeBuilder clone() throws CloneNotSupportedException { |
|
269 |
// This implementation of CodeBuilder does not maintain state, so |
|
270 |
// we only call the super class. |
|
271 |
DefaultCodeBuilder other = (DefaultCodeBuilder) super.clone(); |
|
272 |
return other; |
|
273 |
} |
|
274 |
|
|
275 |
@Override |
|
269 | 276 |
public Constant constant(Object value) { |
270 | 277 |
return new BaseConstant(value); |
271 | 278 |
} |
... | ... | |
293 | 300 |
@Override |
294 | 301 |
public Caller operator(String name, Code arg1) { |
295 | 302 |
Arguments args = args(); |
296 |
args.add(arg1);
|
|
303 |
((BaseArguments)args).add(arg1);
|
|
297 | 304 |
return function(name, Caller.UNARY_OPERATOR, args); |
298 | 305 |
} |
299 | 306 |
|
300 | 307 |
@Override |
301 | 308 |
public Caller operator(String name, Code arg1, Code arg2) { |
302 | 309 |
Arguments args = args(); |
303 |
args.add(arg1);
|
|
304 |
args.add(arg2);
|
|
310 |
((BaseArguments)args).add(arg1);
|
|
311 |
((BaseArguments)args).add(arg2);
|
|
305 | 312 |
return function(name, Caller.BINARY_OPERATOR, args); |
306 | 313 |
} |
307 | 314 |
|
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/SQLLexicalAnalyzer.java | ||
---|---|---|
1 | 1 |
package org.gvsig.expressionevaluator.impl; |
2 | 2 |
|
3 |
import org.gvsig.expressionevaluator.LexicalAnalyzer; |
|
4 |
|
|
3 | 5 |
public class SQLLexicalAnalyzer extends AbstractLexicalAnalyzer { |
4 | 6 |
|
5 | 7 |
public SQLLexicalAnalyzer(String source) { |
... | ... | |
23 | 25 |
} |
24 | 26 |
|
25 | 27 |
@Override |
28 |
public LexicalAnalyzer clone() throws CloneNotSupportedException { |
|
29 |
// As this implementation does not add state to the abstract class, we |
|
30 |
// just call the super class. |
|
31 |
SQLLexicalAnalyzer other = (SQLLexicalAnalyzer) super.clone(); |
|
32 |
|
|
33 |
return other; |
|
34 |
} |
|
35 |
|
|
36 |
|
|
37 |
@Override |
|
26 | 38 |
protected Token getToken() { |
27 | 39 |
skipblanks(); |
28 | 40 |
char ch = getch(); |
... | ... | |
88 | 100 |
} |
89 | 101 |
ungetch(); |
90 | 102 |
parseNumber(); |
91 |
token.literal = "+" + token.literal;
|
|
103 |
token.setLiteral("+" + token.getLiteral());
|
|
92 | 104 |
return token; |
93 | 105 |
case '-': |
94 | 106 |
ch = getch(); |
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/DefaultInterpreter.java | ||
---|---|---|
75 | 75 |
private SymbolTable symbolTable = null; |
76 | 76 |
private Double accuracy; |
77 | 77 |
private Code currentCode; |
78 |
private final Cache cache;
|
|
78 |
private Cache cache; |
|
79 | 79 |
|
80 | 80 |
public DefaultInterpreter() { |
81 |
this.symbolTable = SQLSymbolTable.getInstance(); |
|
82 | 81 |
this.cache = new DefaultCache(); |
83 | 82 |
} |
84 | 83 |
|
85 | 84 |
@Override |
85 |
public Interpreter clone() throws CloneNotSupportedException { |
|
86 |
DefaultInterpreter other = (DefaultInterpreter) super.clone(); |
|
87 |
other.cache = new DefaultCache(); |
|
88 |
if( this.symbolTable!=null ) { |
|
89 |
other.symbolTable = this.symbolTable.clone(); |
|
90 |
} |
|
91 |
|
|
92 |
return other; |
|
93 |
} |
|
94 |
|
|
95 |
@Override |
|
86 | 96 |
public Cache getCache() { |
87 | 97 |
return this.cache; |
88 | 98 |
} |
... | ... | |
94 | 104 |
|
95 | 105 |
@Override |
96 | 106 |
public SymbolTable getSymbolTable() { |
107 |
if( this.symbolTable==null ) { |
|
108 |
this.symbolTable = SQLSymbolTable.getInstance(); |
|
109 |
} |
|
97 | 110 |
return this.symbolTable; |
98 | 111 |
} |
99 | 112 |
@Override |
... | ... | |
124 | 137 |
if( code instanceof Caller ) { |
125 | 138 |
Caller caller = (Caller) code; |
126 | 139 |
if( caller.function() == null ) { |
127 |
caller.function(this.symbolTable.function(caller.name()));
|
|
140 |
caller.function(this.getSymbolTable().function(caller.name()));
|
|
128 | 141 |
} |
129 | 142 |
if( caller.args() != null ) { |
130 | 143 |
for( Code arg : caller.args() ) { |
... | ... | |
144 | 157 |
|
145 | 158 |
case Code.IDENTIFIER: |
146 | 159 |
String name = ((Identifier) code).name(); |
147 |
if( !symbolTable.exists(name) ) {
|
|
160 |
if( !this.getSymbolTable().exists(name) ) {
|
|
148 | 161 |
throw new RuntimeException("Variable '" + name + "' not found."); |
149 | 162 |
} |
150 |
value = symbolTable.value(name);
|
|
163 |
value = this.getSymbolTable().value(name);
|
|
151 | 164 |
break; |
152 | 165 |
|
153 | 166 |
case Code.CALLER: |
154 | 167 |
Caller caller = (Caller) code; |
155 | 168 |
Function function = caller.function(); |
156 | 169 |
if( function == null ) { |
157 |
function = this.symbolTable.function(caller.name());
|
|
170 |
function = this.getSymbolTable().function(caller.name());
|
|
158 | 171 |
if( function == null ) { |
159 | 172 |
throw new RuntimeException("Function '" + caller.name() + "' not found."); |
160 | 173 |
} |
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/AbstractLexicalAnalyzer.java | ||
---|---|---|
7 | 7 |
import java.util.Locale; |
8 | 8 |
import java.util.Map; |
9 | 9 |
import java.util.Stack; |
10 |
import org.gvsig.tools.lang.Cloneable; |
|
10 | 11 |
|
11 | 12 |
public abstract class AbstractLexicalAnalyzer implements LexicalAnalyzer { |
12 | 13 |
|
13 |
protected class Buffer { |
|
14 |
protected class Buffer implements Cloneable {
|
|
14 | 15 |
|
15 | 16 |
StringBuilder builder; |
16 | 17 |
|
... | ... | |
18 | 19 |
this.builder = new StringBuilder(); |
19 | 20 |
} |
20 | 21 |
|
22 |
@Override |
|
23 |
public Buffer clone() throws CloneNotSupportedException { |
|
24 |
Buffer other = (Buffer) super.clone(); |
|
25 |
other.builder = new StringBuilder(builder); |
|
26 |
return other; |
|
27 |
} |
|
28 |
|
|
21 | 29 |
public void clear() { |
22 | 30 |
builder.delete(0, builder.length()); |
23 | 31 |
} |
... | ... | |
38 | 46 |
|
39 | 47 |
protected static final char EOF = 0; |
40 | 48 |
|
41 |
private final NumberFormat nf;
|
|
42 |
private final ParsePosition nfPos;
|
|
43 |
private final Stack<Integer> states;
|
|
49 |
private NumberFormat nf; |
|
50 |
private ParsePosition nfPos; |
|
51 |
private Stack<Integer> states; |
|
44 | 52 |
private String source; |
45 | 53 |
private int position; |
46 | 54 |
|
47 |
protected final Buffer buffer;
|
|
48 |
protected final DefaultToken token;
|
|
49 |
protected final Map<String, Integer> tokens;
|
|
55 |
protected Buffer buffer; |
|
56 |
protected DefaultToken token; |
|
57 |
protected Map<String, Integer> tokens; |
|
50 | 58 |
|
51 | 59 |
public AbstractLexicalAnalyzer(String source) { |
52 | 60 |
this.position = 0; |
... | ... | |
66 | 74 |
} |
67 | 75 |
|
68 | 76 |
@Override |
77 |
public LexicalAnalyzer clone() throws CloneNotSupportedException { |
|
78 |
AbstractLexicalAnalyzer other = (AbstractLexicalAnalyzer) super.clone(); |
|
79 |
other.nf = NumberFormat.getInstance(Locale.UK); |
|
80 |
other.nfPos = new ParsePosition(0); |
|
81 |
other.buffer = buffer.clone(); |
|
82 |
other.token = (DefaultToken) token.clone(); |
|
83 |
other.states = new Stack<>(); |
|
84 |
other.states.addAll(states); |
|
85 |
other.tokens = new HashMap<>(tokens); |
|
86 |
return other; |
|
87 |
} |
|
88 |
|
|
89 |
@Override |
|
69 | 90 |
public void setSource(String source) { |
70 | 91 |
this.source = source; |
71 | 92 |
this.position = 0; |
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/SQLSymbolTable.java | ||
---|---|---|
224 | 224 |
addFunction(new STYFunction()); |
225 | 225 |
addFunction(new STZFunction()); |
226 | 226 |
} |
227 |
|
|
228 |
@Override |
|
229 |
@SuppressWarnings("CloneDoesntCallSuperClone") |
|
230 |
public SymbolTable clone() throws CloneNotSupportedException { |
|
231 |
// SQLSymbolTable is singleton and immutable, so we just return |
|
232 |
// the same instance. |
|
233 |
return this; |
|
234 |
} |
|
227 | 235 |
|
228 | 236 |
private void addFunction(Function function) { |
229 | 237 |
this.functions.put(function.name().toLowerCase(), function); |
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/DefaultCompiler.java | ||
---|---|---|
21 | 21 |
} |
22 | 22 |
|
23 | 23 |
@Override |
24 |
public Compiler clone() throws CloneNotSupportedException { |
|
25 |
DefaultCompiler other = (DefaultCompiler) super.clone(); |
|
26 |
other.lexer = lexer.clone(); |
|
27 |
other.codeBuilder = codeBuilder.clone(); |
|
28 |
|
|
29 |
return other; |
|
30 |
} |
|
31 |
|
|
32 |
@Override |
|
24 | 33 |
public void setLexicalAnalyzer(LexicalAnalyzer lexer) { |
25 | 34 |
this.lexer = lexer; |
26 | 35 |
} |
... | ... | |
29 | 38 |
public void setCodeBuilder(CodeBuilder codeBuilder) { |
30 | 39 |
this.codeBuilder = codeBuilder; |
31 | 40 |
} |
41 |
|
|
32 | 42 |
@Override |
43 |
public CodeBuilder getCodeBuilder() { |
|
44 |
return this.codeBuilder; |
|
45 |
} |
|
46 |
|
|
47 |
@Override |
|
33 | 48 |
public Code compileExpression(String expression) { |
34 | 49 |
this.lexer.setSource(expression); |
35 | 50 |
return parseExpression(); |
... | ... | |
255 | 270 |
if( args == null ) { |
256 | 271 |
args = codeBuilder.args(); |
257 | 272 |
} |
258 |
args.add(arg);
|
|
273 |
((DefaultCodeBuilder.BaseArguments)args).add(arg);
|
|
259 | 274 |
} |
260 | 275 |
Token next = lexer.look(); |
261 | 276 |
switch( next.getType() ) { |
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.api/src/main/java/org/gvsig/expressionevaluator/CodeBuilder.java | ||
---|---|---|
5 | 5 |
import org.gvsig.expressionevaluator.Code.Constant; |
6 | 6 |
import org.gvsig.expressionevaluator.Code.Identifier; |
7 | 7 |
|
8 |
public interface CodeBuilder { |
|
9 |
|
|
8 |
import org.gvsig.tools.lang.Cloneable; |
|
9 |
|
|
10 |
public interface CodeBuilder extends Cloneable { |
|
11 |
|
|
12 |
@Override |
|
13 |
public CodeBuilder clone() throws CloneNotSupportedException; |
|
14 |
|
|
10 | 15 |
Constant constant(Object value); |
11 | 16 |
|
12 | 17 |
Identifier identifier(String name); |
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.api/src/main/java/org/gvsig/expressionevaluator/ExpressionEvaluator.java | ||
---|---|---|
1 | 1 |
package org.gvsig.expressionevaluator; |
2 | 2 |
|
3 | 3 |
import org.gvsig.tools.evaluator.EvaluatorWithDescriptions; |
4 |
import org.gvsig.tools.lang.Cloneable; |
|
4 | 5 |
|
5 |
public interface ExpressionEvaluator extends EvaluatorWithDescriptions { |
|
6 |
public interface ExpressionEvaluator extends EvaluatorWithDescriptions, Cloneable {
|
|
6 | 7 |
|
7 | 8 |
public void compile(); |
8 | 9 |
|
... | ... | |
31 | 32 |
public Double getAccuracy(); |
32 | 33 |
|
33 | 34 |
public void setAccuracy(Double accuracy); |
35 |
|
|
36 |
@Override |
|
37 |
public ExpressionEvaluator clone() throws CloneNotSupportedException; |
|
34 | 38 |
|
39 |
|
|
40 |
|
|
35 | 41 |
} |
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.api/src/main/java/org/gvsig/expressionevaluator/Interpreter.java | ||
---|---|---|
1 | 1 |
package org.gvsig.expressionevaluator; |
2 | 2 |
|
3 |
public interface Interpreter {
|
|
3 |
import org.gvsig.tools.lang.Cloneable;
|
|
4 | 4 |
|
5 |
public interface Interpreter extends Cloneable { |
|
6 |
|
|
5 | 7 |
public interface Cache { |
6 | 8 |
|
7 | 9 |
public Object get(Object context, Object key); |
... | ... | |
28 | 30 |
public Code getCurrentCode(); |
29 | 31 |
|
30 | 32 |
public Cache getCache(); |
33 |
|
|
34 |
@Override |
|
35 |
public Interpreter clone() throws CloneNotSupportedException; |
|
36 |
|
|
37 |
|
|
31 | 38 |
} |
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.api/src/main/java/org/gvsig/expressionevaluator/LexicalAnalyzer.java | ||
---|---|---|
1 | 1 |
package org.gvsig.expressionevaluator; |
2 | 2 |
|
3 |
public interface LexicalAnalyzer { |
|
4 | 3 |
|
5 |
public interface Token {
|
|
4 |
import org.gvsig.tools.lang.Cloneable;
|
|
6 | 5 |
|
6 |
|
|
7 |
public interface LexicalAnalyzer extends Cloneable { |
|
8 |
|
|
9 |
public interface Token extends Cloneable { |
|
10 |
|
|
7 | 11 |
public static final int EOF = -1; |
8 | 12 |
public static final int IDENTIFIER = 0; |
9 | 13 |
public static final int STRING_LITERAL = 1; |
... | ... | |
37 | 41 |
public static final int PARENTHESIS_CLOSE = 31; |
38 | 42 |
public static final int COMA = 32; |
39 | 43 |
|
44 |
@Override |
|
45 |
public Token clone() throws CloneNotSupportedException; |
|
46 |
|
|
40 | 47 |
public void set(int type, String literal); |
41 | 48 |
|
42 | 49 |
public void set(int type, String literal, Object value); |
... | ... | |
55 | 62 |
|
56 | 63 |
public Token next(); |
57 | 64 |
|
65 |
@Override |
|
66 |
public LexicalAnalyzer clone() throws CloneNotSupportedException; |
|
67 |
|
|
68 |
|
|
58 | 69 |
} |
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.api/src/main/java/org/gvsig/expressionevaluator/MutableSymbolTable.java | ||
---|---|---|
14 | 14 |
public void removeVar(String name); |
15 | 15 |
|
16 | 16 |
public void removeFunction(String name); |
17 |
|
|
18 |
@Override |
|
19 |
public MutableSymbolTable clone() throws CloneNotSupportedException; |
|
17 | 20 |
} |
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.api/src/main/java/org/gvsig/expressionevaluator/Code.java | ||
---|---|---|
27 | 27 |
|
28 | 28 |
public interface Arguments extends Iterable<Code>, Visitable { |
29 | 29 |
|
30 |
public void add(Code arg); |
|
31 |
|
|
32 | 30 |
public int count(); |
33 | 31 |
|
34 | 32 |
@Override |
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.api/src/main/java/org/gvsig/expressionevaluator/Compiler.java | ||
---|---|---|
1 | 1 |
package org.gvsig.expressionevaluator; |
2 | 2 |
|
3 |
import org.gvsig.tools.lang.Cloneable; |
|
3 | 4 |
|
4 |
public interface Compiler { |
|
5 |
public interface Compiler extends Cloneable {
|
|
5 | 6 |
|
6 | 7 |
public void setLexicalAnalyzer(LexicalAnalyzer lex); |
7 | 8 |
|
8 | 9 |
public void setCodeBuilder(CodeBuilder codeBuilder); |
9 | 10 |
|
11 |
public CodeBuilder getCodeBuilder(); |
|
12 |
|
|
10 | 13 |
public Code compileExpression(String expression); |
11 | 14 |
|
15 |
@Override |
|
16 |
public Compiler clone() throws CloneNotSupportedException; |
|
17 |
|
|
18 |
|
|
12 | 19 |
} |
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.api/src/main/java/org/gvsig/expressionevaluator/SymbolTable.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import java.util.Iterator; |
4 | 4 |
|
5 |
public interface SymbolTable extends Iterable<Function>{
|
|
5 |
import org.gvsig.tools.lang.Cloneable;
|
|
6 | 6 |
|
7 |
public interface SymbolTable extends Iterable<Function>, Cloneable { |
|
8 |
|
|
7 | 9 |
public Function function(String name); |
8 | 10 |
|
9 | 11 |
public boolean exists(String name); |
... | ... | |
13 | 15 |
public Iterator<String> itervars(); |
14 | 16 |
|
15 | 17 |
public Iterator<Function> iterfuncs(); |
18 |
|
|
19 |
@Override |
|
20 |
public SymbolTable clone() throws CloneNotSupportedException; |
|
21 |
|
|
22 |
|
|
16 | 23 |
} |
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/feature/FeatureStore.java | ||
---|---|---|
895 | 895 |
* @return |
896 | 896 |
*/ |
897 | 897 |
SpatialIndex wrapSpatialIndex(SpatialIndex index); |
898 |
|
|
899 |
public FeatureReference getFeatureReference(String code); |
|
898 | 900 |
} |
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/feature/FeatureReference.java | ||
---|---|---|
63 | 63 |
* @return true if not in the original store |
64 | 64 |
*/ |
65 | 65 |
public boolean isNewFeature(); |
66 |
|
|
67 |
public String getCode(); |
|
66 | 68 |
} |
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/impl/DefaultFeatureStore.java | ||
---|---|---|
2707 | 2707 |
SpatialIndex wrappedIndex = new WrappedSpatialIndex(index, this); |
2708 | 2708 |
return wrappedIndex; |
2709 | 2709 |
} |
2710 |
|
|
2711 |
@Override |
|
2712 |
public FeatureReference getFeatureReference(String code) { |
|
2713 |
FeatureReference featureReference = new DefaultFeatureReference(this, code); |
|
2714 |
return featureReference; |
|
2715 |
} |
|
2710 | 2716 |
} |
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/impl/DefaultFeatureReference.java | ||
---|---|---|
25 | 25 |
|
26 | 26 |
import java.lang.ref.WeakReference; |
27 | 27 |
import java.util.Arrays; |
28 |
import java.util.Base64; |
|
28 | 29 |
import java.util.List; |
29 | 30 |
import org.apache.commons.lang3.ArrayUtils; |
30 | 31 |
|
... | ... | |
40 | 41 |
import org.gvsig.tools.persistence.Persistent; |
41 | 42 |
import org.gvsig.tools.persistence.PersistentState; |
42 | 43 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
44 |
import org.json.JSONArray; |
|
45 |
import org.json.JSONObject; |
|
43 | 46 |
|
44 | 47 |
public class DefaultFeatureReference implements |
45 | 48 |
FeatureReferenceProviderServices, Persistent { |
... | ... | |
52 | 55 |
private boolean isNewFeature; |
53 | 56 |
private String featureTypeId; |
54 | 57 |
|
58 |
|
|
59 |
private final int OID_INDEX = 0; |
|
60 |
private final int MYHASHCODE_INDEX = 1; |
|
61 |
private final int ISNEWFEATURE_INDEX = 2; |
|
62 |
private final int FEATURETYPEID_INDEX = 3; |
|
63 |
private final int PKNAMES_SIZE_INDEX = 4; |
|
64 |
private final int PKNAMES_INDEX = 5; |
|
65 |
private final int PK_INDEX = 6; |
|
66 |
|
|
55 | 67 |
/** |
56 | 68 |
* Constructor used by the persistence manager. Don't use directly. |
57 | 69 |
* After to invoke this method, the persistence manager calls |
... | ... | |
108 | 120 |
this.storeRef = new WeakReference(store); |
109 | 121 |
} |
110 | 122 |
|
111 |
private DefaultFeatureStore getStore() { |
|
123 |
public DefaultFeatureReference(FeatureStore store, String code) { |
|
124 |
this.storeRef = new WeakReference(store); |
|
125 |
|
|
126 |
String json = new String(Base64.getDecoder().decode(code.getBytes())); |
|
127 |
|
|
128 |
JSONArray x = new JSONArray(json); |
|
129 |
this.oid = x.get(OID_INDEX); |
|
130 |
if( x.get(MYHASHCODE_INDEX)==JSONObject.NULL ) { |
|
131 |
this.myHashCode = null; |
|
132 |
} else { |
|
133 |
this.myHashCode = x.getInt(MYHASHCODE_INDEX); |
|
134 |
} |
|
135 |
this.isNewFeature = x.getBoolean(ISNEWFEATURE_INDEX); |
|
136 |
this.featureTypeId = x.getString(FEATURETYPEID_INDEX); |
|
137 |
int pkNames_size = x.getInt(PKNAMES_SIZE_INDEX); |
|
138 |
if( pkNames_size<0 ) { |
|
139 |
this.pk = null; |
|
140 |
this.pkNames = null; |
|
141 |
} else { |
|
142 |
this.pk = new Object[pkNames_size]; |
|
143 |
this.pkNames = new String[pkNames_size]; |
|
144 |
JSONArray xx = x.getJSONArray(PKNAMES_INDEX); |
|
145 |
for( int i=0; i<xx.length(); i++ ) { |
|
146 |
this.pkNames[i] = xx.getString(i); |
|
147 |
} |
|
148 |
xx = x.getJSONArray(PKNAMES_INDEX); |
|
149 |
for( int i=0; i<xx.length(); i++ ) { |
|
150 |
this.pk[i] = xx.get(i); |
|
151 |
} |
|
152 |
} |
|
153 |
|
|
154 |
// JSONObject x = new JSONObject(json); |
|
155 |
// this.oid = x.get("oid"); |
|
156 |
// this.myHashCode = x.getInt("myHashCode"); |
|
157 |
// this.isNewFeature = x.getBoolean("isNewFeature"); |
|
158 |
// this.featureTypeId = x.getString("featureTypeId"); |
|
159 |
// int pkNames_size = x.getInt("pkNames_size"); |
|
160 |
// if( pkNames_size<0 ) { |
|
161 |
// this.pk = null; |
|
162 |
// this.pkNames = null; |
|
163 |
// } else { |
|
164 |
// this.pk = new Object[pkNames_size]; |
|
165 |
// this.pkNames = new String[pkNames_size]; |
|
166 |
// JSONArray xx = x.getJSONArray("pkNames"); |
|
167 |
// for( int i=0; i<xx.length(); i++ ) { |
|
168 |
// this.pkNames[i] = xx.getString(i); |
|
169 |
// } |
|
170 |
// xx = x.getJSONArray("pk"); |
|
171 |
// for( int i=0; i<xx.length(); i++ ) { |
|
172 |
// this.pk[i] = xx.get(i); |
|
173 |
// } |
|
174 |
// } |
|
175 |
} |
|
176 |
|
|
177 |
private DefaultFeatureStore getStore() { |
|
112 | 178 |
return (DefaultFeatureStore) this.storeRef.get(); |
113 | 179 |
} |
114 | 180 |
|
... | ... | |
263 | 329 |
} |
264 | 330 |
|
265 | 331 |
} |
332 |
|
|
333 |
@Override |
|
334 |
public String getCode() { |
|
335 |
// JSONObject x = new JSONObject(); |
|
336 |
//// x.put("store", (Persistent) storeRef.get()); |
|
337 |
// x.put("oid", oid); |
|
338 |
// x.put("myHashCode", myHashCode); |
|
339 |
// x.put("isNewFeature", isNewFeature); |
|
340 |
// x.put("featureTypeId", featureTypeId); |
|
341 |
// if( this.pk == null ) { |
|
342 |
// x.put("pkNames_size", -1); |
|
343 |
// x.put("pkNames", JSONObject.NULL); |
|
344 |
// x.put("pk", JSONObject.NULL); |
|
345 |
// } else { |
|
346 |
// x.put("pkNames_size", pkNames.length); |
|
347 |
// x.put("pkNames", new JSONArray(this.pkNames)); |
|
348 |
// x.put("pk", new JSONArray(this.pk)); |
|
349 |
// } |
|
350 |
// |
|
351 |
Object[] data = new Object[7]; |
|
352 |
data[OID_INDEX] = this.oid; |
|
353 |
data[MYHASHCODE_INDEX] = this.myHashCode; |
|
354 |
data[ISNEWFEATURE_INDEX] = this.isNewFeature; |
|
355 |
data[FEATURETYPEID_INDEX] = this.featureTypeId; |
|
356 |
if( this.pk == null ) { |
|
357 |
data[PKNAMES_SIZE_INDEX] = -1; |
|
358 |
data[PKNAMES_INDEX] = JSONObject.NULL; |
|
359 |
data[PK_INDEX] = JSONObject.NULL; |
|
360 |
} else { |
|
361 |
data[PKNAMES_SIZE_INDEX] = pkNames.length; |
|
362 |
data[PKNAMES_INDEX] = new JSONArray(this.pkNames); |
|
363 |
data[PK_INDEX] = new JSONArray(this.pk); |
|
364 |
} |
|
365 |
String s = new JSONArray(data).toString(); |
|
366 |
String r = Base64.getEncoder().encodeToString(s.getBytes()); |
|
367 |
|
|
368 |
return r; |
|
369 |
} |
|
266 | 370 |
|
267 | 371 |
public static void registerPersistent() { |
268 | 372 |
DynStruct definition = ToolsLocator.getPersistenceManager().addDefinition( |
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/main/java/org/gvsig/fmap/mapcontext/layers/ExtendedPropertiesSupport.java | ||
---|---|---|
25 | 25 |
|
26 | 26 |
import java.util.Map; |
27 | 27 |
|
28 |
/** |
|
29 |
* |
|
30 |
* @deprecated use org.gvsig.tools.util.PropertiesSupport |
|
31 |
*/ |
|
28 | 32 |
public interface ExtendedPropertiesSupport { |
29 | 33 |
|
30 | 34 |
/** |
31 | 35 |
Also available in: Unified diff