📄 exceptionstrategy.java
字号:
/**
* Copyright (c) 2002, Siddhartha P. Chandurkar siddhartha@visioncodified.com
* All rights reserved.
* Licensed under the Academic Free License version 1.1
* See the file LICENSE.TXT for details.
* LICENSE.txt is located in the directory <install-directory>\Jenerator
* of your Jenertaor Installation.
*
*/
package com.jenerator.transformer;
import com.jenerator.struct.ConfigStructs;
import com.jenerator.struct.ejb.EntityStruct;
import com.jenerator.struct.ejb.MDBStruct;
import com.jenerator.struct.ejb.SessionStruct;
import com.jenerator.util.Configurator;
import org.apache.log4j.Logger;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.StringTokenizer;
import java.util.Vector;
/**
* ExceptionStrategy
* This class is used for generating Exceptions.
*
* @author Siddhartha P. Chandurkar
* @version 0.9.0
*/
public class ExceptionStrategy extends TransformStrategy {
//ATTRIBUTES
private Logger log = Logger.getLogger(com.jenerator.transformer.BeanStrategy.class.getName());
//METHODS
/**
*
*
*/
public void transform() throws TransformFailedException {
try {
ConfigStructs configStructs = Configurator.getInstance().getConfigStructs();
Vector ejbStructs = configStructs.getEjbStructs();
for (int i = 0; i < ejbStructs.size(); i++) {
if (ejbStructs.elementAt(i) instanceof com.jenerator.struct.ejb.EntityStruct) {
EntityStruct entityStruct = (EntityStruct) ejbStructs.elementAt(i);
Hashtable methodSigs = entityStruct.getMethodSignatures();
if (!methodSigs.isEmpty()) {
Enumeration keys = methodSigs.keys();
while (keys.hasMoreElements()) {
String signature = keys.nextElement().toString();
String exceptions = methodSigs.get(signature).toString();
StringTokenizer tokens = new StringTokenizer(exceptions, ",");
while (tokens.hasMoreTokens()) {
String name = tokens.nextToken().trim();
if (!name.equals("null"))
processor.process(makeXmlForException(entityStruct.getPackageName(), name), "exception.xsl", name + ".java", entityStruct.getPackageDir());
}
}
}
} else if (ejbStructs.elementAt(i) instanceof com.jenerator.struct.ejb.SessionStruct) {
SessionStruct sessionStruct = (SessionStruct) ejbStructs.elementAt(i);
Hashtable methodSigs = sessionStruct.getMethodSignatures();
if (!methodSigs.isEmpty()) {
Enumeration keys = methodSigs.keys();
while (keys.hasMoreElements()) {
String signature = keys.nextElement().toString();
String exceptions = methodSigs.get(signature).toString();
StringTokenizer tokens = new StringTokenizer(exceptions, ",");
while (tokens.hasMoreTokens()) {
String name = tokens.nextToken().trim();
if (!name.equals("null"))
processor.process(makeXmlForException(sessionStruct.getPackageName(), name), "exception.xsl", name + ".java", sessionStruct.getPackageDir());
}
}
}
} else if (ejbStructs.elementAt(i) instanceof com.jenerator.struct.ejb.MDBStruct) {
MDBStruct mdbStruct = (MDBStruct) ejbStructs.elementAt(i);
Hashtable methodSigs = mdbStruct.getMethodSignatures();
if (!methodSigs.isEmpty()) {
Enumeration keys = methodSigs.keys();
while (keys.hasMoreElements()) {
String signature = keys.nextElement().toString();
String exceptions = methodSigs.get(signature).toString();
StringTokenizer tokens = new StringTokenizer(exceptions, ",");
while (tokens.hasMoreTokens()) {
String name = tokens.nextToken().trim();
if (!name.equals("null"))
processor.process(makeXmlForException(mdbStruct.getPackageName(), name), "exception.xsl", name + ".java", mdbStruct.getPackageDir());
}
}
}
}
}
} catch (NotProcessableException ex) {
log.fatal(ex);
throw new TransformFailedException(ex);
}
}
/**
*
*/
private String makeXmlForException(String _package, String _name) {
StringBuffer xmlBuffer = new StringBuffer();
xmlBuffer.append("<?xml version='1.0'?>");
xmlBuffer.append("<exception>");
xmlBuffer.append("<package>");
xmlBuffer.append(_package);
xmlBuffer.append("</package>");
xmlBuffer.append("<name>");
xmlBuffer.append(_name);
xmlBuffer.append("</name>");
xmlBuffer.append("</exception>");
return xmlBuffer.toString();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -