⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tcubaseclassstr.java

📁 为公司做的质量考核接口源码,用spring,hibernate,XML实现,对XML接口编程很有帮助
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;		
	}

	public boolean Assign(TcuBaseClassSTR value) {
		// TODO 自动生成方法存根
		try{
			//StrItems.Clear();
			//TcuBaseClassSTR obj= (TcuBaseClassSTR)value;
			//value.CreateStrItems();
			//StrItems.Assign(value.getStrItems());
			//ParseStrItems();
			LoadFromByteArray(value.SaveToByteArray());
			return true;
		}catch(Exception e){
			return false;				
		}
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自动生成方法存根
		

	}

	public boolean CreateStrItems() throws Exception{
		// TODO 自动生成方法存根
		return false;
	}

	public boolean ParseStrItems() throws Exception {
		// TODO 自动生成方法存根
		return false;
	}

	/**
	 * @return 返回 strItems。
	 */
	public TcuBaseItemsSTR getStrItems() throws Exception{
		//System.out.println(getPkgName()); 
		//CreateStrItems();		
		return StrItems;
	}

	public TcuBaseItemsSTR getEmptyStrItems() {
		//System.out.println(getPkgName()); 
		StrItems.Clear();	
		return StrItems;
	}
	/**
	 * @param strItems 要设置的 strItems。
	 */
	protected void setStrItems(TcuBaseItemsSTR strItems) {
		StrItems = strItems;	
	}

	/**
	 * @return 返回 packName。
	 */
	protected String getPkgName() {
		return PkgName;
	}

	/**
	 * @param packName 要设置的 packName。
	 */
	protected void setPkgName(String packName) {
		PkgName = packName;
	}

	public boolean LoadFromByteArray(byte[] value)  {
		// TODO 自动生成方法存根
		if (value==null){
			System.out.println("BaseClassSTR LoadFromByteArray error,Null bytearray");
			return false;
		}
		try {
			StrItems.Clear();
			//System.out.println("PackName:"+PkgName);
			if (!StrItems.fromByteArray(value)) return false;
			if (!ParseStrItems()) return false;
			return true;
		} catch (IOException e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
		} catch (Exception e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
		}
		return false;
	}

	public byte[] SaveToByteArray()  {
		// TODO 自动生成方法存根
		try {
			//System.out.println("PackName:"+PkgName);
			StrItems.Clear();
			if (!CreateStrItems()) return null;
			byte[] value=StrItems.toByteArray();
			return value;
		} catch (IOException e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
		} catch (Exception e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * @param debugMode the debugMode to set
	 */
	public void setDebugMode(boolean debugMode) {
		DebugMode = debugMode;
	}

	public String GetCustItems() {
		// TODO Auto-generated method stub
		return "";
	}

	public boolean LoadFromXMLWithHead(InputStream in) {
		// TODO Auto-generated method stub
		try{
			SAXBuilder sb = new SAXBuilder();
			Document doc = sb.build(in);
			Element root = doc.getRootElement(); //得到根元素	
			System.out.println(root.getName());
			return LoadFromXML(root);			
		}catch(Exception e){
			System.err.println(e+"error");		
		}
		return false;
	}
	
	public boolean LoadFromXMLWithHead(String xml) {
		ByteArrayInputStream bi=new ByteArrayInputStream(xml.getBytes());
		return LoadFromXMLWithHead(bi);
	}
	
	public boolean LoadFromXMLWithoutHead(String Xml) {
		String xml="<?xml version='1.0' encoding='gb2312'?>"; // XML的头部信息
		xml+="<GZJRDP Version='1.0'>";
		xml+=Xml;
		xml+="</GZJRDP>";
		ByteArrayInputStream bi=new ByteArrayInputStream(xml.getBytes());
		return LoadFromXMLWithHead(bi);
	}		
	
	public boolean LoadFromXML(Element root) {
		Element xml=root.getChild(getPkgName());
		System.out.println(xml.getName());
		return ParseXMLItems(xml);
	}
	
	public boolean ParseXMLItems(Element xml){
		String name=null;
		String value="";
		Element item=null;
		Class fieldTypeClass=null;
		try{
			Field[] fields= this.getClass().getDeclaredFields();
			Method[] methods=this.getClass().getDeclaredMethods();
			Object[] args=new Object[1];
			for (int i=0;i<fields.length;i++){
				Field field=fields[i];
				name=field.getName();
				//print.println(name);
				fieldTypeClass=field.getType();
				//print.println(fieldTypeClass.toString());
				value=xml.getChildText(name);
				//print.println(value+" "+name);
				item=xml.getChild(name);
				//print.println(item+" "+name);
				if (value!=null){
		            if (fieldTypeClass==String.class){                		
		            	Method method=CheckMethod(methods,"set"+name);
		            	if (method!=null){
		            		args[0]=value;
		            		InvokeStaticMethod(this,method.getName(),args);
		            	}
		            }
		            else if (fieldTypeClass==Integer.class){
		            	Method method=CheckMethod(methods,"set"+name);
		            	if (method!=null){
		            		args[0]=Integer.valueOf(value);
		            		InvokeStaticMethod(this,method.getName(),args);
		            	}
			        }
		            else if (fieldTypeClass==long.class){
		            	Method method=CheckMethod(methods,"set"+name);
		            	if (method!=null){
		            		args[0]=Long.valueOf(value);
		            		InvokeStaticMethod(this,method.getName(),args);
		            	}           
		            }
		            else if (fieldTypeClass==short.class){
		             	Method method=CheckMethod(methods,"set"+name);
		            	if (method!=null){
		            		args[0]=Short.valueOf(value);
		            		InvokeStaticMethod(this,method.getName(),args);	
		            	}
		            }
		            else if (fieldTypeClass==float.class){
		              	Method method=CheckMethod(methods,"set"+name);
		            	if (method!=null){
		            		args[0]=Float.valueOf(value);
		            		InvokeStaticMethod(this,method.getName(),args);
		            	}  
		            }
		            else if (fieldTypeClass==double.class){
		            	Method method=CheckMethod(methods,"set"+name);
		            	if (method!=null){
		            		args[0]=Double.valueOf(value);
		            		InvokeStaticMethod(this,method.getName(),args);
		            	}  
		            }
		            else if (fieldTypeClass==byte.class){
		            Method method=CheckMethod(methods,"set"+name);
		            	if (method!=null){
		            		args[0]=Byte.valueOf(value);
		            		InvokeStaticMethod(this,method.getName(),args);
		            	}  
		            }
		            else if (fieldTypeClass==char.class){

		            	Method method=CheckMethod(methods,"set"+name);
		            	if (method!=null){
		            		args[0]=(value);
		            		InvokeStaticMethod(this,method.getName(),args);
		            	}  
		            }
		            else if (fieldTypeClass==boolean.class){
		            	Method method=CheckMethod(methods,"set"+name);
		            	if (method!=null){
		            		args[0]=Boolean.valueOf(value);
		            		InvokeStaticMethod(this,method.getName(),args);
		            	}  
		            }
		            else if (fieldTypeClass==byte[].class){
		            	Method method=CheckMethod(methods,"set"+name);
		            	if (method!=null){
		            		value=JrUtility.getFromBASE64(value);
		            		args[0]=value.getBytes();
		            		InvokeStaticMethod(this,method.getName(),args);
		            	}
		            }	
		            else if (fieldTypeClass==Date.class){
		            	Method method=CheckMethod(methods,"set"+name);
		            	if (method!=null){
		            		args[0]=new Date(java.sql.Date.valueOf(value).getTime());
		            		InvokeStaticMethod(this,method.getName(),args);
		            	}
		            }	 
		            else {
		            	Method method=CheckMethod(methods,"get"+name);
		            	if (method!=null){
		            		Object[] args2=new Object[0];
		            		Object obj=InvokeStaticMethod(this,method.getName(),args2);
		            		if (TcuBaseClassSTR.class.isInstance(obj)){
		            			((TcuBaseClassSTR)obj).ParseXMLItems(item);
		            		}
		            	}	            
		            }
	            }
	            //print.println(value);		           
			}
			return ParseCustItems(xml);
		}
        catch(Exception ex){
                ex.printStackTrace();
        }
        return false;
	}

	public boolean ParseCustItems(Element xml) {
		// TODO Auto-generated method stub
		return true;
	}
	


}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -