public GeoServerInfo getGlobal() { if (global == null) { return null; } return ModificationProxy.create(global, GeoServerInfo.class); }
private <T extends CatalogInfo> T wrapInModificationProxy(T ci, Class<T> clazz) { if (ci != null) { return ModificationProxy.create(ci, clazz); } else { return null; } }
public LoggingInfo getLogging() { if (logging == null) { return null; } return ModificationProxy.create(logging, LoggingInfo.class); }
public MapInfo getMap(String id) { for (MapInfo map : maps) { if (id.equals(map.getId())) { return ModificationProxy.create(map, MapInfo.class); } } return null; }
public MapInfo add(MapInfo map) { resolve(map); synchronized (maps) { maps.add(map); } return ModificationProxy.create(map, MapInfo.class); }
public SettingsInfo getSettings(WorkspaceInfo workspace) { for (SettingsInfo s : settings) { if (s.getWorkspace().equals(workspace)) { return ModificationProxy.create(s, SettingsInfo.class); } } return null; }
public MapInfo getMapByName(String name) { for (MapInfo map : maps) { if (name.equals(map.getName())) { return ModificationProxy.create(map, MapInfo.class); } } return null; }
protected <T> T createProxy(T proxyObject, Class<T> proxyInterface) { if (proxyObject instanceof Proxy) { InvocationHandler h = handler(proxyObject); if (h != null && h instanceof ModificationProxy) { return proxyObject; } } return ModificationProxy.create(proxyObject, proxyInterface); }
public <T extends ServiceInfo> T getService(String id, Class<T> clazz) { for (ServiceInfo si : services) { if (id.equals(si.getId())) { return ModificationProxy.create((T) si, clazz); } } if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine( "Could not locate service of type " + clazz + " and id '" + id + "', available services were " + services); } return null; }
public DataStoreInfo getDefaultDataStore(WorkspaceInfo workspace) { if (defaultStores.containsKey(workspace.getId())) { DataStoreInfo defaultStore = defaultStores.get(workspace.getId()); return ModificationProxy.create(defaultStore, DataStoreInfo.class); } else { return null; } }
public LayerGroupInfo add(LayerGroupInfo layerGroup) { resolve(layerGroup); synchronized (layerGroups) { layerGroups.add(layerGroup); } return ModificationProxy.create(layerGroup, LayerGroupInfo.class); }
public LayerInfo add(LayerInfo layer) { resolve(layer); layers.add(layer); return ModificationProxy.create(layer, LayerInfo.class); }
public StyleInfo add(StyleInfo style) { resolve(style); synchronized (styles) { styles.add(style); } return ModificationProxy.create(style, StyleInfo.class); }
public StoreInfo add(StoreInfo store) { resolve(store); stores.add(store); return ModificationProxy.create(store, StoreInfo.class); }
public ResourceInfo add(ResourceInfo resource) { resolve(resource); synchronized (resources) { resources.add(resource); } return ModificationProxy.create(resource, ResourceInfo.class); }
public WorkspaceInfo add(WorkspaceInfo workspace) { resolve(workspace); WorkspaceInfo unwrapped = unwrap(workspace); workspaces.add(unwrapped); return ModificationProxy.create(unwrapped, WorkspaceInfo.class); }
public NamespaceInfo add(NamespaceInfo namespace) { resolve(namespace); NamespaceInfo unwrapped = unwrap(namespace); namespaces.add(unwrapped); return ModificationProxy.create(unwrapped, NamespaceInfo.class); }
@Test public void testCanSecureProxied() throws Exception { // get a delegate final D delegate = createDelegate(); // wrap the delegate in a ModificationProxy ResourceInfo proxy = ModificationProxy.create(delegate, getDelegateClass()); // secure it Object secure = SecuredObjects.secure(proxy, policy); assertTrue( "Unable to secure proxied Resourceinfo", getSecuredDecoratorClass().isAssignableFrom(secure.getClass())); }
@Test public void testRewrapEmptyProxyIdentity() throws Exception { TestBean bean = new TestBeanImpl("Mr. Bean", "Uhh", "Bean"); TestBean proxy = ModificationProxy.create(bean, TestBean.class); TestBean result = ModificationProxy.rewrap(proxy, b -> b, TestBean.class); assertThat(result, modProxy(sameInstance(bean))); assertThat(result.getValue(), equalTo("Mr. Bean")); assertThat(result.getListValue(), contains("Uhh", "Bean")); }
@Test public void testRewrapChangedProxyIdentity() throws Exception { TestBean bean = new TestBeanImpl("Mr. Bean", "Uhh", "Bean"); TestBean proxy = ModificationProxy.create(bean, TestBean.class); proxy.setValue("Edmond Blackadder"); proxy.setListValue(Arrays.asList("Cunning", "Plan")); TestBean result = ModificationProxy.rewrap(proxy, b -> b, TestBean.class); // Should be a new wrapper assertThat(result, not(sameInstance(proxy))); // Wrapping the same object assertThat(result, modProxy(sameInstance(bean))); // With the same changes assertThat(result.getValue(), equalTo("Edmond Blackadder")); assertThat(result.getListValue(), contains("Cunning", "Plan")); // The changes should not have been committed assertThat(bean.getValue(), equalTo("Mr. Bean")); assertThat(bean.getListValue(), contains("Uhh", "Bean")); }