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

📄 typecommentgenerator.java

📁 《精通SOA:基于服务总线的Struts+EJB+Web Service整合应用开发》原书的实例代码
💻 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 TypeCommentGenerator
{
  protected final String NL = System.getProperties().getProperty("line.separator");
  protected final String TEXT_1 = "   " + NL + "/**" + NL + " *" + NL + " * <!-- begin-user-doc -->" + NL + " * You can insert your documentation for '<em><b>";
  protected final String TEXT_2 = "</b></em>'." + NL + " * <!-- end-user-doc -->" + NL + " *" + NL + " <!--  begin-lomboz-definition -->";
  protected final String TEXT_3 = NL + " ";
  protected final String TEXT_4 = NL + " <!--  end-lomboz-definition -->" + NL + " *" + NL + " * <!-- begin-xdoclet-definition -->";
  protected final String TEXT_5 = NL + " * @ejb.bean name=\"";
  protected final String TEXT_6 = "\"" + NL + " *\tjndi-name=\"";
  protected final String TEXT_7 = "\"" + NL + " *\ttype=\"CMP\"";
  protected final String TEXT_8 = NL + " *  primkey-field=\"";
  protected final String TEXT_9 = "\"";
  protected final String TEXT_10 = " " + NL + " *  schema=\"";
  protected final String TEXT_11 = "\" " + NL + " *  cmp-version=\"";
  protected final String TEXT_12 = "\"" + NL + " *  data-source=\"";
  protected final String TEXT_13 = "\"" + NL + " * " + NL + " *  @ejb.persistence " + NL + " *   table-name=\"";
  protected final String TEXT_14 = "\" " + NL + " * " + NL + " * @ejb.finder " + NL + " *    query=\"SELECT OBJECT(a) FROM ";
  protected final String TEXT_15 = " as a\"  " + NL + " *    signature=\"java.util.Collection findAll()\"  " + NL + " *" + NL + " * @ejb.pk class=\"";
  protected final String TEXT_16 = "\"" + NL + " * <!-- end-xdoclet-definition -->" + NL + " * @generated" + NL + " **/" + NL;
  protected final String TEXT_17 = NL + NL + NL + NL + "/**" + NL + " * @ejb.bean name=\"";
  protected final String TEXT_18 = "\"" + NL + " *\tjndi-name=\"";
  protected final String TEXT_19 = "\"" + NL + " *\ttype=\"BMP\"" + NL + " * " + NL + " * <!-- end-xdoclet-defintion -->" + NL + " * @generated" + NL + " **/" + NL;
  protected final String TEXT_20 = 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 ejbName = eb.getEjbClass().getUnqualifiedClassName();
   if(ejbName.endsWith("Bean") ){
      ejbName = ejbName.substring(0,ejbName.length()-4);
   }else if(ejbName.endsWith("Ejb") ){
      ejbName = ejbName.substring(0,ejbName.length()-3);
   }
   
   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);
    stringBuffer.append(TEXT_3);
    stringBuffer.append( root.asString() );
    stringBuffer.append(TEXT_4);
     if( isCMP ) { 
    stringBuffer.append(TEXT_5);
    stringBuffer.append(ejbName);
    stringBuffer.append(TEXT_6);
    stringBuffer.append(eb.getEjbName());
    stringBuffer.append(TEXT_7);
    if(eb.getPrimkeyField() != null ){
    stringBuffer.append(TEXT_8);
    stringBuffer.append( eb.getPrimkeyField().getValue() );
    stringBuffer.append(TEXT_9);
    }
    stringBuffer.append(TEXT_10);
    stringBuffer.append( eb.getAbstractSchemaName().getValue() );
    stringBuffer.append(TEXT_11);
    stringBuffer.append( eb.getCmpVersion().getValue() );
    stringBuffer.append(TEXT_12);
    stringBuffer.append(leb.getDataSourceName());
    stringBuffer.append(TEXT_13);
    stringBuffer.append(leb.getTableName());
    stringBuffer.append(TEXT_14);
    stringBuffer.append( eb.getAbstractSchemaName().getValue() );
    stringBuffer.append(TEXT_15);
    stringBuffer.append( primaryKeyType );
    stringBuffer.append(TEXT_16);
     } else { 
    stringBuffer.append(TEXT_17);
    stringBuffer.append(ejbName);
    stringBuffer.append(TEXT_18);
    stringBuffer.append(eb.getEjbName());
    stringBuffer.append(TEXT_19);
     } 
    stringBuffer.append(TEXT_20);
    return stringBuffer.toString();
  }
}

⌨️ 快捷键说明

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