@Test public void testDeSerialize() throws Exception { Properties props = StandardSettings.getProps(CoreTestHelper.PATHS.PATH1.getFile().getAbsolutePath(), CoreTestHelper.RESOURCENAME); CoreTestHelper.getStorage(CoreTestHelper.PATHS.PATH1.getFile()); ResourceConfiguration resConf = mResourceConfig.create(props); CoreTestHelper.createResource(resConf); ResourceConfiguration serializedConf = ResourceConfiguration.deserialize(new File(props.getProperty(ConstructorProps.STORAGEPATH)), props.getProperty(ConstructorProps.RESOURCE)); assertEquals(resConf.toString(), serializedConf.toString()); }
public static ResourceConfiguration deserialize(final File pFile, final String pResource) throws TTIOException { try { final File file = new File(new File(new File(pFile, StorageConfiguration.Paths.Data.getFile().getName()), pResource), Paths.ConfigBinary.getFile().getName()); FileReader fileReader = new FileReader(file); JsonReader jsonReader = new JsonReader(fileReader); jsonReader.beginObject(); jsonReader.nextName().equals(JSONNAMES[0]); Class<?> metaBucketClazz = Class.forName(jsonReader.nextString()); jsonReader.nextName().equals(JSONNAMES[1]); Class<?> revClazz = Class.forName(jsonReader.nextString()); jsonReader.nextName().equals(JSONNAMES[2]); Class<?> dataFacClazz = Class.forName(jsonReader.nextString()); List<IByteHandler> handlerList = new ArrayList<IByteHandler>(); if (jsonReader.nextName().equals(JSONNAMES[3])) { jsonReader.beginArray(); while (jsonReader.hasNext()) { Class<?> handlerClazz = Class.forName(jsonReader.nextString()); Constructor<?> handlerCons = handlerClazz.getConstructors()[0]; if (handlerClazz.getName().equals(Encryptor.class.getName())) { handlerList.add((IByteHandler)handlerCons.newInstance(StandardSettings.KEY)); } else { handlerList.add((IByteHandler)handlerCons.newInstance()); } } jsonReader.endArray(); } ByteHandlerPipeline pipeline = new ByteHandlerPipeline(handlerList.toArray(new IByteHandler[handlerList.size()])); jsonReader.nextName().equals(JSONNAMES[4]); Class<?> storageClazz = Class.forName(jsonReader.nextString()); jsonReader.nextName().equals(JSONNAMES[5]); Properties props = new Properties(); jsonReader.beginObject(); while (jsonReader.hasNext()) { props.setProperty(jsonReader.nextName(), jsonReader.nextString()); } jsonReader.endObject(); jsonReader.endObject(); jsonReader.close(); fileReader.close(); Constructor<?> metaBucketCons = metaBucketClazz.getConstructors()[0]; IMetaEntryFactory metaFac = (IMetaEntryFactory)metaBucketCons.newInstance(); Constructor<?> dataFacCons = dataFacClazz.getConstructors()[0]; IDataFactory dataFactory = (IDataFactory)dataFacCons.newInstance(); Constructor<?> revCons = revClazz.getConstructors()[0]; IRevisioning revObject = (IRevisioning)revCons.newInstance(); Constructor<?> storageCons = storageClazz.getConstructors()[0]; IBackend backend = (IBackend)storageCons.newInstance(props, dataFactory, metaFac, pipeline); return new ResourceConfiguration(props, backend, revObject, dataFactory, metaFac); } catch (IOException | ClassNotFoundException | InstantiationException | IllegalAccessException | InvocationTargetException exc) { throw new TTIOException(exc); } }
ResourceConfiguration { public static ResourceConfiguration deserialize(final File pFile, final String pResource) throws TTIOException { try { final File file = new File(new File(new File(pFile, StorageConfiguration.Paths.Data.getFile().getName()), pResource), Paths.ConfigBinary.getFile().getName()); FileReader fileReader = new FileReader(file); JsonReader jsonReader = new JsonReader(fileReader); jsonReader.beginObject(); jsonReader.nextName().equals(JSONNAMES[0]); Class<?> metaBucketClazz = Class.forName(jsonReader.nextString()); jsonReader.nextName().equals(JSONNAMES[1]); Class<?> revClazz = Class.forName(jsonReader.nextString()); jsonReader.nextName().equals(JSONNAMES[2]); Class<?> dataFacClazz = Class.forName(jsonReader.nextString()); List<IByteHandler> handlerList = new ArrayList<IByteHandler>(); if (jsonReader.nextName().equals(JSONNAMES[3])) { jsonReader.beginArray(); while (jsonReader.hasNext()) { Class<?> handlerClazz = Class.forName(jsonReader.nextString()); Constructor<?> handlerCons = handlerClazz.getConstructors()[0]; if (handlerClazz.getName().equals(Encryptor.class.getName())) { handlerList.add((IByteHandler)handlerCons.newInstance(StandardSettings.KEY)); } else { handlerList.add((IByteHandler)handlerCons.newInstance()); } } jsonReader.endArray(); } ByteHandlerPipeline pipeline = new ByteHandlerPipeline(handlerList.toArray(new IByteHandler[handlerList.size()])); jsonReader.nextName().equals(JSONNAMES[4]); Class<?> storageClazz = Class.forName(jsonReader.nextString()); jsonReader.nextName().equals(JSONNAMES[5]); Properties props = new Properties(); jsonReader.beginObject(); while (jsonReader.hasNext()) { props.setProperty(jsonReader.nextName(), jsonReader.nextString()); } jsonReader.endObject(); jsonReader.endObject(); jsonReader.close(); fileReader.close(); Constructor<?> metaBucketCons = metaBucketClazz.getConstructors()[0]; IMetaEntryFactory metaFac = (IMetaEntryFactory)metaBucketCons.newInstance(); Constructor<?> dataFacCons = dataFacClazz.getConstructors()[0]; IDataFactory dataFactory = (IDataFactory)dataFacCons.newInstance(); Constructor<?> revCons = revClazz.getConstructors()[0]; IRevisioning revObject = (IRevisioning)revCons.newInstance(); Constructor<?> storageCons = storageClazz.getConstructors()[0]; IBackend backend = (IBackend)storageCons.newInstance(props, dataFactory, metaFac, pipeline); return new ResourceConfiguration(props, backend, revObject, dataFactory, metaFac); } catch (IOException | ClassNotFoundException | InstantiationException | IllegalAccessException | InvocationTargetException exc) { throw new TTIOException(exc); } } }
ResourceConfiguration { public static ResourceConfiguration deserialize(final File pFile, final String pResource) throws TTIOException { try { final File file = new File(new File(new File(pFile, StorageConfiguration.Paths.Data.getFile().getName()), pResource), Paths.ConfigBinary.getFile().getName()); FileReader fileReader = new FileReader(file); JsonReader jsonReader = new JsonReader(fileReader); jsonReader.beginObject(); jsonReader.nextName().equals(JSONNAMES[0]); Class<?> metaBucketClazz = Class.forName(jsonReader.nextString()); jsonReader.nextName().equals(JSONNAMES[1]); Class<?> revClazz = Class.forName(jsonReader.nextString()); jsonReader.nextName().equals(JSONNAMES[2]); Class<?> dataFacClazz = Class.forName(jsonReader.nextString()); List<IByteHandler> handlerList = new ArrayList<IByteHandler>(); if (jsonReader.nextName().equals(JSONNAMES[3])) { jsonReader.beginArray(); while (jsonReader.hasNext()) { Class<?> handlerClazz = Class.forName(jsonReader.nextString()); Constructor<?> handlerCons = handlerClazz.getConstructors()[0]; if (handlerClazz.getName().equals(Encryptor.class.getName())) { handlerList.add((IByteHandler)handlerCons.newInstance(StandardSettings.KEY)); } else { handlerList.add((IByteHandler)handlerCons.newInstance()); } } jsonReader.endArray(); } ByteHandlerPipeline pipeline = new ByteHandlerPipeline(handlerList.toArray(new IByteHandler[handlerList.size()])); jsonReader.nextName().equals(JSONNAMES[4]); Class<?> storageClazz = Class.forName(jsonReader.nextString()); jsonReader.nextName().equals(JSONNAMES[5]); Properties props = new Properties(); jsonReader.beginObject(); while (jsonReader.hasNext()) { props.setProperty(jsonReader.nextName(), jsonReader.nextString()); } jsonReader.endObject(); jsonReader.endObject(); jsonReader.close(); fileReader.close(); Constructor<?> metaBucketCons = metaBucketClazz.getConstructors()[0]; IMetaEntryFactory metaFac = (IMetaEntryFactory)metaBucketCons.newInstance(); Constructor<?> dataFacCons = dataFacClazz.getConstructors()[0]; IDataFactory dataFactory = (IDataFactory)dataFacCons.newInstance(); Constructor<?> revCons = revClazz.getConstructors()[0]; IRevisioning revObject = (IRevisioning)revCons.newInstance(); Constructor<?> storageCons = storageClazz.getConstructors()[0]; IBackend backend = (IBackend)storageCons.newInstance(props, dataFactory, metaFac, pipeline); return new ResourceConfiguration(props, backend, revObject, dataFactory, metaFac); } catch (IOException | ClassNotFoundException | InstantiationException | IllegalAccessException | InvocationTargetException exc) { throw new TTIOException(exc); } } @Inject  ResourceConfiguration(@Assisted Properties pProperties, IBackendFactory pBackend,
        IRevisioning pRevision, IDataFactory pDataFac, IMetaEntryFactory pMetaFac);  ResourceConfiguration(Properties pProperties, IBackend pStorage, IRevisioning pRevisioning,
        IDataFactory pDataFac, IMetaEntryFactory pMetaFac); }
