Java Code Examples for org.osgi.service.blueprint.reflect.ComponentMetadata

The following examples show how to use org.osgi.service.blueprint.reflect.ComponentMetadata. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: cxf   Source File: JettyServerEngineFactoryParser.java    License: Apache License 2.0 6 votes vote down vote up
protected Metadata parseEngineConnector(List<Element> engines, ComponentMetadata enclosingComponent,
                                        ParserContext context) {
    MutableMapMetadata map = context.createMetadata(MutableMapMetadata.class);
    map.setKeyType("java.lang.String");
    map.setValueType("org.eclipse.jetty.server.Connector");

    for (Element engine : engines) {
        String port = engine.getAttribute("port");
        ValueMetadata keyValue = createValue(context, port);
        Element connector = DOMUtils
            .getFirstChildWithName(engine, HTTPJettyTransportNamespaceHandler.JETTY_TRANSPORT,
                                   "connector");
        if (connector != null) {
            Element first = DOMUtils.getFirstElement(connector);
            Metadata valValue = context.parseElement(Metadata.class, enclosingComponent, first);
            map.addEntry(keyValue, valValue);
        }
    }

    return map;
}
 
Example 2
Source Project: cxf   Source File: JettyServerEngineFactoryParser.java    License: Apache License 2.0 6 votes vote down vote up
protected Metadata parseEngineHandlers(List<Element> engines, ComponentMetadata enclosingComponent,
                                       ParserContext context) {
    MutableMapMetadata map = context.createMetadata(MutableMapMetadata.class);
    map.setKeyType("java.lang.String");
    map.setValueType("java.util.List");

    for (Element engine : engines) {
        String port = engine.getAttribute("port");
        ValueMetadata keyValue = createValue(context, port);
        Element handlers = DOMUtils
            .getFirstChildWithName(engine, HTTPJettyTransportNamespaceHandler.JETTY_TRANSPORT,
                                   "handlers");
        if (handlers != null) {
            Metadata valValue = parseListData(context, enclosingComponent, handlers);
            map.addEntry(keyValue, valValue);
        }
    }
    return map;
}
 
Example 3
Source Project: cxf   Source File: UndertowServerEngineFactoryParser.java    License: Apache License 2.0 6 votes vote down vote up
protected Metadata parseEngineHandlers(List<Element> engines, ComponentMetadata enclosingComponent,
                                       ParserContext context) {
    MutableMapMetadata map = context.createMetadata(MutableMapMetadata.class);
    map.setKeyType("java.lang.String");
    map.setValueType("java.util.List");

    for (Element engine : engines) {
        String port = engine.getAttribute("port");
        ValueMetadata keyValue = createValue(context, port);
        Element handlers = DOMUtils
            .getFirstChildWithName(engine, HTTPUndertowTransportNamespaceHandler.UNDERTOW_TRANSPORT,
                                   "handlers");
        if (handlers != null) {
            Metadata valValue = parseListData(context, enclosingComponent, handlers);
            map.addEntry(keyValue, valValue);
        }
    }
    return map;
}
 
Example 4
Source Project: cxf   Source File: NettyServerEngineFactoryParser.java    License: Apache License 2.0 6 votes vote down vote up
public Metadata parse(Element element, ParserContext context) {

        //Endpoint definition
        MutableBeanMetadata ef = context.createMetadata(MutableBeanMetadata.class);
        if (!StringUtils.isEmpty(getIdOrName(element))) {
            ef.setId(getIdOrName(element));
        } else {
            ef.setId("netty.engine.factory-holder-" + UUID.randomUUID().toString());
        }
        ef.setRuntimeClass(NettyHttpServerEngineFactoryHolder.class);

        try {
            // Print the DOM node
            String xmlString = StaxUtils.toString(element);
            ef.addProperty("parsedElement", createValue(context, xmlString));
            ef.setInitMethod("init");
            ef.setActivation(ComponentMetadata.ACTIVATION_EAGER);
            ef.setDestroyMethod("destroy");
            return ef;
        } catch (Exception e) {
            throw new RuntimeException("Could not process configuration.", e);
        }
    }
 
