Service Method and Returning Objects to screen - TheOpenCloudEngine/metaworks GitHub Wiki
Service Method λ₯Ό ν΅ν μ‘μ μ€ν
@ServiceMethod(callByContent=true)
public Object login(){
System.out.println("User clicked login");
}
Return μ ν΅ν νλ©΄ μΆλ ₯
λ©νμμ€μ λͺ¨λΈ μ€μ¬ νλ‘κ·Έλλ° κΈ°λ²μ κ°μ²΄λ₯Ό 리ν΄ν¨μΌλ‘μ νλ©΄ μΆλ ₯μ μ λνλ€. λ€μμ μ΄λ ν μ‘μ μ λ°λΌ νλ©΄μ μ νμ νλ μμ μ΄λ€.
μμ
μλ μμ λ ServiceMethod μ κ°λ¨ν μ¬μ© μμ λ‘μ, Login.java λ Main.java λ₯Ό 리ν΄ν¨μΌλ‘μ¨ λ©μΈ νλ©΄μΌλ‘μ μ νμ κ°λ₯νκ² νλ€.
Login.java
import org.metaworks.annotation.ServiceMethod;
public class Login {
String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
String message;
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
String password;
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@ServiceMethod(callByContent=true)
public Object login(){
if(getName().equals(getPassword()))
return new Main();
else{
setMessage("μνΈκ° νλ Έμ΅λλ€.");
return this;
// throw new RuntimeException("μνΈκ° νλ Έμ΅λλ€.");
}
}
}
Main.java
import org.metaworks.annotation.ServiceMethod;
public class Main {
public Main(){}
@ServiceMethod(needToConfirm=true)
public Login logout(){
return new Login();
}
}
μΊμ€ν μ μν λ¦¬ν΄ κ°μ²΄μ μμΉ μ‘κΈ°
λ©νμμ€μ DDD κ°λ μ νμ₯μΌλ‘ 리ν΄λλ κ°μ²΄μ μμΉλ κ°μ²΄ μμ ꡬ쑰μ κ°μ₯ μ μ ν μμΉλ₯Ό μ°Ύμκ°κ² λλ€. λ€μμ μμ λ₯Ό 보μ.
Main.java
package org.metaworks.example.navigation;
public class Main {
Menu menu;
public Menu getMenu() {
return menu;
}
public void setMenu(Menu menu) {
this.menu = menu;
}
Content content;
public Content getContent() {
return content;
}
public void setContent(Content content) {
this.content = content;
}
protected Main(){
setMenu(new Menu());
setContent(new Content());
}
}
Menu.java
package org.metaworks.example.navigation;
public class Menu {
protected Menu(){
Selection selection1 = new Selection();
selection1.setContentClassName("AContent");
Selection selection2 = new Selection();
selection2.setContentClassName("BContent");
setSelections(new Selection[]{selection1, selection2});
}
Selection[] selections;
public Selection[] getSelections() {
return selections;
}
public void setSelections(Selection[] selections) {
this.selections = selections;
}
}
Selection.java
package org.metaworks.example.navigation;
import org.metaworks.annotation.Id;
import org.metaworks.annotation.ServiceMethod;
public class Selection {
String contentClassName;
@Id
public String getContentClassName() {
return contentClassName;
}
public void setContentClassName(String contentClassName) {
this.contentClassName = contentClassName;
}
@ServiceMethod
public Content select() throws InstantiationException, IllegalAccessException, ClassNotFoundException{
return (Content) Class.forName("org.metaworks.example.navigation." + getContentClassName()).newInstance();
}
}
AContent.java / BContent.java
package org.metaworks.example.navigation;
public class AContent extends Content{
protected AContent(){
setTitle("A content");
setHtml("Hello, this content is A");
}
}
package org.metaworks.example.navigation;
public class BContent extends Content{
protected BContent(){
setTitle("B content");
setHtml("Hello, this content is B");
}
}