protected <T extends CatalogInfo> T commitProxy(T object) { // this object is a proxy ModificationProxy h = (ModificationProxy) Proxy.getInvocationHandler(object); // get the real object T real = (T) h.getProxyObject(); // commit to the original object h.commit(); return real; }
public void save(LoggingInfo logging) { ModificationProxy proxy = (ModificationProxy) Proxy.getInvocationHandler(logging); List propertyNames = proxy.getPropertyNames(); List oldValues = proxy.getOldValues(); List newValues = proxy.getNewValues(); geoServer.fireLoggingModified(logging, propertyNames, oldValues, newValues); proxy.commit(); }
public void save(GeoServerInfo global) { ModificationProxy proxy = (ModificationProxy) Proxy.getInvocationHandler(global); List propertyNames = proxy.getPropertyNames(); List oldValues = proxy.getOldValues(); List newValues = proxy.getNewValues(); geoServer.fireGlobalModified(global, propertyNames, oldValues, newValues); proxy.commit(); }
public void save(ServiceInfo service) { ModificationProxy proxy = (ModificationProxy) Proxy.getInvocationHandler(service); List propertyNames = proxy.getPropertyNames(); List oldValues = proxy.getOldValues(); List newValues = proxy.getNewValues(); geoServer.fireServiceModified(service, propertyNames, oldValues, newValues); proxy.commit(); }
@Override public void save(SettingsInfo settings) { ModificationProxy proxy = (ModificationProxy) Proxy.getInvocationHandler(settings); List propertyNames = proxy.getPropertyNames(); List oldValues = proxy.getOldValues(); List newValues = proxy.getNewValues(); settings = (SettingsInfo) proxy.getProxyObject(); geoServer.fireSettingsModified(settings, propertyNames, oldValues, newValues); proxy.commit(); }
ModificationProxy h = handler(v); if (h != null && h.isDirty()) { h.commit();
@Test public void testRewrapCommitToNew() throws Exception { TestBean bean = new TestBeanImpl("Mr. Bean", "Uhh", "Bean"); TestBean newBean = new TestBeanImpl("Johnny English", "Not", "Bond"); TestBean proxy = ModificationProxy.create(bean, TestBean.class); proxy.setValue("Edmond Blackadder"); proxy.setListValue(Arrays.asList("Cunning", "Plan")); // Swap the old bean for the new one TestBean result = ModificationProxy.rewrap(proxy, b -> newBean, TestBean.class); // Commit the changes ModificationProxy.handler(result).commit(); // The changes should not have been committed to either bean assertThat(bean.getValue(), equalTo("Mr. Bean")); assertThat(bean.getListValue(), contains("Uhh", "Bean")); assertThat(newBean.getValue(), equalTo("Edmond Blackadder")); assertThat(newBean.getListValue(), contains("Cunning", "Plan")); }
@Test public void test() throws Exception { BeanImpl bean = new BeanImpl(); ModificationProxy handler = new ModificationProxy(bean); Class proxyClass = Proxy.getProxyClass(Bean.class.getClassLoader(), new Class[] {Bean.class}); Bean proxy = (Bean) proxyClass .getConstructor(new Class[] {InvocationHandler.class}) .newInstance(new Object[] {handler}); bean.setFoo("one"); bean.setBar(1); proxy.setFoo("two"); proxy.setBar(2); proxy.getScratch().add("x"); proxy.getScratch().add("y"); assertEquals("one", bean.getFoo()); assertEquals(Integer.valueOf(1), bean.getBar()); assertTrue(bean.getScratch().isEmpty()); assertEquals("two", proxy.getFoo()); assertEquals(Integer.valueOf(2), proxy.getBar()); assertEquals(2, proxy.getScratch().size()); handler.commit(); assertEquals("two", bean.getFoo()); assertEquals(Integer.valueOf(2), bean.getBar()); assertEquals(2, bean.getScratch().size()); }
/** * Helper method that unwraps a layer group making him suitable to be added to the catalog. If * proxyfied the proxy will also be removed. */ private LayerGroupInfo unwrapLayerGroup(LayerGroupInfo layerGroup) { // get the original layer group object while (layerGroup instanceof AbstractDecorator) { AbstractDecorator decorator = (AbstractDecorator) layerGroup; layerGroup = (LayerGroupInfo) decorator.unwrap(LayerGroupInfo.class); } // catalog detach doesn't work for layer groups if (Proxy.isProxyClass(layerGroup.getClass())) { // we have a proxy we need to get rid of the proxy ModificationProxy proxy = (ModificationProxy) Proxy.getInvocationHandler(layerGroup); proxy.commit(); layerGroup = (LayerGroupInfo) proxy.getProxyObject(); } return layerGroup; }