Skip to content

Commit

Permalink
部分小错误
Browse files Browse the repository at this point in the history
  • Loading branch information
、Campanulaceae committed Feb 19, 2016
1 parent 36c37f2 commit e5feb12
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions ioc/3.myioc.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public interface Container {
/**
* 初始化装配
*/
public void initWrited();
public void initWired();
}
```

Expand Down Expand Up @@ -242,7 +242,7 @@ public class SampleContainer implements Container {
}

@Override
public void initWrited() {
public void initWired() {
Iterator<Entry<String, Object>> it = beans.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, Object> entry = (Map.Entry<String, Object>) it.next();
Expand All @@ -261,40 +261,40 @@ public class SampleContainer implements Container {
Field[] fields = object.getClass().getDeclaredFields();
for (Field field : fields) {
// 需要注入的字段
AutoWrited autoWrited = field.getAnnotation(AutoWrited.class);
if (null != autoWrited) {
AutoWired autoWired = field.getAnnotation(autoWired.class);
if (null != autoWired) {

// 要注入的字段
Object autoWritedField = null;
Object autoWiredField = null;

String name = autoWrited.name();
String name = autoWired.name();
if(!name.equals("")){
String className = beanKeys.get(name);
if(null != className && !className.equals("")){
autoWritedField = beans.get(className);
autoWiredField = beans.get(className);
}
if (null == autoWritedField) {
if (null == autoWiredField) {
throw new RuntimeException("Unable to load " + name);
}
} else {
if(autoWrited.value() == Class.class){
autoWritedField = recursiveAssembly(field.getType());
if(autoWired.value() == Class.class){
autoWiredField = recursiveAssembly(field.getType());
} else {
// 指定装配的类
autoWritedField = this.getBean(autoWrited.value());
if (null == autoWritedField) {
autoWritedField = recursiveAssembly(autoWrited.value());
autoWiredField = this.getBean(autoWired.value());
if (null == autoWiredField) {
autoWiredField = recursiveAssembly(autoWired.value());
}
}
}

if (null == autoWritedField) {
if (null == autoWiredField) {
throw new RuntimeException("Unable to load " + field.getType().getCanonicalName());
}

boolean accessible = field.isAccessible();
field.setAccessible(true);
field.set(object, autoWritedField);
field.set(object, autoWiredField);
field.setAccessible(accessible);
}
}
Expand Down Expand Up @@ -334,7 +334,7 @@ public class IocTest {
public static void baseTest(){
container.registerBean(Lol.class);
// 初始化注入
container.initWrited();
container.initWired();

Lol lol = container.getBean(Lol.class);
lol.work();
Expand All @@ -343,7 +343,7 @@ public class IocTest {
public static void iocClassTest(){
container.registerBean(Lol2.class);
// 初始化注入
container.initWrited();
container.initWired();

Lol2 lol = container.getBean(Lol2.class);
lol.work();
Expand All @@ -353,7 +353,7 @@ public class IocTest {
container.registerBean("face", new FaceService2());
container.registerBean(Lol3.class);
// 初始化注入
container.initWrited();
container.initWired();

Lol3 lol = container.getBean(Lol3.class);
lol.work();
Expand Down

0 comments on commit e5feb12

Please sign in to comment.