Skip to content

Commit

Permalink
start filling in namespace support for services
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Brown committed May 10, 2012
1 parent 1b25304 commit 2bd27c3
Showing 1 changed file with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,21 @@ class ServicesGrailsPlugin {
xmlns tx:"http://www.springframework.org/schema/tx"
tx.'annotation-driven'('transaction-manager':'transactionManager')

def aliasNameToListOfBeanNames = [:]
def registeredBeanNames = []
for (serviceGrailsClass in application.serviceClasses) {
GrailsServiceClass serviceClass = serviceGrailsClass

def providingPlugin = manager?.getPluginForClass(serviceClass.clazz)

def beanName
if(providingPlugin && !serviceClass.shortName.toLowerCase().startsWith(providingPlugin.name.toLowerCase())) {
beanName = "${providingPlugin.name}${serviceClass.shortName}"
def aliasName = serviceClass.propertyName
aliasNameToListOfBeanNames.get(aliasName, []) << beanName
} else {
beanName = serviceClass.propertyName
}
registeredBeanNames << beanName
def scope = serviceClass.getPropertyValue("scope")
def lazyInit = serviceClass.hasProperty("lazyInit") ? serviceClass.getPropertyValue("lazyInit") : true

Expand All @@ -71,7 +83,7 @@ class ServicesGrailsPlugin {
}
props."*" = attributes

"${serviceClass.propertyName}"(TypeSpecifyableTransactionProxyFactoryBean, serviceClass.clazz) { bean ->
"${beanName}"(TypeSpecifyableTransactionProxyFactoryBean, serviceClass.clazz) { bean ->
if (scope) bean.scope = scope
bean.lazyInit = lazyInit
target = { innerBean ->
Expand All @@ -87,7 +99,7 @@ class ServicesGrailsPlugin {
}
}
else {
"${serviceClass.propertyName}"(serviceClass.getClazz()) { bean ->
"${beanName}"(serviceClass.getClazz()) { bean ->
bean.autowire = true
bean.lazyInit = lazyInit
if (scope) {
Expand All @@ -96,6 +108,11 @@ class ServicesGrailsPlugin {
}
}
}
aliasNameToListOfBeanNames.each { aliasName, listOfBeanNames ->
if(listOfBeanNames.size() == 1 && !registeredBeanNames.contains(aliasName)) {
registerAlias listOfBeanNames[0], aliasName
}
}
}

boolean shouldCreateTransactionalProxy(GrailsServiceClass serviceClass) {
Expand Down

0 comments on commit 2bd27c3

Please sign in to comment.