ResourceConfiguration { public static ResourceConfiguration deserialize(final File pFile, final String pResource) throws TTIOException { try { final File file = new File(new File(new File(pFile, StorageConfiguration.Paths.Data.getFile().getName()), pResource), Paths.ConfigBinary.getFile().getName()); FileReader fileReader = new FileReader(file); JsonReader jsonReader = new JsonReader(fileReader); jsonReader.beginObject(); jsonReader.nextName().equals(JSONNAMES[0]); Class<?> metaBucketClazz = Class.forName(jsonReader.nextString()); jsonReader.nextName().equals(JSONNAMES[1]); Class<?> revClazz = Class.forName(jsonReader.nextString()); jsonReader.nextName().equals(JSONNAMES[2]); Class<?> dataFacClazz = Class.forName(jsonReader.nextString()); List<IByteHandler> handlerList = new ArrayList<IByteHandler>(); if (jsonReader.nextName().equals(JSONNAMES[3])) { jsonReader.beginArray(); while (jsonReader.hasNext()) { Class<?> handlerClazz = Class.forName(jsonReader.nextString()); Constructor<?> handlerCons = handlerClazz.getConstructors()[0]; if (handlerClazz.getName().equals(Encryptor.class.getName())) { handlerList.add((IByteHandler)handlerCons.newInstance(StandardSettings.KEY)); } else { handlerList.add((IByteHandler)handlerCons.newInstance()); } } jsonReader.endArray(); } ByteHandlerPipeline pipeline = new ByteHandlerPipeline(handlerList.toArray(new IByteHandler[handlerList.size()])); jsonReader.nextName().equals(JSONNAMES[4]); Class<?> storageClazz = Class.forName(jsonReader.nextString()); jsonReader.nextName().equals(JSONNAMES[5]); Properties props = new Properties(); jsonReader.beginObject(); while (jsonReader.hasNext()) { props.setProperty(jsonReader.nextName(), jsonReader.nextString()); } jsonReader.endObject(); jsonReader.endObject(); jsonReader.close(); fileReader.close(); Constructor<?> metaBucketCons = metaBucketClazz.getConstructors()[0]; IMetaEntryFactory metaFac = (IMetaEntryFactory)metaBucketCons.newInstance(); Constructor<?> dataFacCons = dataFacClazz.getConstructors()[0]; IDataFactory dataFactory = (IDataFactory)dataFacCons.newInstance(); Constructor<?> revCons = revClazz.getConstructors()[0]; IRevisioning revObject = (IRevisioning)revCons.newInstance(); Constructor<?> storageCons = storageClazz.getConstructors()[0]; IBackend backend = (IBackend)storageCons.newInstance(props, dataFactory, metaFac, pipeline); return new ResourceConfiguration(props, backend, revObject, dataFactory, metaFac); } catch (IOException | ClassNotFoundException | InstantiationException | IllegalAccessException | InvocationTargetException exc) { throw new TTIOException(exc); } } @Inject  ResourceConfiguration(@Assisted Properties pProperties, IBackendFactory pBackend,
        IRevisioning pRevision, IDataFactory pDataFac, IMetaEntryFactory pMetaFac);  ResourceConfiguration(Properties pProperties, IBackend pStorage, IRevisioning pRevisioning,
        IDataFactory pDataFac, IMetaEntryFactory pMetaFac); static void serialize(final ResourceConfiguration pConfig); static ResourceConfiguration deserialize(final File pFile, final String pResource); @Override int hashCode(); @Override final boolean equals(final Object pObj); @Override String toString(); }
