org.granite.eclipselink.EclipseLinkClassGetter Maven / Gradle / Ivy
/*
GRANITE DATA SERVICES
Copyright (C) 2011 GRANITE DATA SERVICES S.A.S.
This file is part of Granite Data Services.
Granite Data Services is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
Granite Data Services is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
for more details.
You should have received a copy of the GNU Library General Public License
along with this library; if not, see .
*/
package org.granite.eclipselink;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Entity;
import org.granite.logging.Logger;
import org.granite.messaging.amf.io.util.DefaultClassGetter;
import org.granite.eclipselink.EclipseLinkClassGetter;
import org.granite.eclipselink.EclipseLinkProxy;
import org.granite.util.ClassUtil;
import org.eclipse.persistence.indirection.IndirectContainer;
import org.eclipse.persistence.indirection.ValueHolderInterface;
/**
* @author William DRAI
*/
public class EclipseLinkClassGetter extends DefaultClassGetter {
private final static Logger log = Logger.getLogger(EclipseLinkClassGetter.class);
@Override
public Class> getClass(Object o) {
if (o instanceof ValueHolderInterface) {
ValueHolderInterface holder = (ValueHolderInterface)o;
String className = (
holder.isInstantiated() ?
holder.getValue().getClass().getName() :
Object.class.getName()
);
if (className != null && className.length() > 0) {
try {
return ClassUtil.forName(className);
} catch (Exception e) {
log.warn(e, "Could not get class with initializer: %s for: %s", className, className);
}
}
// fallback...
return Object.class;
}
else if (o instanceof EclipseLinkProxy) {
return ((EclipseLinkProxy)o).getProxiedClass();
}
return super.getClass(o);
}
@Override
public boolean isEntity(Object o) {
return o.getClass().isAnnotationPresent(Entity.class);
}
@Override
public boolean isInitialized(Object owner, String propertyName, Object propertyValue) {
if (propertyValue instanceof ValueHolderInterface)
return ((ValueHolderInterface)propertyValue).isInstantiated();
else if (propertyValue instanceof IndirectContainer)
return ((IndirectContainer)propertyValue).isInstantiated();
return true;
}
@Override
public void initialize(Object owner, String propertyName, Object propertyValue) {
if (propertyValue instanceof ValueHolderInterface)
((ValueHolderInterface)propertyValue).getValue().toString();
else if (propertyValue instanceof IndirectContainer)
((IndirectContainer)propertyValue).getValueHolder().getValue().toString();
}
@Override
public List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy