diff --git a/src/main/java/org/myrobotlab/service/config/ServiceConfig.java b/src/main/java/org/myrobotlab/service/config/ServiceConfig.java index 7696e57e2a..233e0c29b8 100755 --- a/src/main/java/org/myrobotlab/service/config/ServiceConfig.java +++ b/src/main/java/org/myrobotlab/service/config/ServiceConfig.java @@ -170,7 +170,7 @@ public ServiceConfig addDefaultGlobalConfig(Plan plan, String key, String global * @param plan * @param key * @param globalName - * @param peer + * @param peerType * @return */ public ServiceConfig addDefaultGlobalConfig(Plan plan, String key, String globalName, String peerType, boolean autoStart) { @@ -215,19 +215,8 @@ public Peer putPeerType(String peerKey, String fullName, String peerType) { } public static Plan getDefault(Plan plan, String name, String inType) { -// if ("Service".equals(inType) || Service.class.getCanonicalName().equals(inType)) { -// ServiceConfig sc = new ServiceConfig(); -// sc.type = inType; -// plan.put(name, sc); -// return plan; -// } try { - // if (type == null) { - // log.error("getDefault(null)"); - // return null; - // } - // FIXME - at some point setting, examining and changing // peer keys to actual names will need to be worky String fullType = getConfigType(inType); @@ -240,12 +229,17 @@ public static Plan getDefault(Plan plan, String name, String inType) { config.getDefault(plan, name); } catch (ClassNotFoundException cnfe) { + // We could not find the config type with the simple {serviceType}Config pattern + // So now we look at its superclasses and try to find a config class in + // the generic type parameters + // FIXME should also perform the simple pattern check on superclasses try { + @SuppressWarnings("rawtypes") Class serviceClass = Class.forName(CodecUtils.makeFullTypeName(inType)).asSubclass(Service.class); Type superClass = serviceClass.getGenericSuperclass(); if (superClass instanceof ParameterizedType) { ParameterizedType genericSuperClass = (ParameterizedType) superClass; - System.out.println("Got generic superclass: " + genericSuperClass + " for service class " + serviceClass); + log.debug("Got generic superclass: " + genericSuperClass + " for service class " + serviceClass); Class configClass = ((Class) genericSuperClass.getActualTypeArguments()[0]).asSubclass(ServiceConfig.class); ServiceConfig newConfig = configClass.getConstructor().newInstance(); newConfig.type = inType; @@ -256,6 +250,10 @@ public static Plan getDefault(Plan plan, String name, String inType) { } catch (NoClassDefFoundError | ClassNotFoundException | NoSuchElementException | NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException | ClassCastException ignored) { + // Many ways for the generic inspection code to fail. NoClassDefFound is thrown when the service isn't installed + // We should probably only attempt to load configs for installed services + // NoSuchElementException is manually thrown when we can't find a generic superclass to inspect + // All others are checked exceptions thrown by the reflection utilities being used log.info("could not find config class for {}, loading generalized ServiceConfig", inType); ServiceConfig sc = new ServiceConfig(); sc.type = inType;