List of usage examples for java.lang.reflect Method getGenericReturnType
public Type getGenericReturnType()
From source file:org.apache.olingo.ext.proxy.commons.AbstractStructuredInvocationHandler.java
@Override public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable { if (method.getName().startsWith("get")) { // Here need check "get"/"set" first for better get-/set- performance because // the below if-statements are really time-consuming, even twice slower than "get" body. // Assumption: for each getter will always exist a setter and viceversa. // get method annotation and check if it exists as expected final Object res; final Method getter = typeRef.getMethod(method.getName()); final Property property = ClassUtils.getAnnotation(Property.class, getter); if (property == null) { final NavigationProperty navProp = ClassUtils.getAnnotation(NavigationProperty.class, getter); if (navProp == null) { throw new UnsupportedOperationException("Unsupported method " + method.getName()); } else { // if the getter refers to a navigation property ... navigate and follow link if necessary res = getNavigationPropertyValue(navProp, getter); }//www . j a v a 2 s . co m } else { // if the getter refers to a property .... get property from wrapped entity res = getPropertyValue(property.name(), getter.getGenericReturnType()); } return res; } else if (method.getName().startsWith("set")) { // get the corresponding getter method (see assumption above) final String getterName = method.getName().replaceFirst("set", "get"); final Method getter = typeRef.getMethod(getterName); final Property property = ClassUtils.getAnnotation(Property.class, getter); if (property == null) { final NavigationProperty navProp = ClassUtils.getAnnotation(NavigationProperty.class, getter); if (navProp == null) { throw new UnsupportedOperationException("Unsupported method " + method.getName()); } else { // if the getter refers to a navigation property ... if (ArrayUtils.isEmpty(args) || args.length != 1) { throw new IllegalArgumentException("Invalid argument"); } setNavigationPropertyValue(navProp, args[0]); } } else { setPropertyValue(property, args[0]); } return ClassUtils.returnVoid(); } else if ("expand".equals(method.getName()) || "select".equals(method.getName()) || "refs".equals(method.getName())) { invokeSelfMethod(method, args); return proxy; } else if (isSelfMethod(method)) { return invokeSelfMethod(method, args); } else if ("load".equals(method.getName()) && ArrayUtils.isEmpty(args)) { load(); return proxy; } else if ("loadAsync".equals(method.getName()) && ArrayUtils.isEmpty(args)) { return service.getClient().getConfiguration().getExecutor().submit(new Callable<Object>() { @Override public Object call() throws Exception { load(); return proxy; } }); } else if ("operations".equals(method.getName()) && ArrayUtils.isEmpty(args)) { final Class<?> returnType = method.getReturnType(); return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class<?>[] { returnType }, OperationInvocationHandler.getInstance(getEntityHandler())); } else if ("annotations".equals(method.getName()) && ArrayUtils.isEmpty(args)) { final Class<?> returnType = method.getReturnType(); return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class<?>[] { returnType }, AnnotatationsInvocationHandler.getInstance(getEntityHandler(), this)); } else { throw new NoSuchMethodException(method.getName()); } }
From source file:com.evolveum.midpoint.prism.parser.PrismBeanConverter.java
private void setExplicitTypeDeclarationIfNeeded(Method getter, Object getterResult, XNode xmap, QName fieldTypeName) {/* w ww. j av a 2s. c o m*/ Class getterReturnType = getter.getReturnType(); Class getterType = null; if (Collection.class.isAssignableFrom(getterReturnType)) { Type genericReturnType = getter.getGenericReturnType(); if (genericReturnType instanceof ParameterizedType) { Type actualType = getTypeArgument(genericReturnType, "explicit type declaration"); if (actualType instanceof Class) { getterType = (Class) actualType; } } } if (getterType == null) { getterType = getterReturnType; } Class getterResultReturnType = getterResult.getClass(); if (getterType != getterResultReturnType && getterType.isAssignableFrom(getterResultReturnType)) { xmap.setExplicitTypeDeclaration(true); xmap.setTypeQName(fieldTypeName); } }
From source file:edu.ku.brc.specify.tools.datamodelgenerator.DatamodelGenerator.java
/** * @param method/*from w ww . j av a 2 s . co m*/ * @return */ protected String getReturnType(final Method method) { Class<?> classObj = method.getReturnType(); // If there is a better way, PLEASE help me! if (classObj == Set.class) { ParameterizedType type = (ParameterizedType) method.getGenericReturnType(); for (Type t : type.getActualTypeArguments()) { String cls = t.toString(); return cls.substring(6, cls.length()); } } return classObj.getName(); }
From source file:com.snaplogic.snaps.firstdata.Create.java
private ObjectSchema getSchema(SchemaProvider provider, Class<?> classType, SnapType snapType) { ArrayList<Method> getterMethods = findGetters(classType); ObjectSchema schema = null;/*from w w w .j ava2 s . c om*/ if (!getterMethods.isEmpty()) { schema = provider.createSchema(snapType, classType.getSimpleName()); } String name; String paramType; Class<?> subClass; Class<?> fieldTypeParameterType; ObjectSchema subSchema; ParameterizedType fieldGenericType; for (Method method : getterMethods) { try { paramType = method.getReturnType().getName(); if (paramType.startsWith(FD_PROXY_PKG_PREFIX) && !paramType.endsWith(TYPE)) { try { subClass = Class.forName(paramType); } catch (ClassNotFoundException e) { log.error(e.getMessage(), e); throw new ExecutionException(e.getMessage()); } subSchema = getSchema(provider, subClass, SnapType.STRING); if (subSchema != null) { schema.addChild(subSchema); } } else if (paramType.endsWith(List.class.getSimpleName())) { fieldGenericType = (ParameterizedType) method.getGenericReturnType(); fieldTypeParameterType = (Class<?>) fieldGenericType.getActualTypeArguments()[0]; if (fieldTypeParameterType == String.class) { subSchema = provider.createSchema(SnapType.COMPOSITE, getFieldName(method.getName())); } else { subSchema = getSchema(provider, fieldTypeParameterType, SnapType.COMPOSITE); } if (subSchema != null) { schema.addChild(subSchema); } } else { name = getFieldName(method.getName()); schema.addChild(provider.createSchema(getDataTypes(paramType), name)); } } catch (Exception e) { log.error(e.getMessage(), e); return null; } } return schema; }
From source file:com.flexoodb.engines.FlexJAXBDBDataEngine2.java
public Collection<Object> runQuery(String query, Class c, boolean usedefaultimplementation) throws Exception { Vector v = new Vector(); Connection conn = null;/* w w w . ja v a 2s . com*/ try { conn = (Connection) _pool.getConnection(); String tablename = query.split("\\s")[3]; // always search the index! if (checkTable(tablename, conn, false)) { StringBuffer q = new StringBuffer("where "); if (query.toUpperCase().indexOf("WHERE") > 0) { String sub = query.substring(query.toUpperCase().indexOf("WHERE") + 5); sub = sub.replaceAll("<=", " <eq; "); sub = sub.replaceAll(">=", " >eq; "); sub = sub.replaceAll("<>", " &nteq; "); sub = sub.replaceAll("=", " = "); sub = sub.replaceAll(">", " > "); sub = sub.replaceAll("<", " < "); sub = sub.replaceAll("<eq;", "<="); sub = sub.replaceAll(">eq;", ">="); sub = sub.replaceAll("&nteq;", "<>").trim(); //System.out.println("from:"+sub); boolean done = false; boolean id = false; int seq = 0; String col = null; String condition = null; while (!done) { int x = sub.indexOf(" "); String word = sub.substring(0, x < 0 ? sub.length() : x); int wlen = word.length(); if (word.startsWith("'")) { word = sub.substring(1, sub.indexOf("'", 1)); wlen = word.length() + 2; } //System.out.println("w:"+word+"< "+wlen+" wl:"+word.length()); // check if its a predicate if (":like:=:>:<:<=:>=:<>:".indexOf(":" + word.toLowerCase() + ":") > -1) { condition = word; seq = 2; } else if (":and:or:not:".indexOf(":" + word.toLowerCase() + ":") > -1) { q.append(" " + word.trim() + " "); seq = 0; } else if (seq == 0)// it must be a field! { seq = 1; // fields sequence if (word.trim().equalsIgnoreCase("parentid") || word.trim().equalsIgnoreCase("id")) { q.append(" " + word.trim()); id = true; } else if (word.trim().equalsIgnoreCase("order")) { String[] order = sub.split("\\s"); if (!order[2].equalsIgnoreCase("id") && !order[2].equalsIgnoreCase("parentid")) { // get the 3rd word -- ie the field if (!q.toString().toUpperCase().endsWith("WHERE")) { q.append(" and "); } q.append(" (element='" + order[2] + "')"); q.append(" " + order[0] + " by value " + sub.substring(sub.indexOf(order[2]) + order[2].length()).trim()); } else { q.append(" " + sub); } done = true; } else if (word.trim().equalsIgnoreCase("element") || word.trim().equalsIgnoreCase("limit") || word.trim().equalsIgnoreCase("desc") || word.trim().equalsIgnoreCase("asc")) { q.append(" " + sub); done = true; } else { word = word.replaceAll("'", "\'").trim(); //q.append(" (element='"+word.trim().replaceAll("'","")+"'"); q.append(" (element='" + word + "'"); //col = word.trim().replaceAll("'",""); col = word; } } else if (seq == 2) { //word = word.replaceAll("'"," "); word = word.replaceAll("'", "\'"); if (id) { q.append("" + condition + "'" + word.trim() + "'"); } else { boolean valchanged = false; try { // we look for dates! if (col != null) { Method met = c.getMethod( "get" + col.substring(0, 1).toUpperCase() + col.substring(1), (Class[]) null); Class c1 = (Class) met.getGenericReturnType(); if (c1.getSimpleName().equalsIgnoreCase("XMLGregorianCalendar") && !word.isEmpty()) { //q.append(" and str_to_date(value,\"%Y-%m-%d\") "+condition+" '"+word.trim().replaceAll("'","")+"')"); q.append(" and str_to_date(value,\"%Y-%m-%d\") " + condition + " '" + word.trim() + "')"); valchanged = true; } } } catch (Exception e) { e.printStackTrace(); } if (!valchanged) { //q.append(" and value "+condition+" '"+word.trim().replaceAll("'","")+"')"); q.append(" and value " + condition + " '" + word.trim() + "')"); } col = null; } seq = 0; condition = null; id = false; } sub = sub.substring(wlen).trim(); if (x < 0 || sub.length() == 0) { done = true; } } } else { int tl = tablename.length(); q = new StringBuffer(query.substring(query.indexOf(tablename) + tl)); } PreparedStatement ps = null; boolean searchindex = false; if (!usedefaultimplementation) { ps = (PreparedStatement) conn.prepareStatement( "select distinct id from " + tablename.toLowerCase() + " " + q.toString()); } else { ps = (PreparedStatement) conn.prepareStatement( "select distinct id from " + tablename.toLowerCase() + "_index " + q.toString()); searchindex = true; } System.out.println(">>>Query:" + ps.toString() + "<<< " + usedefaultimplementation); ResultSet rec = ps.executeQuery(); // check if a record was found while (rec != null && !rec.isClosed() && rec.next()) { String id = rec.getString("id"); try { Object o = null; PreparedStatement ps2 = (PreparedStatement) conn .prepareStatement("select id,parentid,content from " + tablename.toLowerCase() + " where id='" + id + "'"); ResultSet res = ps2.executeQuery(); // check if a record was found if (res != null && res.next()) { String i = res.getString("id"); String p = res.getString("parentid"); o = new FlexContainer(_flexutils.getObject(res.getString("content"), c)); ((FlexContainer) o).setId(i); ((FlexContainer) o).setParentId(p); ps2.close(); } else { ps2.close(); if (searchindex) { // then the values found must be orphans! we delete the index contents removeValues(id, tablename, conn); } } if (o != null) { v.add(o); Enumeration en = v.elements(); while (en.hasMoreElements()) { en.nextElement(); } } } catch (Exception g) { throw g; } } } } catch (Exception f) { throw f; } finally { try { if (conn != null) { _pool.releaseConnection(conn); } } catch (Exception g) { } } return v; }
From source file:com.xwtec.xwserver.util.json.JSONArray.java
/** * Get the collection type from a getter or setter, or null if no type was * found.<br/>/*from w w w.j ava 2s . c om*/ * Contributed by [Matt Small @ WaveMaker]. */ public static Class[] getCollectionType(PropertyDescriptor pd, boolean useGetter) throws JSONException { Type type; if (useGetter) { Method m = pd.getReadMethod(); type = m.getGenericReturnType(); } else { Method m = pd.getWriteMethod(); Type[] gpts = m.getGenericParameterTypes(); if (1 != gpts.length) { throw new JSONException("method " + m + " is not a standard setter"); } type = gpts[0]; } if (!(type instanceof ParameterizedType)) { return null; // throw new JSONException("type not instanceof ParameterizedType: // "+type.getClass()); } ParameterizedType pType = (ParameterizedType) type; Type[] actualTypes = pType.getActualTypeArguments(); Class[] ret = new Class[actualTypes.length]; for (int i = 0; i < ret.length; i++) { ret[i] = (Class) actualTypes[i]; } return ret; }
From source file:com.flexoodb.engines.FlexJAXBDBDataEngine.java
public Collection<Object> runQuery(String query, Class c, boolean usedefaultimplementation) throws Exception { Vector v = new Vector(); Connection conn = null;/*from w w w .j a v a 2s . c o m*/ try { //System.out.println(">>>>orginal:["+query+"]"); conn = (Connection) _pool.getConnection(); String tablename = query.split("\\s")[3]; // always search the index! if (checkTable(tablename, conn, false)) { StringBuffer q = new StringBuffer("where "); if (query.toUpperCase().indexOf("WHERE") > 0) { String sub = query.substring(query.toUpperCase().indexOf("WHERE") + 5); sub = sub.replaceAll("<=", " <eq; "); sub = sub.replaceAll(">=", " >eq; "); sub = sub.replaceAll("<>", " &nteq; "); sub = sub.replaceAll("=", " = "); sub = sub.replaceAll(">", " > "); sub = sub.replaceAll("<", " < "); sub = sub.replaceAll("<eq;", "<="); sub = sub.replaceAll(">eq;", ">="); sub = sub.replaceAll("&nteq;", "<>").trim(); sub = sub.replaceAll("<", "<"); sub = sub.replaceAll(">", ">"); //System.out.println("from:"+sub); boolean done = false; boolean id = false; int seq = 0; String col = null; String condition = null; while (!done) { int x = sub.indexOf(" "); String word = sub.substring(0, x < 0 ? sub.length() : x); int wlen = word.length(); if (word.startsWith("'")) { word = sub.substring(1, sub.indexOf("'", 1)); wlen = word.length() + 2; } //System.out.println("w:"+word+"< "+wlen+" wl:"+word.length()); // check if its a predicate if (":like:=:>:<:<=:>=:<>:".indexOf(":" + word.toLowerCase() + ":") > -1) { condition = word; seq = 2; } else if (":and:or:not:".indexOf(":" + word.toLowerCase() + ":") > -1) { q.append(" " + word.trim() + " "); seq = 0; } else if (seq == 0)// it must be a field! { seq = 1; // fields sequence if (word.trim().equalsIgnoreCase("parentid") || word.trim().equalsIgnoreCase("id")) { q.append(" " + word.trim()); id = true; } else if (word.trim().equalsIgnoreCase("order")) { String[] order = sub.split("\\s"); if (!order[2].equalsIgnoreCase("id") && !order[2].equalsIgnoreCase("parentid")) { // get the 3rd word -- ie the field if (!q.toString().toUpperCase().endsWith("WHERE")) { q.append(" and "); } q.append(" (element='" + order[2] + "')"); q.append(" " + order[0] + " by value " + sub.substring(sub.indexOf(order[2]) + order[2].length()).trim()); } else { q.append(" " + sub); } done = true; } else if (word.trim().equalsIgnoreCase("element") || word.trim().equalsIgnoreCase("limit") || word.trim().equalsIgnoreCase("desc") || word.trim().equalsIgnoreCase("asc")) { q.append(" " + sub); done = true; } else { word = word.replaceAll("'", "\'").trim(); //q.append(" (element='"+word.trim().replaceAll("'","")+"'"); q.append(" (element='" + word + "'"); //col = word.trim().replaceAll("'",""); col = word; } } else if (seq == 2) { //word = word.replaceAll("'"," "); word = word.replaceAll("'", "\'"); if (id) { q.append("" + condition + "'" + word.trim() + "'"); } else { boolean valchanged = false; try { // we look for dates! if (col != null) { Method met = c.getMethod( "get" + col.substring(0, 1).toUpperCase() + col.substring(1), (Class[]) null); Class c1 = (Class) met.getGenericReturnType(); if (c1.getSimpleName().equalsIgnoreCase("XMLGregorianCalendar") && !word.isEmpty()) { //q.append(" and str_to_date(value,\"%Y-%m-%d\") "+condition+" '"+word.trim().replaceAll("'","")+"')"); q.append(" and str_to_date(value,\"%Y-%m-%d\") " + condition + " '" + word.trim() + "')"); valchanged = true; } } } catch (Exception e) { e.printStackTrace(); } if (!valchanged) { //q.append(" and value "+condition+" '"+word.trim().replaceAll("'","")+"')"); q.append(" and value " + condition + " '" + word.trim() + "')"); } col = null; } seq = 0; condition = null; id = false; } sub = sub.substring(wlen).trim(); if (x < 0 || sub.length() == 0) { done = true; } } } else { int tl = tablename.length(); q = new StringBuffer(query.substring(query.indexOf(tablename) + tl)); } PreparedStatement ps = null; boolean searchindex = false; if (!usedefaultimplementation) { ps = (PreparedStatement) conn.prepareStatement( "select distinct id from " + tablename.toLowerCase() + " " + q.toString()); } else { ps = (PreparedStatement) conn.prepareStatement( "select distinct id from " + tablename.toLowerCase() + "_index " + q.toString()); searchindex = true; } ResultSet rec = ps.executeQuery(); //System.out.println(">>>Query:["+ps.toString()+"]"); // check if a record was found while (rec != null && !rec.isClosed() && rec.next()) { String id = rec.getString("id"); String xml = null; try { Object o = null; PreparedStatement ps2 = (PreparedStatement) conn .prepareStatement("select id,parentid,content from " + tablename.toLowerCase() + " where id='" + id + "'"); ResultSet res = ps2.executeQuery(); // check if a record was found if (res != null && res.next()) { String i = res.getString("id"); String p = res.getString("parentid"); xml = res.getString("content"); o = new FlexContainer(_flexutils.getObject(FlexUtils.stripNonValidChars(xml), c)); ((FlexContainer) o).setId(i); ((FlexContainer) o).setParentId(p); ps2.close(); } else { ps2.close(); if (searchindex) { // then the values found must be orphans! we delete the index contents removeValues(id, tablename, conn); } } if (o != null) { v.add(o); Enumeration en = v.elements(); while (en.hasMoreElements()) { en.nextElement(); } } } catch (Exception g) { g.printStackTrace(); System.out.println(">>>FlexJAXDBDataEngine Error due to XML:" + xml); throw g; } } } } catch (Exception f) { f.printStackTrace(); throw f; } finally { try { if (conn != null) { _pool.releaseConnection(conn); } } catch (Exception g) { } } return v; }
From source file:com.flexoodb.engines.FlexJAXBDBDataEngine.java
public Collection<Object> runQuery2(String query, Class c, boolean usedefaultimplementation) throws Exception { Vector v = new Vector(); Connection conn = null;/*from www.ja v a2 s . c o m*/ try { conn = (Connection) _pool.getConnection(); String tablename = query.split("\\s")[3]; // always search the index! if (checkTable(tablename, conn, false)) { StringBuffer q = new StringBuffer("where "); boolean hasid = false; if (query.toUpperCase().indexOf("WHERE") > 0) { String sub = query.substring(query.toUpperCase().indexOf("WHERE") + 5); sub = sub.replaceAll("<=", " <eq; "); sub = sub.replaceAll(">=", " >eq; "); sub = sub.replaceAll("<>", " &nteq; "); sub = sub.replaceAll("=", " = "); sub = sub.replaceAll(">", " > "); sub = sub.replaceAll("<", " < "); sub = sub.replaceAll("<eq;", "<="); sub = sub.replaceAll(">eq;", ">="); sub = sub.replaceAll("&nteq;", "<>").trim(); //System.out.println("from:"+sub); boolean done = false; boolean id = false; int seq = 0; String col = null; String condition = null; while (!done) { int x = sub.indexOf(" "); String word = sub.substring(0, x < 0 ? sub.length() : x); int wlen = word.length(); if (word.startsWith("'")) { word = sub.substring(1, sub.indexOf("'", 1)); wlen = word.length() + 2; } //System.out.println("w:"+word+"< "+wlen+" wl:"+word.length()); // check if its a predicate if (":like:=:>:<:<=:>=:<>:".indexOf(":" + word.toLowerCase() + ":") > -1) { condition = word; seq = 2; } else if (":and:or:not:".indexOf(":" + word.toLowerCase() + ":") > -1) { q.append(" " + word.trim() + " "); seq = 0; } else if (seq == 0)// it must be a field! { seq = 1; // fields sequence if (word.trim().equalsIgnoreCase("parentid") || word.trim().equalsIgnoreCase("id")) { q.append(" _a." + word.trim()); id = true; hasid = true; } else if (word.trim().equalsIgnoreCase("order")) { String[] order = sub.split("\\s"); if (!order[2].equalsIgnoreCase("id") && !order[2].equalsIgnoreCase("parentid")) { // get the 3rd word -- ie the field if (!q.toString().toUpperCase().endsWith("WHERE")) { q.append(" and "); } q.append(" (_b.element='" + order[2] + "')"); q.append(" " + order[0] + " by _b.value " + sub.substring(sub.indexOf(order[2]) + order[2].length()).trim()); } else { q.append(" " + sub); } done = true; } else if (word.trim().equalsIgnoreCase("element") || word.trim().equalsIgnoreCase("limit") || word.trim().equalsIgnoreCase("desc") || word.trim().equalsIgnoreCase("asc")) { q.append(" " + sub); done = true; } else { word = word.replaceAll("'", "\'").trim(); //q.append(" (element='"+word.trim().replaceAll("'","")+"'"); q.append(" (_b.element='" + word + "'"); //col = word.trim().replaceAll("'",""); col = word; } } else if (seq == 2) { //word = word.replaceAll("'"," "); word = word.replaceAll("'", "\'"); if (id) { q.append("" + condition + "'" + word.trim() + "' and _a.id=_b.id "); } else { boolean valchanged = false; try { // we look for dates! if (col != null) { Method met = c.getMethod( "get" + col.substring(0, 1).toUpperCase() + col.substring(1), (Class[]) null); Class c1 = (Class) met.getGenericReturnType(); if (c1.getSimpleName().equalsIgnoreCase("XMLGregorianCalendar") && !word.isEmpty()) { //q.append(" and str_to_date(value,\"%Y-%m-%d\") "+condition+" '"+word.trim().replaceAll("'","")+"')"); q.append(" and str_to_date(_b.value,\"%Y-%m-%d\") " + condition + " '" + word.trim() + "')"); valchanged = true; } } } catch (Exception e) { e.printStackTrace(); } if (!valchanged) { //q.append(" and value "+condition+" '"+word.trim().replaceAll("'","")+"')"); q.append(" and _b.value " + condition + " '" + word.trim() + "')"); } col = null; } seq = 0; condition = null; id = false; } sub = sub.substring(wlen).trim(); if (x < 0 || sub.length() == 0) { done = true; } } // restructure query with parenthesis int i = q.toString().indexOf("_a.id=_b.id and"); if (i > 0) { String qf = q.toString(); qf = qf.substring(0, i + 16) + " (" + qf.substring(i + 17).trim() + ")"; q = new StringBuffer(qf); } } else { int tl = tablename.length(); q = new StringBuffer(query.substring(query.indexOf(tablename) + tl)); } PreparedStatement ps = null; boolean searchindex = false; System.out.println(">>>>111"); String stmt = "select distinct " + (hasid ? "_a" : "_b") + ".id from " + tablename.toLowerCase() + " _a, " + tablename.toLowerCase() + "_index _b " + q.toString(); System.out.println(">>>>" + stmt); ps = (PreparedStatement) conn.prepareStatement(stmt); if (!usedefaultimplementation) { //ps = (PreparedStatement) conn.prepareStatement("select distinct a.id from "+tablename.toLowerCase()+" a, "+tablename.toLowerCase()+"_index b "+q.toString()); } else { //ps = (PreparedStatement) conn.prepareStatement("select distinct a.id from "+tablename.toLowerCase()+"_index a"+q.toString()); searchindex = true; } if (_showsql) { System.out.println(this.getClass().getName() + " SQL Query:>" + ps.toString() + "<<"); } ResultSet rec = ps.executeQuery(); // check if a record was found while (rec != null && !rec.isClosed() && rec.next()) { String id = rec.getString("id"); try { Object o = null; PreparedStatement ps2 = (PreparedStatement) conn .prepareStatement("select id,parentid,content from " + tablename.toLowerCase() + " where id='" + id + "'"); ResultSet res = ps2.executeQuery(); // check if a record was found if (res != null && res.next()) { String i = res.getString("id"); String p = res.getString("parentid"); o = new FlexContainer(_flexutils.getObject(res.getString("content"), c)); ((FlexContainer) o).setId(i); ((FlexContainer) o).setParentId(p); ps2.close(); } else { ps2.close(); if (searchindex) { // then the values found must be orphans! we delete the index contents removeValues(id, tablename, conn); } } if (o != null) { v.add(o); Enumeration en = v.elements(); while (en.hasMoreElements()) { en.nextElement(); } } } catch (Exception g) { throw g; } } } } catch (Exception f) { throw f; } finally { try { if (conn != null) { _pool.releaseConnection(conn); } } catch (Exception g) { } } return v; }
From source file:org.castor.jaxb.reflection.ClassInfoBuilder.java
/** * Build the FieldInfo for a Method./*w w w .ja va2 s.c o m*/ * * @param classInfo * the ClassInfo to look in if this field already exists * @param method * the Method to describe * @return the ClassInfo containing the FieldInfo build */ private void buildFieldInfo(final ClassInfo classInfo, final Method method) { if (classInfo == null) { String message = "Argument classInfo must not be null."; LOG.warn(message); throw new IllegalArgumentException(message); } if (method == null) { String message = "Argument method must not be null."; LOG.warn(message); throw new IllegalArgumentException(message); } String fieldName = javaNaming.extractFieldNameFromMethod(method); FieldInfo fieldInfo = classInfo.getFieldInfo(fieldName); if (fieldInfo == null) { fieldInfo = createFieldInfo(fieldName); classInfo.addFieldInfo(fieldInfo); fieldInfo.setParentClassInfo(classInfo); } JaxbFieldNature jaxbFieldNature = new JaxbFieldNature(fieldInfo); if (javaNaming.isAddMethod(method)) { jaxbFieldNature.setMethodAdd(method); jaxbFieldNature.setMultivalued(true); } else if (javaNaming.isCreateMethod(method)) { jaxbFieldNature.setMethodCreate(method); } else if (javaNaming.isGetMethod(method)) { jaxbFieldNature.setMethodGet(method); handleMultivaluedness(method.getReturnType(), jaxbFieldNature, method.getGenericReturnType()); } else if (javaNaming.isSetMethod(method)) { jaxbFieldNature.setMethodSet(method); Class<?>[] parameterTypes = method.getParameterTypes(); if (parameterTypes.length == 1) { handleMultivaluedness(parameterTypes[0], jaxbFieldNature, method.getGenericParameterTypes()[0]); } } else if (javaNaming.isIsMethod(method)) { jaxbFieldNature.setMethodIs(method); } else { if (LOG.isDebugEnabled()) { String message = "Method: " + method + " is of unsupported type and ignored."; LOG.debug(message); } } fieldAnnotationProcessingService.processAnnotations(jaxbFieldNature, method.getAnnotations()); }
From source file:com.bstek.dorado.config.xml.XmlParserHelper.java
protected void doInitObjectParser(Context context, ObjectParser objectParser, XmlNodeInfo xmlNodeInfo, Class<?> beanType) throws Exception { objectParser.setAnnotationOwnerType(beanType); if (!Modifier.isAbstract(beanType.getModifiers())) { objectParser.setImpl(beanType.getName()); }/*from w w w . ja va2 s .co m*/ if (xmlNodeInfo != null) { if (StringUtils.isNotEmpty(xmlNodeInfo.getDefinitionType())) { objectParser.setDefinitionType(xmlNodeInfo.getDefinitionType()); } Map<String, XmlParser> propertyParsers = objectParser.getPropertyParsers(); Map<String, XmlParser> subParsers = objectParser.getSubParsers(); if (!(objectParser instanceof CompositePropertyParser)) { boolean inheritable = objectParser.isInheritable() || xmlNodeInfo.isInheritable(); objectParser.setInheritable(inheritable); if (inheritable) { if (propertyParsers.get("parent") == null) { objectParser.registerPropertyParser("parent", beanFactory.getBean(IGNORE_PARSER, XmlParser.class)); } } boolean scopable = objectParser.isScopable() || xmlNodeInfo.isScopable(); objectParser.setScopable(scopable); if (scopable) { if (propertyParsers.get("scope") == null) { objectParser.registerPropertyParser("scope", beanFactory.getBean(IGNORE_PARSER, XmlParser.class)); } } for (String fixedProperty : xmlNodeInfo.getFixedProperties().keySet()) { if (propertyParsers.get(fixedProperty) == null) { objectParser.registerPropertyParser(fixedProperty, beanFactory.getBean(IGNORE_PARSER, XmlParser.class)); } } } for (XmlSubNode xmlSubNode : xmlNodeInfo.getSubNodes()) { if (StringUtils.isNotEmpty(xmlSubNode.propertyType())) { List<XmlParserInfo> xmlParserInfos = getSubNodeXmlParserInfos(context, beanType, xmlSubNode.propertyName(), null, xmlSubNode); if (xmlParserInfos != null) { for (XmlParserInfo xmlParserInfo : xmlParserInfos) { objectParser.registerSubParser(xmlParserInfo.getPath(), xmlParserInfo.getParser()); } } } else if (StringUtils.isNotEmpty(xmlSubNode.nodeName()) && StringUtils.isNotEmpty(xmlSubNode.parser())) { BeanWrapper beanWrapper = BeanFactoryUtils.getBean(xmlSubNode.parser(), Scope.instant); objectParser.registerSubParser(xmlSubNode.nodeName(), (XmlParser) beanWrapper.getBean()); } } for (Map.Entry<String, XmlProperty> entry : xmlNodeInfo.getProperties().entrySet()) { XmlProperty xmlProperty = entry.getValue(); XmlParserInfo xmlParserInfo = getPropertyXmlParserInfo(context, beanType, xmlProperty.propertyName(), null, xmlProperty); if (xmlParserInfo != null) { objectParser.registerPropertyParser(xmlParserInfo.getPath(), xmlParserInfo.getParser()); } } if (ClientEventSupported.class.isAssignableFrom(beanType) && subParsers.get("ClientEvent") == null) { objectParser.registerSubParser("ClientEvent", beanFactory.getBean(CLIENT_EVENT_PARSER, XmlParser.class)); } } PropertyDescriptor[] propertyDescriptors = PropertyUtils.getPropertyDescriptors(beanType); for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { String propertyName = propertyDescriptor.getName(); if ("class".equals(propertyName)) { continue; } Method readMethod = propertyDescriptor.getReadMethod(); if (readMethod == null) { continue; } if (readMethod.getDeclaringClass() != beanType) { try { readMethod = beanType.getMethod(readMethod.getName(), readMethod.getParameterTypes()); } catch (NoSuchMethodException e) { // do nothing } } TypeInfo typeInfo; Class<?> propertyType = propertyDescriptor.getPropertyType(); if (Collection.class.isAssignableFrom(propertyType)) { typeInfo = TypeInfo.parse((ParameterizedType) readMethod.getGenericReturnType(), true); propertyType = typeInfo.getType(); } else { typeInfo = new TypeInfo(propertyType, false); } XmlSubNode xmlSubNode = readMethod.getAnnotation(XmlSubNode.class); if (xmlSubNode != null) { if (StringUtils.isNotEmpty(xmlSubNode.propertyName())) { throw new IllegalArgumentException("@XmlSubNode.propertyName should be empty. [" + beanType.getName() + '#' + propertyName + "]"); } List<XmlParserInfo> xmlParserInfos = getSubNodeXmlParserInfos(context, beanType, propertyName, typeInfo, xmlSubNode); if (xmlParserInfos != null) { for (XmlParserInfo xmlParserInfo : xmlParserInfos) { objectParser.registerSubParser(xmlParserInfo.getPath(), xmlParserInfo.getParser()); } } } else { XmlProperty xmlProperty = readMethod.getAnnotation(XmlProperty.class); if (xmlProperty != null && StringUtils.isNotEmpty(xmlProperty.propertyName())) { throw new IllegalArgumentException("@XmlProperty.propertyName should be empty. [" + beanType.getName() + '#' + propertyName + "]"); } XmlParserInfo xmlParserInfo = getPropertyXmlParserInfo(context, beanType, propertyName, typeInfo, xmlProperty); if (xmlParserInfo != null) { XmlParser parser = xmlParserInfo.getParser(); if (parser instanceof TextPropertyParser) { TextPropertyParser textPropertyParser = (TextPropertyParser) parser; if (textPropertyParser.getTextParser() == null) { TextParser textParser = textParserHelper.getTextParser(propertyType); textPropertyParser.setTextParser(textParser); } } objectParser.registerPropertyParser(xmlParserInfo.getPath(), parser); } } } if (objectParser instanceof ObjectParserInitializationAware) { ((ObjectParserInitializationAware) objectParser).postObjectParserInitialized(objectParser); } Map<String, XmlParserHelperListener> listenerMap = ((ListableBeanFactory) beanFactory) .getBeansOfType(XmlParserHelperListener.class); for (XmlParserHelperListener listener : listenerMap.values()) { listener.onInitParser(this, objectParser, beanType); } }