-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2a6d72a
commit 7c15219
Showing
4 changed files
with
174 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 51 additions & 1 deletion
52
...g/nop-spring-delta/src/main/java/io/nop/spring/delta/beans/NopBeansAutoConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,59 @@ | ||
package io.nop.spring.delta.beans; | ||
|
||
import io.nop.api.core.exceptions.NopException; | ||
import io.nop.commons.util.StringHelper; | ||
import io.nop.core.lang.xml.XNode; | ||
import io.nop.core.module.ModuleManager; | ||
import io.nop.core.resource.IResource; | ||
import io.nop.xlang.xdsl.DslNodeLoader; | ||
import io.nop.xlang.xdsl.XDslExtendResult; | ||
import org.springframework.beans.factory.support.BeanDefinitionRegistry; | ||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar; | ||
import org.springframework.core.io.ByteArrayResource; | ||
import org.springframework.core.io.Resource; | ||
import org.springframework.core.type.AnnotationMetadata; | ||
|
||
@Import(NopBeansRegistrar.class) | ||
import java.io.ByteArrayOutputStream; | ||
import java.util.List; | ||
|
||
@Import(NopBeansAutoConfiguration.NopBeansRegistrar.class) | ||
@Configuration | ||
public class NopBeansAutoConfiguration { | ||
|
||
public static class NopBeansRegistrar implements ImportBeanDefinitionRegistrar { | ||
@Override | ||
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, | ||
BeanDefinitionRegistry registry) { | ||
List<IResource> resources = ModuleManager.instance().findModuleResources("/beans", "beans.xml"); | ||
if (resources.isEmpty()) | ||
return; | ||
|
||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(registry); | ||
for (IResource resource : resources) { | ||
if (!resource.getName().startsWith("spring-")) | ||
continue; | ||
|
||
XDslExtendResult result = DslNodeLoader.INSTANCE.loadFromResource(resource); | ||
XNode node = result.getNode(); | ||
node.removeAttr("xmlns:x"); | ||
|
||
Resource springResource = toResource(node); | ||
reader.loadBeanDefinitions(springResource); | ||
} | ||
} | ||
|
||
private Resource toResource(XNode node) { | ||
ByteArrayOutputStream out = new ByteArrayOutputStream(); | ||
try { | ||
node.saveToStream(out, StringHelper.ENCODING_UTF8); | ||
} catch (Exception e) { | ||
throw NopException.adapt(e); | ||
} | ||
return new ByteArrayResource(out.toByteArray(), node.resourcePath()); | ||
} | ||
} | ||
|
||
} |
51 changes: 0 additions & 51 deletions
51
nop-spring/nop-spring-delta/src/main/java/io/nop/spring/delta/beans/NopBeansRegistrar.java
This file was deleted.
Oops, something went wrong.