use of lucee.transformer.bytecode.util.ASMProperty in project Lucee by lucee.
the class Axis1Client method _mapComplex.
private Class _mapComplex(PageContext pc, SymbolTable symbolTable, Config secondChanceConfig, org.apache.axis.encoding.TypeMapping tm, TypeEntry type) throws PageException {
// extension
Class ex = null;
if (type instanceof DefinedType) {
DefinedType dt = (DefinedType) type;
TypeEntry exType = dt.getComplexTypeExtensionBase(symbolTable);
if (exType != null)
ex = map(pc, symbolTable, secondChanceConfig, tm, exType);
}
Vector children = type.getContainedElements();
ArrayList<ASMPropertyImpl> properties = new ArrayList<ASMPropertyImpl>();
if (children != null) {
Iterator it = children.iterator();
ElementDecl el;
Class clazz;
TypeEntry t;
String name;
while (it.hasNext()) {
clazz = null;
el = (ElementDecl) it.next();
t = el.getType();
Vector els = t.getContainedElements();
// again handle children
if (els != null) {
clazz = mapComplex(pc, symbolTable, secondChanceConfig, tm, t);
}
name = lucee.runtime.type.util.ListUtil.last(el.getQName().getLocalPart(), '>');
if (clazz == null)
clazz = tm.getClassForQName(t.getQName());
if (clazz == null)
clazz = Object.class;
properties.add(new ASMPropertyImpl(clazz, name));
}
}
ASMProperty[] props = properties.toArray(new ASMProperty[properties.size()]);
String clientClassName = getClientClassName(type, props);
Class pojo;
if (pc == null)
pojo = ComponentUtil.getComponentPropertiesClass(secondChanceConfig, clientClassName, props, ex);
else
pojo = ComponentUtil.getClientComponentPropertiesClass(pc, clientClassName, props, ex);
TypeMappingUtil.registerBeanTypeMapping(tm, pojo, type.getQName());
return pojo;
}
use of lucee.transformer.bytecode.util.ASMProperty in project Lucee by lucee.
the class ComponentUtil method _getComponentPropertiesClass.
private static Class _getComponentPropertiesClass(PageContext pc, Component component) throws PageException, IOException, ClassNotFoundException {
ASMProperty[] props = ASMUtil.toASMProperties(component.getProperties(false, true, false, false));
String className = getClassname(component, props);
String real = className.replace('.', '/');
Mapping mapping = component.getPageSource().getMapping();
PhysicalClassLoader cl = (PhysicalClassLoader) ((PageContextImpl) pc).getRPCClassLoader(false);
Resource classFile = cl.getDirectory().getRealResource(real.concat(".class"));
// get component class information
String classNameOriginal = component.getPageSource().getClassName();
String realOriginal = classNameOriginal.replace('.', '/');
Resource classFileOriginal = mapping.getClassRootDirectory().getRealResource(realOriginal.concat(".class"));
// load existing class when pojo is still newer than component class file
if (classFile.lastModified() >= classFileOriginal.lastModified()) {
try {
Class clazz = cl.loadClass(className);
// ClassUtil.loadInstance(clazz);
if (clazz != null && !hasChangesOfChildren(classFile.lastModified(), clazz))
return clazz;
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
}
}
// extends
String strExt = component.getExtends();
Class<?> ext = Object.class;
if (!StringUtil.isEmpty(strExt, true)) {
ext = Caster.cfTypeToClass(strExt);
}
//
// create file
byte[] barr = ASMUtil.createPojo(real, props, ext, new Class[] { Pojo.class }, component.getPageSource().getDisplayPath());
ResourceUtil.touch(classFile);
IOUtil.copy(new ByteArrayInputStream(barr), classFile, true);
cl = (PhysicalClassLoader) ((PageContextImpl) pc).getRPCClassLoader(true);
// ClassUtil.loadInstance(cl.loadClass(className));
return cl.loadClass(className);
}
use of lucee.transformer.bytecode.util.ASMProperty in project Lucee by lucee.
the class ComponentUtil method _getStructPropertiesClass.
private static Class _getStructPropertiesClass(PageContext pc, Struct sct, PhysicalClassLoader cl) throws PageException, IOException, ClassNotFoundException {
// create hash based on the keys of the struct
String hash = StructUtil.keyHash(sct);
char c = hash.charAt(0);
if (c >= '0' && c <= '9')
hash = "a" + hash;
// create class name (struct class name + hash)
String className = sct.getClass().getName() + "." + hash;
// create physcal location for the file
String real = className.replace('.', '/');
Resource classFile = cl.getDirectory().getRealResource(real.concat(".class"));
// load existing class
if (classFile.exists()) {
try {
Class clazz = cl.loadClass(className);
if (clazz != null)
return clazz;
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
}
}
// Properties
List<ASMProperty> props = new ArrayList<ASMProperty>();
Iterator<Entry<Key, Object>> it = sct.entryIterator();
Entry<Key, Object> e;
while (it.hasNext()) {
e = it.next();
props.add(new ASMPropertyImpl(ASMUtil.toType(e.getValue() == null ? Object.class : Object.class, /*e.getValue().getClass()*/
true), e.getKey().getString()));
}
// create file
byte[] barr = ASMUtil.createPojo(real, props.toArray(new ASMProperty[props.size()]), Object.class, new Class[] { Pojo.class }, null);
// create class file from bytecode
ResourceUtil.touch(classFile);
IOUtil.copy(new ByteArrayInputStream(barr), classFile, true);
cl = (PhysicalClassLoader) ((PageContextImpl) pc).getRPCClassLoader(true);
return cl.loadClass(className);
}
Aggregations