Example 5
Source Project: cxf   Source File: BlueprintBeanLocator.java    License: Apache License 2.0 6 votes vote down vote up
static Class<?> getClassForMetaData(BlueprintContainer container, ComponentMetadata cmd) {
    Class<?> cls = null;
    if (cmd instanceof BeanMetadata) {
        BeanMetadata bm = (BeanMetadata)cmd;
        if (bm instanceof ExtendedBeanMetadata) {
            cls = ((ExtendedBeanMetadata)bm).getRuntimeClass();
        }
        if (cls == null && container instanceof ExtendedBlueprintContainer && bm.getClassName() != null) {
            try {
                cls = ((ExtendedBlueprintContainer)container).loadClass(bm.getClassName());
            } catch (ClassNotFoundException cnfe) {
                //ignore
            }
        }
    }
    return cls;
}
 
Example 6
Source Project: cxf   Source File: ConfigurerImpl.java    License: Apache License 2.0 6 votes vote down vote up
private void initializeWildcardMap() {
    for (String s : container.getComponentIds()) {
        if (isWildcardBeanName(s)) {
            ComponentMetadata cmd = container.getComponentMetadata(s);
            Class<?> cls = BlueprintBeanLocator.getClassForMetaData(container, cmd);
            if (cls != null) {
                final String cid = s.charAt(0) != '*' ? s
                        : "." + s.replaceAll("\\.", "\\."); //old wildcard
                Matcher matcher = Pattern.compile(cid).matcher("");
                List<MatcherHolder> m = wildCardBeanDefinitions.get(cls.getName());
                if (m == null) {
                    m = new ArrayList<>();
                    wildCardBeanDefinitions.put(cls.getName(), m);
                }
                MatcherHolder holder = new MatcherHolder(s, matcher);
                m.add(holder);
            }
        }
    }
}
 
Example 7
Source Project: cxf   Source File: ConfigurerImpl.java    License: Apache License 2.0 6 votes vote down vote up
public synchronized void configureBean(String bn, Object beanInstance, boolean checkWildcards) {
    if (null == bn) {
        bn = getBeanName(beanInstance);
    }

    if (null == bn) {
        return;
    }
    if (checkWildcards) {
        configureWithWildCard(bn, beanInstance);
    }

    if (container instanceof ExtendedBlueprintContainer) {
        ComponentMetadata cm = null;
        try {
            cm = container.getComponentMetadata(bn);
        } catch (NoSuchComponentException nsce) {
            cm = null;
        }
        if (cm instanceof BeanMetadata) {
            ((ExtendedBlueprintContainer)container).injectBeanInstance((BeanMetadata)cm, beanInstance);
        }
    }
}
 
Example 8
Source Project: peer-os   Source File: AuthorizationNsHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ComponentMetadata decorate( Node node, ComponentMetadata cm, ParserContext pc )
{
    if ( node instanceof Element )
    {
        parseElement( ( Element ) node, pc );
    }

    return cm;
}
 
Example 9
Source Project: cxf   Source File: ServerFactoryBeanDefinitionParser.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Metadata parse(Element element, ParserContext context) {
    MutableBeanMetadata bean = (MutableBeanMetadata)super.parse(element, context);
    bean.setInitMethod("init");
    bean.setDestroyMethod("destroy");

    // We don't really want to delay the registration of our Server
    bean.setActivation(ComponentMetadata.ACTIVATION_EAGER);
    return bean;
}
 
Example 10
@Override
public Metadata parse(Element element, ParserContext context) {
    MutableBeanMetadata bean = (MutableBeanMetadata)super.parse(element, context);
   
    bean.setInitMethod("init");
    bean.setDestroyMethod("destroy");
    // We don't really want to delay the registration of our Server
    bean.setActivation(ComponentMetadata.ACTIVATION_EAGER);
    return bean;
}
 
Example 11
Source Project: cxf   Source File: JettyServerEngineFactoryParser.java    License: Apache License 2.0 5 votes vote down vote up
public Metadata parse(Element element, ParserContext context) {

        //Endpoint definition
        MutableBeanMetadata ef = context.createMetadata(MutableBeanMetadata.class);
        if (!StringUtils.isEmpty(getIdOrName(element))) {
            ef.setId(getIdOrName(element));
        } else {
            ef.setId("jetty.engine.factory-holder-" + UUID.randomUUID().toString());
        }
        ef.setRuntimeClass(JettyHTTPServerEngineFactoryHolder.class);

        // setup the ConnectorMap and HandlersMap property for the JettyHTTPServerEngineFactoryHolder

        try {
            // Print the DOM node
            String xmlString = StaxUtils.toString(element);
            ef.addProperty("parsedElement", createValue(context, xmlString));
            ef.setInitMethod("init");
            ef.setActivation(ComponentMetadata.ACTIVATION_EAGER);
            ef.setDestroyMethod("destroy");

            // setup the EngineConnector
            List<Element> engines = DOMUtils
                .getChildrenWithName(element, HTTPJettyTransportNamespaceHandler.JETTY_TRANSPORT, "engine");
            ef.addProperty("connectorMap", parseEngineConnector(engines, ef, context));
            ef.addProperty("handlersMap", parseEngineHandlers(engines, ef, context));
            return ef;
        } catch (Exception e) {
            throw new RuntimeException("Could not process configuration.", e);
        }
    }
 
Example 12
Source Project: cxf   Source File: UndertowServerEngineFactoryParser.java    License: Apache License 2.0 5 votes vote down vote up
public Metadata parse(Element element, ParserContext context) {

        //Endpoint definition
        MutableBeanMetadata ef = context.createMetadata(MutableBeanMetadata.class);
        if (!StringUtils.isEmpty(getIdOrName(element))) {
            ef.setId(getIdOrName(element));
        } else {
            ef.setId("undertow.engine.factory-holder-" + UUID.randomUUID().toString());
        }
        ef.setRuntimeClass(UndertowHTTPServerEngineFactoryHolder.class);

        // setup the HandlersMap property for the UndertowHTTPServerEngineFactoryHolder

        try {
            // Print the DOM node
            String xmlString = StaxUtils.toString(element);
            ef.addProperty("parsedElement", createValue(context, xmlString));
            ef.setInitMethod("init");
            ef.setActivation(ComponentMetadata.ACTIVATION_EAGER);
            ef.setDestroyMethod("destroy");

            // setup the EngineConnector
            List<Element> engines = DOMUtils
                .getChildrenWithName(element, HTTPUndertowTransportNamespaceHandler.UNDERTOW_TRANSPORT, "engine");
            ef.addProperty("handlersMap", parseEngineHandlers(engines, ef, context));
            return ef;
        } catch (Exception e) {
            throw new RuntimeException("Could not process configuration.", e);
        }
    }
 
Example 13
Source Project: cxf   Source File: AbstractBPBeanDefinitionParser.java    License: Apache License 2.0 5 votes vote down vote up
protected Metadata parseListData(ParserContext context,
                                 ComponentMetadata enclosingComponent,
                                 Element element) {
    MutableCollectionMetadata m
        = (MutableCollectionMetadata) context.parseElement(CollectionMetadata.class,
                                                           enclosingComponent, element);
    m.setCollectionClass(List.class);
    return m;
}
 
