📄 objectpropertys.java
字号:
package com.eshaper.appbuilder.objectbase.property;
import java.util.*;
import com.eshaper.appbuilder.util.StringList;
public class ObjectPropertys
{
public ObjectPropertys()
{
}
public String getObjectName()
{
return objectName;
}
public void setObjectName(String value)
{
if(value!=null)objectName=value.trim();
}
public int getCount()
{
return propertys.length;
}
public int getIndex(String name)
{
if (getCount()==0) return -1;
for(int i=0;i<getCount();i++)
{
if(propertys[i].getName().equalsIgnoreCase(name)) return i;
}
return -1;
}
public ObjectProperty getProperty(int index)
{
if (index<0 || index>=getCount()) return null;
return propertys[index];
}
public ObjectProperty getProperty(String name)
{
int index=getIndex(name);
return getProperty(index);
}
//从文件装载
public void loadFromFile(String file) throws Exception
{
String sourceType=null;
String sourceName=null;
String str=null;
StringList list=new StringList();
String name=null;
String type=null;
int length=0;
String refer=null;
String referProperty=null;
list.load(file);
if(list.getSize()==0) return;
sourceType=list.value(tagSourceType).trim();
sourceName=list.value(tagSourceName).trim();
if(!sourceType.equalsIgnoreCase(keyType)) return;
for(int i=0;i<list.getSize();i++)
{
str=list.name(i);
if(str.toLowerCase().startsWith(tagProperty))
{
name=str.substring(tagProperty.length(),str.length());
str=list.value(i).trim();
if(str.length()==0) continue;
StringTokenizer st =new StringTokenizer(str);
if(!st.hasMoreTokens()) continue;
type=st.nextToken();
if(!st.hasMoreTokens()) continue;
try
{
length=Integer.parseInt(st.nextToken());
}
catch (Exception e) { continue;}
while (st.hasMoreTokens())
{
str=st.nextToken();
if(str.startsWith(tagRef))
{
str=str.substring(tagRef.length(),str.length()).trim();
String[] ary = str.split(tagRefSplit);
if(ary.length!=2) break;
refer=ary[0];
referProperty=ary[1];
}
}
addProperty(name,type,length,refer,referProperty);
}
}
}
//增加数据
public void addProperty(String name,
String type,
int length,
String refer,
String referProperty)
{
if (getIndex(name)==-1)
{
ObjectProperty property=new ObjectProperty();
property.setName(name);
property.setLength(length);
property.setType(type);
property.setRefer(refer);
property.setReferProperty(referProperty);
addStdProperty(property);
}
}
public void addProperty(ObjectProperty property)
{
if (getIndex(property.getName())==-1) addStdProperty(property);
}
protected void addStdProperty(ObjectProperty property)
{
int len = propertys.length ;
ObjectProperty[] newpropertys = new ObjectProperty[len + 1];
System.arraycopy(propertys, 0, newpropertys, 0, len);
newpropertys[len] = property;
propertys = newpropertys;
}
private static String keyType="table";
private static String tagSourceType="type";
private static String tagSourceName="source";
private static String tagProperty="property.";
private static String tagRef="->";
private static String tagRefSplit="[.]";
private ObjectProperty[] propertys = new ObjectProperty[0];
private String objectName = "";
public static void main(String args[]) throws Exception
{
System.out.println("Test");
ObjectPropertys propertys = new ObjectPropertys();
propertys.loadFromFile("D:\\work\\test\\file\\Users.tdf");
System.out.println(propertys.getCount());
System.out.println(propertys.getProperty("orgid").getRefer());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -