org.nakedobjects.metamodel.spec.NakedObjectSpecification.isOfType()方法的使用及代码示例

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

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

NakedObjectSpecification.isOfType介绍

暂无

代码示例

代码示例来源:origin: org.nakedobjects/metamodel

/**
 * Determines if this class represents the same class, or a subclass, of the specified class.
 */
@Override
public boolean isOfType(final NakedObjectSpecification specification) {
  if (specification == this) {
    return true;
  } else {
    if (interfaces != null) {
      for (int i = 0, len = interfaces.length; i < len; i++) {
        if (interfaces[i].isOfType(specification)) {
          return true;
        }
      }
    }
    if (superClassSpecification != null) {
      return superClassSpecification.isOfType(specification);
    }
  }
  return false;
}

代码示例来源:origin: org.nakedobjects.core/metamodel

/**
 * Determines if this class represents the same class, or a subclass, of the specified class.
 */
@Override
public boolean isOfType(final NakedObjectSpecification specification) {
  if (specification == this) {
    return true;
  } else {
    if (interfaces != null) {
      for (int i = 0, len = interfaces.length; i < len; i++) {
        if (interfaces[i].isOfType(specification)) {
          return true;
        }
      }
    }
    if (superClassSpecification != null) {
      return superClassSpecification.isOfType(specification);
    }
  }
  return false;
}

代码示例来源:origin: org.nakedobjects.plugins/htmlviewer-viewer

/**
 * Returns an array of instances of the specified type that are currently known in the current context, ie
 * have been recently seen by the user.
 */
public NakedObject[] getKnownInstances(final NakedObjectSpecification type) {
  final List instances = new ArrayList();
  for(String id: objectMap.keySet()) {
    final NakedObject object = getMappedObject(id);
    if (object.getSpecification().isOfType(type)) {
      instances.add(object);
    }
  }
  final NakedObject[] array = new NakedObject[instances.size()];
  instances.toArray(array);
  return array;
}

代码示例来源:origin: org.nakedobjects.plugins/html-viewer

/**
 * Returns an array of instances of the specified type that are currently known in the current context, ie
 * have been recently seen by the user.
 * 
 * <p>
 * These will be resolved if required, with a transaction created (and ended) if required.
 */
public NakedObject[] getKnownInstances(final NakedObjectSpecification type) {
  
  final List<NakedObject> instances = new ArrayList<NakedObject>();
  for(String id: objectMap.keySet()) {
    final NakedObject adapter = getMappedObject(id);
    NakedObjectsContext.getPersistenceSession().resolveImmediately(adapter);
    if (adapter.getSpecification().isOfType(type)) {
      instances.add(adapter);
    }
  }
  
  final NakedObject[] array = new NakedObject[instances.size()];
  instances.toArray(array);
  return array;
}

代码示例来源:origin: org.nakedobjects/metamodel

public NakedObjectAction[] getServiceActionsFor(final NakedObjectActionType type) {
  final List<NakedObject> services = getRuntimeContext().getServices();
  final List<NakedObjectAction> relatedActions = new ArrayList<NakedObjectAction>();
  for (NakedObject serviceAdapter : services) {
    final NakedObjectAction[] serviceActions = serviceAdapter.getSpecification().getObjectActions(type);
    final List<NakedObjectAction> matchingActions = new ArrayList<NakedObjectAction>();
    for (int j = 0; j < serviceActions.length; j++) {
      final NakedObjectSpecification returnType = serviceActions[j].getReturnType();
      if (returnType != null && returnType.isCollection()) {
        final TypeOfFacet facet = returnType.getFacet(TypeOfFacet.class);
        final NakedObjectSpecification elementType = facet.valueSpec();
        if (elementType.isOfType(this)) {
          matchingActions.add(serviceActions[j]);
        }
      } else if (returnType != null && returnType.isOfType(this)) {
        matchingActions.add(serviceActions[j]);
      }
    }
    if (matchingActions.size() > 0) {
      final NakedObjectActionSet set = new NakedObjectActionSet("id", serviceAdapter.titleString(), matchingActions, runtimeContext);
      relatedActions.add(set);
    }
  }
  return (NakedObjectAction[]) relatedActions.toArray(new NakedObjectAction[relatedActions.size()]);
}

代码示例来源:origin: org.nakedobjects/metamodel

