public Bean(String classPackage, String clazz, ClassLoaderStrategy cls, Bean topLevelBean) throws Exception { // Get the no-arg constructor and create the bean try { Class classOfBean = ObjectXml.getClassOfBean((ClassLoader) cls, classPackage + "." + clazz); Constructor ct = null; // check whether this class is an inner class if (classOfBean.getEnclosingClass() != null) { ct = classOfBean.getConstructor(new Class[] {classOfBean.getEnclosingClass()}); beanObject = ct.newInstance(new Object[] {topLevelBean.getBeanObject()}); } else { ct = classOfBean.getConstructor((Class[]) null); beanObject = ct.newInstance((Object[]) null); } // Get an array of property descriptors beanInfo = Introspector.getBeanInfo(classOfBean); PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors(); // load property descriptors into hashtable propDesc = new Properties(); for (int i = 0; i < pds.length; i++) { propDesc.put(pds[i].getName(), pds[i]); } } catch (Exception e) { System.err.println("Exception creating bean: " + e.getMessage()); e.printStackTrace(); throw e; } }
public ParameterizedTypeImpl(Type ownerType, Type rawType, Type... typeArguments) { // require an owner type if the raw type needs it if (rawType instanceof Class<?>) { Class<?> rawTypeAsClass = (Class<?>) rawType; try { Assert.isTrue(ownerType != null || rawTypeAsClass.getEnclosingClass() == null); Assert.isTrue(ownerType == null || rawTypeAsClass.getEnclosingClass() != null); } catch (RuntimeException e) { // R][2011-09-27 21:08:14,570] [ORM._log] ownerType:null // [ERROR][2011-09-27 21:08:14,572] [ORM._log] // rawTypeAsClass:interface java.util.Map$Entry // [ERROR][2011-09-27 21:08:14,573] [ORM._log] // getEnclosingClass:interface java.util.Map LogUtil.error("ownerType:" + ownerType); LogUtil.error("rawTypeAsClass:" + rawTypeAsClass); LogUtil.error("getEnclosingClass:" + rawTypeAsClass.getEnclosingClass()); throw e; } } this.ownerType = ownerType == null ? null : canonicalize(ownerType); this.rawType = canonicalize(rawType); this.typeArguments = typeArguments.clone(); for (int t = 0; t < this.typeArguments.length; t++) { Assert.notNull(this.typeArguments[t]); checkNotPrimitive(this.typeArguments[t]); this.typeArguments[t] = canonicalize(this.typeArguments[t]); } }
@NotNull public static ContractsContext getContext(@NotNull Class<?> clazz) { Class<?> outer = clazz; while (outer.getEnclosingClass() != null) { outer = outer.getEnclosingClass(); } synchronized (CONTEXTS) { return getContext0(outer.getName()); } }
@Test public void testEnclosingType() throws Exception { for (Class<?> type : standardTypes) { assertThat( describe(type).getEnclosingType(), type.getEnclosingClass() == null ? nullValue(TypeDescription.class) : is((TypeDescription) new TypeDescription.ForLoadedType(type.getEnclosingClass()))); } }
/** * @return Returns the given objects enclosing container type, i.e the first class on the * enclosing classes path that is abstract or the outermost enclosing class. The latter is the * primary type. */ public static Class<?> getEnclosingContainerType(Object o) { if (o == null) { return null; } Class<?> c = o.getClass(); while (!Modifier.isAbstract(c.getModifiers()) && c.getEnclosingClass() != null) { c = c.getEnclosingClass(); } return c; }
@Override public String shorten(Class<?> cls) { if (cls.getEnclosingClass() != null) { return shorten(cls.getEnclosingClass()) + "." + cls.getSimpleName(); } else if (cls.getPackage() != null) { return getPrefixForTopLevelClass(cls.getPackage().getName(), cls.getSimpleName()) + cls.getSimpleName(); } else { return cls.getSimpleName(); } }
private static int putEnumTypeInHash(Class<?> type, Hashtable<String, Class<?>> enums) { Class<?> flagsType = QFlags.class.isAssignableFrom(type) ? type : null; Class<?> enumType = type.isEnum() ? type : null; if (enumType == null && flagsType != null) { enumType = getEnumForQFlags(flagsType); } if (enumType == null) return 0; // Since Qt supports enums that are not part of the meta object // we need to check whether the enum can actually be used in // a property. Class<?> enclosingClass = enumType.getEnclosingClass(); if (enclosingClass != null && ((!QObject.class.isAssignableFrom(enclosingClass) && !Qt.class.equals(enclosingClass)) || enumType.isAnnotationPresent(QtBlockedEnum.class))) { return -1; } int enumConstantCount = 0; if (!enums.contains(enumType.getName())) { enums.put(enumType.getName(), enumType); enumConstantCount = enumType.getEnumConstants().length; } if (flagsType != null && !enums.contains(flagsType.getName())) enums.put(flagsType.getName(), flagsType); return enumConstantCount; }
public static String isLocalType(Class<?> type) { /* As per [JACKSON-187], GAE seems to throw SecurityExceptions * here and there... and GAE itself has a bug, too * (see []). Bah. */ try { // one more: method locals, anonymous, are not good: if (type.getEnclosingMethod() != null) { return "local/anonymous"; } /* But how about non-static inner classes? Can't construct * easily (theoretically, we could try to check if parent * happens to be enclosing... but that gets convoluted) */ if (type.getEnclosingClass() != null) { if (!Modifier.isStatic(type.getModifiers())) { return "non-static member class"; } } } catch (SecurityException e) { } catch (NullPointerException e) { } return null; }
@Test public void testTwoWayFieldBridgeCanHandleNullInObjectToString() throws Exception { List<Class<?>> classes = getClasses("org.hibernate.search.bridge.builtin"); assertTrue("Guarding against a package refactoring", classes.size() > 0); for (Class<?> clazz : classes) { // not interested in abstract classes if (Modifier.isAbstract(clazz.getModifiers())) { continue; } // neither in non TwoWayFieldBridge if (!TwoWayFieldBridge.class.isAssignableFrom(clazz)) { continue; } // the NumericFieldBridge is an emum (go figure) - we need special massaging here if (Enum.class.isAssignableFrom(clazz)) { assertTrue( "Unexpected enum class" + clazz, NumericFieldBridge.class.isAssignableFrom(clazz)); for (Object o : clazz.getEnclosingClass().getEnumConstants()) { TwoWayFieldBridge bridge = (TwoWayFieldBridge) o; assertEquals( "All TwoWayFieldBridgeTest should return 'null' for 'null' passed to 'objectToString", null, bridge.objectToString(null)); } } else { TwoWayFieldBridge bridge = (TwoWayFieldBridge) clazz.newInstance(); assertEquals( "All TwoWayFieldBridgeTest should return 'null' for 'null' passed to 'objectToString", null, bridge.objectToString(null)); } } }
@Override public String getPartId(final Class<? extends PartPermission> permissionClass) { String permission = WordUtils.uncapitalize(permissionClass.getEnclosingClass().getSimpleName()) + permissionClass.getSimpleName(); return permission; }
private void validateClass(Class<?> source, ValidationProblemCollector problems) { int modifiers = source.getModifiers(); if (Modifier.isInterface(modifiers)) { problems.add("Must be a class, not an interface"); } if (source.getEnclosingClass() != null) { if (Modifier.isStatic(modifiers)) { if (Modifier.isPrivate(modifiers)) { problems.add("Class cannot be private"); } } else { problems.add("Enclosed classes must be static and non private"); } } Constructor<?>[] constructors = source.getDeclaredConstructors(); for (Constructor<?> constructor : constructors) { if (constructor.getParameterTypes().length > 0) { problems.add("Cannot declare a constructor that takes arguments"); break; } } Field[] fields = source.getDeclaredFields(); for (Field field : fields) { int fieldModifiers = field.getModifiers(); if (!field.isSynthetic() && !(Modifier.isStatic(fieldModifiers) && Modifier.isFinal(fieldModifiers))) { problems.add(field, "Fields must be static final."); } } }
public JavaType findType(String name) { if (_bindings == null) { _resolve(); } JavaType t = _bindings.get(name); if (t != null) { return t; } if (_placeholders != null && _placeholders.contains(name)) { return UNBOUND; } // New with 1.7: check parent context if (_parentBindings != null) { return _parentBindings.findType(name); } // nothing found, so... // Should we throw an exception or just return null? /* [JACKSON-499] 18-Feb-2011, tatu: There are some tricky type bindings within * java.util, such as HashMap$KeySet; so let's punt the problem * (honestly not sure what to do -- they are unbound for good, I think) */ if (_contextClass != null) { Class<?> enclosing = _contextClass.getEnclosingClass(); if (enclosing != null) { // [JACKSON-572]: Actually, let's skip this for all non-static inner classes // (which will also cover 'java.util' type cases... if (!Modifier.isStatic(_contextClass.getModifiers())) { return UNBOUND; } // ... so this piece of code should not be needed any more /* Package pkg = enclosing.getPackage(); if (pkg != null) { // as per [JACKSON-533], also include "java.util.concurrent": if (pkg.getName().startsWith("java.util")) { return UNBOUND; } } */ } } String className; if (_contextClass != null) { className = _contextClass.getName(); } else if (_contextType != null) { className = _contextType.toString(); } else { className = "UNKNOWN"; } throw new IllegalArgumentException( "Type variable '" + name + "' can not be resolved (with context of class " + className + ")"); // t = UNBOUND; }
/** What feature does this story belong to? */ public static Class<?> getFeatureClass(Class<?> userStoryClass) { if (userStoryClass != null) { Class<?> enclosingClass = userStoryClass.getEnclosingClass(); if (isAFeature(enclosingClass)) { return enclosingClass; } } return null; }
@Nullable @Override Class<?> getOwnerType(Class<?> rawType) { if (rawType.isLocalClass()) { return null; } else { return rawType.getEnclosingClass(); } }
public static <E extends Enum<E>> E enumValue(final String value, final E defaultValue) { requireNonNull(defaultValue, "No default value provided"); E enumValue; if (value == null) { enumValue = defaultValue; } else { try { Class<?> enumClass = defaultValue.getClass(); if (enumClass.getEnclosingClass() != null) { enumClass = enumClass.getEnclosingClass(); } enumValue = Enum.valueOf((Class<E>) enumClass, value); } catch (final Exception e) { enumValue = defaultValue; } } return enumValue; }
private boolean isEnclosingClassParameter() { if (enclosingClassCache == null) { Class<T> owningType = entity.getType(); this.enclosingClassCache = owningType.isMemberClass() && type.getType().equals(owningType.getEnclosingClass()); } return enclosingClassCache; }
/** * Returns a type where {@code rawType} is parameterized by {@code arguments} and is owned by * {@code ownerType}. */ static ParameterizedType newParameterizedTypeWithOwner( @Nullable Type ownerType, Class<?> rawType, Type... arguments) { if (ownerType == null) { return newParameterizedType(rawType, arguments); } // ParameterizedTypeImpl constructor already checks, but we want to throw NPE before IAE checkNotNull(arguments); checkArgument(rawType.getEnclosingClass() != null, "Owner type for unenclosed %s", rawType); return new ParameterizedTypeImpl(ownerType, rawType, arguments); }
static ParameterizedType newParameterizedTypeWithOwner( @Nullable Type var0, Class<?> var1, Type... var2) { if (var0 == null) { return newParameterizedType(var1, var2); } else { Preconditions.checkNotNull(var2); Preconditions.checkArgument( var1.getEnclosingClass() != null, "Owner type for unenclosed %s", new Object[] {var1}); return new Types.ParameterizedTypeImpl(var0, var1, var2); } }
private static String getClassName(Class<?> clazz) { if (clazz != null) { if (!TextUtils.isEmpty(clazz.getSimpleName())) { return clazz.getSimpleName(); } return getClassName(clazz.getEnclosingClass()); } return ""; }
private static String[] getTypeMetadata(Class<?> clazz, int index) { Class<?> mostOuterClass = clazz.getEnclosingClass(); ArrayList<Class<?>> outerClasses = new ArrayList<Class<?>>(); while (mostOuterClass != null) { outerClasses.add(0, mostOuterClass); Class<?> nextOuterClass = mostOuterClass.getEnclosingClass(); if (nextOuterClass == null) break; mostOuterClass = nextOuterClass; } Package p = (mostOuterClass != null) ? mostOuterClass.getPackage() : clazz.getPackage(); int packageCount = 1; String pname = p.getName(); for (int i = 0; i < pname.length(); i++) { if (pname.charAt(i) == '.') ++packageCount; } String name = clazz.getName(); String[] parts = name.split("[\\.\\$]"); int endIdx = parts.length; int len = endIdx - index; String[] result = new String[len]; int endOuterTypeIdx = packageCount + outerClasses.size(); for (int i = index; i < endIdx; i++) { if (i < packageCount) { result[i - index] = "P"; } else { if (i < endOuterTypeIdx) { result[i - index] = getTypeMetadata(outerClasses.get(i - packageCount)); } else { result[i - index] = getTypeMetadata(clazz); } } } return result; }
/** * Creates a new Instance of the <code>sectionClass</code> using its default-constructor * * <p>the <code>parent</code> is needed when trying to instantiating a non-static inner-class * Section * * @param sectionClass the class of the Section to instantiate * @param parent an instance of the enclosing class of the <code>sectionClass</code> * @return the instantiated Section */ public static Section newSectionInstance(Class<? extends Section> sectionClass, Object parent) { try { if (sectionClass.getEnclosingClass() == null) { return sectionClass.newInstance(); } else if (Modifier.isStatic(sectionClass.getModifiers())) { return sectionClass.newInstance(); } else { return sectionClass .getDeclaredConstructor(sectionClass.getEnclosingClass()) .newInstance(parent); } } catch (InstantiationException e) { throw new ReflectedInstantiationException(sectionClass, e); } catch (InvocationTargetException e) { throw new ReflectedInstantiationException(sectionClass, e); } catch (NoSuchMethodException e) { throw new ReflectedInstantiationException(sectionClass, e); } catch (IllegalAccessException e) { throw new ReflectedInstantiationException(sectionClass, e); } }
/** * 批量将 fromObject 中的数据使用 targetClass的set方法,传入targetObject中 * * @param fromObject * @param targetClss * @param targetObject */ public static void batchSetter(Object fromObject, Class<?> targetClss, Object targetObject) { try { for (Field field : fromObject.getClass().getDeclaredFields()) { GenerateClassSetter nestSetter = field.getType().getAnnotation(GenerateClassSetter.class); if (nestSetter != null) { boolean sameTypeWithEnclosingObj = false; for (TargetClassDefine targetClass : nestSetter.targetType()) { sameTypeWithEnclosingObj = targetClass.name().equals(targetClss.getCanonicalName()); if (sameTypeWithEnclosingObj) { break; } } if (sameTypeWithEnclosingObj) { if (!Modifier.isPublic(field.getModifiers())) { if (Debug) System.out.println( fromObject.getClass().getSimpleName() + "." + field.getName() + ", not public, ignored"); } else { if (field.get(fromObject) != null) { batchSetter(field.get(fromObject), targetClss, targetObject); if (Debug) System.out.println("recursive invoke: " + field.getName()); } } } } } String packageLoc = fromObject.getClass().getPackage().getName(); String enclosingClassPrefix = ""; Class<?> enclosingClass = fromObject.getClass().getEnclosingClass(); while (enclosingClass != null) { enclosingClassPrefix = enclosingClass.getSimpleName() + "_" + enclosingClassPrefix; enclosingClass = enclosingClass.getEnclosingClass(); } Class<?> injectorClass = Class.forName( packageLoc + "." + enclosingClassPrefix + fromObject.getClass().getSimpleName() + "Setter"); injectorClass .getMethod("set", fromObject.getClass(), targetClss) .invoke(null, fromObject, targetObject); } catch (Exception e) { throw new RuntimeException(e); } }
private void assertValid(final Class<?> clazz) { if (clazz.getEnclosingClass() == null) { throw new OpenGammaRuntimeException("AutoFudgable can be used only with inner classes"); } if (clazz.getSuperclass().getEnclosingClass() != null) { throw new OpenGammaRuntimeException( "AutoFudgable can be used only with inner classes which enclosing classes are not inner themselves."); } if (!hasSingleZeroArgConstructor(clazz.getSuperclass())) { throw new OpenGammaRuntimeException( "AutoFudgable can be used only with inner classes which enclosing classes have single, zero argument constructor."); } }
public static <ItemDataType> ViewHolderCreator<ItemDataType> create( final Object enclosingInstance, final Class<?> cls, final Object... args) { if (cls == null) { throw new IllegalArgumentException("ViewHolderClass is null."); } // top class boolean isEnclosingInstanceClass = false; if (cls.getEnclosingClass() != null && !Modifier.isStatic(cls.getModifiers())) { isEnclosingInstanceClass = true; } // inner instance class should pass enclosing class, so +1 int argsLen = isEnclosingInstanceClass ? args.length + 1 : args.length; final Object[] instanceObjects = new Object[argsLen]; int copyStart = 0; // if it is inner instance class, first argument should be the enclosing class instance if (isEnclosingInstanceClass) { instanceObjects[0] = enclosingInstance; copyStart = 1; } // has copy construction parameters if (args.length > 0) { System.arraycopy(args, 0, instanceObjects, copyStart, args.length); } // fill the types final Class[] parameterTypes = new Class[argsLen]; for (int i = 0; i < instanceObjects.length; i++) { parameterTypes[i] = instanceObjects[i].getClass(); } Constructor<?> constructor = null; try { constructor = cls.getDeclaredConstructor(parameterTypes); } catch (NoSuchMethodException e) { e.printStackTrace(); } if (constructor == null) { throw new IllegalArgumentException("ViewHolderClass can not be initiated"); } ViewHolderCreator lazyCreator = new LazyViewHolderCreator(constructor, instanceObjects); return lazyCreator; }
public ParameterizedTypeImpl(Type ownerType, Type rawType, Type... typeArguments) { // require an owner type if the raw type needs it if (rawType instanceof Class<?>) { Class<?> rawTypeAsClass = (Class<?>) rawType; boolean isStaticOrTopLevelClass = Modifier.isStatic(rawTypeAsClass.getModifiers()) || rawTypeAsClass.getEnclosingClass() == null; checkArgument(ownerType != null || isStaticOrTopLevelClass); } this.ownerType = ownerType == null ? null : canonicalize(ownerType); this.rawType = canonicalize(rawType); this.typeArguments = typeArguments.clone(); for (int t = 0; t < this.typeArguments.length; t++) { checkNotNull(this.typeArguments[t]); checkNotPrimitive(this.typeArguments[t]); this.typeArguments[t] = canonicalize(this.typeArguments[t]); } }
@Override public <TAggregate extends AggregateRoot, TEvent extends AggregateDomainEvent<TAggregate>> Future<TAggregate> submit(final TEvent domainEvent, final String uri) { if (uri == null) throw new IllegalArgumentException("uri can't be null."); final Class<?> eventClazz = domainEvent.getClass(); @SuppressWarnings("unchecked") final Class<TAggregate> manifest = (Class<TAggregate>) eventClazz.getEnclosingClass(); final String domainName = client.getDslName(manifest); return client.sendRequest( manifest, DOMAIN_URI + "submit/" + domainName + "/" + eventClazz.getSimpleName() + "?uri=" + encode(uri), "POST", domainEvent, new int[] {201}); }
/** * @param aParserClass * @param aDelimiter * @param aThreadPoolSize * @throws AppException */ public FileParserBatch(Class<T> aParserClass, String aDelimiter, int aThreadPoolSize) throws AppException { super(aThreadPoolSize); try { this.parserClass = aParserClass; if (InnerLogParser.class.isAssignableFrom(aParserClass)) { this.constructor = aParserClass.getConstructor( new Class[] {aParserClass.getEnclosingClass(), File.class, String.class}); } else { this.constructor = aParserClass.getConstructor(new Class[] {File.class, String.class}); } } catch (Exception error) { killListner(); throw new AppException(error); } this.delimiter = aDelimiter; }
private String canonicalName(Class<?> clazz) { if (clazz.isArray()) { Class<?> leafType = clazz; do { leafType = leafType.getComponentType(); } while (leafType.isArray()); Class<?> enclosing = leafType.getEnclosingClass(); if (enclosing != null) { // com.foo.Enclosing$Name[] return canonicalName(enclosing) + "$" + clazz.getSimpleName(); } else if (leafType.getPackage() == null) { // Name0[ return clazz.getSimpleName(); } else { // com.foo.Name[] return leafType.getPackage().getName() + "." + clazz.getSimpleName(); } } else { return clazz.getName(); } }
/** Finds the editor message bundle for the supplied class. */ protected static String findMessageBundle(Class<?> clazz) { EditorMessageBundle annotation = clazz.getAnnotation(EditorMessageBundle.class); if (annotation != null) { return annotation.value(); } Class<?> eclazz = clazz.getEnclosingClass(); if (eclazz != null) { return getMessageBundle(eclazz); } String name = clazz.getName(); int idx; while ((idx = name.lastIndexOf('.')) != -1) { name = name.substring(0, idx); Package pkg = Package.getPackage(name); if (pkg != null) { annotation = pkg.getAnnotation(EditorMessageBundle.class); if (annotation != null) { return annotation.value(); } } } return EditorMessageBundle.DEFAULT; }
/** * Creates a map of concrete json request handler invokers keyed by <b><code> * <service-name>/<op-name></code></b>. * * @param handlerInstance The request handler instance to generate invokers for * @return the map of generated invokers */ public static Map<String, Map<String, AbstractJSONRequestHandlerInvoker>> createInvokers( Object handlerInstance) { if (handlerInstance == null) throw new IllegalArgumentException("The passed handlerInstance was null"); Map<String, AbstractJSONRequestHandlerInvoker> subInvokerMap = new HashMap<String, AbstractJSONRequestHandlerInvoker>(); Map<String, Map<String, AbstractJSONRequestHandlerInvoker>> invokerMap = invokerCache.get(handlerInstance.getClass()); if (invokerMap != null) { LOG.info("Found Cached Invokers for [{}]", handlerInstance.getClass().getName()); return invokerMap; } invokerMap = new HashMap<String, Map<String, AbstractJSONRequestHandlerInvoker>>(1); LOG.info("Generating Invokers for [{}]", handlerInstance.getClass().getName()); JSONRequestService svc = handlerInstance.getClass().getAnnotation(JSONRequestService.class); final String invokerServiceKey = svc.name(); final String invokerServiceDescription = svc.description(); invokerMap.put(invokerServiceKey, subInvokerMap); ClassPool cp = new ClassPool(); cp.appendClassPath(new ClassClassPath(handlerInstance.getClass())); cp.appendClassPath(new ClassClassPath(AbstractJSONRequestHandlerInvoker.class)); cp.importPackage(handlerInstance.getClass().getPackage().getName()); Set<ClassLoader> classPathsAdded = new HashSet<ClassLoader>(); Set<String> packagesImported = new HashSet<String>(); try { final CtClass jsonRequestCtClass = cp.get(JSONRequest.class.getName()); final CtClass parent = cp.get(AbstractJSONRequestHandlerInvoker.class.getName()); CtClass targetClass = cp.get(handlerInstance.getClass().getName()); Collection<Method> methods = getTargetMethods(handlerInstance.getClass()); for (Method m : methods) { final JSONRequestHandler jsonHandler = m.getAnnotation(JSONRequestHandler.class); final String opName = jsonHandler.name(); final String opDescription = jsonHandler.description(); final RequestType opType = jsonHandler.type(); int targetMethodHashCode = m.toGenericString().hashCode(); final String className = String.format( "%s-%s%s-%s-%s", handlerInstance.getClass().getName(), invokerServiceKey, opName, "ServiceInvoker", targetMethodHashCode); final CtClass invokerClass = cp.makeClass(className, parent); CtField ctf = new CtField(targetClass, "typedTarget", invokerClass); ctf.setModifiers(ctf.getModifiers() | Modifier.FINAL); invokerClass.addField(ctf); for (CtConstructor parentCtor : parent.getConstructors()) { CtConstructor invokerCtor = CtNewConstructor.copy(parentCtor, invokerClass, null); invokerCtor.setBody( "{ super($$); typedTarget = (" + handlerInstance.getClass().getName() + ")$1; }"); invokerClass.addConstructor(invokerCtor); } CtMethod invokerMethod = CtNewMethod.copy( parent.getDeclaredMethod("doInvoke", new CtClass[] {jsonRequestCtClass}), invokerClass, null); StringBuilder b = new StringBuilder("{this.typedTarget.").append(m.getName()).append("($1"); final Class<?>[] ptypes = m.getParameterTypes(); final int remainingParamCount = ptypes.length - 1; // Set<Class<?>> classPathsAdded = new HashSet<Class<?>>(); // Set<String> packagesImported = new HashSet<String>(); if (remainingParamCount > 0) { for (int i = 0; i < remainingParamCount; i++) { final Class<?> type = ptypes[i + 1]; if (type.getName().contains("UniqueIdType")) { System.err.println("Comin Up...."); } if (type.isPrimitive()) { b.append(", (").append(type.getName()).append(") null"); } else { if (classPathsAdded.add(type.getClassLoader())) { cp.appendClassPath(new LoaderClassPath(type.getClassLoader())); } try { Package p = type.getPackage(); if (p == null) { if (type.isArray()) { if (!type.getComponentType().isPrimitive()) { p = type.getComponentType().getPackage(); } } } if (type.isEnum()) { final String f = type.getEnclosingClass().getName() + "." + type.getSimpleName(); b.append(", (").append(f).append(") null"); String pack = type.getEnclosingClass().getPackage().getName(); if (packagesImported.add(pack)) { cp.importPackage(pack); } continue; } if (p != null) { if (packagesImported.add(p.getName())) { cp.importPackage(p.getName()); } } } catch (Exception ex) { ex.printStackTrace(System.err); } b.append(", (").append(type.getSimpleName()).append(") null"); } } } b.append(");}"); System.out.println("[" + m.getName() + "]: [" + b.toString() + "]"); // invokerMethod.setBody("{this.typedTarget." + m.getName() + "($1);}"); invokerMethod.setBody(b.toString()); invokerMethod.setModifiers(invokerMethod.getModifiers() & ~Modifier.ABSTRACT); invokerClass.addMethod(invokerMethod); // invokerClass.writeFile(System.getProperty("java.io.tmpdir") + File.separator + // "jsoninvokers"); Class<?> clazz = invokerClass.toClass( handlerInstance.getClass().getClassLoader(), handlerInstance.getClass().getProtectionDomain()); Constructor<?> ctor = clazz.getDeclaredConstructor( Object.class, String.class, String.class, String.class, String.class, RequestType.class); AbstractJSONRequestHandlerInvoker invokerInstance = (AbstractJSONRequestHandlerInvoker) ctor.newInstance( handlerInstance, invokerServiceKey, invokerServiceDescription, opName, opDescription, opType); subInvokerMap.put(opName, invokerInstance); } invokerCache.put(handlerInstance.getClass(), invokerMap); return invokerMap; } catch (Exception ex) { LOG.error( "Failed to create RequestHandlerInvoker for [{}]", handlerInstance.getClass().getName(), ex); throw new RuntimeException( "Failed to create RequestHandlerInvoker [" + handlerInstance.getClass().getName() + "]", ex); } }