Package com.sun.jsftemplating.layout.descriptors.handler

Examples of com.sun.jsftemplating.layout.descriptors.handler.HandlerDefinition


    public static void addHandler(HandlerContext handlerCtx) {
  String id = (String) handlerCtx.getInputValue("id");
  String desc = (String) handlerCtx.getInputValue("desc");
  String cls = (String) handlerCtx.getInputValue("class");
  String meth = (String) handlerCtx.getInputValue("method");
  HandlerDefinition def = new HandlerDefinition(id);
  def.setHandlerMethod(cls, meth);
  if (desc != null) {
      def.setDescription(desc);
  }
  LayoutDefinitionManager.addGlobalHandlerDefinition(def);
    }
View Full Code Here


     *
     *  @return  The value returned from the {@link Handler} if any.
     */
    public static Object dispatchHandler(String handlerId, LayoutElement elt, Object ... args) {
  // Get the Handler
  HandlerDefinition def = elt.getLayoutDefinition().getHandlerDefinition(handlerId);
  if (def == null) {
      def = LayoutDefinitionManager.getGlobalHandlerDefinition(handlerId);
  }
  if (def == null) {
      throw new IllegalArgumentException(
View Full Code Here

    LayoutElementUtil.isLayoutComponentChild(parent));
  }

  // Set the Handlers on the parent...
  if (createHandlerDefinitionOnLayoutDefinition) {
      HandlerDefinition def = new HandlerDefinition(eventName);
      def.setChildHandlers(handlers);
      parent.getLayoutDefinition().setHandlerDefinition(eventName, def);
  } else {
      parent.setHandlers(eventName, handlers);
  }
    }
