com.haulmont.chile.core.model.MetaClass.getProperty()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(11.2k)|赞(0)|评价(0)|浏览(94)

本文整理了Java中com.haulmont.chile.core.model.MetaClass.getProperty()方法的一些代码示例,展示了MetaClass.getProperty()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MetaClass.getProperty()方法的具体详情如下:
包路径:com.haulmont.chile.core.model.MetaClass
类名称:MetaClass
方法名:getProperty

MetaClass.getProperty介绍

[英]Get MetaProperty by its name.
[中]通过名称获取元属性。

代码示例

代码示例来源:origin: com.haulmont.cuba/cuba-global

@Override
  public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    if ("hashCode".equals(method.getName())) {
      return hashCode();
    }
    if (metaProperty == null) {
      synchronized (this) {
        if (metaProperty == null) {
          metaProperty = domain.getProperty(name);
        }
      }
    }
    return method.invoke(metaProperty, args);
  }
}

代码示例来源:origin: com.haulmont.cuba/cuba-global

protected Object readResolve() throws InvalidObjectException {
  Session session = SessionImpl.serializationSupportSession;
  if (session == null) {
    return Proxy.newProxyInstance(
        this.getClass().getClassLoader(),
        new Class[]{MetaProperty.class},
        new MetaPropertyInvocationHandler(domain, name)
    );
  } else {
    return domain.getProperty(name);
  }
}

代码示例来源:origin: com.haulmont.cuba/cuba-global

/**
 * Get message reference of an entity property.
 * Messages pack part of the reference corresponds to the entity's package.
 * @param metaClass     MetaClass containing the property
 * @param propertyName  property's name
 * @return              message key in the form {@code msg://message_pack/message_id}
 */
public String getMessageRef(MetaClass metaClass, String propertyName) {
  MetaProperty property = metaClass.getProperty(propertyName);
  if (property == null) {
    throw new RuntimeException("Property " + propertyName + " is wrong for metaclass " + metaClass);
  }
  return getMessageRef(property);
}

代码示例来源:origin: com.haulmont.charts/charts-gui

protected boolean isEmbeddedIdProperty(String property, MetaClass metaClass) {
  MetaClass embeddedMetaClass = getEmbeddedIdMetaClass(metaClass);
  if (embeddedMetaClass == null) {
    return false;
  }
  String[] propertyPathParts = property.split("\\.");
  String propertyName = propertyPathParts[propertyPathParts.length - 1];
  MetaProperty metaProperty = embeddedMetaClass.getProperty(propertyName);
  return embeddedMetaClass.getOwnProperties().contains(metaProperty);
}

代码示例来源:origin: com.haulmont.cuba/cuba-global

protected void assignInverse(MetaPropertyImpl property, Range range, String inverseField) {
  if (inverseField == null)
    return;
  if (!range.isClass())
    throw new IllegalArgumentException("Range of class type expected");
  MetaClass metaClass = range.asClass();
  MetaProperty inverseProp = metaClass.getProperty(inverseField);
  if (inverseProp == null)
    throw new RuntimeException(String.format(
        "Unable to assign inverse property '%s' for '%s'", inverseField, property));
  property.setInverse(inverseProp);
}

代码示例来源:origin: com.haulmont.cuba/cuba-gui

@Override
public void setup(String id, Datasource masterDs, String property) {
  this.id = id;
  this.masterDs = masterDs;
  metaProperty = masterDs.getMetaClass().getProperty(property);
  initParentDsListeners();
}

代码示例来源:origin: com.haulmont.cuba/cuba-gui

@Override
public void setup(String id, Datasource masterDs, String property) {
  this.id = id;
  this.masterDs = masterDs;
  metaProperty = masterDs.getMetaClass().getProperty(property);
  initParentDsListeners();
}

代码示例来源:origin: com.haulmont.cuba/cuba-global

protected void addSystemPropertiesFrom(Class<?> baseClass, Class<?> entityClass, MetaClass metaClass,
                    Metadata metadata, Set<String> result) {
  if (baseClass.isAssignableFrom(entityClass)) {
    MetadataTools metadataTools = metadata.getTools();
    for (String property : getInterfaceProperties(baseClass)) {
      MetaProperty metaProperty = metaClass.getProperty(property);
      if (metaProperty != null && metadataTools.isPersistent(metaProperty)) {
        result.add(property);
      }
    }
  }
}

代码示例来源:origin: com.haulmont.cuba/cuba-global

