/** * On deserialization, replace this proxy by the static constant. * * @return The resolved key. * @throws ObjectStreamException If the key has not been found. This exception should not occur is * the key is deserialized using the same Geotk version than the one that serialized the key. */ protected Object readResolve() throws ObjectStreamException { try { return definer.getField(field).get(null); } catch (ReflectiveOperationException cause) { final InvalidClassException e = new InvalidClassException( definer.getName(), Errors.format(Errors.Keys.IllegalKey_1, this)); e.initCause(cause); throw e; } }
private <O> O instantiate(ClassTypeModel<O> typeModel, Map<FieldModel<? super O, ?>, ?> state) throws InvalidClassException { try { ObjectFactory<? super O> factory = context.getFactory(typeModel.getJavaType()); // return factory.create(typeModel.getJavaType(), state); } catch (Exception e) { InvalidClassException ice = new InvalidClassException( "Cannot instantiate object from class " + typeModel.getJavaType().getName()); ice.initCause(e); throw ice; } }
/** * Creates a tile manager from the given file or directory. * * <p> * * <ul> * <li>If the argument {@linkplain Files#isRegularFile(Path, LinkOption...)} is a file} having * the {@code ".serialized"} suffix, then this method deserializes the object in the given * file and passes it to {@link #createFromObject(Object)}. * <li>If the given argument {@linkplain Files#isDirectory(Path, LinkOption...)} is a * directory}, then this method delegates to {@link #create(Path, PathMatcher, * ImageReaderSpi)} which scan all image files found in the directory. * <li>Otherwise an {@link IOException} is thrown. * </ul> * * @param file The serialized file or the directory to scan. * @return A tile manager created from the tiles in the given directory. * @throws IOException If the given file is not recognized, or an I/O operation failed. * @since 3.15 */ public TileManager[] create(final Path file) throws IOException { if (Files.isRegularFile(file, LinkOption.NOFOLLOW_LINKS)) { final String suffix = file.getFileName().toString(); if (!suffix.endsWith(".serialized")) { throw new IOException(Errors.format(Errors.Keys.UnknownFileSuffix_1, suffix)); } final Object manager; try (InputStream fin = Files.newInputStream(file); ObjectInputStream in = new ObjectInputStream(fin)) { try { manager = in.readObject(); } catch (ClassNotFoundException cause) { InvalidClassException ex = new InvalidClassException(cause.getLocalizedMessage()); ex.initCause(cause); throw ex; } } return setSourceFile(createFromObject(manager), file); } else if (Files.isDirectory(file, LinkOption.NOFOLLOW_LINKS)) { return create(file, null, null); } else { throw new IOException(Errors.format(Errors.Keys.NotADirectory_1, file)); } }