Example 14
Source Project: cxf   Source File: AbstractBPBeanDefinitionParser.java    License: Apache License 2.0 5 votes vote down vote up
protected MutableBeanMetadata getBus(ParserContext context, String name) {
    ComponentDefinitionRegistry cdr = context.getComponentDefinitionRegistry();
    ComponentMetadata meta = cdr.getComponentDefinition("blueprintBundle");

    if (!cdr.containsComponentDefinition(InterceptorTypeConverter.class.getName())) {
        MutablePassThroughMetadata md = context.createMetadata(MutablePassThroughMetadata.class);
        md.setObject(new InterceptorTypeConverter());

        md.setId(InterceptorTypeConverter.class.getName());
        context.getComponentDefinitionRegistry().registerTypeConverter(md);
    }
    if (!cdr.containsComponentDefinition(name)) {
        //Create a bus

        MutableBeanMetadata bus = context.createMetadata(MutableBeanMetadata.class);
        bus.setId(name);
        bus.setRuntimeClass(BlueprintBus.class);
        if (meta != null) {
            //blueprint-no-osgi does not provide a bundleContext
            bus.addProperty("bundleContext", createRef(context, "blueprintBundleContext"));
        }
        bus.addProperty("blueprintContainer", createRef(context, "blueprintContainer"));
        bus.setDestroyMethod("shutdown");
        bus.setInitMethod("initialize");

        context.getComponentDefinitionRegistry().registerComponentDefinition(bus);

        return bus;
    }
    return (MutableBeanMetadata) cdr.getComponentDefinition(name);
}
 
Example 15
Source Project: cxf   Source File: BlueprintBeanLocator.java    License: Apache License 2.0 5 votes vote down vote up
private ComponentMetadata getComponentMetadata(String id) {
    try {
        return container.getComponentMetadata(id);
    } catch (NoSuchComponentException nsce) {
        return null;
    }
}
 
Example 16
Source Project: cxf   Source File: BlueprintBeanLocator.java    License: Apache License 2.0 5 votes vote down vote up
public <T> T getBeanOfType(String name, Class<T> type) {

        ComponentMetadata cmd = getComponentMetadata(name);
        Class<?> cls = getClassForMetaData(cmd);
        if (cls != null && type.isAssignableFrom(cls)) {
            return type.cast(container.getComponentInstance(name));
        }
        return orig.getBeanOfType(name, type);
    }
 
Example 17
Source Project: cxf   Source File: BlueprintBeanLocator.java    License: Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc}*/
public List<String> getBeanNamesOfType(Class<?> type) {
    Set<String> names = new LinkedHashSet<>();
    for (String s : container.getComponentIds()) {
        ComponentMetadata cmd = container.getComponentMetadata(s);
        Class<?> cls = getClassForMetaData(cmd);
        if (cls != null && type.isAssignableFrom(cls)) {
            names.add(s);
        }
    }
    names.addAll(orig.getBeanNamesOfType(type));
    return new ArrayList<>(names);
}
 
Example 18
Source Project: cxf   Source File: BlueprintBeanLocator.java    License: Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc}*/
public <T> Collection<? extends T> getBeansOfType(Class<T> type) {
    List<T> list = new ArrayList<>();

    for (String s : container.getComponentIds()) {
        ComponentMetadata cmd = container.getComponentMetadata(s);
        Class<?> cls = getClassForMetaData(cmd);
        if (cls != null && type.isAssignableFrom(cls)) {
            list.add(type.cast(container.getComponentInstance(s)));
        }
    }
    if (list.isEmpty() && context != null) {
        try {
            ServiceReference<?>[] refs = context.getServiceReferences(type.getName(), null);
            if (refs != null) {
                for (ServiceReference<?> r : refs) {
                    list.add(type.cast(context.getService(r)));
                }
            }
        } catch (Exception ex) {
            //ignore, just don't support the OSGi services
            LOG.info("Try to find the Bean with type:" + type
                + " from OSGi services and get error: " + ex);
        }
    }
    list.addAll(orig.getBeansOfType(type));

    return list;
}
 
Example 19
Source Project: cxf   Source File: BlueprintBeanLocator.java    License: Apache License 2.0 5 votes vote down vote up
public boolean hasConfiguredPropertyValue(String beanName, String propertyName, String value) {
    ComponentMetadata cmd = getComponentMetadata(beanName);
    if (cmd instanceof BeanMetadata) {
        BeanMetadata br = (BeanMetadata)cmd;
        for (BeanProperty s : br.getProperties()) {
            if (propertyName.equals(s.getName())) {
                return true;
            }
        }
        return false;
    }
    return orig.hasConfiguredPropertyValue(beanName, propertyName, value);
}
 
