/** * Adds a child model to this model. * @param child the child to add * @return this model (useful for chaining) */ protected final Model addChildModel(Model child) { if (child != null) { _config.addChild(child.getModelConfiguration()); } return this; }
/** * Get the content of the requires attribute as a set of strings. * @param model the model to query for required policy * @return set of policy requirements; empty set if nothing found */ public static Set<QName> getRequirements(Model model) { return model.getModelConfiguration().getAttributeAsQNames(REQUIRES, " "); }
/** * Adds a child model to this model. * @param child the child to add * @return this model (useful for chaining) */ protected final Model addChildModel(Model child) { if (child != null) { _config.addChild(child.getModelConfiguration()); } return this; }
/** * Get the content of the requires attribute as a set of strings. * @param model the model to query for required policy * @return set of policy requirements; empty set if nothing found */ public static Set<QName> getRequirements(Model model) { return model.getModelConfiguration().getAttributeAsQNames(REQUIRES, " "); }
/** * Set the content of the requires attribute for a given config model. * @param model the model to set policy requirements on. * @param requirements the set of policy requirements. */ public static void setRequirements(Model model, Set<QName> requirements) { Configuration config = model.getModelConfiguration(); if (requirements == null || requirements.isEmpty()) { config.setAttribute(REQUIRES, null); return; } StringBuilder requires = new StringBuilder(); for (QName req : requirements) { requires.append(" "); String ns = req.getNamespaceURI(); if (XMLConstants.DEFAULT_NS_PREFIX.equals(ns)) { requires.append(req.getLocalPart()); } else { String pfx = config.lookupPrefix(ns); if (pfx != null) { requires.append(pfx + ":" + req.getLocalPart()); } else { // SCA cvc-datatype-valid.1.2.1 XSD doesn't allow for {namespaceURI}localPart format //requires.append(req.toString()); requires.append(req.getLocalPart()); } } } config.setAttribute(REQUIRES, requires.toString().trim()); }
/** * Set the content of the requires attribute for a given config model. * @param model the model to set policy requirements on. * @param requirements the set of policy requirements. */ public static void setRequirements(Model model, Set<QName> requirements) { Configuration config = model.getModelConfiguration(); if (requirements == null || requirements.isEmpty()) { config.setAttribute(REQUIRES, null); return; } StringBuilder requires = new StringBuilder(); for (QName req : requirements) { requires.append(" "); String ns = req.getNamespaceURI(); if (XMLConstants.DEFAULT_NS_PREFIX.equals(ns)) { requires.append(req.getLocalPart()); } else { String pfx = config.lookupPrefix(ns); if (pfx != null) { requires.append(pfx + ":" + req.getLocalPart()); } else { // SCA cvc-datatype-valid.1.2.1 XSD doesn't allow for {namespaceURI}localPart format //requires.append(req.toString()); requires.append(req.getLocalPart()); } } } config.setAttribute(REQUIRES, requires.toString().trim()); }
/** * Lazily gets (and possibly creating and caching) a Marshaller based on the namespace of the wrapped Configuration of the specified Model. * @param model the Model * @return the appropriate Marshaller to use * @see #getMarshaller(Configuration) * @see #getMarshaller(String) */ public static Marshaller getMarshaller(Model model) { if (model != null) { Descriptor desc = model.getModelDescriptor(); if (desc != null) { return desc.getMarshaller(model.getModelConfiguration()); } } return null; }
/** * Creates a new Schema based on the namespaces of the Configuration wrapped by the specified Model. * @param model the Model * @return the new Schema * @see #getSchema(Configuration) * @see #getSchema(Set) */ public static Schema getSchema(Model model) { if (model != null) { Descriptor desc = model.getModelDescriptor(); if (desc != null) { return desc.getSchema(model.getModelConfiguration()); } } return null; }
/** * Lazily gets (and possibly creating and caching) a Marshaller based on the namespace of the wrapped Configuration of the specified Model. * @param model the Model * @return the appropriate Marshaller to use * @see #getMarshaller(Configuration) * @see #getMarshaller(String) */ public static Marshaller getMarshaller(Model model) { if (model != null) { Descriptor desc = model.getModelDescriptor(); if (desc != null) { return desc.getMarshaller(model.getModelConfiguration()); } } return null; }
/** * Creates a new Schema based on the namespaces of the Configuration wrapped by the specified Model. * @param model the Model * @return the new Schema * @see #getSchema(Configuration) * @see #getSchema(Set) */ public static Schema getSchema(Model model) { if (model != null) { Descriptor desc = model.getModelDescriptor(); if (desc != null) { return desc.getSchema(model.getModelConfiguration()); } } 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; }
/** * First removes all child models with a wrapped Configuration which has a matching qualified name, then adds the single, specified child model. * @param child the child model to add * @return this model (useful for chaining) */ protected final Model setChildModel(Model child) { if (child != null) { Configuration child_config = child.getModelConfiguration(); _config.removeChildren(child_config.getQName()); _config.addChild(child_config); } return this; }
/** * First removes all child models with a wrapped Configuration which has a matching qualified name, then adds the single, specified child model. * @param child the child model to add * @return this model (useful for chaining) */ protected final Model setChildModel(Model child) { if (child != null) { Configuration child_config = child.getModelConfiguration(); _config.removeChildren(child_config.getQName()); _config.addChild(child_config); } return this; }
protected <T extends Model> T replaceChildren(String children, T model) { Configuration config = getModelConfiguration().getFirstChild(children); if (config != null) { // set an existing config value getModelConfiguration().removeChildren(children); getModelConfiguration().addChild(model.getModelConfiguration()); } else { setChildModel(model); } return model; }
protected <T extends Model> T replaceChildren(String children, T model) { Configuration config = getModelConfiguration().getFirstChild(children); if (config != null) { // set an existing config value getModelConfiguration().removeChildren(children); getModelConfiguration().addChild(model.getModelConfiguration()); } else { setChildModel(model); } return model; }
Configuration config = merged.getModelConfiguration(); final String xmlns_x2 = XMLNS_ATTRIBUTE + ":" + XMLNS_ATTRIBUTE; if (config.hasAttribute(xmlns_x2)) {
Configuration config = merged.getModelConfiguration(); final String xmlns_x2 = XMLNS_ATTRIBUTE + ":" + XMLNS_ATTRIBUTE; if (config.hasAttribute(xmlns_x2)) {