@SuppressWarnings("unchecked") private <T> T unmarshalCustomization( final CPluginCustomization customization, T defaultValue, Merge<T> merge) throws AssertionError { if (customization == null) { return null; } else { final T value = (T) this.customizationsMap.get(customization); if (value != null) { // return value instanceof CopyTo ? (T) ((CopyTo) value) // .copyTo(((CopyTo) value).createNewInstance()) : value; return value; } else { final T t = (T) CustomizationUtils.unmarshall( Customizations.getContext(), customization); if (defaultValue != null) { Validate.notNull(merge); merge.merge(t, defaultValue); } this.customizationsMap.put(customization, t); return t; // return t instanceof CopyTo ? (T) ((CopyTo) t) // .copyTo(((CopyTo) t).createNewInstance()) : t; } } }
@SuppressWarnings("unchecked") private <T> T unmarshalCustomization( final CPluginCustomization customization, T defaultValue, Merge<T> merge) throws AssertionError { if (customization == null) { return null; } else { final T value = (T) this.customizationsMap.get(customization); if (value != null) { // return value instanceof CopyTo ? (T) ((CopyTo) value) // .copyTo(((CopyTo) value).createNewInstance()) : value; return value; } else { final T t = (T) CustomizationUtils.unmarshall( Customizations.getContext(), customization); if (defaultValue != null) { Validate.notNull(merge); merge.merge(t, defaultValue); } this.customizationsMap.put(customization, t); return t; // return t instanceof CopyTo ? (T) ((CopyTo) t) // .copyTo(((CopyTo) t).createNewInstance()) : t; } } }
@Override public void postProcessModel(Model model, ErrorHandler errorHandler){ super.postProcessModel(model, errorHandler); Map<String, CClassRef> classRefCache = new HashMap<>(); CClassRef defaultBaseClazz = getClassRef(classRefCache, model, "org.dmg.pmml.PMMLObject"); Collection<CClassInfo> classInfos = (model.beans()).values(); for(CClassInfo classInfo : classInfos){ CClassRef baseClazz = defaultBaseClazz; CPluginCustomization extendsCustomization = CustomizationUtils.findCustomization(classInfo, Customizations.EXTENDS_ELEMENT_NAME); if(extendsCustomization != null){ ExtendsClass extendsClass = (ExtendsClass)CustomizationUtils.unmarshall(Customizations.getContext(), extendsCustomization); String name = getClassName(extendsClass); int lt = name.indexOf('<'); if(lt > -1){ name = name.substring(0, lt); } baseClazz = getClassRef(classRefCache, model, name); } classInfo.setBaseClass(baseClazz); } }
@Override public boolean run(Outline outline, Options options, ErrorHandler errorHandler){ JCodeModel codeModel = outline.getCodeModel(); Map<String, JClass> typeCache = new HashMap<>(); Collection<? extends ClassOutline> classOutlines = outline.getClasses(); for(ClassOutline classOutline : classOutlines){ JDefinedClass beanClazz = classOutline.implClass; CPluginCustomization extendsCustomization = CustomizationUtils.findCustomization(classOutline, Customizations.EXTENDS_ELEMENT_NAME); if(extendsCustomization != null){ ExtendsClass extendsClass = (ExtendsClass)CustomizationUtils.unmarshall(Customizations.getContext(), extendsCustomization); JClass type = parseType(typeCache, codeModel, getClassName(extendsClass)); beanClazz._extends(type); } List<CPluginCustomization> implementsCustomizations = CustomizationUtils.findCustomizations(classOutline, Customizations.IMPLEMENTS_ELEMENT_NAME); for(CPluginCustomization implementsCustomization : implementsCustomizations){ ImplementsInterface implementsInterface = (ImplementsInterface)CustomizationUtils.unmarshall(Customizations.getContext(), implementsCustomization); JClass type = parseType(typeCache, codeModel, getInterfaceName(implementsInterface)); beanClazz._implements(type); } // See https://github.com/highsource/jaxb2-basics/issues/70 FieldOutline[] fieldOutlines = classOutline.getDeclaredFields(); for(FieldOutline fieldOutline : fieldOutlines){ CPropertyInfo propertyInfo = fieldOutline.getPropertyInfo(); CustomizationUtils.findPropertyCustomizationsInProperty(propertyInfo, Customizations.EXTENDS_ELEMENT_NAME); CustomizationUtils.findPropertyCustomizationsInProperty(propertyInfo, Customizations.IMPLEMENTS_ELEMENT_NAME); } } return true; }