in core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/wrapper/handlers/DomainObjectInvocationHandler.java [147:262]
public Object invoke(final Object proxyObjectUnused, final Method method, final Object[] args) throws Throwable {
if (isObjectMethod(method)) {
return delegate(method, args);
}
if(isEnhancedEntityMethod(method)) {
return delegate(method, args);
}
final ManagedObject targetAdapter = getObjectManager().adapt(getDelegate());
if(!targetAdapter.getSpecialization().isMixin()) {
MmAssertionUtils.assertIsBookmarkSupported(targetAdapter);
}
if (method.equals(titleMethod)) {
return handleTitleMethod(targetAdapter);
}
final ObjectSpecification targetSpec = targetAdapter.getSpecification();
// save method, through the proxy
if (method.equals(__causeway_saveMethod)) {
return handleSaveMethod(targetAdapter, targetSpec);
}
if (method.equals(__causeway_wrappedMethod)) {
return getDelegate();
}
if (method.equals(__causeway_executionModes)) {
return getSyncControl().getExecutionModes();
}
val objectMember = targetSpec.getMemberElseFail(method);
val memberId = objectMember.getId();
val intent = ImperativeFacet.getIntent(objectMember, method);
if(intent == Intent.CHECK_IF_HIDDEN || intent == Intent.CHECK_IF_DISABLED) {
throw new UnsupportedOperationException(String.format("Cannot invoke supporting method '%s'", memberId));
}
if (intent == Intent.DEFAULTS || intent == Intent.CHOICES_OR_AUTOCOMPLETE) {
return method.invoke(getDelegate(), args);
}
if (objectMember.isOneToOneAssociation()) {
if (intent == Intent.CHECK_IF_VALID || intent == Intent.MODIFY_PROPERTY_SUPPORTING) {
throw new UnsupportedOperationException(String.format("Cannot invoke supporting method for '%s'; use only property accessor/mutator", memberId));
}
final OneToOneAssociation otoa = (OneToOneAssociation) objectMember;
if (intent == Intent.ACCESSOR) {
return handleGetterMethodOnProperty(targetAdapter, args, otoa);
}
if (intent == Intent.MODIFY_PROPERTY || intent == Intent.INITIALIZATION) {
return handleSetterMethodOnProperty(targetAdapter, args, otoa);
}
}
if (objectMember.isOneToManyAssociation()) {
if (intent == Intent.CHECK_IF_VALID) {
throw new UnsupportedOperationException(String.format("Cannot invoke supporting method '%s'; use only collection accessor/mutator", memberId));
}
final OneToManyAssociation otma = (OneToManyAssociation) objectMember;
if (intent == Intent.ACCESSOR) {
return handleGetterMethodOnCollection(targetAdapter, args, otma, memberId);
}
}
if (objectMember instanceof ObjectAction) {
if (intent == Intent.CHECK_IF_VALID) {
throw new UnsupportedOperationException(String.format("Cannot invoke supporting method '%s'; use only the 'invoke' method", memberId));
}
val objectAction = (ObjectAction) objectMember;
if(Facets.mixinIsPresent(targetSpec)) {
if (mixeeAdapter == null) {
throw _Exceptions.illegalState(
"Missing the required mixeeAdapter for action '%s'",
objectAction.getId());
}
MmAssertionUtils.assertIsBookmarkSupported(mixeeAdapter);
final ObjectMember mixinMember = determineMixinMember(mixeeAdapter, objectAction);
if (mixinMember != null) {
if(mixinMember instanceof ObjectAction) {
return handleActionMethod(mixeeAdapter, args, (ObjectAction)mixinMember);
}
if(mixinMember instanceof OneToOneAssociation) {
return handleGetterMethodOnProperty(mixeeAdapter, new Object[0], (OneToOneAssociation)mixinMember);
}
if(mixinMember instanceof OneToManyAssociation) {
return handleGetterMethodOnCollection(mixeeAdapter, new Object[0], (OneToManyAssociation)mixinMember, memberId);
}
} else {
throw _Exceptions.illegalState(String.format(
"Could not locate mixin member for action '%s' on spec '%s'", objectAction.getId(), targetSpec));
}
}
// this is just a regular non-mixin action.
return handleActionMethod(targetAdapter, args, objectAction);
}
throw new UnsupportedOperationException(String.format("Unknown member type '%s'", objectMember));
}