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.saga.annotation;
 
 
Utility class that inspects annotation on a Saga instance and returns the relevant configuration for its Event Handlers.

Parameters:
<T> The type of saga targeted by this inspector
Author(s):
Allard Buijze
Since:
0.7
 
Initialize the inspector.

Parameters:
sagaType The type of saga this inspector handles
 
     public SagaAnnotationInspector(Class<T> sagaType) {
         super(sagaTypeSagaEventHandler.class);
     }

    
Find the configuration for the handler on the given sagaType for the given event.

Parameters:
event The Event to investigate the handler for
Returns:
the configuration of the handler, as defined by the annotations.
 
         Handler handler = findHandlerMethod(event.getClass());
         if (handler == null) {
             return HandlerConfiguration.noHandler();
         }
         Method handlerMethod = handler.getMethod();
         SagaEventHandler handlerAnnotation = handlerMethod.getAnnotation(SagaEventHandler.class);
         StartSaga startAnnotation = handlerMethod.getAnnotation(StartSaga.class);
         EndSaga endAnnotation = handlerMethod.getAnnotation(EndSaga.class);
         String associationProperty = handlerAnnotation.associationProperty();
         String associationKey = handlerAnnotation.keyName().isEmpty()
                 ? associationProperty
                 : handlerAnnotation.keyName();
         Object associationValue = getPropertyValue(eventassociationProperty);
         AssociationValue association = new AssociationValue(associationKeyassociationValue);
         return new HandlerConfiguration(creationPolicy(startAnnotation),
                                         handlerMethod,
                                         endAnnotation != null,
                                         association);
     }
 
     private SagaCreationPolicy creationPolicy(StartSaga startSaga) {
         if (startSaga == null) {
             return .;
         } else if (startSaga.forceNew()) {
             return .;
         } else {
             return .;
         }
     }
 
     private Object getPropertyValue(Event eventString property) {
         try {
             Method m = event.getClass().getMethod("get" + capitalize(property));
             return m.invoke(event);
         } catch (NoSuchMethodException e) {
             throw new AxonConfigurationException(""e);
         } catch (InvocationTargetException e) {
             throw new AxonConfigurationException(""e);
         } catch (IllegalAccessException e) {
             throw new AxonConfigurationException(""e);
         }
     }
 
     private String capitalize(String s) {
         return s.substring(0, 1).toUpperCase(.) + s.substring(1);
    }

    
Returns the type of saga this inspector handles.

Returns:
the type of saga (Class) this inspector handles
    @SuppressWarnings({"unchecked"})
    public Class<T> getSagaType() {
        return (Class<T>) super.getTargetType();
    }
New to GrepCode? Check out our FAQ X