001/** 002 * Copyright (c) 2012, 2015, Credit Suisse (Anatole Tresch), Werner Keil and others by the @author tag. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 005 * use this file except in compliance with the License. You may obtain a copy of 006 * the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 013 * License for the specific language governing permissions and limitations under 014 * the License. 015 */ 016package org.javamoney.moneta.spi; 017 018import java.net.URI; 019import java.util.Map; 020import java.util.Objects; 021 022import org.javamoney.moneta.spi.LoaderService.LoaderListener; 023import org.javamoney.moneta.spi.LoaderService.UpdatePolicy; 024 025/** 026 * Builder to {@link LoadDataInformation} 027 * Programmatically registers a remote resource {@code resourceLocation}, 028 * backed up by a classpath resource {@code backupResource}, reachable as 029 * {@code dataId}. 030 * 031 * @param resourceId The unique identifier of the resource that must also be used 032 * for accessing the resource, not {@code null}. 033 * @param resourceLocations The remote resource locations, not {@code null}. 034 * @param backupResource The backup resource location in the classpath, not 035 * {@code null}. 036 * @param loaderListener An (optional) LoaderListener to be registered. 037 */ 038public class LoadDataInformationBuilder { 039 040 private String resourceId; 041 042 private UpdatePolicy updatePolicy; 043 044 private Map<String, String> properties; 045 046 private LoaderListener loaderListener; 047 048 private URI backupResource; 049 050 private URI[] resourceLocations; 051 052 private boolean startRemote; 053 054 public LoadDataInformationBuilder withResourceId(String resourceId) { 055 this.resourceId = resourceId; 056 return this; 057 } 058 059 public LoadDataInformationBuilder withUpdatePolicy(UpdatePolicy updatePolicy) { 060 this.updatePolicy = updatePolicy; 061 return this; 062 } 063 064 public LoadDataInformationBuilder withProperties(Map<String, String> properties) { 065 this.properties = properties; 066 return this; 067 } 068 069 public LoadDataInformationBuilder withLoaderListener(LoaderListener loaderListener) { 070 this.loaderListener = loaderListener; 071 return this; 072 } 073 074 public LoadDataInformationBuilder withBackupResource(URI backupResource) { 075 this.backupResource = backupResource; 076 return this; 077 } 078 079 public LoadDataInformationBuilder withResourceLocations(URI... resourceLocations) { 080 this.resourceLocations = resourceLocations; 081 return this; 082 } 083 084 public LoadDataInformationBuilder withStartRemote(boolean startRemote) { 085 this.startRemote = startRemote; 086 return this; 087 } 088 089 public LoadDataInformation build() { 090 if(Objects.isNull(resourceId) || resourceId.isEmpty()) { 091 throw new IllegalStateException("The resourceId should be informed"); 092 } 093 else if (Objects.isNull(updatePolicy)) { 094 throw new IllegalStateException("The updatePolicy should be informed"); 095 } 096 else if (Objects.isNull(properties)) { 097 throw new IllegalStateException("The properties should be informed"); 098 } 099 else if (Objects.isNull(resourceLocations)) { 100 throw new IllegalStateException("The properties should be informed"); 101 } 102 return new LoadDataInformation(resourceId, updatePolicy, properties, 103 loaderListener, backupResource, resourceLocations, startRemote); 104 } 105 106 107}