📄 methodgenerator.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 MethodGenerator
{
protected final String NL = System.getProperties().getProperty("line.separator");
protected final String TEXT_1 = NL + "/**" + NL + " *" + NL + " * <!-- begin-user-doc -->" + NL + " * The ejbCreate method." + NL + " * <!-- end-user-doc -->" + NL + " *" + NL + " * <!-- begin-xdoclet-definition --> " + NL + " * @ejb.create-method " + NL + " * <!-- end-xdoclet-definition --> " + NL + " * @generated" + NL + " */" + NL + "public ";
protected final String TEXT_2 = " ejbCreate() throws javax.ejb.CreateException {" + NL + "\t// EJB 2.0 spec says return null for CMP ejbCreate methods." + NL + "\t// TODO: YOU MUST INITIALIZE THE FIELDS FOR THE BEAN HERE. " + NL + "\t// setMyField(\"Something\"); " + NL + "\t// begin-user-code" + NL + "\treturn null;" + NL + "\t// end-user-code" + NL + "}" + NL + "" + NL + "/**" + NL + " * <!-- begin-user-doc -->" + NL + " * The container invokes this method immediately after it calls ejbCreate." + NL + " * <!-- end-user-doc -->" + NL + " * " + NL + " * @generated" + NL + " */" + NL + "public void ejbPostCreate() throws javax.ejb.CreateException {" + NL + "\t// begin-user-code" + NL + "\t// end-user-code" + NL + "}" + NL + "\t";
protected final String TEXT_3 = NL + NL + "/**" + NL + "*" + NL + "*" + NL + "* <!-- begin-user-doc -->" + NL + "* CMP Field ";
protected final String TEXT_4 = NL + "*" + NL + "* Returns the ";
protected final String TEXT_5 = NL + "* @return the ";
protected final String TEXT_6 = NL + "* " + NL + "* <!-- end-user-doc -->" + NL + "*" + NL + "* <!-- begin-xdoclet-definition --> " + NL + "*" + NL + "* @ejb.persistent-field " + NL + "* @ejb.persistence" + NL + "* column-name=\"";
protected final String TEXT_7 = "\"" + NL + "* jdbc-type=\"";
protected final String TEXT_8 = "\"" + NL + "* sql-type=\"";
protected final String TEXT_9 = "\"" + NL + "* read-only=\"";
protected final String TEXT_10 = "\"" + NL + "* ";
protected final String TEXT_11 = " " + NL + "*" + NL + "* @ejb.interface-method" + NL + "* " + NL + "* <!-- end-xdoclet-definition --> " + NL + "* @generated" + NL + "*/";
protected final String TEXT_12 = NL + "public abstract ";
protected final String TEXT_13 = " get";
protected final String TEXT_14 = "();" + NL + "" + NL + "" + NL + "/**" + NL + "* <!-- begin-user-doc -->" + NL + "* Sets the ";
protected final String TEXT_15 = NL + "* " + NL + "* @param ";
protected final String TEXT_16 = " the new ";
protected final String TEXT_17 = " value" + NL + "* <!-- end-user-doc -->" + NL + "* " + NL + "* <!-- begin-xdoclet-definition --> " + NL + "* @ejb.interface-method" + NL + "* <!-- end-xdoclet-definition -->" + NL + "* @generated " + NL + "*/" + NL + "public abstract void set";
protected final String TEXT_18 = "(";
protected final String TEXT_19 = " ";
protected final String TEXT_20 = ");" + NL + NL + NL;
protected final String TEXT_21 = NL + NL;
protected final String TEXT_22 = 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( primaryKeyType );
stringBuffer.append(TEXT_2);
if( isCMP ) {
Iterator fieldMappings = leb.getFieldMappings().iterator();
while(fieldMappings.hasNext()){
FieldMapping mapping = (FieldMapping) fieldMappings.next();
stringBuffer.append(TEXT_3);
stringBuffer.append( mapping.getFieldName().getValue() );
stringBuffer.append(TEXT_4);
stringBuffer.append( mapping.getFieldName().getValue() );
stringBuffer.append(TEXT_5);
stringBuffer.append( mapping.getFieldName().getValue() );
stringBuffer.append(TEXT_6);
stringBuffer.append( mapping.getColumnName().getValue() );
stringBuffer.append(TEXT_7);
stringBuffer.append( mapping.getJdbcType().getValue() );
stringBuffer.append(TEXT_8);
stringBuffer.append( mapping.getSqlType().getValue() );
stringBuffer.append(TEXT_9);
stringBuffer.append( mapping.isReadOnly() );
stringBuffer.append(TEXT_10);
stringBuffer.append( (mapping.isPrimaryKey() ? "@ejb.pk-field" : "" ) );
stringBuffer.append(TEXT_11);
String methodName = mapping.getFieldName().getValue();
methodName = Character.toUpperCase(methodName.charAt(0)) + methodName.substring(1,methodName.length());
stringBuffer.append(TEXT_12);
stringBuffer.append( mapping.getFieldType().getValue() );
stringBuffer.append(TEXT_13);
stringBuffer.append( methodName );
stringBuffer.append(TEXT_14);
stringBuffer.append( mapping.getFieldName().getValue() );
stringBuffer.append(TEXT_15);
stringBuffer.append( mapping.getFieldType().getValue() );
stringBuffer.append(TEXT_16);
stringBuffer.append( mapping.getFieldName().getValue() );
stringBuffer.append(TEXT_17);
stringBuffer.append( methodName );
stringBuffer.append(TEXT_18);
stringBuffer.append( mapping.getFieldType().getValue() );
stringBuffer.append(TEXT_19);
stringBuffer.append( mapping.getFieldName().getValue() );
stringBuffer.append(TEXT_20);
}
}
stringBuffer.append(TEXT_21);
stringBuffer.append(TEXT_22);
return stringBuffer.toString();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -