Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Copyright (c) 2010-2011. Axon Framework
  *
  * Licensed 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.axonframework.commandhandling.annotation;
import static org.axonframework.util.ReflectionUtils.ensureAccessible;

Command Handler that creates a new aggregate instance by invoking that aggregate's constructor.

Parameters:
<T> the type of aggregate this handler handles commands for
Author(s):
Allard Buijze
Since:
1.2
    private final Constructor<T> constructor;
    private final Class<?> parameterType;
    private final boolean optionalParameter;

    
Creates a new instance for the given constructor, accepting the given parameterType and an optionalParameter.

Parameters:
constructor The constructor this handler should invoke
parameterType The type of parameter accepted by the constructor
optionalParameter Indicator of whether this constructor accepts the optional second parameter
    ConstructorCommandHandler(Constructor<T> constructorClass<?> parameterTypeboolean optionalParameter) {
        this. = constructor;
        this. = parameterType;
        this. = optionalParameter;
    }

    
Invokes the constructor using the given command and optionally unitOfWork.

Parameters:
command The command to pass to the constructor
unitOfWork The optional unitOfWork to pass if the constructor contains the optional parameter
Returns:
The constructed aggregate instance
Throws:
java.lang.IllegalAccessException if the security settings prevent access to the constructor
java.lang.InstantiationException if an error occurs creating the aggregate instance
java.lang.reflect.InvocationTargetException if the constructor threw an exception
    public T invoke(Object commandUnitOfWork unitOfWork)
        if () {
            return .newInstance(commandunitOfWork);
        } else {
            return .newInstance(command);
        }
    }

    
Returns the type of command this handler handles.

Returns:
the type of command this handler handles
    public Class<?> getCommandType() {
        return ;
    }
New to GrepCode? Check out our FAQ X