use of com.sun.jdo.api.persistence.support.JDOUserException in project Payara by payara.
the class JDOCodeGenerator method generate.
/**
* @see CMPGenerator#generate(IASEjbCMPEntityDescriptor, File, File)
*/
public void generate(IASEjbCMPEntityDescriptor ejbcmp, File srcout, File classout) throws GeneratorException {
String beanName = ejbcmp.getName();
// StringBuffer to store validation exception messages if there are any.
// If there are no validation exceptions, the reference will be null.
StringBuffer validateex = null;
boolean debug = logger.isLoggable(Logger.FINE);
if (debug)
// NOI18N
logger.fine("gen file in " + srcout.getAbsolutePath());
// We need to create a new ArrayList because model validation
// returns an unmodifiable list. This may be a place to look
// for a performance improvement later for the case of empty
// or singleton collection (extra copies).
Collection c = new ArrayList(validateModel(ejbcmp));
// if the mapping info is not present, throw the exception and
// stop the generation process
GeneratorException mappingMissingEx = getMappingMissingException(c);
if (mappingMissingEx != null)
throw mappingMissingEx;
c.addAll(validateSupported(ejbcmp));
JDOConcreteBeanGenerator cmpGenerator = getCMPGenerator(ejbcmp);
MethodHelper mh = new MethodHelper(ejbcmp);
c.addAll(cmpGenerator.validate(mh, beanName));
if (!c.isEmpty()) {
// Validation failed the test. We will try to display all the
// exceptions in a concatenated message and a GeneratorException
// is thrown.
validateex = new StringBuffer();
Iterator iter = c.iterator();
while (iter.hasNext()) {
Exception ex = (Exception) iter.next();
if (debug)
// NOI18N
logger.log(Logger.FINE, "validation exception: ", ex);
// NOI18N
validateex.append(ex.getMessage()).append('\n');
}
if (!ignoreValidationResults)
throw JDOCodeGeneratorHelper.createGeneratorException(// NOI18N
"CMG.ExceptionInValidate", beanName, bundle, validateex.toString());
}
try {
Collection<File> newfiles = null;
if (!ejbcmp.isEJB20())
ejbcmp.setQueryParser(jdoqlParamDeclParser);
// IMPORTANT:
// Concrete impl class generation must happen before generation of
// PC class as cmpGenerator will override cascadeDelete (DeleteAction)
// property if it is set, and generatePC() saves .mapping file.
newfiles = cmpGenerator.generate(mh, beanName, appName, srcout, classout);
files.addAll(newfiles);
newfiles = generatePC(ejbcmp, srcout, classout);
files.addAll(newfiles);
if (validateex != null)
throw JDOCodeGeneratorHelper.createGeneratorException(// NOI18N
"CMG.ExceptionInValidate", beanName, bundle, validateex.toString());
} catch (JDOUserException e) {
// messages if there are any.
throw JDOCodeGeneratorHelper.createGeneratorException(// NOI18N
"CMG.ExceptionInGenerate", beanName, bundle, e, validateex);
} catch (EJBQLException e) {
// validation messages if there are any.
throw JDOCodeGeneratorHelper.createGeneratorException(// NOI18N
"CMG.ExceptionInGenerate", beanName, bundle, e, validateex);
} catch (IOException e) {
// validation messages if there are any.
throw JDOCodeGeneratorHelper.createGeneratorException(// NOI18N
"CMG.IOExceptionInGenerate", beanName, bundle, e, validateex);
}
}
use of com.sun.jdo.api.persistence.support.JDOUserException in project Payara by payara.
the class JDOEJB11HelperImpl method writeSerializableObjectToByteArray.
/**
* Serializes serializableObject into a byte array
* @param serializableObject Instance of a Serializable Object
* @return serializableObject serialized into a byte array
*/
public byte[] writeSerializableObjectToByteArray(Serializable serializableObject) {
byte[] byteArray = null;
if (serializableObject != null) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = null;
try {
oos = new ObjectOutputStream(bos);
oos.writeObject(serializableObject);
byteArray = bos.toByteArray();
} catch (java.io.IOException e) {
String clsName = serializableObject.getClass().getName();
throw new JDOUserException(I18NHelper.getMessage(messages, "EXC_IOWriteSerializableObject", clsName), // NOI18N
e);
}
}
return byteArray;
}
use of com.sun.jdo.api.persistence.support.JDOUserException in project Payara by payara.
the class ArrayList method addAll.
/**
* Inserts all of the elements in in the specified Collection into this
* ArrayList at the specified position. Shifts the element currently at
* that position (if any) and any subsequent elements to the right
* (increases their indices). The new elements will appear in the ArrayList
* in the order that they are returned by the specified Collection's
* iterator.
*
* @param index index at which to insert first element
* from the specified collection.
* @param c elements to be inserted into this ArrayList.
* @exception IndexOutOfBoundsException index out of range (index
* < 0 || index > size()).
* @see java.util.ArrayList
*/
public boolean addAll(int index, Collection c) {
if (allowNulls == false && c.contains(null)) {
throw new JDOUserException(I18NHelper.getMessage(messages, // NOI18N
"sco.nulls_not_allowed"));
}
java.util.Vector errc = new java.util.Vector();
if (elementType != null) {
// iterate the collection and make a list of wrong elements.
Iterator i = c.iterator();
while (i.hasNext()) {
Object o = i.next();
if (!elementType.isAssignableFrom(o.getClass()))
errc.add(o);
}
}
if (errc != null && errc.size() > 0) {
throw new JDOUserException(I18NHelper.getMessage(messages, "sco.classcastexception", // NOI18N
elementType.getName()), new ClassCastException(), errc.toArray());
}
// Mark the field as dirty
StateManager stateManager = this.makeDirty();
removed.removeAll(c);
added.addAll(c);
boolean modified = super.addAll(index, c);
// Apply updates
this.applyUpdates(stateManager, modified);
return modified;
}
use of com.sun.jdo.api.persistence.support.JDOUserException in project Payara by payara.
the class ArrayList method addAll.
/**
* Appends all of the elements in the specified Collection to the end of
* this ArrayList, in the order that they are returned by the specified
* Collection's Iterator.
*
* @param c elements to be inserted into this ArrayList.
* @exception IndexOutOfBoundsException index out of range (index
* < 0 || index > size()).
* @see java.util.ArrayList
*/
public boolean addAll(Collection c) {
if (allowNulls == false && c.contains(null)) {
throw new JDOUserException(I18NHelper.getMessage(messages, // NOI18N
"sco.nulls_not_allowed"));
}
java.util.Vector errc = new java.util.Vector();
if (elementType != null) {
// iterate the collection and make a list of wrong elements.
Iterator i = c.iterator();
while (i.hasNext()) {
Object o = i.next();
if (!elementType.isAssignableFrom(o.getClass()))
errc.add(o);
}
}
if (errc != null && errc.size() > 0) {
throw new JDOUserException(I18NHelper.getMessage(messages, "sco.classcastexception", // NOI18N
elementType.getName()), new ClassCastException(), errc.toArray());
}
// Mark the field as dirty
StateManager stateManager = this.makeDirty();
removed.removeAll(c);
added.addAll(c);
boolean modified = super.addAll(c);
// Apply updates
this.applyUpdates(stateManager, modified);
return modified;
}
use of com.sun.jdo.api.persistence.support.JDOUserException in project Payara by payara.
the class ArrayList method add.
/**
* Inserts the specified element at the specified position in this ArrayList.
*
* @param index index at which the specified element is to be inserted.
* @param element element to be inserted.
* @exception IndexOutOfBoundsException index is out of range
* (index < 0 || index > size()).
* @see java.util.ArrayList
*/
public void add(int index, Object element) {
if (allowNulls == false && element == null) {
throw new JDOUserException(I18NHelper.getMessage(messages, // NOI18N
"sco.nulls_not_allowed"));
}
if (elementType == null || elementType.isAssignableFrom(element.getClass())) {
// Mark the field as dirty
StateManager stateManager = this.makeDirty();
super.add(index, element);
if (removed.remove(element) == false)
added.add(element);
// Apply updates
this.applyUpdates(stateManager, true);
} else {
throw new JDOUserException(I18NHelper.getMessage(messages, "sco.classcastexception", // NOI18N
elementType.getName()), new ClassCastException(), new Object[] { element });
}
}
Aggregations