private static AttributeDefinition createAttributeDefinition(Map<String, String> beanAttr) { if (beanAttr == null) return null; AttributeDefinition attributeDefinition = new AttributeDefinition(); attributeDefinition.setId(Integer.valueOf(beanAttr.get("id")).intValue()); attributeDefinition.setFriendlyName(BeansUtils.eraseEscaping(beanAttr.get("friendlyName"))); attributeDefinition.setNamespace(BeansUtils.eraseEscaping(beanAttr.get("namespace"))); attributeDefinition.setType(BeansUtils.eraseEscaping(beanAttr.get("type"))); return attributeDefinition; }
private void registerDependencies(AttributeDefinition defn) { // checks List<Check<?>> checks = defn.getChecks(); for (Check<?> check : checks) { registerCheckDependencies(defn, check); } if (defn instanceof CodeAttributeDefinition) { // register parent code dependencies CodeAttributeDefinition currentCodeDefn = (CodeAttributeDefinition) defn; while (currentCodeDefn != null) { validationDependencies.registerDependencies(defn, currentCodeDefn.getParentExpression()); currentCodeDefn = currentCodeDefn.getParentCodeAttributeDefinition(); } } // calculated values if (defn.isCalculated()) { List<AttributeDefault> attributeDefaults = defn.getAttributeDefaults(); for (AttributeDefault attributeDefault : attributeDefaults) { calculatedValueDependencies.registerDependencies(defn, attributeDefault.getCondition()); calculatedValueDependencies.registerDependencies(defn, attributeDefault.getExpression()); } } }
@Override public AttributeDefinition getAttributeDefinition() { AttributeDefinition attr = new AttributeDefinition(); attr.setNamespace(AttributesManager.NS_FACILITY_ATTR_DEF); attr.setFriendlyName("ldapBaseDN"); attr.setDisplayName("LDAP base DN"); attr.setType(String.class.getName()); attr.setDescription( "Base part of DN, which will be used for all entities propagated to facility. Should be like \"ou=sth,dc=example,dc=domain\" (without quotes)"); return attr; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; ProductMarketingTypeAttribute other = (ProductMarketingTypeAttribute) obj; if (attributeDefinition == null) { if (other.attributeDefinition != null) return false; } else if (!attributeDefinition.equals(other.attributeDefinition)) return false; if (!Arrays.equals(blobValue, other.blobValue)) return false; if (booleanValue == null) { if (other.booleanValue != null) return false; } else if (!booleanValue.equals(other.booleanValue)) return false; if (dateCreate == null) { if (other.dateCreate != null) return false; } else if (!dateCreate.equals(other.dateCreate)) return false; if (dateUpdate == null) { if (other.dateUpdate != null) return false; } else if (!dateUpdate.equals(other.dateUpdate)) return false; if (doubleValue == null) { if (other.doubleValue != null) return false; } else if (!doubleValue.equals(other.doubleValue)) return false; if (endDate == null) { if (other.endDate != null) return false; } else if (!endDate.equals(other.endDate)) return false; if (floatValue == null) { if (other.floatValue != null) return false; } else if (!floatValue.equals(other.floatValue)) return false; if (id == null) { if (other.id != null) return false; } else if (!id.equals(other.id)) return false; if (integerValue == null) { if (other.integerValue != null) return false; } else if (!integerValue.equals(other.integerValue)) return false; if (localizationCode == null) { if (other.localizationCode != null) return false; } else if (!localizationCode.equals(other.localizationCode)) return false; if (startDate == null) { if (other.startDate != null) return false; } else if (!startDate.equals(other.startDate)) return false; if (stringValue == null) { if (other.stringValue != null) return false; } else if (!stringValue.equals(other.stringValue)) return false; if (version != other.version) return false; return true; }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((attributeDefinition == null) ? 0 : attributeDefinition.hashCode()); result = prime * result + Arrays.hashCode(blobValue); result = prime * result + ((booleanValue == null) ? 0 : booleanValue.hashCode()); result = prime * result + ((dateCreate == null) ? 0 : dateCreate.hashCode()); result = prime * result + ((dateUpdate == null) ? 0 : dateUpdate.hashCode()); result = prime * result + ((doubleValue == null) ? 0 : doubleValue.hashCode()); result = prime * result + ((endDate == null) ? 0 : endDate.hashCode()); result = prime * result + ((floatValue == null) ? 0 : floatValue.hashCode()); result = prime * result + ((id == null) ? 0 : id.hashCode()); result = prime * result + ((integerValue == null) ? 0 : integerValue.hashCode()); result = prime * result + ((localizationCode == null) ? 0 : localizationCode.hashCode()); result = prime * result + ((startDate == null) ? 0 : startDate.hashCode()); result = prime * result + ((stringValue == null) ? 0 : stringValue.hashCode()); result = prime * result + version; return result; }
@Override public ModelNode getModelDescription(final Locale locale) { final ResourceBundle bundle = getResourceBundle(locale); final ModelNode operation = new ModelNode(); operation.get(OPERATION_NAME).set(ADD); operation.get(DESCRIPTION).set(bundle.getString("xa-data-source.add")); for (AttributeDefinition propertyType : XA_DATASOURCE_ATTRIBUTE) { operation .get(REQUEST_PROPERTIES, propertyType.getName(), DESCRIPTION) .set(bundle.getString(propertyType.getName())); operation .get(REQUEST_PROPERTIES, propertyType.getName(), TYPE) .set(propertyType.getModelType()); operation .get(REQUEST_PROPERTIES, propertyType.getName(), REQUIRED) .set(propertyType.isRequired()); } return operation; }
@Override public ModelNode getModelDescription(final Locale locale) { final ResourceBundle bundle = getResourceBundle(locale); final ModelNode node = new ModelNode(); node.get(DESCRIPTION).set(bundle.getString("data-source.description")); node.get(HEAD_COMMENT_ALLOWED).set(true); node.get(TAIL_COMMENT_ALLOWED).set(true); for (AttributeDefinition propertyType : DATASOURCE_ATTRIBUTE) { node.get(ATTRIBUTES, propertyType.getName(), DESCRIPTION) .set(bundle.getString(propertyType.getName())); node.get(ATTRIBUTES, propertyType.getName(), TYPE).set(propertyType.getModelType()); node.get(ATTRIBUTES, propertyType.getName(), REQUIRED).set(propertyType.isRequired()); } for (String name : LocalAndXaDataSourcesJdbcMetrics.ATTRIBUTES) { node.get(ATTRIBUTES, name, DESCRIPTION).set(jdbcMetrics.getDescription(name)); ModelType modelType = ModelType.STRING; if (jdbcMetrics.getType(name) == int.class) { modelType = ModelType.INT; } if (jdbcMetrics.getType(name) == long.class) { modelType = ModelType.LONG; } node.get(ATTRIBUTES, name, TYPE).set(modelType); node.get(ATTRIBUTES, name, REQUIRED).set(false); } for (String name : PoolMetrics.ATTRIBUTES) { node.get(ATTRIBUTES, name, DESCRIPTION).set(poolMetrics.getDescription(name)); ModelType modelType = ModelType.STRING; if (poolMetrics.getType(name) == int.class) { modelType = ModelType.INT; } if (poolMetrics.getType(name) == long.class) { modelType = ModelType.LONG; } node.get(ATTRIBUTES, name, TYPE).set(modelType); node.get(ATTRIBUTES, name, REQUIRED).set(false); } return node; }
private CatalogCategoryMasterAttribute getCatalogCategoryAttribute( Set<CatalogCategoryMasterAttribute> catalogCategoryAttributes, String attributeCode, Long marketAreaId, String localizationCode) { CatalogCategoryMasterAttribute catalogCategoryAttributeToReturn = null; List<CatalogCategoryMasterAttribute> catalogCategoryAttributesFilter = new ArrayList<CatalogCategoryMasterAttribute>(); if (catalogCategoryAttributes != null) { // GET ALL CategoryAttributes FOR THIS ATTRIBUTE for (Iterator<CatalogCategoryMasterAttribute> iterator = catalogCategoryAttributes.iterator(); iterator.hasNext(); ) { CatalogCategoryMasterAttribute catalogCategoryAttribute = (CatalogCategoryMasterAttribute) iterator.next(); AttributeDefinition attributeDefinition = catalogCategoryAttribute.getAttributeDefinition(); if (attributeDefinition != null && attributeDefinition.getCode().equalsIgnoreCase(attributeCode)) { catalogCategoryAttributesFilter.add(catalogCategoryAttribute); } } // REMOVE ALL CategoryAttributes NOT ON THIS MARKET AREA if (marketAreaId != null) { for (Iterator<CatalogCategoryMasterAttribute> iterator = catalogCategoryAttributesFilter.iterator(); iterator.hasNext(); ) { CatalogCategoryMasterAttribute catalogCategoryAttribute = (CatalogCategoryMasterAttribute) iterator.next(); AttributeDefinition attributeDefinition = catalogCategoryAttribute.getAttributeDefinition(); if (BooleanUtils.negate(attributeDefinition.isGlobal())) { if (catalogCategoryAttribute.getMarketAreaId() != null && BooleanUtils.negate( catalogCategoryAttribute.getMarketAreaId().equals(marketAreaId))) { iterator.remove(); } } } } // FINALLY RETAIN ONLY CategoryAttributes FOR THIS LOCALIZATION CODE if (StringUtils.isNotEmpty(localizationCode)) { for (Iterator<CatalogCategoryMasterAttribute> iterator = catalogCategoryAttributesFilter.iterator(); iterator.hasNext(); ) { CatalogCategoryMasterAttribute catalogCategoryAttribute = (CatalogCategoryMasterAttribute) iterator.next(); AttributeDefinition attributeDefinition = catalogCategoryAttribute.getAttributeDefinition(); if (BooleanUtils.negate(attributeDefinition.isGlobal())) { String attributeLocalizationCode = catalogCategoryAttribute.getLocalizationCode(); if (StringUtils.isNotEmpty(attributeLocalizationCode) && BooleanUtils.negate(attributeLocalizationCode.equals(localizationCode))) { iterator.remove(); } } } if (catalogCategoryAttributesFilter.size() == 0) { // TODO : warning ? // NOT ANY CategoryAttributes FOR THIS LOCALIZATION CODE - GET A FALLBACK for (Iterator<CatalogCategoryMasterAttribute> iterator = catalogCategoryMarketAreaAttributes.iterator(); iterator.hasNext(); ) { CatalogCategoryMasterAttribute catalogCategoryAttribute = (CatalogCategoryMasterAttribute) iterator.next(); // TODO : get a default locale code from setting database ? if (Constants.DEFAULT_LOCALE_CODE.equals( catalogCategoryAttribute.getLocalizationCode())) { catalogCategoryAttributeToReturn = catalogCategoryAttribute; } } } } } if (catalogCategoryAttributesFilter.size() == 1) { catalogCategoryAttributeToReturn = catalogCategoryAttributesFilter.get(0); } else { // TODO : throw error ? } return catalogCategoryAttributeToReturn; }
public OperationResult execute( final OperationContext context, final ModelNode operation, final ResultHandler resultHandler) throws OperationFailedException { final ModelNode opAddr = operation.require(OP_ADDR); final String jndiName = PathAddress.pathAddress(opAddr).getLastElement().getValue(); // Compensating is add final ModelNode model = context.getSubModel(); final ModelNode compensating = Util.getEmptyOperation(ADD, opAddr); if (model.has(CONNECTION_PROPERTIES)) { for (ModelNode property : model.get(CONNECTION_PROPERTIES).asList()) { compensating .get(CONNECTION_PROPERTIES, property.asProperty().getName()) .set(property.asString()); } } for (final AttributeDefinition attribute : getModelProperties()) { if (model.get(attribute.getName()).isDefined()) { compensating.get(attribute.getName()).set(model.get(attribute.getName())); } } if (context.getRuntimeContext() != null) { context .getRuntimeContext() .setRuntimeTask( new RuntimeTask() { public void execute(RuntimeTaskContext context) throws OperationFailedException { final ServiceRegistry registry = context.getServiceRegistry(); final ServiceName binderServiceName = ContextNames.JAVA_CONTEXT_SERVICE_NAME.append(jndiName); final ServiceController<?> binderController = registry.getService(binderServiceName); if (binderController != null) { binderController.setMode(ServiceController.Mode.REMOVE); } final ServiceName referenceFactoryServiceName = DataSourceReferenceFactoryService.SERVICE_NAME_BASE.append(jndiName); final ServiceController<?> referenceFactoryController = registry.getService(referenceFactoryServiceName); if (referenceFactoryController != null) { referenceFactoryController.setMode(ServiceController.Mode.REMOVE); } final ServiceName dataSourceServiceName = AbstractDataSourceService.SERVICE_NAME_BASE.append(jndiName); final ServiceController<?> dataSourceController = registry.getService(dataSourceServiceName); if (dataSourceController != null) { dataSourceController.setMode(ServiceController.Mode.REMOVE); } resultHandler.handleResultComplete(); } }); } else { resultHandler.handleResultComplete(); } return new BasicOperationResult(compensating); }
/** * Process an "attribute" element. * * @param element The "attribute" element. */ protected void processAttribute(Element element) { // Check to see whether this is an attribute reference first. String ref = element.getAttributeValue("ref"); if (ref != null) { println("Parsing attribute reference to '" + ref + "'"); AttributeReference reference = scope.getAttributeReference(ref); // Add the attribute reference to the enclosing attribute list. attributeList.add(reference); // Nothing else to do. return; } // Ensure that the element has a name. String name = element.getAttributeValue("name"); if (name == null) { throw new IllegalStateException("Attribute does not have a name"); } println("Parsing attribute definition for '" + name + "'"); // Create a new AttributeDefinition object in the current scope, this // will throw an exception if there is a clash. AttributeDefinition definition = scope.addAttributeDefinition(name); // Process the attributes. List attributes = element.getAttributes(); for (Iterator i = attributes.iterator(); i.hasNext(); ) { Attribute attribute = (Attribute) i.next(); Namespace attributeNamespace = attribute.getNamespace(); String attributeName = attribute.getName(); if (attributeNamespace == xsdNamespace || attributeNamespace == Namespace.NO_NAMESPACE) { if ("default".equals(attributeName)) { // Set the attribute default value. definition.setDefault(attribute.getValue()); } else if ("name".equals(attributeName)) { // Don't do anything else. } else if ("fixed".equals(attributeName)) { // Don't do anything else. } else if ("type".equals(attributeName)) { // Set the attribute type. definition.setType(attribute.getValue()); } else if ("use".equals(attributeName)) { // Set the attribute use. definition.setUse(attribute.getValue()); } else { throw new IllegalStateException("Unknown schema attribute '" + attributeName + "'"); } } else { throw new IllegalStateException("Unknown attribute namespace '" + attributeNamespace + "'"); } } // Add the attribute definition to the list of attributes. attributeList.add(definition); // Push the attribute definition object onto the stack. schemaObjects.push(definition); // Process the contents of the attribute. parseContent(element); // Pop the attribute definition object from the stack. schemaObjects.pop(); }