📄 typestubgenerator.java
字号:
package com.objectlearn.gmf.templates.entity;
import java.util.*;
import com.objectlearn.lomboz.xml.lomboz.DocumentRoot;
import com.objectlearn.lomboz.xml.lomboz.EntityBean;
import com.objectlearn.lomboz.xml.lomboz.FieldMapping;
import com.sun.java.xml.ns.j2ee.EntityBeanType;
import com.sun.java.xml.ns.j2ee.FullyQualifiedClassType;
public class TypeStubGenerator
{
protected final String NL = System.getProperties().getProperty("line.separator");
protected final String TEXT_1 = "public abstract class ";
protected final String TEXT_2 = " implements javax.ejb.EntityBean {" + NL + " ";
protected final String TEXT_3 = NL + " /**" + NL + " * Generated Primary Key Class" + NL + " * @generated" + NL + " */" + NL + " public class PrimaryKey {";
protected final String TEXT_4 = NL + "\t\t /**" + NL + "\t\t * @generated" + NL + "\t\t */\t " + NL + "\t public ";
protected final String TEXT_5 = " ";
protected final String TEXT_6 = " ;";
protected final String TEXT_7 = NL + "\t}";
protected final String TEXT_8 = NL + NL + "}";
protected final String TEXT_9 = NL;
public String generate(Object argument)
{
StringBuffer stringBuffer = new StringBuffer();
DocumentRoot root = (DocumentRoot)argument;
EntityBean leb = (EntityBean) root.getEjb().getEntity();
EntityBeanType eb = leb.getEntityEjb();
boolean isCMP = "Container".equals(eb.getPersistenceType().getValue());
String primaryKeyType = "java.lang.String";
int pkCount=0;
boolean isComposite = false;
boolean createCompositeKey = false;
if( isCMP ) {
FullyQualifiedClassType pkClassType = eb.getPrimKeyClass();
if(pkClassType != null && pkClassType.getValue() != null && pkClassType.getValue().length() > 0 )
primaryKeyType = pkClassType.getValue();
Iterator fieldMappings = leb.getFieldMappings().iterator();
String pkType = "";
while(fieldMappings.hasNext()){
FieldMapping mapping = (FieldMapping) fieldMappings.next();
if(mapping.isPrimaryKey()){
pkType = mapping.getFieldType().getValue();
pkCount++;
}
}
isComposite = pkCount > 1;
if(!isComposite )
primaryKeyType = pkType;
else if(pkClassType == null || pkClassType.getValue() == null || pkClassType.getValue().length() < 1 ){
createCompositeKey = true;
primaryKeyType = eb.getEjbClass().getValue()+".PrimaryKey";
}else if(pkClassType != null && pkClassType.getValue() != null ){
if(primaryKeyType.equals(eb.getEjbClass().getValue()+".PrimaryKey") )
createCompositeKey = true;
}
}
stringBuffer.append(TEXT_1);
stringBuffer.append(eb.getEjbClass().getUnqualifiedClassName());
stringBuffer.append(TEXT_2);
if(createCompositeKey ){
stringBuffer.append(TEXT_3);
Iterator fieldMappings = leb.getFieldMappings().iterator();
while(fieldMappings.hasNext()){
FieldMapping mapping = (FieldMapping) fieldMappings.next();
if(mapping.isPrimaryKey()){
stringBuffer.append(TEXT_4);
stringBuffer.append( mapping.getFieldType().getValue() );
stringBuffer.append(TEXT_5);
stringBuffer.append( mapping.getFieldName().getValue() );
stringBuffer.append(TEXT_6);
} }
stringBuffer.append(TEXT_7);
}
stringBuffer.append(TEXT_8);
stringBuffer.append(TEXT_9);
return stringBuffer.toString();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -