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.contextsupport.spring;
 
 
 import java.util.List;

The RepositoryBeanDefinitionParser is responsible for parsing the repository element from the Axon namespace. It creates a org.springframework.beans.factory.config.BeanDefinition based on the org.axonframework.eventsourcing.GenericEventSourcingRepository.

Author(s):
Ben Z. Tels
Allard Buijze
Since:
0.7
 
The conflict resolver attribute name.
 
     private static final String CONFLICT_RESOLVER_ATTRIBUTE = "conflict-resolver";
    
The event store attribute name.
 
     private static final String EVENT_STORE_ATTRIBUTE = "event-store";
    
The event bus attribute name.
 
     private static final String EVENT_BUS_ATTRIBUTE = "event-bus";
    
The locking strategy attribute name.
 
     private static final String LOCKING_STRATEGY_ATTRIBUTE = "locking-strategy";
    
The aggregate root type attribute name.
 
     private static final String AGGREGATE_ROOT_TYPE_ATTRIBUTE = "aggregate-type";
     private static final String CACHE_ATTRIBUTE = "cache-ref";
 
     private static final String EVENT_PROCESSORS_ELEMENT = "event-processors";
     private static final String SNAPSHOT_TRIGGER_ELEMENT = "snapshotter-trigger";
 
     private static final String EVENT_STREAM_DECORATORS_PROPERTY = "eventStreamDecorators";
     private static final String SNAPSHOTTER_TRIGGER_PROPERTY = "snapshotterTrigger";
 
 
     @Override
     protected AbstractBeanDefinition parseInternal(Element elementParserContext parserContext) {
         GenericBeanDefinition repositoryDefinition = new GenericBeanDefinition();
         if (element.hasAttribute()) {
             repositoryDefinition.setBeanClass(CachingEventSourcingRepository.class);
         } else {
             repositoryDefinition.setBeanClass(EventSourcingRepository.class);
             parseLockingStrategy(elementrepositoryDefinition);
         }
 
         parseAggregateRootType(elementrepositoryDefinition);
         parseReferenceAttribute(element"eventBus"repositoryDefinition.getPropertyValues(),
                                 EventBus.class);
         parseReferenceAttribute(element"eventStore"repositoryDefinition.getPropertyValues(),
                                 EventStore.class);
         parseReferenceAttribute(element"conflictResolver",
                                 repositoryDefinition.getPropertyValues(), null);
         parseReferenceAttribute(element"cache"repositoryDefinition.getPropertyValues(), null);
         parseProcessors(elementparserContextrepositoryDefinition);
         return repositoryDefinition;
     }
    @SuppressWarnings({"unchecked"})
    private void parseProcessors(Element elementParserContext parserContextGenericBeanDefinition beanDefinition) {
        Element processorsElement = DomUtils.getChildElementByTagName(element);
        Element snapshotTriggerElement = DomUtils.getChildElementByTagName(element);
        if (snapshotTriggerElement != null) {
            BeanDefinition triggerDefinition = .parse(snapshotTriggerElementparserContext);
            PropertyValue aggregateCache = beanDefinition.getPropertyValues().getPropertyValue("cache");
            if (aggregateCache != null) {
                triggerDefinition.getPropertyValues().add("aggregateCache"aggregateCache.getValue());
            }
            beanDefinition.getPropertyValues().add(triggerDefinition);
        }
        if (processorsElement != null) {
            List<ObjectprocessorsList = parserContext.getDelegate().parseListElement(processorsElement,
                                                                                       beanDefinition);
            if (!processorsList.isEmpty()) {
                beanDefinition.getPropertyValues().add(processorsList);
            }
        }
    }

    
Parse the named reference attribute and make it a property reference value.

Parameters:
element The org.w3c.dom.Element being parsed.
referenceName The name of the reference attribute.
propertyName The name of the property to set the references object to
properties The properties of the bean definition
autowiredType An optional class defining the type to autowire. Use null to indicate that no autowiring is required.
    private void parseReferenceAttribute(Element elementString referenceNameString propertyName,
                                         MutablePropertyValues propertiesClass<?> autowiredType) {
        if (element.hasAttribute(referenceName)) {
            properties.add(propertyNamenew RuntimeBeanReference(element.getAttribute(referenceName)));
        } else if (autowiredType != null) {
            properties.add(propertyNamenew AutowiredBean(autowiredType));
        }
    }

    
Parse the org.axonframework.repository.LockingStrategy selection and make it a constructor argument.

    private void parseLockingStrategy(Element elementGenericBeanDefinition builder) {
        if (element.hasAttribute()) {
            LockingStrategy strategy = LockingStrategy.valueOf(element.getAttribute());
            builder.getConstructorArgumentValues().addGenericArgumentValue(strategy);
        }
    }

    
Parse the org.axonframework.domain.AggregateRoot type information and make it a constructor argument.

Parameters:
element The Element being parsed.
builder The org.springframework.beans.factory.support.BeanDefinitionBuilder being used to construct the BeanDefinition.
    @SuppressWarnings({"unchecked"})
    private void parseAggregateRootType(Element elementGenericBeanDefinition builder) {
        // Mandatory in the XSD
        String aggregateRootTypeString = element.getAttribute();
        try {
            Class<?> aggregateRootType = Class.forName(aggregateRootTypeString);
            builder.getConstructorArgumentValues()
                   .addGenericArgumentValue(new GenericAggregateFactory(aggregateRootType));
        } catch (ClassNotFoundException e) {
            throw new IllegalArgumentException(
                    "No class of name " + aggregateRootTypeString + " was found on the classpath"e);
        }
    }
New to GrepCode? Check out our FAQ X