Example 20
Source Project: cxf   Source File: BlueprintBeanLocator.java    License: Apache License 2.0 5 votes vote down vote up
public boolean hasBeanOfName(String name) {
    ComponentMetadata cmd = getComponentMetadata(name);
    if (cmd instanceof BeanMetadata) {
        return true;
    }
    return orig.hasBeanOfName(name);
}
 
Example 21
Source Project: peer-os   Source File: AuthorizationInterceptor.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void postCallWithException( ComponentMetadata cm, Method m, Throwable ex, Object preCallToken )
{
}
 
Example 22
Source Project: peer-os   Source File: AuthorizationInterceptor.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void postCallWithReturn( ComponentMetadata cm, Method method, Object returnType, Object preCallToken )
        throws Exception
{
}
 
Example 23
Source Project: peer-os   Source File: AuthorizationInterceptor.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Object preCall( ComponentMetadata cm, Method method, Object... parameters ) throws Throwable
{
    Annotation ann = new SecurityAnnotationParser().getEffectiveAnnotation( beanClass, method );
    if ( ann == null )
    {
        return null;
    }

    if ( ann instanceof PermitAll )
    {
        return null;
    }
    String[] rolesAr = new String[] {}; // Also applies for @DenyAll
    if ( ann instanceof RolesAllowed )
    {
        rolesAr = ( ( RolesAllowed ) ann ).value();
    }

    if ( ann instanceof RelationCredibility )
    {
        return null;
    }

    Set<String> roles = new HashSet<>( Arrays.asList( rolesAr ) );
    AccessControlContext acc = AccessController.getContext();
    Subject subject = Subject.getSubject( acc );
    if ( subject == null )
    {
        throw new AccessControlException( "Method call " + method.getDeclaringClass() + "." + method.getName()
                + " denied. No JAAS login present" );
    }
    Set<Principal> principals = subject.getPrincipals();

    for ( Principal principal : principals )
    {
        if ( roles.contains( principal.getName() ) )
        {
            logger.debug( "Granting access to Method: {} for {}.", method, principal );
            return null;
        }
    }
    String msg = String.format( "Method call %s.%s denied. Roles allowed are %s. Your principals are %s.",
            method.getDeclaringClass(), method.getName(), roles, getNames( principals ) );
    throw new AccessControlException( msg );
}
 
Example 24
Source Project: cxf   Source File: JAXWSBPNamespaceHandler.java    License: Apache License 2.0 4 votes vote down vote up
public ComponentMetadata decorate(Node node, ComponentMetadata component, ParserContext context) {
    return null;
}
 
Example 25
Source Project: cxf   Source File: SimpleBPNamespaceHandler.java    License: Apache License 2.0 4 votes vote down vote up
public ComponentMetadata decorate(Node node, ComponentMetadata component, ParserContext context) {
    return null;
}
 
Example 26
Source Project: cxf   Source File: JAXRSBPNamespaceHandler.java    License: Apache License 2.0 4 votes vote down vote up
public ComponentMetadata decorate(Node node, ComponentMetadata component, ParserContext context) {
    return null;
}
 
Example 27
Source Project: cxf   Source File: PolicyBPHandler.java    License: Apache License 2.0 4 votes vote down vote up
public ComponentMetadata decorate(Node node, ComponentMetadata componentMetadata, ParserContext context) {
    return null;
}
 
Example 28
Source Project: cxf   Source File: WsBPHandler.java    License: Apache License 2.0 4 votes vote down vote up
public ComponentMetadata decorate(Node node, ComponentMetadata componentMetadata, ParserContext context) {
    return null;
}
 
Example 29
Source Project: cxf   Source File: RMBPHandler.java    License: Apache License 2.0 4 votes vote down vote up
public ComponentMetadata decorate(Node node, ComponentMetadata componentMetadata, ParserContext context) {
    return null;
}
 
Example 30
Source Project: cxf   Source File: ClusteringBPNamespaceHandler.java    License: Apache License 2.0 4 votes vote down vote up
public ComponentMetadata decorate(Node node, ComponentMetadata component, ParserContext context) {
    return null;
}