Changeset 725


Ignore:
Timestamp:
01/21/14 10:10:57 (10 years ago)
Author:
jts21
Message:

Auto-correct widget names with invalid capitalisation and/or missing widget package prefix

Location:
trunk/src/org/expeditee
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/actions/Actions.java

    r570 r725  
    7575
    7676        // Package and class file locations
    77         private static final String ACTIONS_PACKAGE = ROOT_PACKAGE + "actions.";
    78 
    79         private static final String AGENTS_PACKAGE = ROOT_PACKAGE + "agents.";
    80 
    81         private static final String WIDGET_PACKAGE = ROOT_PACKAGE + "items.widgets.";
    82 
    83         private static final String CHARTS_PACKAGE = ROOT_PACKAGE + "items.widgets.charts.";
    84 
    85         private static final String NAVIGATIONS_CLASS = ROOT_PACKAGE + "actions.NavigationActions";
     77        public static final String ACTIONS_PACKAGE = ROOT_PACKAGE + "actions.";
     78
     79        public static final String AGENTS_PACKAGE = ROOT_PACKAGE + "agents.";
     80
     81        public static final String WIDGET_PACKAGE = ROOT_PACKAGE + "items.widgets.";
     82
     83        public static final String CHARTS_PACKAGE = ROOT_PACKAGE + "items.widgets.charts.";
     84
     85        public static final String NAVIGATIONS_CLASS = ROOT_PACKAGE + "actions.NavigationActions";
    8686
    8787        // public static Class[] getClasses(String pckgname)
  • trunk/src/org/expeditee/items/widgets/InteractiveWidget.java

    r720 r725  
    190190                String classname = tokens[0];
    191191                if (classname.charAt(0) == '$'){
    192                         String shortClassname = classname.substring(1);
    193                         classname = Actions.getClassName(shortClassname);
    194                        
    195                         if (classname == null) // ensure it exists
    196                                 throw new InteractiveWidgetNotAvailableException(shortClassname
    197                                                 + " does not exist or is not an InteractiveWidget");
    198                 }
     192                        classname = classname.substring(1);
     193                }
     194               
    199195                // Attempt to locate the class using reflection
    200196                Class<?> iwclass = findIWidgetClass(classname);
     
    248244                if(classname == null)
    249245                        return null;
    250                
     246                // try just the classname
    251247                try {
    252248                        Class c = Class.forName(classname); // attempt to find the class
     249
     250                        // If one is found, ensure that it is a descendant of an
     251                        // InteractiveWidget
     252                        for (Class superclass = c.getSuperclass(); superclass != null
     253                                        && superclass != Item.class; superclass = superclass
     254                                        .getSuperclass()) {
     255                                if (superclass == InteractiveWidget.class)
     256                                        return c;
     257                        }
     258
     259                } catch (ClassNotFoundException e) {
     260                }
     261                // see if the class is a widget with invalid capitalisation, or missing the widget package prefix
     262                if(classname.startsWith(Actions.WIDGET_PACKAGE)) {
     263                        classname = classname.substring(Actions.WIDGET_PACKAGE.length());
     264                }
     265                try {
     266                        Class c = Class.forName(Actions.getClassName(classname)); // attempt to find the class
    253267
    254268                        // If one is found, ensure that it is a descendant of an
Note: See TracChangeset for help on using the changeset viewer.