/**
 * Determine whether the given property is not persistent. Inverse of {@link #isPersistent(MetaClass, MetaProperty)}.
 * <p>
 * For objects and properties not registered in metadata this method returns {@code true}.
 */
public boolean isNotPersistent(Object object, String property) {
  Objects.requireNonNull(object, "object is null");
  MetaClass metaClass = metadata.getSession().getClass(object.getClass());
  if (metaClass == null)
    return true;
  MetaProperty metaProperty = metaClass.getProperty(property);
  return metaProperty == null || !isPersistent(metaClass, metaProperty);
}

代码示例来源:origin: com.haulmont.cuba/cuba-gui

private void loadProperties(Element element, KeyValueContainer container) {
  Element propsEl = element.element("properties");
  if (propsEl != null) {
    for (Element propEl : propsEl.elements()) {
      String name = propEl.attributeValue("name");
      String className = propEl.attributeValue("class");
      if (className != null) {
        container.addProperty(name, ReflectionHelper.getClass(className));
      } else {
        String typeName = propEl.attributeValue("datatype");
        Datatype datatype = typeName == null ? Datatypes.getNN(String.class) : Datatypes.get(typeName);
        container.addProperty(name, datatype);
      }
    }
    String idProperty = propsEl.attributeValue("idProperty");
    if (idProperty != null) {
      if (container.getEntityMetaClass().getProperty(idProperty) == null)
        throw new DevelopmentException(String.format("Property '%s' is not defined", idProperty));
      container.setIdName(idProperty);
    }
  }
}

代码示例来源:origin: com.haulmont.cuba/cuba-global

@Override
public MetaPropertyPath getPropertyPath(String propertyPath) {
  String[] properties = propertyPath.split("\\."); // split should not create java.util.regex.Pattern
  // do not use ArrayList, leads to excessive memory allocation
  MetaProperty[] metaProperties = new MetaProperty[properties.length];
  MetaProperty currentProperty;
  MetaClass currentClass = this;
  for (int i = 0; i < properties.length; i++) {
    if (currentClass == null) {
      return null;
    }
    currentProperty = currentClass.getProperty(properties[i]);
    if (currentProperty == null) {
      return null;
    }
    Range range = currentProperty.getRange();
    currentClass = range.isClass() ? range.asClass() : null;
    metaProperties[i] = currentProperty;
  }
  return new MetaPropertyPath(this, metaProperties);
}

代码示例来源:origin: com.haulmont.charts/charts-gui

protected void checkValidProperty(@Nullable MetaClass metaClass, String name) {
  if (metaClass != null) {
    MetaProperty property = metaClass.getProperty(name);
    if (property != null
        && property.getRange().getCardinality() != null
        && property.getRange().getCardinality().isMany()) {
      throw new GuiDevelopmentException(String.format("'%s' cannot be added as a property, because " +
          "PivotTable doesn't support collections as properties", name), context.getFullFrameId());
    }
  }
}

代码示例来源:origin: com.haulmont.cuba/cuba-gui

/**
 * Determine whether the given metaProperty relates to at least one non local property
 */
