package net.bat.service;
/**
* @author chen4w
*/
import java.beans.BeanInfo;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;
import java.text.SimpleDateFormat;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.Vector;
import java.util.Map.Entry;
import javax.servlet.http.HttpServletRequest;
import net.bat.prototype.AdviceInfo;
import net.bat.prototype.Item;
import net.bat.prototype.Obj;
import net.bat.prototype.Req;
import org.hibernate.EntityMode;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.metadata.ClassMetadata;
import org.hibernate.metadata.CollectionMetadata;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.type.SetType;
import org.springframework.beans.BeanWrapper;
import org.springframework.beans.BeanWrapperImpl;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.web.context.support.WebApplicationContextUtils;
import uk.ltd.getahead.dwr.WebContext;
import uk.ltd.getahead.dwr.WebContextFactory;
public class BService extends HibernateDaoSupport implements IBService {
static private final SimpleDateFormat fmt = new SimpleDateFormat(
"yyyy��MM��dd�� HH:mm:ss");
/**
*
* @return ��ǰSession
* @throws HibernateException
*/
private Session currentSession() throws HibernateException {
return this.getSession();
}
/**
* ���ض���IJ����������л����
*
* @param so
* ���������
* @param r
* ����j���������
* @param rp
* �ӱ��j����������б�
* @param cm
* �ӱ��Ӧ���Ԫ���
* @return �����������л��Ķ���
* @throws Exception
*/
private void setItemValue(Item it, Object v) {
if (v == null) {
it.setValue(null);
} else {
Class ct = v.getClass();
String cn = ct.getName();
if (ct.isPrimitive())
it.setValue(v.toString());
else if (cn.startsWith("java")) {
if (cn.equals("java.util.Date")
|| cn.equals("java.sql.Timestamp"))
it.setValue(fmt.format(v));
else
it.setValue(v.toString());
} else {
int pos = cn.indexOf("$");
if (pos != -1)
cn = cn.substring(0, pos);
ClassMetadata ck = getSessionFactory().getClassMetadata(cn);
// �Ƿ�composite-id
if (ck != null) {
String kn = ck.getIdentifierPropertyName();
// �Ƿ������
if (kn != null) {
BeanWrapper beanWrapper = new BeanWrapperImpl(v);
it
.setValue(beanWrapper.getPropertyValue(kn)
.toString());
} else
it.setValue(v.toString());
} else {
// ��ʱ��5�ֹ����봦��composite-id,bat������
}
}
}
}
public Obj objToItems(Object so, Req r, Map rp, ClassMetadata cm)
throws Exception {
Obj ro = new Obj();
ro.setAction(Obj.ACTION_UPDATE);
ro.setCn(cm.getEntityName());
Map<String, Item> fm = new TreeMap<String, Item>();
ro.setItems(fm);
ro.setKey(cm.getIdentifierPropertyName());
String[] ps = null;
String objcn = so.getClass().getName();
if (r != null && r.getProperties() != null)
ps = r.getProperties();
else {
ps = props(objcn);
}
// ����Ŀ�����hibernate��ǿobj
if (objcn.equals("java.util.HashMap")) {
Map mo = (Map) so;
for (int i = 0; i < ps.length; i++) {
Item it = new Item();
setItemValue(it, mo.get(ps[i]));
fm.put(ps[i], it);
}
return ro;
}
BeanWrapper wp = new BeanWrapperImpl(so);
int poscn = objcn.indexOf("$");
if (poscn != -1) {
objcn = objcn.substring(0, poscn);
}
for (int i = 0; i < ps.length; i++) {
Item it = new Item();
Class ct = wp.getPropertyType(ps[i]);
// �ӱ�����
if (ct.getName().equals("java.util.Set")) {
SetType tp = (SetType) cm.getPropertyType(ps[i]);
CollectionMetadata ccm = getSessionFactory()
.getCollectionMetadata(tp.getRole());
String scn = ccm.getElementType().getName();
Class scls = Class.forName(scn);
ClassMetadata scm = getSessionFactory().getClassMetadata(scls);
Obj[] subros;
// �ӱ����
Req sr = null;
if (rp != null)
sr = (Req) rp.get(ps[i]);
if (sr != null) {
subros = this.get(sr, rp);
} else {
Set v = (Set) wp.getPropertyValue(ps[i]);
Obj SObj = objToItems(scls.newInstance(), sr, rp, scm);
SObj.setAction(Obj.ACTION_DEFAULT);
int len = (v == null || v.isEmpty()) ? 1 : v.size() + 1;
subros = new Obj[len];
subros[0] = SObj;
if (len > 1) {
Object[] vos = v.toArray();
for (int pos = 0; pos < vos.length; pos++) {
subros[pos + 1] = objToItems(vos[pos], sr, null,
scm);
}
}
}
it.setSobjs(subros);
}
// ���ӱ�����
else {
Object v = wp.getPropertyValue(ps[i]);
setItemValue(it, v);
}
fm.put(ps[i], it);
}
// String keyprop = ((AbstractEntityPersister
// )cm).getIdentifierPropertyName();
// ro.setKey(keyprop);
return ro;
}
/**
* ��ݲ��������ֶθ��µ�����
*
* @param po
* ����¶���
* @param vo
* ��������
* @param s
* ��ǰsession
* @throws Exception
*/
public void itemsToObj(Object po, Obj vo, Session s) throws Exception {
Map flds = vo.getItems();
if (flds == null || flds.size() == 0)
return;
String key = null;
if (vo.getKey() != null)
key = vo.getKey();
org.hibernate.proxy.map.MapProxy mo = null;
if (po.getClass().getName().equals("org.hibernate.proxy.MapProxy"))
mo = (org.hibernate.proxy.map.MapProxy) po;
BeanWrapper wp = new BeanWrapperImpl(po);
HashMap<String, Item> fldmap = new HashMap<String, Item>();
HashMap<String, Set<?>> listmap = new HashMap<String, Set<?>>();
Iterator it = flds.entrySet().iterator();
while (it.hasNext()) {
Entry entry = (Entry) it.next();
String name = (String) entry.getKey();
Object oldval;
Item fldval = (Item) entry.getValue();
if (mo != null) {
oldval = mo.get(name);
if (!name.equals(key))
mo.put(name, fldval.getValue());
continue;
} else
oldval = wp.getPropertyValue(name);
// ���ֵ���ɸı� ���assign�������add
if (key != null) {
if (name.equals(key)) {
if (oldval != null)
continue;
}
}
Class paramType = wp.getPropertyType(name);
String cname = paramType.getName();
// ���ӱ�����
if (fldval.getSobjs() == null) {
String val = fldval.getValue();
if (!paramType.isPrimitive() && !cname.startsWith("java")) {
ClassMetadata ck = getSessionFactory().getClassMetadata(
cname);
// �����
if (ck != null && oldval == null)
wp.setPropertyValue(name, val);
else { // composite-id
if (oldval == null)
oldval = paramType.newInstance();
BeanWrapper cnWrap = new BeanWrapperImpl(oldval);
Iterator es = flds.entrySet().iterator();
while (es.hasNext()) {
Entry en = (Entry) es.next();
String propName = (String) en.getKey();
if (propName.startsWith(name + ".")) {
int pos = propName.indexOf(".");
String cnProp = propName.substring(po
没有合适的资源?快使用搜索试试~ 我知道了~
e x t文件管理系统
共999个文件
gif:417个
js:388个
class:65个
5星 · 超过95%的资源 需积分: 7 174 下载量 104 浏览量
2008-05-13
12:15:40
上传
评论
收藏 9.27MB RAR 举报
温馨提示
ext文件管理系统,可以重命名,上传,删除.
资源详情
资源评论
资源推荐
收起资源包目录
e x t文件管理系统 (999个子文件)
BService.class 17KB
BService.class 13KB
uploadServlet.class 11KB
uploadServlet.class 10KB
FileWrapper.class 7KB
FileWrapper.class 7KB
FeedServlet.class 5KB
test_jsp.class 4KB
FeedWriter.class 4KB
TaskCenter.class 4KB
TaskCenter.class 4KB
SummeryUtil.class 4KB
UrlParser.class 4KB
chanelAct.class 3KB
RpArticle.class 3KB
DirList.class 3KB
DirList.class 3KB
Req.class 3KB
Req.class 3KB
batreq.class 3KB
batreq.class 3KB
jspToHtml.class 3KB
ChanelUtil.class 3KB
Global.class 2KB
Global.class 2KB
WrapperResponse.class 2KB
UploadListener.class 2KB
UploadListener.class 2KB
BSJDBC.class 2KB
BSJDBC.class 2KB
BSJDBC$1.class 2KB
Obj.class 1KB
Obj.class 1KB
BSJDBC$1.class 1KB
MonitoredDiskFileItemFactory.class 1KB
MonitoredDiskFileItemFactory.class 1KB
MonitoredOutputStream.class 1KB
MonitoredOutputStream.class 1KB
MonitoredDiskFileItem.class 1KB
InitServlet.class 1KB
InitServlet.class 1KB
MonitoredDiskFileItem.class 1KB
AdviceInfo.class 1KB
AdviceInfo.class 1KB
RpRelArticle.class 1KB
Task.class 1KB
Task.class 1KB
BService$HotItemComparator.class 1KB
BService$HotItemComparator.class 1KB
Item.class 834B
Item.class 834B
WrapperResponse$ByteArrayServletOutputStream.class 787B
DirList$1.class 670B
DirList$1.class 645B
IBService.class 566B
IBService.class 566B
IURLAction.class 383B
OutputStreamListener.class 288B
OutputStreamListener.class 288B
IBAdvice.class 227B
IBAdvice.class 227B
IBatService.class 119B
IBatService.class 119B
IBatAdvice.class 117B
IBatAdvice.class 117B
.classpath 2KB
org.eclipse.wst.common.component 425B
ext-all.css 67KB
xtheme-aero.css 15KB
xtheme-vista.css 14KB
xtheme-gray.css 12KB
form.css 8KB
grid.css 7KB
basic-dialog.css 6KB
layout.css 6KB
date-picker.css 5KB
core.css 5KB
tree.css 5KB
toolbar.css 5KB
resizable.css 4KB
button.css 3KB
tabs.css 3KB
qtips.css 3KB
box.css 3KB
menu.css 2KB
editor.css 2KB
dd.css 1KB
debug.css 1KB
combo.css 1KB
viewdef.css 939B
reset-min.css 480B
rp.css 98B
Thumbs.db 95KB
Thumbs.db 33KB
Thumbs.db 18KB
Thumbs.db 17KB
Thumbs.db 6KB
sql.ddl 3KB
sql.ddl 3KB
dlg-bg.gif 27KB
共 999 条
- 1
- 2
- 3
- 4
- 5
- 6
- 10
guangting001
- 粉丝: 0
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论3