Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions group21/28394073/homework/bin/com/coderising/litestruts/struts.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<struts>
<action name="login" class="com.coderising.litestruts.LoginAction">
<result name="success">/jsp/homepage.jsp</result>
<result name="fail">/jsp/showLogin.jsp</result>
</action>
<action name="logout" class="com.coderising.action.LogoutAction">
<result name="success">/jsp/welcome.jsp</result>
<result name="error">/jsp/error.jsp</result>
</action>
</struts>
24 changes: 24 additions & 0 deletions group21/28394073/homework/src/com/coderising/jvm/Util.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.coderising.jvm.util;

public class Util {
public static int byteToInt(byte[] codes){
String s1 = byteToHexString(codes);
return Integer.valueOf(s1, 16).intValue();
}



public static String byteToHexString(byte[] codes ){
StringBuffer buffer = new StringBuffer();
for(int i=0;i<codes.length;i++){
byte b = codes[i];
int value = b & 0xFF;
String strHex = Integer.toHexString(value);
if(strHex.length()< 2){
strHex = "0" + strHex;
}
buffer.append(strHex);
}
return buffer.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.coderising.jvm.clz;

public class AccessFlag {
private int flagValue;

public AccessFlag(int value) {
this.flagValue = value;
}

public int getFlagValue() {
return flagValue;
}

public void setFlagValue(int flag) {
this.flagValue = flag;
}

public boolean isPublicClass(){
return (this.flagValue & 0x0001) != 0;
}
public boolean isFinalClass(){
return (this.flagValue & 0x0010) != 0;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.coderising.jvm.clz;

import com.coderising.jvm.constant.ClassInfo;
import com.coderising.jvm.constant.ConstantPool;

public class ClassFile {

private int minorVersion;
private int majorVersion;

private AccessFlag accessFlag;
private ClassIndex clzIndex;
private ConstantPool pool;


public ClassIndex getClzIndex() {
return clzIndex;
}
public AccessFlag getAccessFlag() {
return accessFlag;
}
public void setAccessFlag(AccessFlag accessFlag) {
this.accessFlag = accessFlag;
}



public ConstantPool getConstantPool() {
return pool;
}
public int getMinorVersion() {
return minorVersion;
}
public void setMinorVersion(int minorVersion) {
this.minorVersion = minorVersion;
}
public int getMajorVersion() {
return majorVersion;
}
public void setMajorVersion(int majorVersion) {
this.majorVersion = majorVersion;
}
public void setConstPool(ConstantPool pool) {
this.pool = pool;

}
public void setClassIndex(ClassIndex clzIndex) {
this.clzIndex = clzIndex;
}




public void print(){

if(this.accessFlag.isPublicClass()){
System.out.println("Access flag : public ");
}
System.out.println("Class Name:"+ getClassName());

System.out.println("Super Class Name:"+ getSuperClassName());


}

private String getClassName(){
int thisClassIndex = this.clzIndex.getThisClassIndex();
ClassInfo thisClass = (ClassInfo)this.getConstantPool().getConstantInfo(thisClassIndex);
return thisClass.getClassName();
}
private String getSuperClassName(){
ClassInfo superClass = (ClassInfo)this.getConstantPool().getConstantInfo(this.clzIndex.getSuperClassIndex());
return superClass.getClassName();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.coderising.jvm.clz;

public class ClassIndex {
private int thisClassIndex;
private int superClassIndex;

public int getThisClassIndex() {
return thisClassIndex;
}
public void setThisClassIndex(int thisClassIndex) {
this.thisClassIndex = thisClassIndex;
}
public int getSuperClassIndex() {
return superClassIndex;
}
public void setSuperClassIndex(int superClassIndex) {
this.superClassIndex = superClassIndex;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.coderising.jvm.constant;

public class ClassInfo extends ConstantInfo {
private int type = ConstantInfo.CLASS_INFO;
private int utf8Index ;
public ClassInfo(ConstantPool pool) {
super(pool); //这里不理解
}
public int getUtf8Index() {
return utf8Index;
}
public void setUtf8Index(int utf8Index) {
this.utf8Index = utf8Index;
}
public int getType() {
return type;
}

public String getClassName() {
int index = getUtf8Index();
UTF8Info utf8Info = (UTF8Info)constantPool.getConstantInfo(index);
return utf8Info.getValue();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.coderising.jvm.constant;

public abstract class ConstantInfo {
public static final int UTF8_INFO = 1;
public static final int FLOAT_INFO = 4;
public static final int CLASS_INFO = 7;
public static final int STRING_INFO = 8;
public static final int FIELD_INFO = 9;
public static final int METHOD_INFO = 10;
public static final int NAME_AND_TYPE_INFO = 12;
protected ConstantPool constantPool;

public ConstantInfo(){

}

public ConstantInfo(ConstantPool pool) {
this.constantPool = pool;
}
public abstract int getType();

public ConstantPool getConstantPool() {
return constantPool;
}
public ConstantInfo getConstantInfo(int index){
return this.constantPool.getConstantInfo(index);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.coderising.jvm.constant;

import java.util.ArrayList;
import java.util.List;

public class ConstantPool {

private List<ConstantInfo> constantInfos = new ArrayList<ConstantInfo>();


public ConstantPool(){

}
public void addConstantInfo(ConstantInfo info){

this.constantInfos.add(info);

}

public ConstantInfo getConstantInfo(int index){
return this.constantInfos.get(index);
}
public String getUTF8String(int index){
return ((UTF8Info)this.constantInfos.get(index)).getValue();
}
public Object getSize() {
return this.constantInfos.size() -1;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.coderising.jvm.constant;

public class FieldRefInfo extends ConstantInfo{
private int type = ConstantInfo.FIELD_INFO;
private int classInfoIndex;
private int nameAndTypeIndex;

public FieldRefInfo(ConstantPool pool) {
super(pool);
}
public int getType() {
return type;
}

public int getClassInfoIndex() {
return classInfoIndex;
}
public void setClassInfoIndex(int classInfoIndex) {
this.classInfoIndex = classInfoIndex;
}
public int getNameAndTypeIndex() {
return nameAndTypeIndex;
}
public void setNameAndTypeIndex(int nameAndTypeIndex) {
this.nameAndTypeIndex = nameAndTypeIndex;
}

public String toString(){

NameAndTypeInfo typeInfo = (NameAndTypeInfo)this.getConstantInfo(this.getNameAndTypeIndex());

return getClassName() +" : "+ typeInfo.getName() + ":" + typeInfo.getTypeInfo() +"]";
}

public String getClassName(){

ClassInfo classInfo = (ClassInfo) this.getConstantInfo(this.getClassInfoIndex());

UTF8Info utf8Info = (UTF8Info)this.getConstantInfo(classInfo.getUtf8Index());

return utf8Info.getValue();

}

public String getFieldName(){
NameAndTypeInfo typeInfo = (NameAndTypeInfo)this.getConstantInfo(this.getNameAndTypeIndex());
return typeInfo.getName();
}

public String getFieldType(){
NameAndTypeInfo typeInfo = (NameAndTypeInfo)this.getConstantInfo(this.getNameAndTypeIndex());
return typeInfo.getTypeInfo();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.coderising.jvm.constant;

public class MethodRefInfo extends ConstantInfo {

private int type = ConstantInfo.METHOD_INFO;

private int classInfoIndex;
private int nameAndTypeIndex;

public MethodRefInfo(ConstantPool pool) {
super(pool);
}

public int getType() {
return type;
}

public int getClassInfoIndex() {
return classInfoIndex;
}
public void setClassInfoIndex(int classInfoIndex) {
this.classInfoIndex = classInfoIndex;
}
public int getNameAndTypeIndex() {
return nameAndTypeIndex;
}
public void setNameAndTypeIndex(int nameAndTypeIndex) {
this.nameAndTypeIndex = nameAndTypeIndex;
}

public String toString(){

return getClassName() +" : "+ this.getMethodName() + " : " + this.getParamAndReturnType() ;
}
public String getClassName(){
ConstantPool pool = this.getConstantPool();
ClassInfo clzInfo = (ClassInfo)pool.getConstantInfo(this.getClassInfoIndex());
return clzInfo.getClassName();
}

public String getMethodName(){
ConstantPool pool = this.getConstantPool();
NameAndTypeInfo typeInfo = (NameAndTypeInfo)pool.getConstantInfo(this.getNameAndTypeIndex());
return typeInfo.getName();
}

public String getParamAndReturnType(){
ConstantPool pool = this.getConstantPool();
NameAndTypeInfo typeInfo = (NameAndTypeInfo)pool.getConstantInfo(this.getNameAndTypeIndex());
return typeInfo.getTypeInfo();
}



}
Loading