List of usage examples for java.lang Class isPrimitive
@HotSpotIntrinsicCandidate public native boolean isPrimitive();
From source file:com.mystudy.source.spring.aop.JdkDynamicAopProxy.java
/** * //from w ww . j ava 2 s. com */ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { MethodInvocation invocation; Object oldProxy = null; boolean setProxyContext = false; TargetSource targetSource = this.advised.targetSource; Class<?> targetClass = null; Object target = null; try {//eqal if (!this.equalsDefined && AopUtils.isEqualsMethod(method)) { // The target does not implement the equals(Object) method itself. return equals(args[0]); } //hashcode if (!this.hashCodeDefined && AopUtils.isHashCodeMethod(method)) { // The target does not implement the hashCode() method itself. return hashCode(); } if (!this.advised.opaque && method.getDeclaringClass().isInterface() && method.getDeclaringClass().isAssignableFrom(Advised.class)) { // Service invocations on ProxyConfig with the proxy config... return AopUtils.invokeJoinpointUsingReflection(this.advised, method, args); } Object retVal; if (this.advised.exposeProxy) { // Make invocation available if necessary. oldProxy = AopContext.setCurrentProxy(proxy); setProxyContext = true; } // May be null. Get as late as possible to minimize the time we "own" the target, // in case it comes from a pool. target = targetSource.getTarget(); if (target != null) { targetClass = target.getClass(); } // Get the interception chain for this method. List<Object> chain = this.advised.getInterceptorsAndDynamicInterceptionAdvice(method, targetClass); // Check whether we have any advice. If we don't, we can fallback on direct // reflective invocation of the target, and avoid creating a MethodInvocation. if (chain.isEmpty()) { // We can skip creating a MethodInvocation: just invoke the target directly // Note that the final invoker must be an InvokerInterceptor so we know it does // nothing but a reflective operation on the target, and no hot swapping or fancy proxying. retVal = AopUtils.invokeJoinpointUsingReflection(target, method, args); } else { //chain???? // We need to create a method invocation... invocation = new ReflectiveMethodInvocation(proxy, target, method, args, targetClass, chain); // Proceed to the joinpoint through the interceptor chain. retVal = invocation.proceed(); } // Massage return value if necessary. Class<?> returnType = method.getReturnType(); if (retVal != null && retVal == target && returnType.isInstance(proxy) && !RawTargetAccess.class.isAssignableFrom(method.getDeclaringClass())) { // Special case: it returned "this" and the return type of the method // is type-compatible. Note that we can't help if the target sets // a reference to itself in another returned object. retVal = proxy; } else if (retVal == null && returnType != Void.TYPE && returnType.isPrimitive()) { throw new AopInvocationException( "Null return value from advice does not match primitive return type for: " + method); } return retVal; } finally { if (target != null && !targetSource.isStatic()) { // Must have come from TargetSource. targetSource.releaseTarget(target); } if (setProxyContext) { // Restore old proxy. AopContext.setCurrentProxy(oldProxy); } } }
From source file:ResultSetIterator.java
/** * Convert a <code>ResultSet</code> column into an object. Simple * implementations could just call <code>rs.getObject(index)</code> while * more complex implementations could perform type manipulation to match * the column's type to the bean property type. * //from w w w . ja v a 2s . c o m * <p> * This implementation calls the appropriate <code>ResultSet</code> getter * method for the given property type to perform the type conversion. If * the property type doesn't match one of the supported * <code>ResultSet</code> types, <code>getObject</code> is called. * </p> * * @param rs The <code>ResultSet</code> currently being processed. It is * positioned on a valid row before being passed into this method. * * @param index The current column index being processed. * * @param propType The bean property type that this column needs to be * converted into. * * @throws SQLException if a database access error occurs * * @return The object from the <code>ResultSet</code> at the given column * index after optional type processing or <code>null</code> if the column * value was SQL NULL. */ protected Object processColumn(ResultSet rs, int index, Class propType) throws SQLException { if (!propType.isPrimitive() && rs.getObject(index) == null) { return null; } if (propType.equals(String.class)) { return rs.getString(index); } else if (propType.equals(Integer.TYPE) || propType.equals(Integer.class)) { return new Integer(rs.getInt(index)); } else if (propType.equals(Boolean.TYPE) || propType.equals(Boolean.class)) { return new Boolean(rs.getBoolean(index)); } else if (propType.equals(Long.TYPE) || propType.equals(Long.class)) { return new Long(rs.getLong(index)); } else if (propType.equals(Double.TYPE) || propType.equals(Double.class)) { return new Double(rs.getDouble(index)); } else if (propType.equals(Float.TYPE) || propType.equals(Float.class)) { return new Float(rs.getFloat(index)); } else if (propType.equals(Short.TYPE) || propType.equals(Short.class)) { return new Short(rs.getShort(index)); } else if (propType.equals(Byte.TYPE) || propType.equals(Byte.class)) { return new Byte(rs.getByte(index)); } else if (propType.equals(Timestamp.class)) { return rs.getTimestamp(index); } else { return rs.getObject(index); } }
From source file:edu.cmu.tetrad.util.TetradSerializableUtils.java
/** * Checks all of the classes in the serialization scope that implement * TetradSerializable to make sure all of their fields are either themselves * (a) primitive, (b) TetradSerializable, or (c) assignable from types * designated as safely serializable by virtue of being included in the * safelySerializableTypes array (see), or are arrays whose lowest order * component types satisfy either (a), (b), or (c). Safely serializable * classes in the Java API currently include collections classes, plus * String and Class. Collections classes are included, since their types * will be syntactically checkable in JDK 1.5. String and Class are members * of a broader type of Class whose safely can by checked by making sure * there is no way to pass into them via constructor or method argument any * object that is not TetradSerializable or safely serializable. But it's * easy enough now to just make a list.//w w w . java2s. c o m * * @see #safelySerializableTypes */ public void checkNestingOfFields() { List classes = getAssignableClasses(new File(getSerializableScope()), TetradSerializable.class); boolean foundUnsafeField = false; for (Object aClass : classes) { Class clazz = (Class) aClass; if (TetradSerializableExcluded.class.isAssignableFrom(clazz)) { continue; } Field[] fields = clazz.getDeclaredFields(); FIELDS: for (Field field : fields) { // System.out.println(field); if (Modifier.isTransient(field.getModifiers())) { continue; } if (Modifier.isStatic(field.getModifiers())) { continue; } Class type = field.getType(); while (type.isArray()) { type = type.getComponentType(); } if (type.isPrimitive()) { continue; } if (type.isEnum()) { continue; } // // Printing out Collections fields temporarily. // if (Collection.class.isAssignableFrom(type)) { // System.out.println("COLLECTION FIELD: " + field); // } // // if (Map.class.isAssignableFrom(type)) { // System.out.println("MAP FIELD: " + field); // } if (TetradSerializable.class.isAssignableFrom(type) && !TetradSerializableExcluded.class.isAssignableFrom(clazz)) { continue; } for (Class safelySerializableClass : safelySerializableTypes) { if (safelySerializableClass.isAssignableFrom(type)) { continue FIELDS; } } // A reference in an inner class to the outer class. if (field.getName().equals("this$0")) { continue; } System.out.println("UNSAFE FIELD:" + field); foundUnsafeField = true; } } if (foundUnsafeField) { throw new RuntimeException("Unsafe serializable fields found. Please " + "fix immediately."); } }
From source file:com.strider.datadefender.DatabaseAnonymizer.java
/** * Calls the anonymization function for the given Column, and returns its * anonymized value./*w w w . j a v a2s. c om*/ * * @param dbConn * @param row * @param column * @return * @throws NoSuchMethodException * @throws SecurityException * @throws IllegalAccessException * @throws IllegalArgumentException * @throws InvocationTargetException */ private Object callAnonymizingFunctionWithParameters(final Connection dbConn, final ResultSet row, final Column column, final String vendor) throws SQLException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { final String function = column.getFunction(); if (function == null || function.equals("")) { log.warn("Function is not defined for column [" + column + "]. Moving to the next column."); return ""; } try { final String className = Utils.getClassName(function); final String methodName = Utils.getMethodName(function); final Class<?> clazz = Class.forName(className); final CoreFunctions instance = (CoreFunctions) Class.forName(className).newInstance(); instance.setDatabaseConnection(dbConn); instance.setVendor(vendor); final List<Parameter> parms = column.getParameters(); final Map<String, Object> paramValues = new HashMap<>(parms.size()); final String columnValue = row.getString(column.getName()); for (final Parameter param : parms) { if (param.getValue().equals("@@value@@")) { paramValues.put(param.getName(), columnValue); } else if (param.getValue().equals("@@row@@") && param.getType().equals("java.sql.ResultSet")) { paramValues.put(param.getName(), row); } else { paramValues.put(param.getName(), param.getTypeValue()); } } final List<Object> fnArguments = new ArrayList<>(parms.size()); final Method[] methods = clazz.getMethods(); Method selectedMethod = null; methodLoop: for (final Method m : methods) { if (m.getName().equals(methodName) && m.getReturnType() == String.class) { log.debug(" Found method: " + m.getName()); log.debug(" Match w/: " + paramValues); final java.lang.reflect.Parameter[] mParams = m.getParameters(); fnArguments.clear(); for (final java.lang.reflect.Parameter par : mParams) { //log.debug(" Name present? " + par.isNamePresent()); // Note: requires -parameter compiler flag log.debug(" Real param: " + par.getName()); if (!paramValues.containsKey(par.getName())) { continue methodLoop; } final Object value = paramValues.get(par.getName()); Class<?> fnParamType = par.getType(); final Class<?> confParamType = (value == null) ? fnParamType : value.getClass(); if (fnParamType.isPrimitive() && value == null) { continue methodLoop; } if (ClassUtils.isPrimitiveWrapper(confParamType)) { if (!ClassUtils.isPrimitiveOrWrapper(fnParamType)) { continue methodLoop; } fnParamType = ClassUtils.primitiveToWrapper(fnParamType); } if (!fnParamType.equals(confParamType)) { continue methodLoop; } fnArguments.add(value); } // actual parameters check less than xml defined parameters size, because values could be auto-assigned (like 'values' and 'row' params) if (fnArguments.size() != mParams.length || fnArguments.size() < paramValues.size()) { continue; } selectedMethod = m; break; } } if (selectedMethod == null) { final StringBuilder s = new StringBuilder("Anonymization method: "); s.append(methodName).append(" with parameters matching ("); String comma = ""; for (final Parameter p : parms) { s.append(comma).append(p.getType()).append(' ').append(p.getName()); comma = ", "; } s.append(") was not found in class ").append(className); throw new NoSuchMethodException(s.toString()); } log.debug("Anonymizing function: " + methodName + " with parameters: " + Arrays.toString(fnArguments.toArray())); final Object anonymizedValue = selectedMethod.invoke(instance, fnArguments.toArray()); if (anonymizedValue == null) { return null; } return anonymizedValue.toString(); } catch (InstantiationException | ClassNotFoundException ex) { log.error(ex.toString()); } return ""; }
From source file:com.metaparadigm.jsonrpc.JSONSerializer.java
public ObjectMatch tryUnmarshall(SerializerState state, Class clazz, Object json) throws UnmarshallException { /*/*from ww w . j ava2s .c o m*/ * If we have a JSON object class hint that is a sub class of the * signature 'clazz', then override 'clazz' with the hint class. */ if (clazz != null && json instanceof JSONObject && ((JSONObject) json).has("javaClass") && clazz.isAssignableFrom(getClassFromHint(json))) clazz = getClassFromHint(json); if (clazz == null) clazz = getClassFromHint(json); if (clazz == null) throw new UnmarshallException("no class hint"); if (json == null || json == JSONObject.NULL) { if (!clazz.isPrimitive()) return ObjectMatch.NULL; else throw new UnmarshallException("can't assign null primitive"); } Serializer s = getSerializer(clazz, json.getClass()); if (s != null) return s.tryUnmarshall(state, clazz, json); throw new UnmarshallException("no match"); }
From source file:com.metaparadigm.jsonrpc.JSONSerializer.java
public Object unmarshall(SerializerState state, Class clazz, Object json) throws UnmarshallException { /*/*w w w. ja v a 2 s . c om*/ * If we have a JSON object class hint that is a sub class of the * signature 'clazz', then override 'clazz' with the hint class. */ if (clazz != null && json instanceof JSONObject && ((JSONObject) json).has("javaClass") && clazz.isAssignableFrom(getClassFromHint(json))) clazz = getClassFromHint(json); if (clazz == null) clazz = getClassFromHint(json); if (clazz == null) throw new UnmarshallException("no class hint"); if (json == null || json == JSONObject.NULL) { if (!clazz.isPrimitive()) return null; else throw new UnmarshallException("can't assign null primitive"); } Serializer s = getSerializer(clazz, json.getClass()); if (s != null) return s.unmarshall(state, clazz, json); throw new UnmarshallException("can't unmarshall"); }
From source file:com.qpark.maven.plugin.flowmapper.TabularMappingTypeGenerator.java
@Override String generateImplContent() {//from w w w. ja v a2s . c o m this.log.debug("+generateImpl"); final List<String> defaultDefinitionNames = this.getDefaultDefinitionNames(); final ComplexTypeChild inputValueReturnValue = this.getInputValueReturnChild(); final String inputValueName = this.getInputValueName(); final List<ComplexTypeChild> children = this.getChildren(); if (children.size() == 0) { this.log.warn( this.complexType.getType().getName() + " as ComplexMapper does not have children to access"); } Class<?> inputValueClass = String.class; if (inputValueReturnValue != null) { inputValueClass = XsdsUtil .getBuildInJavaClass(inputValueReturnValue.getComplexType().getType().getName()); if (inputValueClass == null) { inputValueClass = String.class; } } final boolean inputValueIsPrimitive = inputValueClass.isPrimitive(); if (inputValueIsPrimitive) { inputValueClass = ClassUtils.primitiveToWrapper(inputValueClass); } String inputValueClassName = inputValueClass.getName(); if (inputValueClassName.startsWith("java.lang.")) { inputValueClassName = inputValueClassName.substring("java.lang.".length()); } final ComplexTypeChild returnValueChild = this.getReturnChild(); Class<?> returnValueClass = XsdsUtil .getBuildInJavaClass(returnValueChild.getComplexType().getType().getName()); if (returnValueClass == null) { returnValueClass = String.class; } final boolean returnValueIsPrimitive = returnValueClass.isPrimitive(); if (returnValueIsPrimitive) { returnValueClass = ClassUtils.primitiveToWrapper(returnValueClass); } String returnValueClassName = returnValueClass.getName(); if (returnValueClassName.startsWith("java.lang.")) { returnValueClassName = returnValueClassName.substring("java.lang.".length()); } ComplexTypeChild ctc; final Set<String> importedClasses = this.complexType.getJavaImportClasses(); final String[] propertyNames = getDirectAccessProperties( this.complexType.getType().getName().getLocalPart()); if (propertyNames.length > 0 && children.size() > 0) { ctc = children.get(0); for (final String propertyName : propertyNames) { ctc = ctc.getComplexType().getChild(propertyName); if (ctc != null) { importedClasses.addAll(ctc.getComplexType().getJavaImportClasses()); } else { break; } } } for (final ComplexTypeChild child : children) { importedClasses.addAll(child.getComplexType().getJavaImportClasses()); } final List<Entry<ComplexTypeChild, List<ComplexTypeChild>>> childrenTree = new ArrayList<Entry<ComplexTypeChild, List<ComplexTypeChild>>>(); importedClasses.addAll(this.getImplImports(childrenTree)); importedClasses.add(new StringBuffer(this.basicFlowPackageName).append(".FlowContext").toString()); final StringBuffer sb = new StringBuffer(1024); sb.append("package "); sb.append(this.packageNameImpl); sb.append(";\n"); sb.append("\n"); importedClasses.add(String.format("%s.%s", this.packageName, this.interfaceName)); importedClasses.add("java.util.HashMap"); importedClasses.add("java.util.Map"); importedClasses.add("java.util.Objects"); for (final String importedClass : importedClasses) { sb.append("import ").append(importedClass).append(";\n"); } sb.append("\n"); sb.append("/**\n"); sb.append(" * The {@link "); sb.append(this.interfaceName); sb.append("} implementation.\n"); if (this.complexType.getAnnotationDocumentation() != null) { sb.append(" * <p/>\n"); sb.append(toJavadocHeader(this.complexType.getAnnotationDocumentation())); } sb.append(" * <p/>\n"); sb.append(" * This is a ").append(this.getMappingType()).append(".\n"); sb.append(Util.getGeneratedAtJavaDocClassHeader(this.getClass(), this.eipVersion)); sb.append(" */\n"); sb.append("@Component\n"); sb.append("public class "); sb.append(this.implName); sb.append(" implements "); sb.append(this.interfaceName); sb.append(" {\n"); sb.append("\t/** The {@link ObjectFactory}. */\n"); sb.append("\tprivate final ObjectFactory of = new ObjectFactory();\n"); sb.append("\t/** The {@link Map} to support tabular mappings. */\n"); sb.append("\tprivate final Map<"); sb.append(inputValueClassName); sb.append(", "); sb.append(returnValueClassName); sb.append("> tabularValueMap = new HashMap<"); sb.append(inputValueClassName); sb.append(", "); sb.append(returnValueClassName); sb.append(">();\n"); sb.append("\n"); sb.append(this.getConstructor(defaultDefinitionNames, inputValueClass, returnValueClass)); sb.append("\n"); sb.append("\t/**\n"); sb.append("\t * Creates the {@link "); sb.append(this.complexType.getClassNameFullQualified()); sb.append("} defined as \n"); sb.append("\t * <i>"); sb.append(this.complexType.getType().getName().getLocalPart()); sb.append("</i> in name space\n"); sb.append("\t * <i>"); sb.append(this.complexType.getType().getName().getNamespaceURI()); sb.append("</i>.\n"); sb.append("\t * This name space is stored in file "); sb.append(this.config.getXsdContainer(this.complexType.getTargetNamespace()).getRelativeName()); sb.append(".\n"); sb.append(this.getSeeInterfaceJavaDoc(children)); sb.append("\t */\n"); sb.append("\tpublic "); sb.append(this.complexType.getClassNameFullQualified()); sb.append(" "); sb.append(this.getMethodName()); final String methodArgs = this.getMethodArgs(children); sb.append("("); sb.append(methodArgs); if (methodArgs.trim().length() > 0) { sb.append(", "); } sb.append("FlowContext flowContext"); sb.append(") {\n"); sb.append("\t\t"); sb.append(this.complexType.getClassNameFullQualified()); sb.append(" mappingType = of.create"); sb.append(this.complexType.getClassName()); sb.append("();\n"); sb.append(this.getSetterStatements("mappingType", children)); sb.append("\n"); sb.append("\t\t"); sb.append(returnValueClassName); sb.append(" mappedValue = this.tabularValueMap.get("); sb.append(inputValueName); if (inputValueClass.equals(Boolean.class) || inputValueClass.equals(boolean.class)) { sb.append(".isReturn());\n"); } else { sb.append(".getReturn());\n"); } if (inputValueClass.equals(String.class)) { sb.append("\t\tif (Objects.isNull(mappedValue) && "); sb.append(inputValueName); sb.append(".getReturn() != null) {\n"); sb.append("\t\t\tfor (String key : this.tabularValueMap.keySet()) {\n"); sb.append("\t\t\t\tif ("); sb.append(inputValueName); sb.append(".getReturn().matches(key)) {\n"); sb.append("\t\t\t\t\tmappedValue = this.tabularValueMap.get(key);\n"); sb.append("\t\t\t\t}\n"); sb.append("\t\t\t}\n"); sb.append("\t\t}\n"); } sb.append("\n"); if (defaultDefinitionNames.contains("DEFAULT_DEFAULT")) { sb.append("\t\tif (Objects.isNull(mappedValue)){\n"); sb.append("\t\t\tmappedValue = "); sb.append(getValueInstance(returnValueClass, "DEFAULT_DEFAULT")); sb.append(";\n"); sb.append("\t\t}\n"); sb.append("\n"); } else if (defaultDefinitionNames.contains("DEFAULT_RETURN")) { sb.append("\t\tif (Objects.isNull(mappedValue)){\n"); sb.append("\t\t\tmappedValue = "); sb.append(getValueInstance(returnValueClass, "DEFAULT_RETURN")); sb.append(";\n"); sb.append("\t\t}\n"); sb.append("\n"); } if (returnValueIsPrimitive) { sb.append("\t\tif (Objects.nonNull(mappedValue)) {\n"); sb.append("\t\t\tmappingType.setValue(mappedValue);\n"); sb.append("\t\t\tmappingType.setReturn(mappedValue);\n"); sb.append("\t\t}\n"); } else { sb.append("\t\tmappingType.setValue(mappedValue);\n"); sb.append("\t\tmappingType.setReturn(mappedValue);\n"); } sb.append("\t\treturn mappingType;\n"); sb.append("\t}\n"); sb.append("}\n"); this.log.debug("-generateImpl"); return sb.toString(); }
From source file:egovframework.rte.itl.webservice.service.impl.EgovWebServiceClassLoaderImpl.java
private byte[] createServiceEndpointInterfaceClass( final ServiceEndpointInterfaceInfo serviceEndpointInterfaceInfo) throws ClassNotFoundException { String serviceEndpointInterfaceClassName = getServiceEndpointInterfaceClassName( serviceEndpointInterfaceInfo.getServiceName()); String asmServiceEndpointInterfaceClassName = serviceEndpointInterfaceClassName.replace('.', '/'); // ClassWriter classWriter = new ClassWriter(false); ClassWriter classWriter = new ClassWriter(0); classWriter.visit(V1_5, // version ACC_PUBLIC | ACC_ABSTRACT | ACC_INTERFACE, // access asmServiceEndpointInterfaceClassName, // name null, // signature "java/lang/Object", // superName null); // interfaces // Create Annotation AnnotationVisitor annotationVisitor = classWriter.visitAnnotation(DESC_OF_WEB_SERVICE, true); annotationVisitor.visit("targetNamespace", serviceEndpointInterfaceInfo.getNamespace()); annotationVisitor.visitEnd();//from w ww . ja v a 2s . c om annotationVisitor = classWriter.visitAnnotation(DESC_OF_SOAP_BINDING, true); annotationVisitor.visitEnum("parameterStyle", DESC_OF_SOAP_BINDING_PARAMETER_STYLE, "BARE"); // Create Method ServiceParamInfo returnInfo = serviceEndpointInterfaceInfo.getReturnInfo(); Collection<ServiceParamInfo> paramInfos = serviceEndpointInterfaceInfo.getParamInfos(); StringBuffer desc = new StringBuffer("("); StringBuffer signature = new StringBuffer("("); for (ServiceParamInfo info : paramInfos) { Class<?> paramClass = loadClass(info.getType()); org.objectweb.asm.Type paramType = org.objectweb.asm.Type.getType(paramClass); String paramSign = paramType.getDescriptor(); if (info.getMode().equals(OUT) || info.getMode().equals(INOUT)) { if (paramClass.isPrimitive()) { paramClass = wrapperClasses.get(paramClass); paramType = org.objectweb.asm.Type.getType(paramClass); paramSign = paramType.getDescriptor(); } paramClass = Holder.class; paramType = TYPE_OF_HOLDER; paramSign = "Ljavax/xml/ws/Holder<" + paramSign + ">;"; } desc.append(paramType.getDescriptor()); signature.append(paramSign); } desc.append(")"); signature.append(")"); org.objectweb.asm.Type returnType = (returnInfo == null ? returnType = org.objectweb.asm.Type.VOID_TYPE : org.objectweb.asm.Type.getType(loadClass(returnInfo.getType()))); desc.append(returnType.getDescriptor()); signature.append(returnType.getDescriptor()); MethodVisitor methodVisitor = classWriter.visitMethod(ACC_PUBLIC | ACC_ABSTRACT, // access serviceEndpointInterfaceInfo.getOperationName(), // name desc.toString(), // desc signature.toString(), // signature null); // exceptions // @WebMethod annotationVisitor = methodVisitor.visitAnnotation(DESC_OF_WEB_METHOD, true); annotationVisitor.visit("operationName", serviceEndpointInterfaceInfo.getOperationName()); annotationVisitor.visitEnd(); // @WebResult if (returnInfo != null) { annotationVisitor = methodVisitor.visitAnnotation(DESC_OF_WEB_RESULT, true); annotationVisitor.visit("name", returnInfo.getName()); // annotationVisitor.visit("partName", // returnInfo.getName()); annotationVisitor.visit("header", returnInfo.isHeader()); annotationVisitor.visit("targetNamespace", serviceEndpointInterfaceInfo.getNamespace()); annotationVisitor.visitEnd(); } // @WebParam int index = 0; for (ServiceParamInfo info : serviceEndpointInterfaceInfo.getParamInfos()) { annotationVisitor = methodVisitor.visitParameterAnnotation(index, DESC_OF_WEB_PARAM, true); annotationVisitor.visit("name", info.getName()); // annotationVisitor.visit("partName", // info.getName()); annotationVisitor.visitEnum("mode", DESC_OF_WEB_PARAM_MODE, info.getMode().toString()); annotationVisitor.visit("header", info.isHeader()); annotationVisitor.visit("targetNamespace", serviceEndpointInterfaceInfo.getNamespace()); annotationVisitor.visitEnd(); index++; } methodVisitor.visitEnd(); // Class finalize classWriter.visitEnd(); // try // { // DataOutputStream dos = new DataOutputStream( // new FileOutputStream("EgovType" + // serviceInfo.getServiceName() + ".class")); // dos.write(classWriter.toByteArray()); // dos.close(); // } // catch (IOException e) // { // e.printStackTrace(); // } return classWriter.toByteArray(); }
From source file:ResultSetIterator.java
/** * Creates a new object and initializes its fields from the ResultSet. * * @param rs The result set.// w w w. j av a 2 s . com * @param type The bean type (the return type of the object). * @param props The property descriptors. * @param columnToProperty The column indices in the result set. * @return An initialized object. * @throws SQLException if a database error occurs. */ private Object createBean(ResultSet rs, Class type, PropertyDescriptor[] props, int[] columnToProperty) throws SQLException { Object bean = this.newInstance(type); for (int i = 1; i < columnToProperty.length; i++) { if (columnToProperty[i] == PROPERTY_NOT_FOUND) { continue; } PropertyDescriptor prop = props[columnToProperty[i]]; Class propType = prop.getPropertyType(); Object value = this.processColumn(rs, i, propType); if (propType != null && value == null && propType.isPrimitive()) { value = primitiveDefaults.get(propType); } this.callSetter(bean, prop, value); } return bean; }
From source file:net.ceos.project.poi.annotated.core.CGen.java
/** * Initialize an cell according the type of field and the PropagationType is * PROPAGATION_HORIZONTAL.//from ww w. j av a 2 s . com * * @param object * the object * @param field * the field * @param xlsAnnotation * the XlsAnnotation * @param values * the cascade level * @param cL * the cascade level * @return in case of the object return the number of cell created, * otherwise 0 * @throws WorkbookException */ private int initializeField(final CConfigCriteria configCriteria, final Object object, final Field field, final XlsElement xlsAnnotation, final int idx) throws WorkbookException { /* set enabled the accessible object */ field.setAccessible(true); int counter = 0; Class<?> fT = field.getType(); boolean isAppliedToBaseObject = toCsv(configCriteria, object, fT, field, xlsAnnotation, idx); if (!isAppliedToBaseObject && !fT.isPrimitive()) { try { Object nO = field.get(object); /* manage null objects */ if (nO == null) { nO = fT.newInstance(); } Class<?> oC = nO.getClass(); counter = marshal(configCriteria, nO, oC, null, idx - 1); } catch (InstantiationException | IllegalAccessException e) { throw new CustomizedRulesException(ExceptionMessage.ELEMENT_NO_SUCH_METHOD.getMessage(), e); } } /* set disabled the accessible object */ field.setAccessible(false); return counter; }