/** * Load the SwitchYard configuration model specified by the configModel stream. * @param <M> Model type. * @param configModel The config model stream. * @param modelType Model type. * @param validate Validate the model? * @return The SwitchYard config model. */ public <M extends Model> M loadConfigModel(InputStream configModel, Class<M> modelType, boolean validate) { if (configModel == null) { throw new IllegalArgumentException("null 'configModel' arg."); } try { M pulledModel = new ModelPuller<M>().pull(configModel); if (validate) { pulledModel.assertModelValid(); } return pulledModel; } catch (IOException e) { Assert.fail("Unexpected error building " + modelType.getSimpleName() + ": " + e.getMessage()); } finally { try { configModel.close(); } catch (IOException e) { Assert.fail("Unexpected error closing " + modelType.getSimpleName() + " stream: " + e.getMessage()); } } return null; }
/** * Load the SwitchYard configuration model specified by the configModel stream. * @param <M> Model type. * @param configModel The config model stream. * @param modelType Model type. * @param validate Validate the model? * @return The SwitchYard config model. */ public <M extends Model> M loadConfigModel(InputStream configModel, Class<M> modelType, boolean validate) { if (configModel == null) { throw new IllegalArgumentException("null 'configModel' arg."); } try { M pulledModel = new ModelPuller<M>().pull(configModel); if (validate) { pulledModel.assertModelValid(); } return pulledModel; } catch (IOException e) { Assert.fail("Unexpected error building " + modelType.getSimpleName() + ": " + e.getMessage()); } finally { try { configModel.close(); } catch (IOException e) { Assert.fail("Unexpected error closing " + modelType.getSimpleName() + " stream: " + e.getMessage()); } } return null; }
/** * Merges two models into a new model. * Note: The act of merging results in fromModel and toModel to have their configurations normalized and children ordered! * @param <M> the type of Model being merged * @param fromModel merge from this model, optionally overriding anything in toModel * @param toModel merge into a copy of this model * @param fromOverridesTo whether fromModel attributes/values should override those in toModel * @param validate whether the newly merged model should be validated before it is returned * @return the newly merged model */ public static <M extends Model> M merge(M fromModel, M toModel, boolean fromOverridesTo, boolean validate) { String from_model_cn = fromModel.getClass().getName(); String to_model_cn = toModel.getClass().getName(); if (!from_model_cn.equals(to_model_cn)) { throw new IllegalArgumentException(from_model_cn + " != " + to_model_cn); } Configuration from_model_config = fromModel.getModelConfiguration(); Configuration to_model_config = toModel.getModelConfiguration(); Configuration merged_model_config = Configurations.merge(from_model_config, to_model_config, fromOverridesTo); @SuppressWarnings("unchecked") M merged_model = (M)Descriptor.getMarshaller(toModel).read(merged_model_config); merged_model.orderModelChildren(); if (validate) { merged_model.assertModelValid(); } return merged_model; }
/** * Merges two models into a new model. * Note: The act of merging results in fromModel and toModel to have their configurations normalized and children ordered! * @param <M> the type of Model being merged * @param fromModel merge from this model, optionally overriding anything in toModel * @param toModel merge into a copy of this model * @param fromOverridesTo whether fromModel attributes/values should override those in toModel * @param validate whether the newly merged model should be validated before it is returned * @return the newly merged model */ public static <M extends Model> M merge(M fromModel, M toModel, boolean fromOverridesTo, boolean validate) { String from_model_cn = fromModel.getClass().getName(); String to_model_cn = toModel.getClass().getName(); if (!from_model_cn.equals(to_model_cn)) { throw new IllegalArgumentException(from_model_cn + " != " + to_model_cn); } Configuration from_model_config = fromModel.getModelConfiguration(); Configuration to_model_config = toModel.getModelConfiguration(); Configuration merged_model_config = Configurations.merge(from_model_config, to_model_config, fromOverridesTo); @SuppressWarnings("unchecked") M merged_model = (M)Descriptor.getMarshaller(toModel).read(merged_model_config); merged_model.orderModelChildren(); if (validate) { merged_model.assertModelValid(); } return merged_model; }
model.assertModelValid(); } else { getLog().warn("Skipping validation of SwitchYard configuration model. (Enable with <validate>true</validate>.)");
model.assertModelValid(); } else { getLog().warn("Skipping validation of SwitchYard configuration model. (Enable with <validate>true</validate>.)");