List of usage examples for java.lang NoSuchFieldException getMessage
public String getMessage()
From source file:xdoclet.modules.ojb.constraints.ModelConstraints.java
/** * Checks the foreignkeys of a reference. * // www .j a v a 2 s .c o m * @param modelDef The model * @param refDef The reference descriptor * @exception ConstraintException If the value for foreignkey is invalid */ private void checkReferenceForeignkeys(ModelDef modelDef, ReferenceDescriptorDef refDef) throws ConstraintException { String foreignkey = refDef.getProperty(PropertyHelper.OJB_PROPERTY_FOREIGNKEY); if ((foreignkey == null) || (foreignkey.length() == 0)) { throw new ConstraintException("The reference " + refDef.getName() + " in class " + refDef.getOwner().getName() + " has no foreignkeys"); } // we know that the class is present because the reference constraints have been checked already ClassDescriptorDef ownerClass = (ClassDescriptorDef) refDef.getOwner(); ArrayList keyFields; FieldDescriptorDef keyField; try { keyFields = ownerClass.getFields(foreignkey); } catch (NoSuchFieldException ex) { throw new ConstraintException("The reference " + refDef.getName() + " in class " + refDef.getOwner().getName() + " specifies a foreignkey " + ex.getMessage() + " that is not a persistent field in its owner class " + ownerClass.getName()); } for (int idx = 0; idx < keyFields.size(); idx++) { keyField = (FieldDescriptorDef) keyFields.get(idx); if (keyField.getBooleanProperty(PropertyHelper.OJB_PROPERTY_IGNORE, false)) { throw new ConstraintException("The reference " + refDef.getName() + " in class " + ownerClass.getName() + " uses the field " + keyField.getName() + " as foreignkey although this field is ignored in this class"); } } // for the referenced class and any subtype that is instantiable (i.e. not an interface or abstract class) // there must be the same number of primary keys and the jdbc types of the primary keys must // match the jdbc types of the foreignkeys (in the correct order) String targetClassName = refDef.getProperty(PropertyHelper.OJB_PROPERTY_CLASS_REF); ArrayList queue = new ArrayList(); ClassDescriptorDef referencedClass; ArrayList primFields; FieldDescriptorDef primField; String primType; String keyType; queue.add(modelDef.getClass(targetClassName)); while (!queue.isEmpty()) { referencedClass = (ClassDescriptorDef) queue.get(0); queue.remove(0); for (Iterator it = referencedClass.getExtentClasses(); it.hasNext();) { queue.add(it.next()); } if (!referencedClass.getBooleanProperty(PropertyHelper.OJB_PROPERTY_GENERATE_REPOSITORY_INFO, true)) { continue; } primFields = referencedClass.getPrimaryKeys(); if (primFields.size() != keyFields.size()) { throw new ConstraintException("The number of foreignkeys (" + keyFields.size() + ") of the reference " + refDef.getName() + " in class " + refDef.getOwner().getName() + " doesn't match the number of primarykeys (" + primFields.size() + ") of the referenced class (or its subclass) " + referencedClass.getName()); } for (int idx = 0; idx < primFields.size(); idx++) { keyField = (FieldDescriptorDef) keyFields.get(idx); primField = (FieldDescriptorDef) primFields.get(idx); primType = primField.getProperty(PropertyHelper.OJB_PROPERTY_JDBC_TYPE); keyType = keyField.getProperty(PropertyHelper.OJB_PROPERTY_JDBC_TYPE); if (!primType.equals(keyType)) { throw new ConstraintException("The jdbc-type of foreignkey " + keyField.getName() + " of the reference " + refDef.getName() + " in class " + refDef.getOwner().getName() + " doesn't match the jdbc-type of the corresponding primarykey " + primField.getName() + " of the referenced class (or its subclass) " + referencedClass.getName()); } } } }
From source file:xdoclet.modules.ojb.constraints.ModelConstraints.java
/** * Checks the foreignkeys of the collection. * //from w w w . j a va 2s.c o m * @param modelDef The model * @param collDef The collection descriptor * @exception ConstraintException If the value for foreignkey is invalid */ private void checkCollectionForeignkeys(ModelDef modelDef, CollectionDescriptorDef collDef) throws ConstraintException { String foreignkey = collDef.getProperty(PropertyHelper.OJB_PROPERTY_FOREIGNKEY); if ((foreignkey == null) || (foreignkey.length() == 0)) { throw new ConstraintException("The collection " + collDef.getName() + " in class " + collDef.getOwner().getName() + " has no foreignkeys"); } String remoteForeignkey = collDef.getProperty(PropertyHelper.OJB_PROPERTY_REMOTE_FOREIGNKEY); if ((remoteForeignkey != null) && (remoteForeignkey.length() > 0)) { // warning because a remote-foreignkey was specified for a 1:n collection (issue OJB-67) LogHelper.warn(true, getClass(), "checkCollectionForeignkeys", "For the collection " + collDef.getName() + " in class " + collDef.getOwner().getName() + ", a remote foreignkey was specified though it is a 1:n, not a m:n collection"); } ClassDescriptorDef ownerClass = (ClassDescriptorDef) collDef.getOwner(); ArrayList primFields = ownerClass.getPrimaryKeys(); String elementClassName = collDef.getProperty(PropertyHelper.OJB_PROPERTY_ELEMENT_CLASS_REF); ArrayList queue = new ArrayList(); ClassDescriptorDef elementClass; ArrayList keyFields; FieldDescriptorDef keyField; FieldDescriptorDef primField; String primType; String keyType; // we know that the class is present because the collection constraints have been checked already queue.add(modelDef.getClass(elementClassName)); while (!queue.isEmpty()) { elementClass = (ClassDescriptorDef) queue.get(0); queue.remove(0); for (Iterator it = elementClass.getExtentClasses(); it.hasNext();) { queue.add(it.next()); } if (!elementClass.getBooleanProperty(PropertyHelper.OJB_PROPERTY_GENERATE_REPOSITORY_INFO, true)) { continue; } try { keyFields = elementClass.getFields(foreignkey); } catch (NoSuchFieldException ex) { throw new ConstraintException("The collection " + collDef.getName() + " in class " + collDef.getOwner().getName() + " specifies a foreignkey " + ex.getMessage() + " that is not a persistent field in the element class (or its subclass) " + elementClass.getName()); } if (primFields.size() != keyFields.size()) { throw new ConstraintException("The number of foreignkeys (" + keyFields.size() + ") of the collection " + collDef.getName() + " in class " + collDef.getOwner().getName() + " doesn't match the number of primarykeys (" + primFields.size() + ") of its owner class " + ownerClass.getName()); } for (int idx = 0; idx < keyFields.size(); idx++) { keyField = (FieldDescriptorDef) keyFields.get(idx); if (keyField.getBooleanProperty(PropertyHelper.OJB_PROPERTY_IGNORE, false)) { throw new ConstraintException("The collection " + collDef.getName() + " in class " + ownerClass.getName() + " uses the field " + keyField.getName() + " as foreignkey although this field is ignored in the element class (or its subclass) " + elementClass.getName()); } } // the jdbc types of the primary keys must match the jdbc types of the foreignkeys (in the correct order) for (int idx = 0; idx < primFields.size(); idx++) { keyField = (FieldDescriptorDef) keyFields.get(idx); if (keyField.getBooleanProperty(PropertyHelper.OJB_PROPERTY_IGNORE, false)) { throw new ConstraintException("The collection " + collDef.getName() + " in class " + ownerClass.getName() + " uses the field " + keyField.getName() + " as foreignkey although this field is ignored in the element class (or its subclass) " + elementClass.getName()); } primField = (FieldDescriptorDef) primFields.get(idx); primType = primField.getProperty(PropertyHelper.OJB_PROPERTY_JDBC_TYPE); keyType = keyField.getProperty(PropertyHelper.OJB_PROPERTY_JDBC_TYPE); if (!primType.equals(keyType)) { throw new ConstraintException("The jdbc-type of foreignkey " + keyField.getName() + " in the element class (or its subclass) " + elementClass.getName() + " used by the collection " + collDef.getName() + " in class " + ownerClass.getName() + " doesn't match the jdbc-type of the corresponding primarykey " + primField.getName()); } } } }
From source file:org.xenei.jdbc4sparql.sparql.SparqlQueryBuilder.java
/** * Get the SPARQL query./*ww w. ja v a 2 s. co m*/ * * @return The constructed SPARQL query. * @throws SQLDataException */ public Query build() throws SQLDataException { if (!isBuilt) { if (!catalog.isService()) { // apply the type filters to each subpart. for (final QueryTableInfo tableInfo : infoSet.getTables()) { try { tableInfo.addQueryFilters(infoSet); } catch (final SQLDataException e1) { throw new IllegalStateException(e1.getMessage(), e1); } } } // renumber the Bnodes. final Element e = new BnodeRenumber().renumber(query.getQueryPattern()); query.setQueryPattern(e); if (catalog.isService()) { // create a copy of the query so that we can verify that it is // good. final Query serviceCall = query.cloneQuery(); final VarExprList vars = serviceCall.getProject(); // reset the serviceCall select vars // protected VarExprList projectVars = new VarExprList() ; try { Field f = Query.class.getDeclaredField("projectVars"); f.setAccessible(true); f.set(serviceCall, new VarExprList()); } catch (NoSuchFieldException e2) { throw new IllegalStateException(e2.getMessage(), e2); } catch (SecurityException e2) { throw new IllegalStateException(e2.getMessage(), e2); } catch (IllegalAccessException e2) { throw new IllegalStateException(e2.getMessage(), e2); } final ElementService service = new ElementService(catalog.getServiceNode(), new ElementSubQuery(serviceCall), false); final Query newResult = new Query(); newResult.setQuerySelectType(); final ElementGroup filterGroup = SparqlQueryBuilder.getElementGroup(newResult); filterGroup.addElement(service); final ElementGroup typeGroup = new ElementGroup(); typeGroup.addElement(filterGroup); infoSet.setUseGUID(false); // we are now building complete set. // create the service call // make sure we project all vars for the filters. final Collection<QueryColumnInfo> typeFilters = new HashSet<QueryColumnInfo>(); final Collection<QueryColumnInfo> dataFilters = new HashSet<QueryColumnInfo>(); final Collection<QueryColumnInfo> columnsInQuery = new ArrayList<QueryColumnInfo>(); for (final Var v : vars.getVars()) { final QueryColumnInfo colInfo = infoSet.findColumnByGUIDVar(v.getName()); if (colInfo == null) { // may be a variable associated with a function if (vars.getExpr(v) != null) { newResult.addResultVar(v, vars.getExpr(v)); } else { throw new IllegalStateException(String.format("can not find column %s", v)); } } else { columnsInQuery.add(colInfo); newResult.addResultVar(colInfo.getVar()); } } // add the columns to the query. // the columns are named by GUID in the query. boolean firstTable = true; for (final QueryTableInfo tableInfo : infoSet.getTables()) { // add the data type filters for (final Column tblCol : tableInfo.getTable().getColumnList()) { QueryColumnInfo columnInfo = new QueryColumnInfo(tblCol); typeFilters.add(columnInfo); serviceCall.addResultVar(columnInfo.getGUIDVar()); } // add the binds for (QueryColumnInfo colInfo : columnsInQuery) { if (colInfo.getBaseColumnInfo().getName().getTableName().equals(tableInfo.getName())) { if (firstTable || !this.columnsInUsing.contains(colInfo.getName().getShortName())) { dataFilters.add(colInfo); } } } try { QueryTableInfo.addTypeFilters(infoSet, typeFilters, dataFilters, tableInfo.getJoinElements(), filterGroup, typeGroup); } catch (final SQLDataException e1) { throw new IllegalStateException(e1.getMessage(), e1); } dataFilters.clear(); typeFilters.clear(); firstTable = false; } // add equality check into service Call for (final String columnName : columnsInUsing) { QueryColumnInfo first = null; Expr expr = null; for (final QueryColumnInfo columnInfo : infoSet .listColumns(new SearchName(null, null, null, columnName))) { if (first == null) { first = columnInfo; } else { final E_Equals eq = new E_Equals(new ExprVar(first.getGUIDVar()), new ExprVar(columnInfo.getGUIDVar())); if (expr == null) { expr = eq; } else { expr = new E_LogicalAnd(expr, eq); } } } if (expr != null) { if (LOG.isDebugEnabled()) { LOG.debug("Adding filter: {}", expr); } ((ElementGroup) serviceCall.getQueryPattern()).addElementFilter(new ElementFilter(expr)); } } newResult.setQueryPattern(typeGroup); query = newResult; } isBuilt = true; if (LOG.isDebugEnabled()) { SparqlQueryBuilder.LOG.debug("Query parsed as {}", query); } } return query; }
From source file:pt.fct.di.benchmarks.TPCW_Riak.database.TPCW_Riak_Executor.java
@Override public void start(WorkloadGeneratorInterface workload, BenchmarkNodeID nodeId, int operation_number, ResultHandler handler) {// w ww.ja v a 2 s . c om global_executor_counter++; executor_id = global_executor_counter; client_result_handler = handler; for (int operation = 0; operation < operation_number; operation++) { long g_init_time = System.currentTimeMillis(); try { long init_time = System.currentTimeMillis(); Operation op = workload.getNextOperation(); executeMethod(op); long end_time = System.currentTimeMillis(); client_result_handler.logResult(op.getOperation(), (end_time - init_time)); simulatedDelay = ThinkTime.getThinkTime(); if (simulatedDelay > 0) { Thread.sleep(simulatedDelay); } } catch (NoSuchFieldException e) { System.out.println("[ERROR:] THIS OPERATION DOES NOT EXIST: " + e.getMessage()); break; } catch (InterruptedException e) { System.out.println("[ERROR:] THINK TIME AFTER METHOD EXECUTION INTERRUPTED: " + e.getMessage()); break; } catch (Exception e) { e.printStackTrace(); System.out.println("-- Error : Client " + executor_id + " going down...."); break; } long end_time = System.currentTimeMillis(); counter.increment(); client_result_handler.logResult("OPERATIONS", (end_time - g_init_time)); } client_result_handler.getResulSet().put("bought", partialBought); client_result_handler.getResulSet().put("total_bought", bought_qty); client_result_handler.getResulSet().put("buying_actions", bought_actions); client_result_handler.getResulSet().put("bought_carts", bought_carts); client_result_handler.getResulSet().put("zeros", zeros); }
From source file:org.ejbca.util.CertTools.java
public static Date getNotAfter(Certificate cert) { Date ret = null;//w w w.j av a 2 s. c o m if (cert == null) { throw new IllegalArgumentException("getNotAfter: cert is null"); } if (cert instanceof X509Certificate) { X509Certificate xcert = (X509Certificate) cert; ret = xcert.getNotAfter(); } else if (StringUtils.equals(cert.getType(), "CVC")) { CardVerifiableCertificate cvccert = (CardVerifiableCertificate) cert; try { ret = cvccert.getCVCertificate().getCertificateBody().getValidTo(); } catch (NoSuchFieldException e) { // it is not uncommon that this field is missing in CVC certificate requests (it's not in the EAC standard so) log.debug("NoSuchFieldException: " + e.getMessage()); return null; } } return ret; }
From source file:org.egov.pims.service.EmployeeServiceImpl.java
public Map getMapForList(List list) { Map<Integer, String> retMap = new LinkedHashMap<Integer, String>(); try {/* w w w. ja v a2s. c o m*/ for (Iterator iter = list.iterator(); iter.hasNext();) { Object object = (Object) iter.next(); Class classObj = object.getClass(); Field id = classObj.getField("id"); Field name = classObj.getField("name"); retMap.put((Integer) id.get(object), (String) name.get(object)); } } catch (NoSuchFieldException nfe) { throw new ApplicationRuntimeException("Exception:" + nfe.getMessage(), nfe); } catch (IllegalAccessException iac) { throw new ApplicationRuntimeException("Exception:" + iac.getMessage(), iac); } return retMap; }
From source file:org.cesecore.util.CertTools.java
public static Date getNotBefore(Certificate cert) { Date ret = null;/* w w w . j a va 2 s .co m*/ if (cert == null) { throw new IllegalArgumentException("getNotBefore: cert is null"); } if (cert instanceof X509Certificate) { X509Certificate xcert = (X509Certificate) cert; ret = xcert.getNotBefore(); } else if (StringUtils.equals(cert.getType(), "CVC")) { CardVerifiableCertificate cvccert = (CardVerifiableCertificate) cert; try { ret = cvccert.getCVCertificate().getCertificateBody().getValidFrom(); } catch (NoSuchFieldException e) { // it is not uncommon that this field is missing in CVC certificate requests (it's not in the EAC standard so) log.debug("NoSuchFieldException: " + e.getMessage()); return null; } } return ret; }
From source file:org.cesecore.util.CertTools.java
public static Date getNotAfter(Certificate cert) { Date ret = null;/*www . j ava 2 s. co m*/ if (cert == null) { throw new IllegalArgumentException("getNotAfter: cert is null"); } if (cert instanceof X509Certificate) { final X509Certificate xcert = (X509Certificate) cert; ret = xcert.getNotAfter(); } else if (StringUtils.equals(cert.getType(), "CVC")) { final CardVerifiableCertificate cvccert = (CardVerifiableCertificate) cert; try { ret = cvccert.getCVCertificate().getCertificateBody().getValidTo(); } catch (NoSuchFieldException e) { // it is not uncommon that this field is missing in CVC certificate requests (it's not in the EAC standard so) if (log.isDebugEnabled()) { log.debug("NoSuchFieldException: " + e.getMessage()); } return null; } } return ret; }
From source file:org.soyatec.windowsazure.table.internal.CloudTableRest.java
/** * Deserial the xml to object accord to the give model class. * * @param partitionKey//from www . jav a 2 s . c o m * @param rowKey * @param eTag * @param timestamp * @param values * @return Instance of the given model class. */ private ITableServiceEntity createObjectByModelClass(String partitionKey, String rowKey, String eTag, String timestamp, List<ICloudTableColumn> values) { ITableServiceEntity newInstance = instanceModel(partitionKey, rowKey, eTag, timestamp, values); if (newInstance == null) { return null; } // Copy Field if (values != null && !values.isEmpty()) { for (ICloudTableColumn column : values) { Field field = null; try { field = newInstance.getClass().getDeclaredField(column.getName()); } catch (NoSuchFieldException e) { continue; } if (field == null) { continue; } int modifier = field.getModifiers(); if (Modifier.isPrivate(modifier) && Modifier.isFinal(modifier) && Modifier.isStatic(modifier)) { if (getModelClass() != null) { Logger.debug(MessageFormat.format( "{0} class {1} is a static final field. Can not set data to it.", getModelClass().getClass(), field.getName())); } continue; } boolean accessible = field.isAccessible(); if (!accessible) { field.setAccessible(true); } ETableColumnType type = column.getType(); String value = column.getValue(); if (value == null) { continue; } else { try { if (type == null) { setStringOrObjectField(newInstance, column, field, value); } else if (type.equals(ETableColumnType.TYPE_BINARY)) { field.set(newInstance, Base64.decode(value)); } else if (type.equals(ETableColumnType.TYPE_BOOL)) { field.setBoolean(newInstance, Boolean.parseBoolean(value)); } else if (type.equals(ETableColumnType.TYPE_DATE_TIME)) { field.set(newInstance, Utilities.tryGetDateTimeFromTableEntry(value)); } else if (type.equals(ETableColumnType.TYPE_DOUBLE)) { field.setDouble(newInstance, Double.parseDouble(value)); } else if (type.equals(ETableColumnType.TYPE_GUID)) { Guid guid = new Guid(); try { Field valueField = guid.getClass().getDeclaredField("value"); boolean accessiable = valueField.isAccessible(); if (!accessible) { valueField.setAccessible(true); } valueField.set(guid, value); valueField.setAccessible(accessiable); field.set(newInstance, guid); } catch (NoSuchFieldException e) { Logger.error(e.getMessage(), e); } } else if (type.equals(ETableColumnType.TYPE_INT)) { try { field.setInt(newInstance, Integer.parseInt(value)); } catch (Exception e) { field.setByte(newInstance, Byte.parseByte(value)); } } else if (type.equals(ETableColumnType.TYPE_LONG)) { field.setLong(newInstance, Long.parseLong(value)); } else if (type.equals(ETableColumnType.TYPE_STRING)) { setStringOrObjectField(newInstance, column, field, value); } } catch (Exception e) { Logger.error( MessageFormat.format("{0} class filed {1} set failed.", getModelClass(), value), e); } } // revert aaccessible field.setAccessible(accessible); } } return newInstance; }
From source file:com.hiperf.common.ui.server.storage.impl.PersistenceHelper.java
@Override public TableConfig getTableConfig(LanguageEnum language, ScreenConfig sc, EntityManager em, Map<String, Map<com.hiperf.common.ui.shared.util.Id, INakedObject>> deproxyContext) throws PersistenceException { List<HeaderInfo> list = null; List<ScreenHeaderInfo> headers = sc.getHeaders(); if (headers != null && !headers.isEmpty()) { list = new ArrayList<HeaderInfo>(); Class cl = null;// www . j a v a 2 s . co m try { cl = Class.forName(sc.getClassName()); for (ScreenHeaderInfo shi : headers) { String att = shi.getAttribute(); try { cl.getDeclaredField(att); } catch (NoSuchFieldException e) { logger.info("Field " + att + " not found"); String name = att.substring(0, 1).toUpperCase() + att.substring(1); String meth = "get" + name; try { cl.getMethod(meth); } catch (NoSuchMethodException e1) { logger.info("Method " + meth + " not found"); meth = "is" + name; try { cl.getMethod(meth); } catch (NoSuchMethodException e2) { logger.log(Level.SEVERE, "Field " + att + " not Found !!!", e2); continue; } } } String label = null; List<Label> labels = shi.getLabels(); if (labels != null && !labels.isEmpty()) { for (Label lbl : labels) { if (lbl.getLanguage().equals(language)) { label = lbl.getLabel(); break; } } } list.add(new HeaderInfo(att, label, shi.getIndex(), shi.isDisplayed(), shi.getEditable())); } } catch (ClassNotFoundException | SecurityException e) { logger.log(Level.SEVERE, "Field not Found !!!", e); throw new PersistenceException(e.getMessage()); } } List<ScreenLabels> lbls = sc.getLabels(); ScreenLabels scLbls = null; if (lbls != null && !lbls.isEmpty()) { for (ScreenLabels lbl : lbls) { if (lbl.getLanguage().equals(language)) { scLbls = lbl; break; } } } scLbls = (ScreenLabels) deproxyNakedObject(scLbls, em, deproxyContext); return new TableConfig(sc.getNbRows(), scLbls, list); }