Exemplo n.º 1
0
 // {{ filters (programmatic)
 @SuppressWarnings("unchecked")
 public static Filter<ToDoItem> thoseDue() {
   return Filters.and(
       Filters.not(thoseComplete()),
       new Filter<ToDoItem>() {
         @Override
         public boolean accept(final ToDoItem t) {
           return t.isDue();
         }
       });
 }
  @Override
  public List<ObjectAction> getObjectActions(
      final List<ActionType> types,
      final Contributed contributed,
      final Filter<ObjectAction> filter) {

    // update our list of actions if requesting for contributed actions
    // and they have not yet been added
    // the "contributed.isIncluded()" guard is required because we cannot do this too early;
    // there must be a session available
    if (contributed.isIncluded() && !contributeeActionsAdded) {
      synchronized (this.objectActions) {
        final List<ObjectAction> actions = Lists.newArrayList(this.objectActions);
        actions.addAll(createContributeeActions());
        sortCacheAndUpdateActions(actions);
        contributeeActionsAdded = true;
      }
    }

    final List<ObjectAction> actions = Lists.newArrayList();
    for (final ActionType type : types) {
      final Collection<ObjectAction> filterActions =
          Collections2.filter(objectActionsByType.get(type), Filters.asPredicate(filter));
      actions.addAll(filterActions);
    }
    return Lists.newArrayList(
        Iterables.filter(actions, ContributeeMember.Predicates.regularElse(contributed)));
  }
  private void addContributeeActionsIfAny(
      final ObjectAdapter serviceAdapter, final List<ObjectAction> contributeeActionsToAppendTo) {
    final ObjectSpecification specification = serviceAdapter.getSpecification();
    if (specification == this) {
      return;
    }
    final List<ObjectAction> contributeeActions = Lists.newArrayList();
    final List<ObjectAction> serviceActions =
        specification.getObjectActions(
            ActionType.ALL, Contributed.INCLUDED, Filters.<ObjectAction>any());
    for (final ObjectAction serviceAction : serviceActions) {
      if (isAlwaysHidden(serviceAction)) {
        continue;
      }
      final NotContributedFacet notContributed = serviceAction.getFacet(NotContributedFacet.class);
      if (notContributed != null && notContributed.toActions()) {
        continue;
      }
      if (!(serviceAction instanceof ObjectActionImpl)) {
        continue;
      }
      final ObjectActionImpl contributedAction = (ObjectActionImpl) serviceAction;

      // see if qualifies by inspecting all parameters
      final int contributeeParam = contributeeParameterMatchOf(contributedAction);
      if (contributeeParam != -1) {
        ObjectActionContributee contributeeAction =
            new ObjectActionContributee(
                serviceAdapter, contributedAction, contributeeParam, this, objectMemberContext);
        facetProcessor.processMemberOrder(metadataProperties, contributeeAction);
        contributeeActions.add(contributeeAction);
      }
    }
    contributeeActionsToAppendTo.addAll(contributeeActions);
  }
 @Override
 public ObjectAction getObjectAction(final ActionType type, final String id) {
   final List<ObjectAction> availableActions =
       ListUtils.combine(
           getObjectActions(type, Contributed.INCLUDED),
           getContributedActions(type, Filters.<ObjectAction>any()));
   return getAction(availableActions, type, id);
 }
 @Override
 public ObjectAction getObjectAction(
     final ActionType type, final String id, final List<ObjectSpecification> parameters) {
   final List<ObjectAction> availableActions =
       ListUtils.combine(
           getObjectActions(Contributed.EXCLUDED),
           getContributedActions(type, Filters.<ObjectAction>any()));
   return getAction(availableActions, type, id, parameters);
 }
Exemplo n.º 6
0
 private static void specificationActionMethods(
     final ObjectSpecification specification, final DebugBuilder debugBuilder) {
   try {
     final List<ObjectAction> userActions =
         specification.getObjectActions(
             ActionType.USER, Contributed.INCLUDED, Filters.<ObjectAction>any());
     final List<ObjectAction> explActions =
         specification.getObjectActions(
             ActionType.EXPLORATION, Contributed.INCLUDED, Filters.<ObjectAction>any());
     final List<ObjectAction> prototypeActions =
         specification.getObjectActions(
             ActionType.PROTOTYPE, Contributed.INCLUDED, Filters.<ObjectAction>any());
     final List<ObjectAction> debActions =
         specification.getObjectActions(
             ActionType.DEBUG, Contributed.INCLUDED, Filters.<ObjectAction>any());
     specificationMethods(userActions, explActions, prototypeActions, debActions, debugBuilder);
   } catch (final RuntimeException e) {
     debugBuilder.appendException(e);
   }
 }
 private void cataloguePropertiesAndCollections(final Map<Method, ObjectMember> membersByMethod) {
   final Filter<ObjectAssociation> noop = Filters.anyOfType(ObjectAssociation.class);
   final List<ObjectAssociation> fields = getAssociations(noop);
   for (int i = 0; i < fields.size(); i++) {
     final ObjectAssociation field = fields.get(i);
     final List<Facet> facets = field.getFacets(ImperativeFacet.FILTER);
     for (final Facet facet : facets) {
       final ImperativeFacet imperativeFacet = ImperativeFacetUtils.getImperativeFacet(facet);
       for (final Method imperativeFacetMethod : imperativeFacet.getMethods()) {
         membersByMethod.put(imperativeFacetMethod, field);
       }
     }
   }
 }
 private void appendServiceActionsReturning(
     final ObjectAdapter serviceAdapter,
     final List<ActionType> types,
     final List<ObjectAction> relatedActionsToAppendTo) {
   final List<ObjectAction> matchingActionsToAppendTo = Lists.newArrayList();
   for (final ActionType type : types) {
     final List<ObjectAction> serviceActions =
         serviceAdapter
             .getSpecification()
             .getObjectActions(type, Contributed.INCLUDED, Filters.<ObjectAction>any());
     for (final ObjectAction serviceAction : serviceActions) {
       addIfReturnsSubtype(serviceAction, matchingActionsToAppendTo);
     }
   }
   relatedActionsToAppendTo.addAll(matchingActionsToAppendTo);
 }
