-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Scopes were added to annotations and JavaBeanConfigurator
- Loading branch information
Showing
16 changed files
with
205 additions
and
96 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package team.annotations; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.TYPE) | ||
public @interface Provided { | ||
} |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package team.annotations; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.TYPE) | ||
public @interface Thread { | ||
} |
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
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,8 +1,16 @@ | ||
package team.configurator; | ||
|
||
import org.reflections.Reflections; | ||
import team.config.DefaultBeanDefinition; | ||
import team.factory.BeanFactory; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
|
||
public interface BeanConfigurator { | ||
<T> Class<? extends T> getImplementationClass(Class<T> interfaceClass); | ||
Reflections getScanner(); | ||
|
||
void setBeanFactory(BeanFactory beanFactory); | ||
|
||
<T> DefaultBeanDefinition generateBean(Class<T> tClass) throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException; | ||
} |
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
70 changes: 68 additions & 2 deletions
70
src/main/java/team/configurator/metadata/XMLBeanConfigurator.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,16 +1,82 @@ | ||
package team.configurator.metadata; | ||
|
||
import lombok.Getter; | ||
import org.reflections.Reflections; | ||
import org.w3c.dom.Document; | ||
import team.config.DefaultBeanDefinition; | ||
import team.configurator.BeanConfigurator; | ||
import team.factory.BeanFactory; | ||
|
||
import javax.xml.parsers.DocumentBuilderFactory; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
public class XMLBeanConfigurator implements BeanConfigurator { | ||
@Getter | ||
private Reflections scanner; | ||
private String FILENAME = "beans.xml"; | ||
private final Map<Class, Class> interfaceToImplementation; | ||
private BeanFactory beanFactory; | ||
|
||
private static final String BASE_PACKAGE_TAG = "base-package"; | ||
private static final String BEAN_TAG = "bean"; | ||
private static final String BEAN_NAME_ATTRIBUTE = "id"; | ||
private static final String BEAN_CLASS_NAME_ATTRIBUTE = "class"; | ||
private static final String SCOPE_ATTRIBUTE = "scope"; | ||
private static final String LAZY_INIT_ATTRIBUTE = "lazy-init"; | ||
private static final String PRIMARY_ATTRIBUTE = "primary"; | ||
private static final String FACTORY_BEAN_ATTRIBUTE = "factory-bean"; | ||
private static final String FACTORY_METHOD_ATTRIBUTE = "factory-method"; | ||
private static final String INIT_METHOD_ATTRIBUTE = "init-method"; | ||
private static final String DESTROY_METHOD_ATTRIBUTE = "destroy-method"; | ||
private static final String CONSTRUCTOR_ARGUMENT_TAG = "constructor-arg"; | ||
private static final String PROPERTY_TAG = "property"; | ||
private static final String NAME_ATTRIBUTE = "name"; | ||
private static final String REF_ATTRIBUTE = "ref"; | ||
|
||
public XMLBeanConfigurator(String filename) { | ||
this.FILENAME = filename; | ||
this.interfaceToImplementation = new ConcurrentHashMap<>(); | ||
} | ||
|
||
public XMLBeanConfigurator(Map<Class, Class> interfaceToImplementation) { | ||
this.interfaceToImplementation = interfaceToImplementation; | ||
} | ||
|
||
public XMLBeanConfigurator(String filename, Map<Class, Class> interfaceToImplementation) { | ||
this.FILENAME = filename; | ||
this.interfaceToImplementation = interfaceToImplementation; | ||
} | ||
|
||
public void parseXML() { | ||
// parse xml file and put classes in map | ||
try { | ||
Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(this.FILENAME); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public <T> Class<? extends T> getImplementationClass(Class<T> interfaceClass) { | ||
return null; | ||
// return class from interfaceToImplementation map | ||
// if class doesn't exist in map -> throw exception | ||
if (interfaceToImplementation.containsKey(interfaceClass)) { | ||
return interfaceToImplementation.get(interfaceClass); | ||
} else { | ||
throw new RuntimeException("No implementation for " + interfaceClass.getName()); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public void setBeanFactory(BeanFactory beanFactory) { | ||
this.beanFactory = beanFactory; | ||
} | ||
|
||
@Override | ||
public Reflections getScanner() { | ||
public <T> DefaultBeanDefinition generateBean(Class<T> tClass) throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { | ||
return null; | ||
} | ||
} |
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
Oops, something went wrong.