net.phoenix.thrift.xml.ServerBeanDefinitionParser.java Source code

Java tutorial

Introduction

Here is the source code for net.phoenix.thrift.xml.ServerBeanDefinitionParser.java

Source

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package net.phoenix.thrift.xml;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.util.xml.DomUtils;
import org.w3c.dom.Element;

/**
 * @author Shamphone Lee<shamphone@gmail.com>
 *
 */
public class ServerBeanDefinitionParser extends ComplexBeanDefinitionParser {

    @Override
    protected void preParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
        // ?init-methoddestroy-method
        String start = element.getAttribute("start");
        if (this.parseBoolean(start)) {
            builder.setInitMethodName("serve");
            builder.setDestroyMethodName("stop");
        }
        String handler = element.getAttribute("event-handler");
        if (StringUtils.isNotBlank(handler)) {
            builder.addPropertyReference("serverEventHandler", handler);
        }
        Element argsElement = DomUtils.getChildElementByTagName(element, "args");
        parserContext.getDelegate().parseCustomElement(argsElement);
        String argsBeanName = argsElement.getAttribute("id");
        builder.addConstructorArgReference(argsBeanName);
    }

    /**
     * ?property?property?server
     */
    @Override
    protected void postParse(Element element, ParserContext parserContext, AbstractBeanDefinition current) {
        parserContext.getDelegate().parsePropertyElements(element, current);
    }

    @Override
    protected String getBeanClassName(Element element) {
        return element.getAttribute("class");
    }

}