Mercurial Hosting > luan
changeset 50:272b6f1d7dac
fix java accessibility
git-svn-id: https://luan-java.googlecode.com/svn/trunk@51 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Fri, 28 Dec 2012 19:48:43 +0000 |
parents | 8ede219cd111 |
children | 28dfd91a816c |
files | src/luan/lib/JavaLib.java src/luan/tools/WebShell.java |
diffstat | 2 files changed, 24 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
diff -r 8ede219cd111 -r 272b6f1d7dac src/luan/lib/JavaLib.java --- a/src/luan/lib/JavaLib.java Fri Dec 28 19:35:04 2012 +0000 +++ b/src/luan/lib/JavaLib.java Fri Dec 28 19:48:43 2012 +0000 @@ -1,6 +1,7 @@ package luan.lib; import java.lang.reflect.Array; +import java.lang.reflect.AccessibleObject; import java.lang.reflect.Member; import java.lang.reflect.Field; import java.lang.reflect.Method; @@ -79,7 +80,7 @@ } } } else { - List<Member> members = getStaticMembers(cls,name); + List<AccessibleObject> members = getStaticMembers(cls,name); if( !members.isEmpty() ) { return member(null,members); } @@ -103,7 +104,7 @@ if( "instanceof".equals(name) ) { return new LuanJavaFunction(instanceOf,new InstanceOf(obj)); } else { - List<Member> members = getMembers(cls,name); + List<AccessibleObject> members = getMembers(cls,name); if( !members.isEmpty() ) { return member(obj,members); } @@ -112,10 +113,13 @@ throw new LuanException(luan,LuanElement.JAVA,"invalid index for java object: "+key); } - private static Object member(Object obj,List<Member> members) throws LuanException { + private static Object member(Object obj,List<AccessibleObject> members) throws LuanException { try { + for( AccessibleObject m : members ) { + m.setAccessible(true); + } if( members.size()==1 ) { - Member member = members.get(0); + AccessibleObject member = members.get(0); if( member instanceof Field ) { Field field = (Field)member; return field.get(obj); @@ -125,7 +129,7 @@ } } else { List<LuanJavaFunction> fns = new ArrayList<LuanJavaFunction>(); - for( Member member : members ) { + for( AccessibleObject member : members ) { Method method = (Method)member; fns.add(new LuanJavaFunction(method,obj)); } @@ -136,26 +140,26 @@ } } - private static Map<Class,Map<String,List<Member>>> memberMap = new HashMap<Class,Map<String,List<Member>>>(); + private static Map<Class,Map<String,List<AccessibleObject>>> memberMap = new HashMap<Class,Map<String,List<AccessibleObject>>>(); - private static synchronized List<Member> getMembers(Class cls,String name) { - Map<String,List<Member>> clsMap = memberMap.get(cls); + private static synchronized List<AccessibleObject> getMembers(Class cls,String name) { + Map<String,List<AccessibleObject>> clsMap = memberMap.get(cls); if( clsMap == null ) { - clsMap = new HashMap<String,List<Member>>(); + clsMap = new HashMap<String,List<AccessibleObject>>(); for( Field field : cls.getFields() ) { String s = field.getName(); - List<Member> list = clsMap.get(s); + List<AccessibleObject> list = clsMap.get(s); if( list == null ) { - list = new ArrayList<Member>(); + list = new ArrayList<AccessibleObject>(); clsMap.put(s,list); } list.add(field); } for( Method method : cls.getMethods() ) { String s = method.getName(); - List<Member> list = clsMap.get(s); + List<AccessibleObject> list = clsMap.get(s); if( list == null ) { - list = new ArrayList<Member>(); + list = new ArrayList<AccessibleObject>(); clsMap.put(s,list); } list.add(method); @@ -165,10 +169,10 @@ return clsMap.get(name); } - private static synchronized List<Member> getStaticMembers(Class cls,String name) { - List<Member> staticMembers = new ArrayList<Member>(); - for( Member m : getMembers(cls,name) ) { - if( Modifier.isStatic(m.getModifiers()) ) + private static synchronized List<AccessibleObject> getStaticMembers(Class cls,String name) { + List<AccessibleObject> staticMembers = new ArrayList<AccessibleObject>(); + for( AccessibleObject m : getMembers(cls,name) ) { + if( Modifier.isStatic(((Member)m).getModifiers()) ) staticMembers.add(m); } return staticMembers;
diff -r 8ede219cd111 -r 272b6f1d7dac src/luan/tools/WebShell.java --- a/src/luan/tools/WebShell.java Fri Dec 28 19:35:04 2012 +0000 +++ b/src/luan/tools/WebShell.java Fri Dec 28 19:48:43 2012 +0000 @@ -48,10 +48,10 @@ PrintWriter out = response.getWriter(); HttpSession session = request.getSession(); - ByteArrayOutputStream history = (ByteArrayOutputStream)session.getValue("history"); + ByteArrayOutputStream history = (ByteArrayOutputStream)session.getValue("luan_history"); if( history==null ) { history = new ByteArrayOutputStream(); - session.putValue("history",history); + session.putValue("luan_history",history); } if( request.getParameter("clear") != null ) { @@ -82,6 +82,7 @@ } catch(LuanException e) { logger.info("",e); writer.write( HtmlLib.encode(e.toString()) ); + writer.write("\r\n"); } writer.flush(); }