http://git-wip-us.apache.org/repos/asf/isis/blob/55f931ae/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/IClassInstantiatorCE.java ---------------------------------------------------------------------- diff --git a/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/IClassInstantiatorCE.java b/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/IClassInstantiatorCE.java new file mode 100644 index 0000000..9b471a5 --- /dev/null +++ b/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/IClassInstantiatorCE.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.isis.core.wrapper.internal; + +/** + * Used to instantiate a given class. + */ +interface IClassInstantiatorCE { + + /** + * Return a new instance of the specified class. The recommended way is + * without calling any constructor. This is usually done by doing like + * <code>ObjectInputStream.readObject()</code> which is JVM specific. + * + * @param c + * Class to instantiate + * @return new instance of clazz + */ + Object newInstance(Class<?> clazz) throws InstantiationException; +}
http://git-wip-us.apache.org/repos/asf/isis/blob/55f931ae/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/IProxyFactory.java ---------------------------------------------------------------------- diff --git a/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/IProxyFactory.java b/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/IProxyFactory.java new file mode 100644 index 0000000..86c35f9 --- /dev/null +++ b/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/IProxyFactory.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.isis.core.wrapper.internal; + +import java.lang.reflect.InvocationHandler; + +public interface IProxyFactory<T> { + T createProxy(Class<T> toProxyClass, InvocationHandler handler); + + T createProxy(T toProxy, InvocationHandler handler); +} http://git-wip-us.apache.org/repos/asf/isis/blob/55f931ae/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/InteractionEventDispatcher.java ---------------------------------------------------------------------- diff --git a/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/InteractionEventDispatcher.java b/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/InteractionEventDispatcher.java new file mode 100644 index 0000000..04585d2 --- /dev/null +++ b/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/InteractionEventDispatcher.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.isis.core.wrapper.internal; + +import org.apache.isis.applib.events.InteractionEvent; + +public interface InteractionEventDispatcher { + + void dispatch(InteractionEvent interactionEvent); + +} http://git-wip-us.apache.org/repos/asf/isis/blob/55f931ae/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/InteractionEventDispatcherTypeSafe.java ---------------------------------------------------------------------- diff --git a/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/InteractionEventDispatcherTypeSafe.java b/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/InteractionEventDispatcherTypeSafe.java new file mode 100644 index 0000000..7fa3735 --- /dev/null +++ b/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/InteractionEventDispatcherTypeSafe.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.isis.core.wrapper.internal; + +import org.apache.isis.applib.events.InteractionEvent; + +public abstract class InteractionEventDispatcherTypeSafe<T extends InteractionEvent> implements InteractionEventDispatcher { + + public abstract void dispatchTypeSafe(T interactionEvent); + + @Override + @SuppressWarnings("unchecked") + public void dispatch(final InteractionEvent interactionEvent) { + dispatchTypeSafe((T) interactionEvent); + } + +} http://git-wip-us.apache.org/repos/asf/isis/blob/55f931ae/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/InvocationHandlerMethodInterceptor.java ---------------------------------------------------------------------- diff --git a/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/InvocationHandlerMethodInterceptor.java b/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/InvocationHandlerMethodInterceptor.java new file mode 100644 index 0000000..0cf6c82 --- /dev/null +++ b/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/InvocationHandlerMethodInterceptor.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.isis.core.wrapper.internal; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; + +import net.sf.cglib.proxy.MethodInterceptor; +import net.sf.cglib.proxy.MethodProxy; + +public class InvocationHandlerMethodInterceptor implements MethodInterceptor { + private final InvocationHandler handler; + + InvocationHandlerMethodInterceptor(final InvocationHandler handler) { + this.handler = handler; + } + + @Override + public Object intercept(final Object obj, final Method method, final Object[] args, final MethodProxy proxy) throws Throwable { + return handler.invoke(obj, method, args); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/isis/blob/55f931ae/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/JavaProxyFactory.java ---------------------------------------------------------------------- diff --git a/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/JavaProxyFactory.java b/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/JavaProxyFactory.java new file mode 100644 index 0000000..efeeb1d --- /dev/null +++ b/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/JavaProxyFactory.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.isis.core.wrapper.internal; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Proxy; + +import org.apache.isis.applib.services.wrapper.WrapperObject; + +public class JavaProxyFactory<T> implements IProxyFactory<T> { + @Override + @SuppressWarnings("unchecked") + public T createProxy(final T toProxy, final InvocationHandler handler) { + final Class<T> proxyClass = (Class<T>) toProxy.getClass(); + return (T) Proxy.newProxyInstance(proxyClass.getClassLoader(), new Class[] { proxyClass }, handler); + } + + @Override + @SuppressWarnings("unchecked") + public T createProxy(final Class<T> toProxy, final InvocationHandler handler) { + return (T) Proxy.newProxyInstance(toProxy.getClassLoader(), new Class[] { toProxy, WrapperObject.class }, handler); + } +} http://git-wip-us.apache.org/repos/asf/isis/blob/55f931ae/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/MapInvocationHandler.java ---------------------------------------------------------------------- diff --git a/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/MapInvocationHandler.java b/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/MapInvocationHandler.java new file mode 100644 index 0000000..b951347 --- /dev/null +++ b/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/MapInvocationHandler.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.isis.core.wrapper.internal; + +import static org.apache.isis.core.commons.lang.MethodUtils.getMethod; + +import java.util.Map; + +import org.apache.isis.core.metamodel.spec.feature.OneToManyAssociation; + +class MapInvocationHandler<T, C> extends AbstractCollectionInvocationHandler<T, C> { + + public MapInvocationHandler(final C collectionToProxy, final String collectionName, final DomainObjectInvocationHandler<T> handler, final OneToManyAssociation otma) { + super(collectionToProxy, collectionName, handler, otma); + + try { + intercept(getMethod(collectionToProxy, "containsKey", Object.class)); + intercept(getMethod(collectionToProxy, "containsValue", Object.class)); + intercept(getMethod(collectionToProxy, "size")); + intercept(getMethod(collectionToProxy, "isEmpty")); + veto(getMethod(collectionToProxy, "put", Object.class, Object.class)); + veto(getMethod(collectionToProxy, "remove", Object.class)); + veto(getMethod(collectionToProxy, "putAll", Map.class)); + veto(getMethod(collectionToProxy, "clear")); + } catch (final NoSuchMethodException e) { + // ///CLOVER:OFF + throw new RuntimeException("A Collection method could not be found: " + e.getMessage()); + // ///CLOVER:ON + } + } + +} http://git-wip-us.apache.org/repos/asf/isis/blob/55f931ae/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/ObjenesisClassInstantiatorCE.java ---------------------------------------------------------------------- diff --git a/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/ObjenesisClassInstantiatorCE.java b/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/ObjenesisClassInstantiatorCE.java new file mode 100644 index 0000000..bd029d9 --- /dev/null +++ b/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/ObjenesisClassInstantiatorCE.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.isis.core.wrapper.internal; + +import org.objenesis.ObjenesisHelper; + +class ObjenesisClassInstantiatorCE implements IClassInstantiatorCE { + + @Override + public Object newInstance(final Class<?> clazz) throws InstantiationException { + return ObjenesisHelper.newInstance(clazz); + } + +} http://git-wip-us.apache.org/repos/asf/isis/blob/55f931ae/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/Proxy.java ---------------------------------------------------------------------- diff --git a/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/Proxy.java b/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/Proxy.java new file mode 100644 index 0000000..46952c6 --- /dev/null +++ b/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/Proxy.java @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.isis.core.wrapper.internal; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.CoreMatchers.nullValue; + +import java.util.Collection; +import java.util.Map; + +import org.apache.isis.applib.services.wrapper.WrapperFactory; +import org.apache.isis.applib.services.wrapper.WrapperFactory.ExecutionMode; +import org.apache.isis.core.commons.authentication.AuthenticationSessionProvider; +import org.apache.isis.core.commons.ensure.Ensure; +import org.apache.isis.core.metamodel.adapter.ObjectPersistor; +import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager; +import org.apache.isis.core.metamodel.spec.SpecificationLoader; +import org.apache.isis.core.metamodel.spec.feature.OneToManyAssociation; + +public class Proxy { + + public static <T> T proxy(final T domainObject, final WrapperFactory wrapperFactory, final ExecutionMode mode, final AuthenticationSessionProvider authenticationSessionProvider, final SpecificationLoader specificationLookup, final AdapterManager adapterManager, final ObjectPersistor objectPersistor) { + + Ensure.ensureThatArg(wrapperFactory, is(not(nullValue()))); + Ensure.ensureThatArg(authenticationSessionProvider, is(not(nullValue()))); + Ensure.ensureThatArg(specificationLookup, is(not(nullValue()))); + Ensure.ensureThatArg(adapterManager, is(not(nullValue()))); + Ensure.ensureThatArg(objectPersistor, is(not(nullValue()))); + + final DomainObjectInvocationHandler<T> invocationHandler = new DomainObjectInvocationHandler<T>(domainObject, wrapperFactory, mode, authenticationSessionProvider, specificationLookup, adapterManager, objectPersistor); + + final CgLibProxy<T> cglibProxy = new CgLibProxy<T>(invocationHandler); + return cglibProxy.proxy(); + } + + /** + * Whether to execute or not will be picked up from the supplied parent + * handler. + */ + public static <T, E> Collection<E> proxy(final Collection<E> collectionToProxy, final String collectionName, final DomainObjectInvocationHandler<T> handler, final OneToManyAssociation otma) { + + final CollectionInvocationHandler<T, Collection<E>> collectionInvocationHandler = new CollectionInvocationHandler<T, Collection<E>>(collectionToProxy, collectionName, handler, otma); + collectionInvocationHandler.setResolveObjectChangedEnabled(handler.isResolveObjectChangedEnabled()); + + final CgLibProxy<Collection<E>> cglibProxy = new CgLibProxy<Collection<E>>(collectionInvocationHandler); + return cglibProxy.proxy(); + } + + /** + * Whether to execute or not will be picked up from the supplied parent + * handler. + */ + public static <T, P, Q> Map<P, Q> proxy(final Map<P, Q> collectionToProxy, final String collectionName, final DomainObjectInvocationHandler<T> handler, final OneToManyAssociation otma) { + + final MapInvocationHandler<T, Map<P, Q>> mapInvocationHandler = new MapInvocationHandler<T, Map<P, Q>>(collectionToProxy, collectionName, handler, otma); + mapInvocationHandler.setResolveObjectChangedEnabled(handler.isResolveObjectChangedEnabled()); + + final CgLibProxy<Map<P, Q>> cglibProxy = new CgLibProxy<Map<P, Q>>(mapInvocationHandler); + return cglibProxy.proxy(); + } + +} http://git-wip-us.apache.org/repos/asf/isis/blob/55f931ae/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/RuntimeExceptionWrapper.java ---------------------------------------------------------------------- diff --git a/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/RuntimeExceptionWrapper.java b/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/RuntimeExceptionWrapper.java new file mode 100644 index 0000000..ef2feda --- /dev/null +++ b/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/RuntimeExceptionWrapper.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.isis.core.wrapper.internal; + +public class RuntimeExceptionWrapper extends RuntimeException { + private static final long serialVersionUID = 1L; + private final RuntimeException runtimeException; + + public RuntimeExceptionWrapper(final RuntimeException runtimeException) { + this.runtimeException = runtimeException; + } + + public RuntimeException getRuntimeException() { + return runtimeException; + } +} http://git-wip-us.apache.org/repos/asf/isis/blob/55f931ae/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/util/Constants.java ---------------------------------------------------------------------- diff --git a/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/util/Constants.java b/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/util/Constants.java new file mode 100644 index 0000000..0021038 --- /dev/null +++ b/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/util/Constants.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.isis.core.wrapper.internal.util; + +public final class Constants { + private Constants() { + } + + public static final String PREFIX_CHOICES = "choices"; + public static final String PREFIX_DEFAULT = "default"; + public static final String PREFIX_HIDE = "hide"; + public static final String PREFIX_DISABLE = "disable"; + public static final String PREFIX_VALIDATE_REMOVE_FROM = "validateRemoveFrom"; + public static final String PREFIX_VALIDATE_ADD_TO = "validateAddTo"; + public static final String PREFIX_VALIDATE = "validate"; + public static final String PREFIX_REMOVE_FROM = "removeFrom"; + public static final String PREFIX_ADD_TO = "addTo"; + public static final String PREFIX_MODIFY = "modify"; + public static final String PREFIX_CLEAR = "clear"; + public static final String PREFIX_SET = "set"; + public static final String PREFIX_GET = "get"; + + public final static String TITLE_METHOD_NAME = "title"; + public final static String TO_STRING_METHOD_NAME = "toString"; + + /** + * Cannot invoke methods with these prefixes. + */ + public final static String[] INVALID_PREFIXES = { PREFIX_MODIFY, PREFIX_CLEAR, PREFIX_DISABLE, PREFIX_VALIDATE, PREFIX_VALIDATE_ADD_TO, PREFIX_VALIDATE_REMOVE_FROM, PREFIX_HIDE, }; + + public final static String[] PROPERTY_PREFIXES = { PREFIX_GET, PREFIX_SET, PREFIX_MODIFY, PREFIX_CLEAR, PREFIX_DISABLE, PREFIX_VALIDATE, PREFIX_HIDE, PREFIX_DEFAULT, PREFIX_CHOICES }; + public final static String[] COLLECTION_PREFIXES = { PREFIX_GET, PREFIX_SET, PREFIX_ADD_TO, PREFIX_REMOVE_FROM, PREFIX_DISABLE, PREFIX_VALIDATE_ADD_TO, PREFIX_VALIDATE_REMOVE_FROM, PREFIX_HIDE, PREFIX_DEFAULT, PREFIX_CHOICES }; + public final static String[] ACTION_PREFIXES = { PREFIX_VALIDATE, PREFIX_DISABLE, PREFIX_HIDE, PREFIX_DEFAULT, PREFIX_CHOICES, }; + +} http://git-wip-us.apache.org/repos/asf/isis/blob/55f931ae/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/util/MethodPrefixFinder.java ---------------------------------------------------------------------- diff --git a/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/util/MethodPrefixFinder.java b/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/util/MethodPrefixFinder.java new file mode 100644 index 0000000..dd78056 --- /dev/null +++ b/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/util/MethodPrefixFinder.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.isis.core.wrapper.internal.util; + +import java.util.Arrays; +import java.util.LinkedHashSet; + +public final class MethodPrefixFinder { + + // a Linked Hash Set is used to ensure that the ordering is preserved. + public final static LinkedHashSet<String> ALL_PREFIXES = new LinkedHashSet<String>() { + private static final long serialVersionUID = 1L; + { + // collection prefixes are added first because we want to + // test validateAddTo and validateRemoveFrom before validate + addAll(Arrays.asList(Constants.COLLECTION_PREFIXES)); + addAll(Arrays.asList(Constants.PROPERTY_PREFIXES)); + addAll(Arrays.asList(Constants.ACTION_PREFIXES)); + } + }; + + public String findPrefix(final String methodName) { + for (final String prefix : ALL_PREFIXES) { + if (methodName.startsWith(prefix)) { + return prefix; + } + } + return ""; + } + +} http://git-wip-us.apache.org/repos/asf/isis/blob/55f931ae/core/wrapper/src/main/java/org/apache/isis/progmodel/wrapper/metamodel/DomainObjectContainerWrapperFactory.java ---------------------------------------------------------------------- diff --git a/core/wrapper/src/main/java/org/apache/isis/progmodel/wrapper/metamodel/DomainObjectContainerWrapperFactory.java b/core/wrapper/src/main/java/org/apache/isis/progmodel/wrapper/metamodel/DomainObjectContainerWrapperFactory.java deleted file mode 100644 index 6b908c8..0000000 --- a/core/wrapper/src/main/java/org/apache/isis/progmodel/wrapper/metamodel/DomainObjectContainerWrapperFactory.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.isis.progmodel.wrapper.metamodel; - -import java.util.List; - -import org.apache.isis.applib.DomainObjectContainer; -import org.apache.isis.applib.events.InteractionEvent; -import org.apache.isis.applib.services.wrapper.WrapperFactory; -import org.apache.isis.applib.services.wrapper.listeners.InteractionListener; -import org.apache.isis.core.commons.authentication.AuthenticationSessionProvider; -import org.apache.isis.core.metamodel.adapter.ObjectPersistor; -import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager; -import org.apache.isis.core.metamodel.services.container.DomainObjectContainerDefault; -import org.apache.isis.core.metamodel.spec.SpecificationLoader; -import org.apache.isis.progmodel.wrapper.metamodel.internal.WrapperFactoryDefault; - -/** - * A combined {@link DomainObjectContainer} and {@link WrapperFactory}. - */ -public class DomainObjectContainerWrapperFactory extends DomainObjectContainerDefault implements WrapperFactory { - - private final WrapperFactoryDefault wrapperFactoryDelegate; - - public DomainObjectContainerWrapperFactory() { - this.wrapperFactoryDelegate = new WrapperFactoryDefault(); - } - - // ///////////////////////////////////////////////////////////// - // Views - // ///////////////////////////////////////////////////////////// - - @Override - public <T> T wrap(final T domainObject) { - return wrapperFactoryDelegate.wrap(domainObject); - } - - @Override - public <T> T wrap(final T domainObject, final ExecutionMode mode) { - return wrapperFactoryDelegate.wrap(domainObject, mode); - } - - @Override - public boolean isWrapper(final Object possibleView) { - return wrapperFactoryDelegate.isWrapper(possibleView); - } - - // ///////////////////////////////////////////////////////////// - // Listeners - // ///////////////////////////////////////////////////////////// - - @Override - public List<InteractionListener> getListeners() { - return wrapperFactoryDelegate.getListeners(); - } - - @Override - public boolean addInteractionListener(final InteractionListener listener) { - return wrapperFactoryDelegate.addInteractionListener(listener); - } - - @Override - public boolean removeInteractionListener(final InteractionListener listener) { - return wrapperFactoryDelegate.removeInteractionListener(listener); - } - - @Override - public void notifyListeners(final InteractionEvent interactionEvent) { - wrapperFactoryDelegate.notifyListeners(interactionEvent); - } - - // ///////////////////////////////////////////////////////////// - // Dependencies - // ///////////////////////////////////////////////////////////// - - @Override - public void setSpecificationLookup(final SpecificationLoader specificationLookup) { - super.setSpecificationLookup(specificationLookup); - wrapperFactoryDelegate.setSpecificationLookup(specificationLookup); - } - - @Override - public void setAuthenticationSessionProvider(final AuthenticationSessionProvider authenticationSessionProvider) { - super.setAuthenticationSessionProvider(authenticationSessionProvider); - wrapperFactoryDelegate.setAuthenticationSessionProvider(authenticationSessionProvider); - } - - @Override - public void setAdapterManager(final AdapterManager adapterManager) { - super.setAdapterManager(adapterManager); - wrapperFactoryDelegate.setAdapterManager(adapterManager); - } - - @Override - public void setObjectPersistor(final ObjectPersistor objectPersistor) { - super.setObjectPersistor(objectPersistor); - wrapperFactoryDelegate.setObjectPersistor(objectPersistor); - } -} http://git-wip-us.apache.org/repos/asf/isis/blob/55f931ae/core/wrapper/src/main/java/org/apache/isis/progmodel/wrapper/metamodel/internal/AbstractCollectionInvocationHandler.java ---------------------------------------------------------------------- diff --git a/core/wrapper/src/main/java/org/apache/isis/progmodel/wrapper/metamodel/internal/AbstractCollectionInvocationHandler.java b/core/wrapper/src/main/java/org/apache/isis/progmodel/wrapper/metamodel/internal/AbstractCollectionInvocationHandler.java deleted file mode 100644 index 75e5fce..0000000 --- a/core/wrapper/src/main/java/org/apache/isis/progmodel/wrapper/metamodel/internal/AbstractCollectionInvocationHandler.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.isis.progmodel.wrapper.metamodel.internal; - -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.List; - -import org.apache.isis.applib.events.CollectionMethodEvent; -import org.apache.isis.applib.events.InteractionEvent; -import org.apache.isis.core.metamodel.spec.feature.OneToManyAssociation; - -abstract class AbstractCollectionInvocationHandler<T, C> extends DelegatingInvocationHandlerDefault<C> { - - private final List<Method> interceptedMethods = new ArrayList<Method>(); - private final List<Method> vetoedMethods = new ArrayList<Method>(); - private final String collectionName; - private final OneToManyAssociation oneToManyAssociation; - private final T domainObject; - - public AbstractCollectionInvocationHandler(final C collectionOrMapToProxy, final String collectionName, final DomainObjectInvocationHandler<T> handler, final OneToManyAssociation otma) { - super(collectionOrMapToProxy, handler.getHeadlessViewer(), handler.getExecutionMode()); - this.collectionName = collectionName; - this.oneToManyAssociation = otma; - this.domainObject = handler.getDelegate(); - } - - protected Method intercept(final Method method) { - this.interceptedMethods.add(method); - return method; - } - - protected Method veto(final Method method) { - this.vetoedMethods.add(method); - return method; - } - - public String getCollectionName() { - return collectionName; - } - - public OneToManyAssociation getCollection() { - return oneToManyAssociation; - } - - public T getDomainObject() { - return domainObject; - } - - @Override - public Object invoke(final Object collectionObject, final Method method, final Object[] args) throws Throwable { - - // delegate - final Object returnValueObj = delegate(method, args); - - if (interceptedMethods.contains(method)) { - - resolveIfRequired(domainObject); - - final InteractionEvent ev = new CollectionMethodEvent(getDelegate(), getCollection().getIdentifier(), getDomainObject(), method.getName(), args, returnValueObj); - notifyListeners(ev); - return returnValueObj; - } - - if (vetoedMethods.contains(method)) { - throw new UnsupportedOperationException(String.format("Method '%s' may not be called directly.", method.getName())); - } - - return returnValueObj; - } - -} http://git-wip-us.apache.org/repos/asf/isis/blob/55f931ae/core/wrapper/src/main/java/org/apache/isis/progmodel/wrapper/metamodel/internal/CgLibClassProxyFactory.java ---------------------------------------------------------------------- diff --git a/core/wrapper/src/main/java/org/apache/isis/progmodel/wrapper/metamodel/internal/CgLibClassProxyFactory.java b/core/wrapper/src/main/java/org/apache/isis/progmodel/wrapper/metamodel/internal/CgLibClassProxyFactory.java deleted file mode 100644 index 1646074..0000000 --- a/core/wrapper/src/main/java/org/apache/isis/progmodel/wrapper/metamodel/internal/CgLibClassProxyFactory.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.isis.progmodel.wrapper.metamodel.internal; - -import java.lang.reflect.InvocationHandler; - -import net.sf.cglib.proxy.Callback; -import net.sf.cglib.proxy.Enhancer; -import net.sf.cglib.proxy.Factory; -import net.sf.cglib.proxy.MethodInterceptor; - -import org.apache.isis.applib.services.wrapper.WrapperObject; - -/** - * Factory generating a mock for a class. - * <p> - * Note that this class is stateful - */ -public class CgLibClassProxyFactory<T> implements IProxyFactory<T> { - - @Override - @SuppressWarnings("unchecked") - public T createProxy(final T toProxy, final InvocationHandler handler) { - final Class<T> proxyClass = (Class<T>) toProxy.getClass(); - return createProxy(proxyClass, handler); - } - - @Override - @SuppressWarnings("unchecked") - public T createProxy(final Class<T> toProxyClass, final InvocationHandler handler) { - - final MethodInterceptor interceptor = new InvocationHandlerMethodInterceptor(handler); - - // Create the proxy - final Enhancer enhancer = new Enhancer(); - enhancer.setSuperclass(toProxyClass); - enhancer.setInterfaces(new Class[] { WrapperObject.class }); - enhancer.setCallbackType(interceptor.getClass()); - - final Class<?> enhancedClass = enhancer.createClass(); - - Enhancer.registerCallbacks(enhancedClass, new Callback[] { interceptor }); - - Factory factory; - try { - factory = (Factory) ClassInstantiatorFactoryCE.getInstantiator().newInstance(enhancedClass); - } catch (final InstantiationException e) { - throw new RuntimeException("Fail to instantiate mock for " + toProxyClass + " on " + ClassInstantiatorFactoryCE.getJVM() + " JVM"); - } - - return (T) factory; - } - -} http://git-wip-us.apache.org/repos/asf/isis/blob/55f931ae/core/wrapper/src/main/java/org/apache/isis/progmodel/wrapper/metamodel/internal/CgLibProxy.java ---------------------------------------------------------------------- diff --git a/core/wrapper/src/main/java/org/apache/isis/progmodel/wrapper/metamodel/internal/CgLibProxy.java b/core/wrapper/src/main/java/org/apache/isis/progmodel/wrapper/metamodel/internal/CgLibProxy.java deleted file mode 100644 index da4211c..0000000 --- a/core/wrapper/src/main/java/org/apache/isis/progmodel/wrapper/metamodel/internal/CgLibProxy.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.isis.progmodel.wrapper.metamodel.internal; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import net.sf.cglib.proxy.Enhancer; -import net.sf.cglib.proxy.Factory; - -import org.apache.isis.applib.services.wrapper.WrapperObject; -import org.apache.isis.core.metamodel.specloader.classsubstitutor.CglibEnhanced; - -public class CgLibProxy<T> { - - private final DelegatingInvocationHandler<T> handler; - - public CgLibProxy(final DelegatingInvocationHandler<T> handler) { - this.handler = handler; - } - - @SuppressWarnings("unchecked") - public T proxy() { - - final T toProxy = handler.getDelegate(); - - // handle if already proxied using cglib. - if (CglibEnhanced.class.isAssignableFrom(toProxy.getClass())) { - - handler.setResolveObjectChangedEnabled(true); - - final Class<? extends Object> enhancedClass = toProxy.getClass(); - final Class<? extends Object> origSuperclass = toProxy.getClass().getSuperclass(); - - final List<Class> interfaces = new ArrayList<Class>(); - interfaces.addAll(Arrays.asList(enhancedClass.getInterfaces())); - interfaces.remove(Factory.class); // if there. - interfaces.add(WrapperObject.class); - - InvocationHandlerMethodInterceptor interceptor = new InvocationHandlerMethodInterceptor(handler); - return (T) Enhancer.create(origSuperclass, interfaces.toArray(new Class[] {}), interceptor); - } - - final Class<T> clazz = (Class<T>) toProxy.getClass(); - - T proxy = null; - try { - final IProxyFactory<T> proxyFactory = clazz.isInterface() ? new JavaProxyFactory<T>() : new CgLibClassProxyFactory<T>(); - proxy = proxyFactory.createProxy(clazz, handler); - } catch (final RuntimeExceptionWrapper e) { - throw (RuntimeException) e.getRuntimeException().fillInStackTrace(); - } - return proxy; - } - -} http://git-wip-us.apache.org/repos/asf/isis/blob/55f931ae/core/wrapper/src/main/java/org/apache/isis/progmodel/wrapper/metamodel/internal/ClassInstantiatorFactoryCE.java ---------------------------------------------------------------------- diff --git a/core/wrapper/src/main/java/org/apache/isis/progmodel/wrapper/metamodel/internal/ClassInstantiatorFactoryCE.java b/core/wrapper/src/main/java/org/apache/isis/progmodel/wrapper/metamodel/internal/ClassInstantiatorFactoryCE.java deleted file mode 100644 index 85bc196..0000000 --- a/core/wrapper/src/main/java/org/apache/isis/progmodel/wrapper/metamodel/internal/ClassInstantiatorFactoryCE.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.isis.progmodel.wrapper.metamodel.internal; - -/** - * Factory returning a {@link IClassInstantiatorCE}for the current JVM - */ -class ClassInstantiatorFactoryCE { - - private static IClassInstantiatorCE instantiator = new ObjenesisClassInstantiatorCE(); - - // ///CLOVER:OFF - private ClassInstantiatorFactoryCE() { - } - - // ///CLOVER:ON - - /** - * Returns the current JVM as specified in the Systtem properties - * - * @return current JVM - */ - public static String getJVM() { - return System.getProperty("java.vm.vendor"); - } - - /** - * Returns the current JVM specification version (1.5, 1.4, 1.3) - * - * @return current JVM specification version - */ - public static String getJVMSpecificationVersion() { - return System.getProperty("java.specification.version"); - } - - public static boolean is1_3Specifications() { - return getJVMSpecificationVersion().equals("1.3"); - } - - /** - * Returns a class instantiator suitable for the current JVM - * - * @return a class instantiator usable on the current JVM - */ - public static IClassInstantiatorCE getInstantiator() { - return instantiator; - } -} http://git-wip-us.apache.org/repos/asf/isis/blob/55f931ae/core/wrapper/src/main/java/org/apache/isis/progmodel/wrapper/metamodel/internal/CollectionInvocationHandler.java ---------------------------------------------------------------------- diff --git a/core/wrapper/src/main/java/org/apache/isis/progmodel/wrapper/metamodel/internal/CollectionInvocationHandler.java b/core/wrapper/src/main/java/org/apache/isis/progmodel/wrapper/metamodel/internal/CollectionInvocationHandler.java deleted file mode 100644 index d143af6..0000000 --- a/core/wrapper/src/main/java/org/apache/isis/progmodel/wrapper/metamodel/internal/CollectionInvocationHandler.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.isis.progmodel.wrapper.metamodel.internal; - -import static org.apache.isis.core.commons.lang.MethodUtils.getMethod; - -import java.util.Collection; -import java.util.List; - -import org.apache.isis.core.metamodel.spec.feature.OneToManyAssociation; - -class CollectionInvocationHandler<T, R> extends AbstractCollectionInvocationHandler<T, R> { - - public CollectionInvocationHandler(final R collectionToProxy, final String collectionName, final DomainObjectInvocationHandler<T> handler, final OneToManyAssociation otma) { - super(collectionToProxy, collectionName, handler, otma); - - try { - intercept(getMethod(collectionToProxy, "contains", Object.class)); - intercept(getMethod(collectionToProxy, "size")); - intercept(getMethod(collectionToProxy, "isEmpty")); - if (collectionToProxy instanceof List) { - intercept(getMethod(collectionToProxy, "get", int.class)); - } - veto(getMethod(collectionToProxy, "add", Object.class)); - veto(getMethod(collectionToProxy, "remove", Object.class)); - veto(getMethod(collectionToProxy, "addAll", Collection.class)); - veto(getMethod(collectionToProxy, "removeAll", Collection.class)); - veto(getMethod(collectionToProxy, "retainAll", Collection.class)); - veto(getMethod(collectionToProxy, "clear")); - } catch (final NoSuchMethodException e) { - // ///CLOVER:OFF - throw new RuntimeException("A Collection method could not be found: " + e.getMessage()); - // ///CLOVER:ON - } - } - -} http://git-wip-us.apache.org/repos/asf/isis/blob/55f931ae/core/wrapper/src/main/java/org/apache/isis/progmodel/wrapper/metamodel/internal/DelegatingInvocationHandler.java ---------------------------------------------------------------------- diff --git a/core/wrapper/src/main/java/org/apache/isis/progmodel/wrapper/metamodel/internal/DelegatingInvocationHandler.java b/core/wrapper/src/main/java/org/apache/isis/progmodel/wrapper/metamodel/internal/DelegatingInvocationHandler.java deleted file mode 100644 index 5772b88..0000000 --- a/core/wrapper/src/main/java/org/apache/isis/progmodel/wrapper/metamodel/internal/DelegatingInvocationHandler.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.isis.progmodel.wrapper.metamodel.internal; - -import java.lang.reflect.InvocationHandler; - -public interface DelegatingInvocationHandler<T> extends InvocationHandler { - - T getDelegate(); - - public boolean isResolveObjectChangedEnabled(); - - public void setResolveObjectChangedEnabled(boolean resolveObjectChangedEnabled); - -} http://git-wip-us.apache.org/repos/asf/isis/blob/55f931ae/core/wrapper/src/main/java/org/apache/isis/progmodel/wrapper/metamodel/internal/DelegatingInvocationHandlerDefault.java ---------------------------------------------------------------------- diff --git a/core/wrapper/src/main/java/org/apache/isis/progmodel/wrapper/metamodel/internal/DelegatingInvocationHandlerDefault.java b/core/wrapper/src/main/java/org/apache/isis/progmodel/wrapper/metamodel/internal/DelegatingInvocationHandlerDefault.java deleted file mode 100644 index 93121ff..0000000 --- a/core/wrapper/src/main/java/org/apache/isis/progmodel/wrapper/metamodel/internal/DelegatingInvocationHandlerDefault.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.isis.progmodel.wrapper.metamodel.internal; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -import org.apache.isis.applib.events.InteractionEvent; -import org.apache.isis.applib.services.wrapper.WrapperFactory; -import org.apache.isis.applib.services.wrapper.WrapperFactory.ExecutionMode; -import org.apache.isis.core.metamodel.adapter.ObjectAdapter; -import org.apache.isis.core.runtime.persistence.container.DomainObjectContainerObjectChanged; -import org.apache.isis.core.runtime.persistence.container.DomainObjectContainerResolve; - -public class DelegatingInvocationHandlerDefault<T> implements DelegatingInvocationHandler<T> { - - private final T delegate; - protected final WrapperFactory wrapperFactory; - private final ExecutionMode executionMode; - - protected final Method equalsMethod; - protected final Method hashCodeMethod; - protected final Method toStringMethod; - - private final DomainObjectContainerObjectChanged domainObjectContainerObjectChanged; - private final DomainObjectContainerResolve domainObjectContainerResolve; - - private boolean resolveObjectChangedEnabled; - - public DelegatingInvocationHandlerDefault(final T delegate, final WrapperFactory headlessViewer, final ExecutionMode executionMode) { - if (delegate == null) { - throw new IllegalArgumentException("delegate must not be null"); - } - this.delegate = delegate; - this.wrapperFactory = headlessViewer; - this.executionMode = executionMode; - - this.domainObjectContainerResolve = new DomainObjectContainerResolve(); - this.domainObjectContainerObjectChanged = new DomainObjectContainerObjectChanged(); - - try { - equalsMethod = delegate.getClass().getMethod("equals", new Class[] { Object.class }); - hashCodeMethod = delegate.getClass().getMethod("hashCode", new Class[] {}); - toStringMethod = delegate.getClass().getMethod("toString", new Class[] {}); - } catch (final NoSuchMethodException e) { - // ///CLOVER:OFF - throw new RuntimeException("An Object method could not be found: " + e.getMessage()); - // ///CLOVER:ON - } - } - - @Override - public boolean isResolveObjectChangedEnabled() { - return resolveObjectChangedEnabled; - } - - @Override - public void setResolveObjectChangedEnabled(final boolean resolveObjectChangedEnabled) { - this.resolveObjectChangedEnabled = resolveObjectChangedEnabled; - } - - protected void resolveIfRequired(final ObjectAdapter targetAdapter) { - resolveIfRequired(targetAdapter.getObject()); - } - - protected void resolveIfRequired(final Object domainObject) { - if (resolveObjectChangedEnabled) { - domainObjectContainerResolve.resolve(domainObject); - } - } - - protected void objectChangedIfRequired(final ObjectAdapter targetAdapter) { - objectChangedIfRequired(targetAdapter.getObject()); - } - - protected void objectChangedIfRequired(final Object domainObject) { - if (resolveObjectChangedEnabled) { - domainObjectContainerObjectChanged.objectChanged(domainObject); - } - } - - public WrapperFactory getHeadlessViewer() { - return wrapperFactory; - } - - @Override - public T getDelegate() { - return delegate; - } - - public ExecutionMode getExecutionMode() { - return executionMode; - } - - protected Object delegate(final Method method, final Object[] args) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { - - return method.invoke(getDelegate(), args); - } - - protected boolean isObjectMethod(final Method method) { - return toStringMethod.equals(method) || hashCodeMethod.equals(method) || equalsMethod.equals(method); - } - - @Override - public Object invoke(final Object object, final Method method, final Object[] args) throws Throwable { - return method.invoke(object, args); - } - - protected InteractionEvent notifyListeners(final InteractionEvent interactionEvent) { - wrapperFactory.notifyListeners(interactionEvent); - return interactionEvent; - } - -}
