use of lucee.commons.lang.PhysicalClassLoader in project Lucee by lucee.
the class AxisCaster method _toPojo.
private static Pojo _toPojo(PageContext pc, Pojo pojo, TypeMapping tm, TypeEntry typeEntry, QName type, Struct sct, Set<Object> done) throws PageException {
// print.ds();System.exit(0);
if (pojo == null) {
try {
PhysicalClassLoader cl = (PhysicalClassLoader) pc.getConfig().getRPCClassLoader(false);
pojo = (Pojo) ClassUtil.loadInstance(ComponentUtil.getStructPropertiesClass(pc, sct, cl));
} catch (ClassException e) {
throw Caster.toPageException(e);
} catch (IOException e) {
throw Caster.toPageException(e);
}
}
// initialize
List<Property> props = new ArrayList<Property>();
Iterator<Entry<Key, Object>> it = sct.entryIterator();
Entry<Key, Object> e;
PropertyImpl p;
while (it.hasNext()) {
e = it.next();
p = new PropertyImpl();
p.setAccess(Component.ACCESS_PUBLIC);
p.setName(e.getKey().getString());
p.setType(e.getValue() == null ? "any" : Caster.toTypeName(e.getValue()));
props.add(p);
}
_initPojo(pc, typeEntry, type, pojo, props.toArray(new Property[props.size()]), sct, null, tm, done);
return pojo;
}
use of lucee.commons.lang.PhysicalClassLoader in project Lucee by lucee.
the class PageContextImpl method getRPCClassLoader.
public ClassLoader getRPCClassLoader(boolean reload, ClassLoader[] parents) throws IOException {
JavaSettingsImpl js = (JavaSettingsImpl) applicationContext.getJavaSettings();
ClassLoader cl = config.getRPCClassLoader(reload, parents);
if (js != null) {
return ((PhysicalClassLoader) cl).getCustomClassLoader(js.getResourcesTranslated(), reload);
}
return cl;
}
use of lucee.commons.lang.PhysicalClassLoader in project Lucee by lucee.
the class ConfigImpl method getRPCClassLoader.
@Override
public ClassLoader getRPCClassLoader(boolean reload) throws IOException {
if (rpcClassLoader != null && !reload)
return rpcClassLoader;
Resource dir = getClassDirectory().getRealResource("RPC");
if (!dir.exists())
dir.createDirectory(true);
rpcClassLoader = new PhysicalClassLoader(this, dir, null, false);
return rpcClassLoader;
}
use of lucee.commons.lang.PhysicalClassLoader in project Lucee by lucee.
the class ComponentUtil method _getComponentPropertiesClass.
private static Class _getComponentPropertiesClass(PageContext pc, Config secondChanceConfig, String className, ASMProperty[] properties, Class extendsClass) throws PageException, IOException, ClassNotFoundException {
String real = className.replace('.', '/');
PhysicalClassLoader cl;
if (pc == null)
cl = (PhysicalClassLoader) secondChanceConfig.getRPCClassLoader(false);
else
cl = (PhysicalClassLoader) ((PageContextImpl) pc).getRPCClassLoader(false);
Resource rootDir = cl.getDirectory();
Resource classFile = rootDir.getRealResource(real.concat(".class"));
if (classFile.exists()) {
try {
Class clazz = cl.loadClass(className);
Field field = clazz.getField("_md5_");
if (ASMUtil.createMD5(properties).equals(field.get(null))) {
// if(equalInterface(properties,clazz)) {
return clazz;
}
} catch (Exception e) {
}
}
// create file
if (extendsClass == null)
extendsClass = Object.class;
byte[] barr = ASMUtil.createPojo(real, properties, extendsClass, new Class[] { Pojo.class }, null);
boolean exist = classFile.exists();
ResourceUtil.touch(classFile);
IOUtil.copy(new ByteArrayInputStream(barr), classFile, true);
if (pc == null)
cl = (PhysicalClassLoader) secondChanceConfig.getRPCClassLoader(exist);
else
cl = (PhysicalClassLoader) ((PageContextImpl) pc).getRPCClassLoader(exist);
return cl.loadClass(className);
}
use of lucee.commons.lang.PhysicalClassLoader 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);
}
Aggregations