ResourceConfiguration { public static ResourceConfiguration deserialize(final File pFile, final String pResource) throws TTIOException { try { final File file = new File(new File(new File(pFile, StorageConfiguration.Paths.Data.getFile().getName()), pResource), Paths.ConfigBinary.getFile().getName()); FileReader fileReader = new FileReader(file); JsonReader jsonReader = new JsonReader(fileReader); jsonReader.beginObject(); jsonReader.nextName().equals(JSONNAMES[0]); Class<?> metaBucketClazz = Class.forName(jsonReader.nextString()); jsonReader.nextName().equals(JSONNAMES[1]); Class<?> revClazz = Class.forName(jsonReader.nextString()); jsonReader.nextName().equals(JSONNAMES[2]); Class<?> dataFacClazz = Class.forName(jsonReader.nextString()); List<IByteHandler> handlerList = new ArrayList<IByteHandler>(); if (jsonReader.nextName().equals(JSONNAMES[3])) { jsonReader.beginArray(); while (jsonReader.hasNext()) { Class<?> handlerClazz = Class.forName(jsonReader.nextString()); Constructor<?> handlerCons = handlerClazz.getConstructors()[0]; if (handlerClazz.getName().equals(Encryptor.class.getName())) { handlerList.add((IByteHandler)handlerCons.newInstance(StandardSettings.KEY)); } else { handlerList.add((IByteHandler)handlerCons.newInstance()); } } jsonReader.endArray(); } ByteHandlerPipeline pipeline = new ByteHandlerPipeline(handlerList.toArray(new IByteHandler[handlerList.size()])); jsonReader.nextName().equals(JSONNAMES[4]); Class<?> storageClazz = Class.forName(jsonReader.nextString()); jsonReader.nextName().equals(JSONNAMES[5]); Properties props = new Properties(); jsonReader.beginObject(); while (jsonReader.hasNext()) { props.setProperty(jsonReader.nextName(), jsonReader.nextString()); } jsonReader.endObject(); jsonReader.endObject(); jsonReader.close(); fileReader.close(); Constructor<?> metaBucketCons = metaBucketClazz.getConstructors()[0]; IMetaEntryFactory metaFac = (IMetaEntryFactory)metaBucketCons.newInstance(); Constructor<?> dataFacCons = dataFacClazz.getConstructors()[0]; IDataFactory dataFactory = (IDataFactory)dataFacCons.newInstance(); Constructor<?> revCons = revClazz.getConstructors()[0]; IRevisioning revObject = (IRevisioning)revCons.newInstance(); Constructor<?> storageCons = storageClazz.getConstructors()[0]; IBackend backend = (IBackend)storageCons.newInstance(props, dataFactory, metaFac, pipeline); return new ResourceConfiguration(props, backend, revObject, dataFactory, metaFac); } catch (IOException | ClassNotFoundException | InstantiationException | IllegalAccessException | InvocationTargetException exc) { throw new TTIOException(exc); } } @Inject  ResourceConfiguration(@Assisted Properties pProperties, IBackendFactory pBackend,
        IRevisioning pRevision, IDataFactory pDataFac, IMetaEntryFactory pMetaFac);  ResourceConfiguration(Properties pProperties, IBackend pStorage, IRevisioning pRevisioning,
        IDataFactory pDataFac, IMetaEntryFactory pMetaFac); static void serialize(final ResourceConfiguration pConfig); static ResourceConfiguration deserialize(final File pFile, final String pResource); @Override int hashCode(); @Override final boolean equals(final Object pObj); @Override String toString(); final IBackend mBackend; final IRevisioning mRevision; final Properties mProperties; final IDataFactory mDataFac; final IMetaEntryFactory mMetaFac; }