use of org.apache.xalan.xsltc.compiler.util.ErrorMsg in project servicemix-bundles by apache.
the class TemplatesImpl method defineTransletClasses.
/**
* Defines the translet class and auxiliary classes.
* Returns a reference to the Class object that defines the main class
*/
private void defineTransletClasses() throws TransformerConfigurationException {
if (_bytecodes == null) {
ErrorMsg err = new ErrorMsg(ErrorMsg.NO_TRANSLET_CLASS_ERR);
throw new TransformerConfigurationException(err.toString());
}
TransletClassLoader loader = (TransletClassLoader) AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return new TransletClassLoader(ObjectFactory.findClassLoader());
}
});
try {
final int classCount = _bytecodes.length;
_class = new Class[classCount];
if (classCount > 1) {
_auxClasses = new Hashtable();
}
for (int i = 0; i < classCount; i++) {
_class[i] = loader.defineClass(_bytecodes[i]);
final Class superClass = _class[i].getSuperclass();
// Check if this is the main class
if (superClass.getName().equals(ABSTRACT_TRANSLET)) {
_transletIndex = i;
} else {
_auxClasses.put(_class[i].getName(), _class[i]);
}
}
if (_transletIndex < 0) {
ErrorMsg err = new ErrorMsg(ErrorMsg.NO_MAIN_TRANSLET_ERR, _name);
throw new TransformerConfigurationException(err.toString());
}
} catch (ClassFormatError e) {
ErrorMsg err = new ErrorMsg(ErrorMsg.TRANSLET_CLASS_ERR, _name);
throw new TransformerConfigurationException(err.toString());
} catch (LinkageError e) {
ErrorMsg err = new ErrorMsg(ErrorMsg.TRANSLET_OBJECT_ERR, _name);
throw new TransformerConfigurationException(err.toString());
}
}
use of org.apache.xalan.xsltc.compiler.util.ErrorMsg in project servicemix-bundles by apache.
the class FunctionCall method getSignature.
/**
* Compute the JVM signature for the class.
*/
static final String getSignature(Class clazz) {
if (clazz.isArray()) {
final StringBuffer sb = new StringBuffer();
Class cl = clazz;
while (cl.isArray()) {
sb.append("[");
cl = cl.getComponentType();
}
sb.append(getSignature(cl));
return sb.toString();
} else if (clazz.isPrimitive()) {
if (clazz == Integer.TYPE) {
return "I";
} else if (clazz == Byte.TYPE) {
return "B";
} else if (clazz == Long.TYPE) {
return "J";
} else if (clazz == Float.TYPE) {
return "F";
} else if (clazz == Double.TYPE) {
return "D";
} else if (clazz == Short.TYPE) {
return "S";
} else if (clazz == Character.TYPE) {
return "C";
} else if (clazz == Boolean.TYPE) {
return "Z";
} else if (clazz == Void.TYPE) {
return "V";
} else {
final String name = clazz.toString();
ErrorMsg err = new ErrorMsg(ErrorMsg.UNKNOWN_SIG_TYPE_ERR, name);
throw new Error(err.toString());
}
} else {
return "L" + clazz.getName().replace('.', '/') + ';';
}
}
use of org.apache.xalan.xsltc.compiler.util.ErrorMsg in project servicemix-bundles by apache.
the class FunctionCall method findMethods.
/**
* Returns a vector with all methods named <code>_fname</code>
* after stripping its namespace or <code>null</code>
* if no such methods exist.
*/
private Vector findMethods() {
Vector result = null;
final String namespace = _fname.getNamespace();
if (_className != null && _className.length() > 0) {
final int nArgs = _arguments.size();
try {
if (_clazz == null) {
_clazz = ObjectFactory.findProviderClass(_className, ObjectFactory.findClassLoader(), true);
if (_clazz == null) {
final ErrorMsg msg = new ErrorMsg(ErrorMsg.CLASS_NOT_FOUND_ERR, _className);
getParser().reportError(Constants.ERROR, msg);
}
}
final String methodName = _fname.getLocalPart();
final Method[] methods = _clazz.getMethods();
for (int i = 0; i < methods.length; i++) {
final int mods = methods[i].getModifiers();
// Is it public and same number of args ?
if (Modifier.isPublic(mods) && methods[i].getName().equals(methodName) && methods[i].getParameterTypes().length == nArgs) {
if (result == null) {
result = new Vector();
}
result.addElement(methods[i]);
}
}
} catch (ClassNotFoundException e) {
final ErrorMsg msg = new ErrorMsg(ErrorMsg.CLASS_NOT_FOUND_ERR, _className);
getParser().reportError(Constants.ERROR, msg);
}
}
return result;
}
use of org.apache.xalan.xsltc.compiler.util.ErrorMsg in project servicemix-bundles by apache.
the class FunctionCall method findConstructors.
/**
* Returns a vector with all constructors named <code>_fname</code>
* after stripping its namespace or <code>null</code>
* if no such methods exist.
*/
private Vector findConstructors() {
Vector result = null;
final String namespace = _fname.getNamespace();
final int nArgs = _arguments.size();
try {
if (_clazz == null) {
_clazz = ObjectFactory.findProviderClass(_className, ObjectFactory.findClassLoader(), true);
if (_clazz == null) {
final ErrorMsg msg = new ErrorMsg(ErrorMsg.CLASS_NOT_FOUND_ERR, _className);
getParser().reportError(Constants.ERROR, msg);
}
}
final Constructor[] constructors = _clazz.getConstructors();
for (int i = 0; i < constructors.length; i++) {
final int mods = constructors[i].getModifiers();
// Is it public, static and same number of args ?
if (Modifier.isPublic(mods) && constructors[i].getParameterTypes().length == nArgs) {
if (result == null) {
result = new Vector();
}
result.addElement(constructors[i]);
}
}
} catch (ClassNotFoundException e) {
final ErrorMsg msg = new ErrorMsg(ErrorMsg.CLASS_NOT_FOUND_ERR, _className);
getParser().reportError(Constants.ERROR, msg);
}
return result;
}
use of org.apache.xalan.xsltc.compiler.util.ErrorMsg in project servicemix-bundles by apache.
the class FunctionCall method typeCheck.
/**
* Type check a function call. Since different type conversions apply,
* type checking is different for standard and external (Java) functions.
*/
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
if (_type != null)
return _type;
final String namespace = _fname.getNamespace();
String local = _fname.getLocalPart();
if (isExtension()) {
_fname = new QName(null, null, local);
return typeCheckStandard(stable);
} else if (isStandard()) {
return typeCheckStandard(stable);
} else // Handle extension functions (they all have a namespace)
{
try {
_className = getClassNameFromUri(namespace);
final int pos = local.lastIndexOf('.');
if (pos > 0) {
_isStatic = true;
if (_className != null && _className.length() > 0) {
_namespace_format = NAMESPACE_FORMAT_PACKAGE;
_className = _className + "." + local.substring(0, pos);
} else {
_namespace_format = NAMESPACE_FORMAT_JAVA;
_className = local.substring(0, pos);
}
_fname = new QName(namespace, null, local.substring(pos + 1));
} else {
if (_className != null && _className.length() > 0) {
try {
_clazz = ObjectFactory.findProviderClass(_className, ObjectFactory.findClassLoader(), true);
_namespace_format = NAMESPACE_FORMAT_CLASS;
} catch (ClassNotFoundException e) {
_namespace_format = NAMESPACE_FORMAT_PACKAGE;
}
} else
_namespace_format = NAMESPACE_FORMAT_JAVA;
if (local.indexOf('-') > 0) {
local = replaceDash(local);
}
String extFunction = (String) _extensionFunctionTable.get(namespace + ":" + local);
if (extFunction != null) {
_fname = new QName(null, null, extFunction);
return typeCheckStandard(stable);
} else
_fname = new QName(namespace, null, local);
}
return typeCheckExternal(stable);
} catch (TypeCheckError e) {
ErrorMsg errorMsg = e.getErrorMsg();
if (errorMsg == null) {
final String name = _fname.getLocalPart();
errorMsg = new ErrorMsg(ErrorMsg.METHOD_NOT_FOUND_ERR, name);
}
getParser().reportError(ERROR, errorMsg);
return _type = Type.Void;
}
}
}
Aggregations