View Full Code Here

     */
    private Handler readHandler(TemplateParser parser, String eventName, LayoutElement parent) throws IOException {
  String target = null;
  String defVal = null;
  NameValuePair nvp = null;
  HandlerDefinition def = null;

  String handlerId = parser.readToken();
  // Check locally defined Handler
  def = parent.getLayoutDefinition().getHandlerDefinition(handlerId);
  if (def == null) {
      // Check globally defined Handler
      def = LayoutDefinitionManager.getGlobalHandlerDefinition(handlerId);
      if (def == null) {
    throw new SyntaxException("Handler '" + handlerId
        + "' in event '" + eventName + "' is not declared!  "
        + "Ensure the '@Handler' annotation has been defined "
        + "on the handler Java method, that it has been "
        + "compiled with the annotation processing tool, and "
        + "that the resulting"
        + " 'META-INF/jsftemplating/Handler.map' is located "
        + "in your classpath (you may need to do a clean "
        + "build).");
      }
  }

  // Create a Handler
  Handler handler = new Handler(def);

  // Get the default name
  Map inputs = def.getInputDefs();
// FIXME: Allow for HandlerDefs to declare their default input
  if (inputs.size() == 1) {
      defVal = inputs.keySet().toArray()[0].toString();
  }

  // Get the outputs so we can see what outputs have been declared
  Map outputs = def.getOutputDefs();

  // Ensure we have an opening parenthesis
  parser.skipCommentsAndWhiteSpace(TemplateParser.SIMPLE_WHITE_SPACE);
  int ch = parser.nextChar();
  if (ch != '(') {
View Full Code Here

  String baseName = (String) descriptor.getEvaluatedOption(context, "basename", parent);
  String var = (String) descriptor.getEvaluatedOption(context, "var", parent);
  Locale locale = (Locale) descriptor.getEvaluatedOption(context, "locale", parent);

  // Create a handler (needed to execute code each time displayed)...
  HandlerDefinition def = LayoutDefinitionManager.
    getGlobalHandlerDefinition("setResourceBundle");
  Handler handler = new Handler(def);
  handler.setInputValue("bundle", baseName);
  handler.setInputValue("key", var);
  handler.setInputValue("locale", locale);
View Full Code Here

    /**
     *  <p> This method writes output for the given {@link Handler}.</p>
     */
    protected void writeHandler(String prefix, Handler handler) throws IOException {
  // Start the handler...
  HandlerDefinition def = handler.getHandlerDefinition();
  write(prefix + def.getId() + "(");

  // Add inputs
  String seperator = "";
  for (String inputKey : def.getInputDefs().keySet()) {
      write(seperator + inputKey + "=\""
    + handler.getInputValue(inputKey) + "\"");
      seperator = ", ";
  }

  // Add outputs
  OutputMapping output = null;
// FIXME: Support EL output mappings, e.g.: output1="#{requestScope.bar}"
  for (String outputKey : def.getOutputDefs().keySet()) {
      output = handler.getOutputValue(outputKey);
      write(seperator + outputKey + "=>$" + output.getStringOutputType()
    + "{" + output.getOutputKey() + "}");
      seperator = ", ";
  }
View Full Code Here

     *
     *  @param  node  Parent <code>Node</code> containing
     *      {@link #HANDLER_DEFINITION_ELEMENT} nodes.
     */
    private void cacheHandlerDefs(Node node) {
  HandlerDefinition def = null;

  // Get the child nodes
  Iterator<Node> it =
    getChildElements(node, HANDLER_DEFINITION_ELEMENT).iterator();
  while (it.hasNext()) {
      // Found a HANDLER_DEFINITION_ELEMENT, cache it
      def = createHandlerDefinition(it.next());
      _handlerDefs.put(def.getId(), def);
  }
    }
View Full Code Here

    public HandlerDefinition createHandlerDefinition(Node node) {

  // Create he HandlerDefinition
  Map<String, String> attributes = getAttributes(node);
  String value = attributes.get(ID_ATTRIBUTE);
  HandlerDefinition hd = new HandlerDefinition(value);

// hd.setDescription(_description)

  // Check for a className
  value = attributes.get(CLASS_NAME_ATTRIBUTE);
  if ((value != null) && !value.equals("")) {
      // Found a className, now get the methodName
      String tmpStr = attributes.get(METHOD_NAME_ATTRIBUTE);
      if ((tmpStr == null) || tmpStr.equals("")) {
    throw new IllegalArgumentException("You must provide a '"
      + METHOD_NAME_ATTRIBUTE + "' attribute on the '"
      + HANDLER_DEFINITION_ELEMENT + "' element with "
      + CLASS_NAME_ATTRIBUTE + " atttribute equal to '"
      + value + "'.");
      }
      hd.setHandlerMethod(value, tmpStr);
  }

  // Add child handlers to this HandlerDefinition.  This allows a
  // HandlerDefinition to define handlers that should be invoked before
  // the method defined by this handler definition is invoked.
  List<Handler> handlers = new ArrayList(hd.getChildHandlers());
  hd.setChildHandlers(getHandlers(node, handlers));

  // Add InputDef objects to the HandlerDefinition
  addInputDefs(hd, node);

  // Add OutputDef objects to the HandlerDefinition
View Full Code Here

        + "' attribute not found on '" + HANDLER_ELEMENT
        + "' Element!");
  }

  // Find the HandlerDefinition associated with this Handler
  HandlerDefinition handlerDef = getHandlerDef(id);
  if (handlerDef == null) {
      throw new IllegalArgumentException(HANDLER_ELEMENT + " elements "
        + ID_ATTRIBUTE + " attribute must match the "
        + ID_ATTRIBUTE + " attribute of a "
        + HANDLER_DEFINITION_ELEMENT + ".  A HANDLER_ELEMENT with '"
View Full Code Here

     *
     *  @return  The desired {@link HandlerDefinition} or <code>null</code>.
     */
    private HandlerDefinition getHandlerDef(String id) {
  // Try local...
  HandlerDefinition def = _handlerDefs.get(id);
  if (def == null) {
      // Try global...
      def = LayoutDefinitionManager.getGlobalHandlerDefinition(id);
  }
  return def;
View Full Code Here

TOP

Related Classes of com.sun.jsftemplating.layout.descriptors.handler.HandlerDefinition

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.