/** * Reads (constructs) a Model based on the specified Configuration. * @param config the Configuration * @return the new Model */ protected final synchronized Model readModel(Configuration config) { if (config != null) { Marshaller marsh = _desc.getMarshaller(config); if (marsh != null) { return marsh.read(config); } } return null; }
/** * Reads (constructs) a Model based on the specified Configuration. * @param config the Configuration * @return the new Model */ protected final synchronized Model readModel(Configuration config) { if (config != null) { Marshaller marsh = _desc.getMarshaller(config); if (marsh != null) { return marsh.read(config); } } return null; }
/** * Safely constructs a Model from an Element. * @param element the Model element * @return the Model, or null if element is null */ @SuppressWarnings("unchecked") public M pull(Element element) { String namespace = element.getNamespaceURI(); if (namespace != null) { Marshaller marshaller = _desc.getMarshaller(namespace); if (marshaller != null) { return (M) marshaller.read(new ConfigurationPuller().pull(element)); } } return null; }
/** * Safely constructs a Model from an Element. * @param element the Model element * @return the Model, or null if element is null */ @SuppressWarnings("unchecked") public M pull(Element element) { String namespace = element.getNamespaceURI(); if (namespace != null) { Marshaller marshaller = _desc.getMarshaller(namespace); if (marshaller != null) { return (M) marshaller.read(new ConfigurationPuller().pull(element)); } } return null; }
/** * Constructs a new V1ComponentImplementationModel with the specified Configuration and Descriptor. * @param config the Configuration * @param desc the Descriptor */ public V1ComponentImplementationModel(Configuration config, Descriptor desc) { super(config, desc); ClassLoader modelLoader = V1ComponentImplementationModel.class.getClassLoader(); for (Configuration eventListener_config : config.getChildren(EventListenerModel.EVENT_LISTENER)) { Marshaller marsh = desc.getMarshaller(eventListener_config.getQName().getNamespaceURI(), modelLoader); EventListenerModel eventListener = (EventListenerModel)marsh.read(eventListener_config); if (eventListener != null) { _eventListeners.add(eventListener); } } for (Configuration resource_config : config.getChildren(ResourceModel.RESOURCE)) { Marshaller marsh = desc.getMarshaller(resource_config.getQName().getNamespaceURI(), modelLoader); ResourceModel resource = (ResourceModel)marsh.read(resource_config); if (resource != null) { _resources.add(resource); } } }
/** * 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; }