forked from ironchefpython/modapi
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created factory to generate components from prototypes
- Loading branch information
1 parent
d0b8874
commit 362a665
Showing
9 changed files
with
199 additions
and
220 deletions.
There are no files selected for viewing
52 changes: 44 additions & 8 deletions
52
src/org/ironchefpython/modapi/AbstractDynamicProperty.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,19 +1,55 @@ | ||
package org.ironchefpython.modapi; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
|
||
import javassist.CannotCompileException; | ||
import javassist.ClassPool; | ||
import javassist.CtClass; | ||
import javassist.CtField; | ||
import javassist.Modifier; | ||
import javassist.NotFoundException; | ||
|
||
import org.ironchefpython.modapi.error.PropertyError; | ||
import org.ironchefpython.modapi.primitives.NumberProperty; | ||
|
||
public abstract class AbstractDynamicProperty implements DynamicProperty { | ||
public DynamicProperty cloneWith(Object object) throws PropertyError { | ||
if (object == null) { | ||
return this; | ||
} | ||
// FIXME (return a component or child component based on the | ||
// string passed) | ||
throw new NoSuchMethodError(); | ||
// public DynamicProperty cloneWith(Object object) throws PropertyError { | ||
// if (object == null) { | ||
// return this; | ||
// } | ||
// // FIXME (return a component or child component based on the | ||
// // string passed) | ||
// throw new NoSuchMethodError(); | ||
// } | ||
// | ||
public boolean isStatic() { | ||
return false; | ||
} | ||
|
||
public Object getValue() { | ||
// FIXME produce a better result for a null value | ||
throw new NoSuchMethodError(); | ||
} | ||
|
||
protected static DynamicProperty makeType(final Class<?> type, final Class<? extends DynamicProperty> propertyClass) { | ||
return new AbstractDynamicProperty() { | ||
public DynamicProperty cloneWith(Object object) { | ||
try { | ||
return (object == null ? this : propertyClass.getConstructor(type).newInstance(object)); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
public Class<?> getJavaType() { | ||
return type; | ||
} | ||
|
||
public Class<?> getFieldType() { | ||
return type; | ||
} | ||
|
||
|
||
}; | ||
} | ||
} |
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,17 +1,13 @@ | ||
package org.ironchefpython.modapi; | ||
|
||
import javassist.CannotCompileException; | ||
import javassist.CtClass; | ||
import javassist.NotFoundException; | ||
|
||
import org.ironchefpython.modapi.error.PropertyError; | ||
import org.mozilla.javascript.Callable; | ||
|
||
public interface DynamicProperty { | ||
|
||
public DynamicProperty cloneWith(Object object) throws PropertyError; | ||
public Object getValue(); | ||
public Object addToClass(String key, CtClass comp) throws CannotCompileException, NotFoundException; | ||
public Class<?> getType(); | ||
public Class<?> getJavaType(); | ||
public Class<?> getFieldType(); | ||
public boolean isStatic(); | ||
|
||
} |
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
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
Oops, something went wrong.