-
Notifications
You must be signed in to change notification settings - Fork 77
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
Showing
18 changed files
with
588 additions
and
81 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
86 changes: 86 additions & 0 deletions
86
src/main/java/com/github/jaemon/dinger/config/DingerAutoConfiguration.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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Copyright ©2015-2021 Jaemon. All Rights Reserved. | ||
* | ||
* 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 com.github.jaemon.dinger.config; | ||
|
||
import com.github.jaemon.dinger.core.DingerRobot; | ||
import com.github.jaemon.dinger.core.entity.DingerProperties; | ||
import com.github.jaemon.dinger.core.session.DingerSessionFactory; | ||
import com.github.jaemon.dinger.core.spring.DingerSessionFactoryBean; | ||
import org.springframework.beans.factory.InitializingBean; | ||
import org.springframework.boot.autoconfigure.AutoConfigureAfter; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.io.Resource; | ||
import org.springframework.core.io.ResourceLoader; | ||
import org.springframework.util.Assert; | ||
import org.springframework.util.StringUtils; | ||
|
||
/** | ||
* DingerAutoConfiguration | ||
* | ||
* @author Jaemon | ||
* @since 1.2 | ||
*/ | ||
@Configuration | ||
@EnableConfigurationProperties(DingerProperties.class) | ||
@AutoConfigureAfter(DingerConfiguration.class) | ||
public class DingerAutoConfiguration implements InitializingBean { | ||
private final DingerProperties properties; | ||
private final DingerRobot dingerRobot; | ||
private final ResourceLoader resourceLoader; | ||
|
||
public DingerAutoConfiguration( | ||
DingerProperties dingerProperties, | ||
DingerRobot dingerRobot, | ||
ResourceLoader resourceLoader | ||
) { | ||
this.properties = dingerProperties; | ||
this.dingerRobot = dingerRobot; | ||
this.resourceLoader = resourceLoader; | ||
} | ||
|
||
@Bean | ||
@ConditionalOnMissingBean | ||
public DingerSessionFactory dingerSessionFactory() throws Exception { | ||
DingerSessionFactoryBean factory = new DingerSessionFactoryBean(); | ||
|
||
factory.setConfiguration( | ||
com.github.jaemon.dinger.core.session.Configuration.of(properties, dingerRobot) | ||
); | ||
|
||
return factory.getObject(); | ||
} | ||
|
||
@Override | ||
public void afterPropertiesSet() throws Exception { | ||
checkConfigFileExists(); | ||
} | ||
|
||
private void checkConfigFileExists() { | ||
|
||
if ( | ||
StringUtils.hasText(this.properties.getDingerLocations()) | ||
) { | ||
|
||
Resource resource = this.resourceLoader.getResource(this.properties.getDingerLocations()); | ||
|
||
Assert.state(resource.exists(), "Cannot find config location: " + resource | ||
+ " (please add config file or check your Dinger configuration)"); | ||
} | ||
} | ||
} |
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
34 changes: 34 additions & 0 deletions
34
src/main/java/com/github/jaemon/dinger/core/DingerInvocationHandler.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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright ©2015-2021 Jaemon. All Rights Reserved. | ||
* | ||
* 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 com.github.jaemon.dinger.core; | ||
|
||
import java.lang.reflect.InvocationHandler; | ||
|
||
/** | ||
* Dinger Invocation Handler | ||
* | ||
* @author Jaemon | ||
* @since 1.2 | ||
*/ | ||
public abstract class DingerInvocationHandler | ||
extends DingerMessageHandler | ||
implements InvocationHandler { | ||
|
||
@Override | ||
public Object clone() throws CloneNotSupportedException { | ||
return super.clone(); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
src/main/java/com/github/jaemon/dinger/core/entity/enums/IgnoreMethod.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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright ©2015-2021 Jaemon. All Rights Reserved. | ||
* | ||
* 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 com.github.jaemon.dinger.core.entity.enums; | ||
|
||
import com.github.jaemon.dinger.core.DingerInvocationHandler; | ||
|
||
/** | ||
* Ignore Method | ||
* | ||
* @author Jaemon | ||
* @since 1.2 | ||
*/ | ||
public enum IgnoreMethod { | ||
|
||
EQUALS("equals") { | ||
@Override | ||
public Boolean execute(DingerInvocationHandler invocationHandler, Object[] args) { | ||
return invocationHandler.equals(args[0]); | ||
} | ||
}, | ||
CLONE("clone") { | ||
@Override | ||
public Object execute(DingerInvocationHandler invocationHandler, Object[] args) throws CloneNotSupportedException { | ||
return invocationHandler.clone(); | ||
} | ||
}, | ||
HASH_CODE("hashCode") { | ||
@Override | ||
public Integer execute(DingerInvocationHandler invocationHandler, Object[] args) throws Exception { | ||
return invocationHandler.hashCode(); | ||
} | ||
}, | ||
TO_STRING("toString") { | ||
@Override | ||
public String execute(DingerInvocationHandler invocationHandler, Object[] args) throws Exception { | ||
return invocationHandler.toString(); | ||
} | ||
}, | ||
|
||
; | ||
|
||
private String methodName; | ||
|
||
IgnoreMethod(String methodName) { | ||
this.methodName = methodName; | ||
} | ||
|
||
|
||
public abstract Object execute(DingerInvocationHandler invocationHandler, Object[] args) throws Exception; | ||
|
||
public String getMethodName() { | ||
return methodName; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/main/java/com/github/jaemon/dinger/core/session/Configuration.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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright ©2015-2021 Jaemon. All Rights Reserved. | ||
* | ||
* 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 com.github.jaemon.dinger.core.session; | ||
|
||
import com.github.jaemon.dinger.core.DingerRobot; | ||
import com.github.jaemon.dinger.core.entity.DingerProperties; | ||
|
||
/** | ||
* Configuration | ||
* | ||
* @author Jaemon | ||
* @version 1.2 | ||
*/ | ||
public class Configuration { | ||
protected DingerProperties dingerProperties; | ||
protected DingerRobot dingerRobot; | ||
|
||
private Configuration(DingerProperties dingerProperties, DingerRobot dingerRobot) { | ||
this.dingerProperties = dingerProperties; | ||
this.dingerRobot = dingerRobot; | ||
} | ||
|
||
public static Configuration of(DingerProperties dingerProperties, DingerRobot dingerRobot) { | ||
return new Configuration(dingerProperties, dingerRobot); | ||
} | ||
|
||
public DingerProperties getDingerProperties() { | ||
return dingerProperties; | ||
} | ||
|
||
public DingerRobot getDingerRobot() { | ||
return dingerRobot; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/main/java/com/github/jaemon/dinger/core/session/DingerSession.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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright ©2015-2021 Jaemon. All Rights Reserved. | ||
* | ||
* 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 com.github.jaemon.dinger.core.session; | ||
|
||
|
||
/** | ||
* DingerSession | ||
* | ||
* @author Jaemon | ||
* @since 1.0 | ||
*/ | ||
public interface DingerSession { | ||
|
||
/** | ||
* Retrieves a dinger. | ||
* | ||
* @param type | ||
* dinger interface class | ||
* @param <T> | ||
* the dinger type | ||
* @return | ||
* a dinger bound to this DingerSession | ||
*/ | ||
<T> T getDinger(Class<T> type); | ||
|
||
/** | ||
* dinger configuration | ||
* | ||
* @return | ||
* {@link Configuration} | ||
*/ | ||
Configuration configuration(); | ||
|
||
} |
Oops, something went wrong.