protected static void checkChoicesType(RuntimeContext runtimeContext, Object[] objects, NakedObjectSpecification paramSpec) {
  for (Object object : objects) {
    NakedObjectSpecification componentSpec = runtimeContext.getSpecificationLoader().loadSpecification(object.getClass());
    if (!componentSpec.isOfType(paramSpec)) {
      throw new ModelException("Choice type incompatible with parameter type; expected " + paramSpec.getFullName() + ", but was " + componentSpec.getFullName());
    }
  }
}

代码示例来源:origin: org.nakedobjects.core/metamodel

protected static void checkChoicesType(RuntimeContext runtimeContext, Object[] objects, NakedObjectSpecification paramSpec) {
  for (Object object : objects) {
    NakedObjectSpecification componentSpec = runtimeContext.getSpecificationLoader().loadSpecification(object.getClass());
    if (!componentSpec.isOfType(paramSpec)) {
      throw new ModelException("Choice type incompatible with parameter type; expected " + paramSpec.getFullName() + ", but was " + componentSpec.getFullName());
    }
  }
}

代码示例来源:origin: org.nakedobjects.plugins/dndviewer

@Override
public Consent canSet(final NakedObject dragSource) {
  if (dragSource.getSpecification().isOfType(getSpecification())) {
    // TODO: move logic into Facet
    return Allow.DEFAULT;
  } else {
    // TODO: move logic into Facet
    return new Veto(String.format("Object must be ", getSpecification().getShortName()));
  }
}

代码示例来源:origin: org.nakedobjects.core/metamodel

public NakedObjectAction[] getServiceActionsFor(final NakedObjectActionType... types) {
  final List<NakedObject> services = getRuntimeContext().getServices();
  final List<NakedObjectAction> relatedActions = new ArrayList<NakedObjectAction>();
    for (NakedObject serviceAdapter : services) {
      final List<NakedObjectAction> matchingActions = new ArrayList<NakedObjectAction>();
    for (NakedObjectActionType type : types) {
      final NakedObjectAction[] serviceActions = serviceAdapter.getSpecification().getObjectActions(type);
      for (int j = 0; j < serviceActions.length; j++) {
        final NakedObjectSpecification returnType = serviceActions[j].getReturnType();
        if (returnType != null && returnType.isCollection()) {
          final TypeOfFacet facet = serviceActions[j].getFacet(TypeOfFacet.class);
          final NakedObjectSpecification elementType = facet.valueSpec();
          if (elementType.isOfType(this)) {
            matchingActions.add(serviceActions[j]);
          }
        } else if (returnType != null && returnType.isOfType(this)) {
          matchingActions.add(serviceActions[j]);
        }
      }
    }
    if (matchingActions.size() > 0) {
      final NakedObjectActionSet set = new NakedObjectActionSet("id", serviceAdapter.titleString(), matchingActions,
          runtimeContext);
      relatedActions.add(set);
    }
  }
  return (NakedObjectAction[]) relatedActions.toArray(new NakedObjectAction[relatedActions.size()]);
}

代码示例来源:origin: org.nakedobjects.plugins/htmlviewer-viewer

public void setFromFields(final Request request, final Context context) {
  int fldNo = 0;
  for (int i = boundaries[step]; i < boundaries[step + 1]; i++) {
    String textEntry = request.getFieldEntry(fldNo++);
    if (readOnly[i]) {
      continue;
    }
    final NakedObjectSpecification spec = fieldSpecifications[i];
    // deal with check boxes specially: expect 'true' if checked and no entry if not checked, hence
    // need to set as 'false'
    if (spec.isOfType(NakedObjectsContext.getSpecificationLoader().loadSpecification(boolean.class))
        || spec.isOfType(NakedObjectsContext.getSpecificationLoader().loadSpecification(Boolean.class))) {
      if (textEntry == null || !textEntry.equals("true")) {
        textEntry = "false";
      }
    }
    entryText[i] = textEntry;
    try {
      errors[i] = null;
      setFromField(context, i, spec, textEntry);
      if (!optional[i] && (textEntry == null || textEntry.equals(""))) {
        errors[i] = "Field required";
      }
    } catch (final InvalidEntryException e) {
      errors[i] = e.getMessage();
    } catch (final TextEntryParseException e) {
      errors[i] = e.getMessage();
    }
  }
}

