PageRenderTime 29ms CodeModel.GetById 22ms app.highlight 6ms RepoModel.GetById 0ms app.codeStats 0ms

/jboss-as-7.1.1.Final/pojo/src/main/java/org/jboss/as/pojo/descriptor/FactoryConfig.java

#
Java | 74 lines | 37 code | 11 blank | 26 comment | 2 complexity | ca49649d7625678ffee51aefb55cecaf MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
 1/*
 2 * JBoss, Home of Professional Open Source.
 3 * Copyright 2011, Red Hat, Inc., and individual contributors
 4 * as indicated by the @author tags. See the copyright.txt file in the
 5 * distribution for a full listing of individual contributors.
 6 *
 7 * This is free software; you can redistribute it and/or modify it
 8 * under the terms of the GNU Lesser General Public License as
 9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */
22
23package org.jboss.as.pojo.descriptor;
24
25import org.jboss.as.pojo.BeanState;
26import org.jboss.as.pojo.PojoMessages;
27import org.jboss.as.pojo.service.BeanInfo;
28import org.jboss.msc.service.ServiceName;
29import org.jboss.msc.value.InjectedValue;
30
31/**
32 * Factory value.
33 *
34 * @author <a href="mailto:ales.justin@jboss.org">Ales Justin</a>
35 */
36public class FactoryConfig extends ValueConfig {
37    private static final long serialVersionUID = 1L;
38
39    private String bean;
40    private BeanState state;
41
42    protected final transient InjectedValue<BeanInfo> beanInfo = new InjectedValue<BeanInfo>();
43    protected final transient InjectedValue<Object> value = new InjectedValue<Object>();
44
45    protected Object getClassValue(Class<?> type) {
46        return value.getValue();
47    }
48
49    @Override
50    public void visit(ConfigVisitor visitor) {
51        if (bean != null) {
52            visitor.addDependency(bean, BeanState.DESCRIBED, beanInfo);
53            ServiceName name = BeanMetaDataConfig.toBeanName(bean, state);
54            visitor.addDependency(name, value); // direct name, since we have describe already
55        }
56        super.visit(visitor);
57    }
58
59    public Class<?> getType(ConfigVisitor visitor, ConfigVisitorNode previous) {
60        throw PojoMessages.MESSAGES.tooDynamicFromFactory();
61    }
62
63    public void setBean(String dependency) {
64        this.bean = dependency;
65    }
66
67    public void setState(BeanState state) {
68        this.state = state;
69    }
70
71    public BeanInfo getBeanInfo() {
72        return beanInfo.getValue();
73    }
74}