/** {@inheritDoc} */ public List<String> getAvailableScopes() { return context.getAvailableScopes(); } }
@Override public Object getProperty(@SuppressWarnings("rawtypes") Map context, Object target, Object name) { Request request = (Request) target; String attributeName = (String) name; for (String scopeName : request.getAvailableScopes()) { Map<String, Object> scope = request.getContext(scopeName); if (scope.containsKey(attributeName)) { return scope.get(attributeName); } } return null; }
protected Map<String,Object> buildScope(Request request) { Map<String,Object> scope = new HashMap<String,Object>(); List<String> availableScopes = request.getAvailableScopes(); for (int i = availableScopes.size() -1; i >= 0; --i) { scope.putAll(request.getContext(availableScopes.get(i))); } return scope; }
@Override public String getSourceAccessor(OgnlContext context, Object target, Object index) { Request request = (Request) target; String attributeName = (String) index; for (String scopeName : request.getAvailableScopes()) { Map<String, Object> scope = request.getContext(scopeName); if (scope.containsKey(attributeName)) { return ".getContext(\"" + scopeName + "\").get(index)"; } } return null; }
@Override public String getSourceSetter(OgnlContext context, Object target, Object index) { Request request = (Request) target; String attributeName = (String) index; String[] availableScopes = request.getAvailableScopes().toArray(new String[0]); for (String scopeName : availableScopes) { Map<String, Object> scope = request.getContext(scopeName); if (scope.containsKey(attributeName)) { return ".getContext(\"" + scopeName + "\").put(index, target)"; } } return ".getContext(\"" + availableScopes[0] + "\").put(index, target)"; }
@Override public void setProperty(@SuppressWarnings("rawtypes") Map context, Object target, Object name, Object value) { Request request = (Request) target; String attributeName = (String) name; String[] availableScopes = request.getAvailableScopes().toArray(new String[0]); for (String scopeName : availableScopes) { Map<String, Object> scope = request.getContext(scopeName); if (scope.containsKey(attributeName)) { scope.put(attributeName, value); return; } } if (availableScopes.length > 0) { request.getContext(availableScopes[0]).put(attributeName, value); } }
/** {@inheritDoc} */ @Override public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) { List<FeatureDescriptor> list = new ArrayList<FeatureDescriptor>(); Request request = (Request) context .getContext(Request.class); for (String scope : request.getAvailableScopes()) { collectBeanInfo(request.getContext(scope), list); } return list.iterator(); }
/** * Executes the model. * * @param name The name of the attribute to import. If it is * <code>null</code>, all the attributes will be imported. * @param scope The scope into which the attribute(s) will be imported. If * <code>null</code>, the import will go in page scope. * @param toName The name of the attribute into which the attribute will be * imported. To be used in conjunction to <code>name</code>. If * <code>null</code>, the value of <code>name</code> will be used. * @param ignore If <code>true</code>, if the attribute is not present, the * problem will be ignored. * @param request The request. */ public void execute(String name, String scope, String toName, boolean ignore, Request request) { Map<String, Object> attributes = getImportedAttributes( name, toName, ignore, request); if (scope == null) { scope = request.getAvailableScopes().get(0); } request.getContext(scope).putAll(attributes); }
/** * Finds an object in request, session or application scope, in this order. * * @param context The context to use. * @param property The property used as an attribute name. * @return The found bean, if it exists, or <code>null</code> otherwise. * @since 2.2.1 */ protected Object findObjectByProperty(ELContext context, Object property) { Object retValue = null; Request request = (Request) context .getContext(Request.class); String prop = property.toString(); String[] scopes = request.getAvailableScopes().toArray(new String[0]); int i = 0; do { retValue = getObject(request.getContext(scopes[i]), prop); i++; } while (retValue == null && i < scopes.length); return retValue; }
/** {@inheritDoc} */ @Override public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) { if (base != null) { List<FeatureDescriptor> retValue = Collections.emptyList(); return retValue.iterator(); } List<FeatureDescriptor> list = new ArrayList<FeatureDescriptor>(); Request request = (Request) context .getContext(Request.class); for (String scope : request.getAvailableScopes()) { FeatureDescriptor descriptor = new FeatureDescriptor(); descriptor.setDisplayName(scope + "Scope"); descriptor.setExpert(false); descriptor.setHidden(false); descriptor.setName(scope + "Scope"); descriptor.setPreferred(true); descriptor.setShortDescription(""); descriptor.setValue("type", Map.class); descriptor.setValue("resolvableAtDesignTime", Boolean.FALSE); list.add(descriptor); } return list.iterator(); }