代码示例来源:origin: org.nakedobjects.plugins/html-viewer

public void setFromFields(final Request request, final Context context) {
  int fldNo = 0;
  for (int i = boundaries[step]; i < boundaries[step + 1]; i++) {
    String textEntry = request.getFieldEntry(fldNo++);
    if (readOnly[i]) {
      continue;
    }
    final NakedObjectSpecification spec = fieldSpecifications[i];
    // deal with check boxes specially: expect 'true' if checked and no entry if not checked, hence
    // need to set as 'false'
    if (spec.isOfType(NakedObjectsContext.getSpecificationLoader().loadSpecification(boolean.class))
        || spec.isOfType(NakedObjectsContext.getSpecificationLoader().loadSpecification(Boolean.class))) {
      if (textEntry == null || !textEntry.equals("true")) {
        textEntry = "false";
      }
    }
    entryText[i] = textEntry;
    try {
      errors[i] = null;
      setFromField(context, i, spec, textEntry);
      if (!optional[i] && (textEntry == null || textEntry.equals(""))) {
        errors[i] = "Field required";
      }
    } catch (final InvalidEntryException e) {
      errors[i] = e.getMessage();
    } catch (final TextEntryParseException e) {
      errors[i] = e.getMessage();
    }
  }
}

代码示例来源:origin: org.nakedobjects/metamodel

public boolean promptForParameters(final NakedObject target) {
  NakedObjectActionParameter[] parameters = getParameters();
  if (isContributed() && !target.getSpecification().isService()) {
    return getParameterCount() > 1 || !target.getSpecification().isOfType(parameters[0].getSpecification());
  } else {
    return getParameterCount() > 0;
  }
}

代码示例来源:origin: org.nakedobjects.core/metamodel

public boolean promptForParameters(final NakedObject target) {
  NakedObjectActionParameter[] parameters = getParameters();
  if (isContributed() && !target.getSpecification().isService()) {
    return getParameterCount() > 1 || !target.getSpecification().isOfType(parameters[0].getSpecification());
  } else {
    return getParameterCount() > 0;
  }
}

代码示例来源:origin: org.nakedobjects.core/metamodel

public NakedObject getDefault(NakedObject nakedObject) {
  if (parentAction.isContributed() && nakedObject != null) {
    if (nakedObject.getSpecification().isOfType(getSpecification())) {
      return nakedObject;
    }
  }
  final ActionParameterDefaultsFacet defaultsFacet = getFacet(ActionParameterDefaultsFacet.class);
  if (defaultsFacet != null) {
    Object dflt = defaultsFacet.getDefault(parentAction.realTarget(nakedObject));
    if (dflt == null) {
      // it's possible that even though there is a default facet, when invoked it
      // is unable to return a default.
      return null;
    }
    return getRuntimeContext().adapterFor(dflt);
  }
  return null;
}

代码示例来源:origin: org.nakedobjects/metamodel

public NakedObject getDefault(NakedObject nakedObject) {
  if (parentAction.isContributed() && nakedObject != null) {
    if (nakedObject.getSpecification().isOfType(getSpecification())) {
      return nakedObject;
    }
  }
  final ActionParameterDefaultsFacet defaultsFacet = getFacet(ActionParameterDefaultsFacet.class);
  if (defaultsFacet != null) {
    Object dflt = defaultsFacet.getDefault(parentAction.realTarget(nakedObject));
    if (dflt == null) {
      // it's possible that even though there is a default facet, when invoked it
      // is unable to return a default.
      return null;
    }
    return getRuntimeContext().adapterFor(dflt);
  }
  return null;
}

代码示例来源:origin: org.nakedobjects.plugins/dndviewer

@Override
public Consent canSet(final NakedObject adapter) {
  final NakedObjectSpecification targetType = getOneToOneAssociation().getSpecification();
  final NakedObjectSpecification spec = adapter.getSpecification();
  if (isEditable().isVetoed()) {
    return isEditable();
  }
  if (!spec.isOfType(targetType)) {
    // TODO: move logic into Facet
    return new Veto(String.format("Can only drop objects of type %s", targetType.getSingularName()));
  }
  if (getParent().isPersistent() && adapter.isTransient()) {
    // TODO: move logic into Facet
    return new Veto("Can't drop a non-persistent into this persistent object");
  }
  final Consent perm = getOneToOneAssociation().isAssociationValid(getParent(), adapter);
  return perm;
}