Exemplo n.º 9
0
 public static Intent getIntent(final ObjectMember member, final Method method) {
   final List<Facet> allFacets = member.getFacets(Filters.anyOfType(Facet.class));
   final List<ImperativeFacet> imperativeFacets = Lists.newArrayList();
   for (final Facet facet : allFacets) {
     final ImperativeFacet imperativeFacet = ImperativeFacet.Util.getImperativeFacet(facet);
     if (imperativeFacet == null) {
       continue;
     }
     final List<Method> methods = imperativeFacet.getMethods();
     if (!methods.contains(method)) {
       continue;
     }
     imperativeFacets.add(imperativeFacet);
   }
   switch (imperativeFacets.size()) {
     case 0:
       break;
     case 1:
       return imperativeFacets.get(0).getIntent(method);
     default:
       Intent intentToReturn = null;
       for (ImperativeFacet imperativeFacet : imperativeFacets) {
         Intent intent = imperativeFacet.getIntent(method);
         if (intentToReturn == null) {
           intentToReturn = intent;
         } else if (intentToReturn != intent) {
           throw new IllegalArgumentException(
               member.getIdentifier().toClassAndNameIdentityString()
                   + ": more than one ImperativeFacet for method "
                   + method.getName()
                   + " , with inconsistent intents: "
                   + imperativeFacets.toString());
         }
       }
       return intentToReturn;
   }
   throw new IllegalArgumentException(
       member.getIdentifier().toClassAndNameIdentityString()
           + ": unable to determine intent of "
           + method.getName());
 }
Exemplo n.º 10
0
  /**
   * Synthesises {@link ObjectAssociation}s from matching {@link ObjectAction}s of any of the
   * services that accept one parameter
   */
  private List<ObjectAssociation> createContributeeAssociations(
      final ObjectAdapter serviceAdapter) {

    final ObjectSpecification specification = serviceAdapter.getSpecification();
    final List<ObjectAction> serviceActions =
        specification.getObjectActions(
            ActionType.USER, Contributed.INCLUDED, Filters.<ObjectAction>any());

    final List<ObjectActionImpl> contributedActions = Lists.newArrayList();
    for (final ObjectAction serviceAction : serviceActions) {
      if (isAlwaysHidden(serviceAction)) {
        continue;
      }
      final NotContributedFacet notContributed = serviceAction.getFacet(NotContributedFacet.class);
      if (notContributed != null && notContributed.toAssociations()) {
        continue;
      }
      if (!serviceAction.hasReturn()) {
        continue;
      }
      if (serviceAction.getParameterCount() != 1
          || contributeeParameterMatchOf(serviceAction) == -1) {
        continue;
      }
      if (!(serviceAction instanceof ObjectActionImpl)) {
        continue;
      }
      if (!serviceAction.getSemantics().isSafeInNature()) {
        continue;
      }
      contributedActions.add((ObjectActionImpl) serviceAction);
    }

    return Lists.newArrayList(
        Iterables.transform(
            contributedActions, createContributeeAssociationFunctor(serviceAdapter, this)));
  }
 @Programmatic
 @Deprecated
 @Override
 public <T> T firstMatch(final Class<T> cls, final Filter<T> filter) {
   return firstMatch(cls, Filters.asPredicate(filter));
 }
 @Programmatic
 @Deprecated
 @Override
 public <T> List<T> allMatches(final Class<T> cls, final Filter<? super T> filter, long... range) {
   return allMatches(cls, Filters.asPredicate(filter), range);
 }
Exemplo n.º 13
0
 @Override
 public List<ObjectAction> getObjectActions(final Contributed contributed) {
   return getObjectActions(ActionType.ALL, contributed, Filters.<ObjectAction>any());
 }
Exemplo n.º 14
0
 @Override
 public List<ObjectAssociation> getAssociations(
     Contributed contributed, final Filter<ObjectAssociation> filter) {
   final List<ObjectAssociation> allAssociations = getAssociations(contributed);
   return Lists.newArrayList(Iterables.filter(allAssociations, Filters.asPredicate(filter)));
 }