protected boolean isRelatedToNonLocalProperty(MetaProperty metaProperty) {
  MetaClass metaClass = metaProperty.getDomain();
  for (String relatedProperty : metadata.getTools().getRelatedProperties(metaProperty)) {
    //noinspection ConstantConditions
    if (metaClass.getProperty(relatedProperty).getRange().isClass()) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: com.haulmont.reports/reports-gui

protected void sortParametersByPosition() {
  MetaClass metaClass = metadata.getClassNN(ReportInputParameter.class);
  MetaPropertyPath mpp = new MetaPropertyPath(metaClass, metaClass.getProperty("position"));
  CollectionDatasource.Sortable.SortInfo<MetaPropertyPath> sortInfo = new CollectionDatasource.Sortable.SortInfo<>();
  sortInfo.setOrder(CollectionDatasource.Sortable.Order.ASC);
  sortInfo.setPropertyPath(mpp);
  parametersDs.sort(new CollectionDatasource.Sortable.SortInfo[]{sortInfo});
}

代码示例来源:origin: com.haulmont.cuba/cuba-global

public String getLocValue(String value) {
    if (Strings.isNullOrEmpty(value)) return value;

    String entityName = getLogItem().getEntity();
    com.haulmont.chile.core.model.MetaClass metaClass = getClassFromEntityName(entityName);
    if (metaClass != null) {
      com.haulmont.chile.core.model.MetaProperty property = metaClass.getProperty(name);
      if (property != null && property.getRange().isEnum()) {
        try {
          Enum caller = Enum.valueOf((Class<Enum>) property.getJavaType(), value);
          Messages messages = AppBeans.get(Messages.NAME);
          return messages.getMessage(caller);
        } catch (IllegalArgumentException ignored) {}
      }
    }

    if (!StringUtils.isBlank(messagesPack)) {
      Messages messages = AppBeans.get(Messages.NAME);
      return messages.getMessage(messagesPack, value);
    } else {
      return value;
    }
  }
}

代码示例来源:origin: com.haulmont.cuba/cuba-global

protected void writeIdField(Entity entity, JsonObject jsonObject) {
  MetaProperty primaryKeyProperty = metadataTools.getPrimaryKeyProperty(entity.getMetaClass());
  if (primaryKeyProperty == null) {
    primaryKeyProperty = entity.getMetaClass().getProperty("id");
  }
  if (primaryKeyProperty == null)
    throw new EntitySerializationException("Primary key property not found for entity " + entity.getMetaClass());
  if (metadataTools.hasCompositePrimaryKey(entity.getMetaClass())) {
    JsonObject serializedIdEntity = serializeEntity((Entity) entity.getId(), null, Collections.emptySet());
    jsonObject.add("id", serializedIdEntity);
  } else {
    Datatype idDatatype = Datatypes.getNN(primaryKeyProperty.getJavaType());
    jsonObject.addProperty("id", idDatatype.format(entity.getId()));
  }
}

代码示例来源:origin: com.haulmont.charts/charts-web

protected void detectDateBasedCategoryAxis() {
  MetaClass metaClass = getDataProvider() instanceof HasMetaClass ?
      ((HasMetaClass) getDataProvider()).getMetaClass() : null;
  if (metaClass != null
      && StringUtils.isNotEmpty(getCategoryField())
      && getCategoryAxis() != null
      && getCategoryAxis().getParseDates() == null) {
    MetaProperty property = metaClass.getProperty(getCategoryField());
    if (property == null) {
      throw new DevelopmentException(
          String.format("Unable to find metaproperty '%s' for class '%s'", getCategoryField(), metaClass));
    }
    if (Date.class.isAssignableFrom(property.getJavaType())) {
      getCategoryAxis().setParseDates(true);
    }
  }
}

代码示例来源:origin: com.haulmont.cuba/cuba-core

protected Set<EntityLogAttr> createDynamicLogAttribute(CategoryAttributeValue entity, @Nullable EntityAttributeChanges changes, boolean registerDeleteOp) {
  Set<EntityLogAttr> result = new HashSet<>();
  EntityLogAttr attr = metadata.create(EntityLogAttr.class);
  attr.setName(DynamicAttributesUtils.encodeAttributeCode(entity.getCode()));
  MetaProperty valueMetaProperty = entity.getMetaClass().getProperty(getCategoryAttributeValueName(entity));
  Object value = entity.getValue();
  attr.setValue(stringify(value, valueMetaProperty));
  Object valueId = getValueId(value);
  if (valueId != null)
    attr.setValueId(valueId.toString());
  if (changes != null || registerDeleteOp) {
    Object oldValue = getOldCategoryAttributeValue(entity, changes);
    attr.setOldValue(stringify(oldValue, valueMetaProperty));
    Object oldValueId = getValueId(oldValue);
    if (oldValueId != null) {
      attr.setOldValueId(oldValueId.toString());
    }
  }
  result.add(attr);
  return result;
}

代码示例来源:origin: com.haulmont.charts/charts-gui

protected void copyViewProperties(View src, View target, MetaClass metaClass) {
  for (ViewProperty viewProperty : src.getProperties()) {
    MetaProperty metaProperty = metaClass.getProperty(viewProperty.getName());
    if (metaProperty == null || !metadata.getTools().isSystemLevel(metaProperty)) {
      if (!target.containsProperty(viewProperty.getName())) {
        target.addProperty(viewProperty.getName(), viewProperty.getView(), viewProperty.getFetchMode());
      }
    }
  }
}

代码示例来源:origin: com.haulmont.cuba/cuba-gui

protected void copyViewProperties(View src, View target) {
    for (ViewProperty viewProperty : src.getProperties()) {
      MetaProperty metaProperty = metaClass.getProperty(viewProperty.getName());
      if (metaProperty == null || !metadata.getTools().isSystemLevel(metaProperty)) {
        if (!target.containsProperty(viewProperty.getName())) {
          target.addProperty(viewProperty.getName(), viewProperty.getView(), viewProperty.getFetchMode());
        }
      }
    }
  }
}

相关文章