代码示例来源:origin: org.nakedobjects.plugins/dndviewer

public Consent canDrop(final Content sourceContent) {
  if (sourceContent.getNaked() instanceof NakedObject) {
    final NakedObject sourceAdapter = sourceContent.getNaked();
    final NakedObject parentAdapter = field.getParent();
    final NakedObject collection = getNaked();
    if (collection == null) {
      // TODO: move logic into Facet
      return new Veto("Collection not set up; can't add elements to a non-existant collection");
    }
    final Consent usableInState = getOneToManyAssociation().isUsable(NakedObjectsContext.getAuthenticationSession(), parentAdapter);
    if (usableInState.isVetoed()) {
      return usableInState;
    }
    final NakedObjectSpecification specification = sourceAdapter.getSpecification();
    final NakedObjectSpecification elementSpecification = getElementSpecification();
    if (!specification.isOfType(elementSpecification)) {
      // TODO: move logic into Facet
      return new Veto(String.format("Only objects of type %s are allowed in this collection", elementSpecification
          .getSingularName()));
    }
    if (parentAdapter.isPersistent() && sourceAdapter.isTransient()) {
      // TODO: move logic into Facet
      return new Veto("Can't set field in persistent object with reference to non-persistent object");
    }
    return getOneToManyAssociation().isValidToAdd(parentAdapter, sourceAdapter);
  } else {
    return Veto.DEFAULT;
  }
}

代码示例来源:origin: org.nakedobjects.plugins/dndviewer

private Consent setFieldOfMatchingType(final NakedObject targetAdapter, final NakedObject sourceAdapter) {
  if (targetAdapter.isTransient() && sourceAdapter.isPersistent()) {
    // TODO: use Facet for this test instead.
    return new Veto("Can't set field in persistent object with reference to non-persistent object");
  }
  final NakedObjectAssociation[] fields = targetAdapter.getSpecification().getAssociations(
      NakedObjectAssociationFilters.dynamicallyVisible(NakedObjectsContext.getAuthenticationSession(), targetAdapter));
  for (final NakedObjectAssociation fld : fields) {
    if (!fld.isOneToOneAssociation()) {
      continue;
    }
    if (!sourceAdapter.getSpecification().isOfType(fld.getSpecification())) {
      continue;
    }
    if (fld.get(targetAdapter) != null) {
      continue;
    }
    final Consent associationValid = ((OneToOneAssociation) fld).isAssociationValid(targetAdapter, sourceAdapter);
    if (associationValid.isAllowed()) {
      return associationValid.setDescription("Set field " + fld.getName());
    }
  }
  // TODO: use Facet for this test instead
  return new Veto(String.format("No empty field accepting object of type %s in %s", sourceAdapter.getSpecification()
      .getSingularName(), title()));
}

代码示例来源:origin: org.nakedobjects.plugins/dndviewer

private static void menuOptions(final NakedObjectAction[] actions, final NakedObject target, final UserActionSet menuOptionSet) {
    for (int i = 0; i < actions.length; i++) {
      UserAction option = null;
      if (actions[i].getActions().length > 0) {
        option = new UserActionSet(actions[i].getName(), menuOptionSet);
        menuOptions(actions[i].getActions(), target, (UserActionSet) option);

      } else {
        final int noOfParameters = actions[i].getParameterCount();
        if (noOfParameters == 0) {
          option = ImmediateObjectOption.createOption(actions[i], target);
        } else if (actions[i].isContributed() && noOfParameters == 1 && target != null
            && target.getSpecification().isOfType(actions[i].getParameters()[0].getSpecification())) {
          option = ImmediateObjectOption.createServiceOption(actions[i], target);
        } else {
          option = DialoggedObjectOption.createOption(actions[i], target);
        }
      }
      if (option != null) {
        menuOptionSet.add(option);
      }
    }
  }
}

代码示例来源:origin: org.nakedobjects.plugins/dndviewer

if (association.isOneToOneAssociation() && source.getSpecification().isOfType(association.getSpecification())) {
  OneToOneAssociation otoa = (OneToOneAssociation) association;
  if (association.get(target) == null &&

相关文章

微信公众号

最新文章

更多