@Test public void checkServiceCopyNested() { String name = "all"; ServiceType serviceType = ServiceType.COMPOUND; String base = ""; InvService service = new InvService( name, serviceType.toString(), base, null, null ); InvService odapService = new InvService( "odap", ServiceType.OPENDAP.toString(), "/thredds/dodsC/", null, null ); odapService.addProperty( new InvProperty( "aProp", "aPropVal" ) ); odapService.addDatasetRoot( new InvProperty( "aDsRoot", "aDsRootVal") ); service.addService( odapService ); service.addService( new InvService( "wms", ServiceType.WMS.toString(), "/thredds/wms/", null, null) ); service.addService( new InvService( "wcs", ServiceType.WCS.toString(), "/thredds/wcs/", null, null) ); InvService serviceCopy = DeepCopyUtils.copyService( service ); assertFalse( service == serviceCopy ); assertEquals( name, serviceCopy.getName() ); assertEquals( serviceType, serviceCopy.getServiceType() ); assertEquals( base, serviceCopy.getBase() ); List<InvService> services = service.getServices(); assertNotNull( services); assertEquals( 3, services.size() ); InvService copyOdapService = services.get( 0 ); assertEquals( "odap", copyOdapService.getName()); assertEquals( "wms", services.get(1).getName()); assertEquals( "wcs", services.get(2).getName()); assertEquals( ServiceType.OPENDAP, copyOdapService.getServiceType()); assertEquals( ServiceType.WMS, services.get(1).getServiceType()); assertEquals( ServiceType.WCS, services.get(2).getServiceType()); assertEquals( "/thredds/dodsC/", copyOdapService.getBase()); assertEquals( "/thredds/wms/", services.get(1).getBase()); assertEquals( "/thredds/wcs/", services.get(2).getBase()); List<InvProperty> properties = copyOdapService.getProperties(); assertNotNull( properties); assertEquals( 1, properties.size() ); assertEquals( "aProp", properties.get(0).getName() ); assertEquals( "aPropVal", properties.get(0).getValue() ); List<InvProperty> dsRoots = copyOdapService.getDatasetRoots(); assertNotNull( dsRoots); assertEquals( 1, dsRoots.size()); assertEquals( "aDsRoot", dsRoots.get(0).getName() ); assertEquals( "aDsRootVal", dsRoots.get(0).getValue() ); }
public static InvService copyService( InvService service ) { if ( service == null ) throw new IllegalArgumentException( "Service may not be null."); InvService resultService = new InvService( service.getName(), service.getServiceType().toString(), service.getBase(), service.getSuffix(), service.getDescription() ); for ( InvService curService : service.getServices()) { resultService.addService( copyService( curService ) ); } for ( InvProperty curProperty : service.getProperties()) { resultService.addProperty( copyProperty( curProperty ) ); } for ( InvProperty curDatasetRoot : service.getDatasetRoots()) { resultService.addDatasetRoot( copyProperty( curDatasetRoot) ); } return resultService; }
DeepCopyUtils { public static InvService copyService( InvService service ) { if ( service == null ) throw new IllegalArgumentException( "Service may not be null."); InvService resultService = new InvService( service.getName(), service.getServiceType().toString(), service.getBase(), service.getSuffix(), service.getDescription() ); for ( InvService curService : service.getServices()) { resultService.addService( copyService( curService ) ); } for ( InvProperty curProperty : service.getProperties()) { resultService.addProperty( copyProperty( curProperty ) ); } for ( InvProperty curDatasetRoot : service.getDatasetRoots()) { resultService.addDatasetRoot( copyProperty( curDatasetRoot) ); } return resultService; } }
DeepCopyUtils { public static InvService copyService( InvService service ) { if ( service == null ) throw new IllegalArgumentException( "Service may not be null."); InvService resultService = new InvService( service.getName(), service.getServiceType().toString(), service.getBase(), service.getSuffix(), service.getDescription() ); for ( InvService curService : service.getServices()) { resultService.addService( copyService( curService ) ); } for ( InvProperty curProperty : service.getProperties()) { resultService.addProperty( copyProperty( curProperty ) ); } for ( InvProperty curDatasetRoot : service.getDatasetRoots()) { resultService.addDatasetRoot( copyProperty( curDatasetRoot) ); } return resultService; } private  DeepCopyUtils(); }
DeepCopyUtils { public static InvService copyService( InvService service ) { if ( service == null ) throw new IllegalArgumentException( "Service may not be null."); InvService resultService = new InvService( service.getName(), service.getServiceType().toString(), service.getBase(), service.getSuffix(), service.getDescription() ); for ( InvService curService : service.getServices()) { resultService.addService( copyService( curService ) ); } for ( InvProperty curProperty : service.getProperties()) { resultService.addProperty( copyProperty( curProperty ) ); } for ( InvProperty curDatasetRoot : service.getDatasetRoots()) { resultService.addDatasetRoot( copyProperty( curDatasetRoot) ); } return resultService; } private  DeepCopyUtils(); static InvCatalog copyCatalog( InvCatalog catalog ); static InvCatalog subsetCatalogOnDataset( InvCatalog catalog, String datasetId ); static InvCatalog subsetCatalogOnDataset( InvCatalog catalog, InvDataset dataset); static InvDataset copyDataset( InvDataset dataset, List<InvService> availableServices,
                                        boolean copyInheritedMetadataFromParents ); static InvAccess copyAccess( InvAccess access, InvDataset parentDataset, List<InvService> availableServices ); static InvService copyService( InvService service ); static InvProperty copyProperty( InvProperty property); }
DeepCopyUtils { public static InvService copyService( InvService service ) { if ( service == null ) throw new IllegalArgumentException( "Service may not be null."); InvService resultService = new InvService( service.getName(), service.getServiceType().toString(), service.getBase(), service.getSuffix(), service.getDescription() ); for ( InvService curService : service.getServices()) { resultService.addService( copyService( curService ) ); } for ( InvProperty curProperty : service.getProperties()) { resultService.addProperty( copyProperty( curProperty ) ); } for ( InvProperty curDatasetRoot : service.getDatasetRoots()) { resultService.addDatasetRoot( copyProperty( curDatasetRoot) ); } return resultService; } private  DeepCopyUtils(); static InvCatalog copyCatalog( InvCatalog catalog ); static InvCatalog subsetCatalogOnDataset( InvCatalog catalog, String datasetId ); static InvCatalog subsetCatalogOnDataset( InvCatalog catalog, InvDataset dataset); static InvDataset copyDataset( InvDataset dataset, List<InvService> availableServices,
                                        boolean copyInheritedMetadataFromParents ); static InvAccess copyAccess( InvAccess access, InvDataset parentDataset, List<InvService> availableServices ); static InvService copyService( InvService service ); static InvProperty copyProperty( InvProperty property);  }