Package org.osgi.service.metatype

Examples of org.osgi.service.metatype.MetaTypeInformation


        if (providingBundle != null)
        {
            final MetaTypeService mts = this.getMetaTypeService();
            if (mts != null)
            {
                final MetaTypeInformation mti = mts.getMetaTypeInformation(providingBundle);
                if (mti != null)
                {
                    try {
                        return mti.getObjectClassDefinition(pid, null) != null;
                    } catch (IllegalArgumentException e) {
                        return false;
                    }
                }
            }
View Full Code Here



    public void testEmpty()
    {
        MetaTypeService mts = new MetaTypeServiceImpl( bundleContext );
        MetaTypeInformation mti = mts.getMetaTypeInformation( bundleContext.getBundle() );
        checkEmpty( mti );
    }
View Full Code Here


    public void testAfterCretionManagedService()
    {
        MetaTypeService mts = new MetaTypeServiceImpl( bundleContext );
        MetaTypeInformation mti = mts.getMetaTypeInformation( bundleContext.getBundle() );

        // assert still empty
        checkEmpty( mti );

        // register a service with PID
        String pid = "testAfterCreation";
        MockManagedService service = new MockManagedService();
        Dictionary props = new Hashtable();
        props.put( Constants.SERVICE_PID, pid );
        ServiceRegistration sr = bundleContext.registerService( ManagedService.class.getName(), service, props );

        // locales should contain MockMetaTypeProvider.LOCALES
        assertNotNull( mti.getLocales() );
        assertTrue( mti.getLocales().length == 1 );
        assertEquals( MockMetaTypeProvider.LOCALES[0], mti.getLocales()[0] );

        // pids must contain pid
        assertNotNull( mti.getPids() );
        assertTrue( mti.getPids().length == 1 );
        assertEquals( pid, mti.getPids()[0] );

        // change the service PID
        String pid2 = "testAfterCreation2";
        Dictionary props2 = new Hashtable();
        props2.put( Constants.SERVICE_PID, pid2 );
        sr.setProperties( props2 );

        // pids must contain pid2
        assertNotNull( mti.getPids() );
        assertTrue( mti.getPids().length == 1 );
        assertEquals( pid2, mti.getPids()[0] );

        // factoryPids must be empty
        assertTrue( mti.getFactoryPids() == null || mti.getFactoryPids().length == 0 );

        // unregister the service
        sr.unregister();

        // ensure everything is clear now again
View Full Code Here


    public void testAfterCretionManagedServiceFactory()
    {
        MetaTypeService mts = new MetaTypeServiceImpl( bundleContext );
        MetaTypeInformation mti = mts.getMetaTypeInformation( bundleContext.getBundle() );

        // assert still empty
        checkEmpty( mti );

        // register a service with PID
        String factoryPid = "testAfterCreation_factory";
        MockManagedServiceFactory service = new MockManagedServiceFactory();
        Dictionary props = new Hashtable();
        props.put( Constants.SERVICE_PID, factoryPid );
        ServiceRegistration sr = bundleContext.registerService( ManagedServiceFactory.class.getName(), service, props );

        // locales should contain MockMetaTypeProvider.LOCALES
        assertNotNull( mti.getLocales() );
        assertTrue( mti.getLocales().length == 1 );
        assertEquals( MockMetaTypeProvider.LOCALES[0], mti.getLocales()[0] );

        // pids must be empty
        assertTrue( mti.getPids() == null || mti.getPids().length == 0 );

        // pids must contain pid
        assertNotNull( mti.getFactoryPids() );
        assertTrue( mti.getFactoryPids().length == 1 );
        assertEquals( factoryPid, mti.getFactoryPids()[0] );

        // change the service PID
        String factoryPid2 = "testAfterCreation2";
        Dictionary props2 = new Hashtable();
        props2.put( Constants.SERVICE_PID, factoryPid2 );
        sr.setProperties( props2 );

        // pids must contain pid2
        assertNotNull( mti.getFactoryPids() );
        assertTrue( mti.getFactoryPids().length == 1 );
        assertEquals( factoryPid2, mti.getFactoryPids()[0] );

        // unregister the service
        sr.unregister();

        // ensure everything is clear now again
View Full Code Here

        if ( mts != null )
        {
            final Bundle[] bundles = this.getBundleContext().getBundles();
            for ( int i = 0; i < bundles.length; i++ )
            {
                final MetaTypeInformation mti = mts.getMetaTypeInformation( bundles[i] );
                if ( mti != null )
                {
                    final String[] idList = idGetter.getIds( mti );
                    for ( int j = 0; idList != null && j < idList.length; j++ )
                    {
                        // After getting the list of PIDs, a configuration  might be
                        // removed. So the getObjectClassDefinition will throw
                        // an exception, and this will prevent ALL configuration from
                        // being displayed. By catching it, the configurations will be
                        // visible
                        ObjectClassDefinition ocd = null;
                        try
                        {
                            ocd = mti.getObjectClassDefinition( idList[j], locale );
                        }
                        catch ( IllegalArgumentException ignore )
                        {
                            // ignore - just don't show this configuration
                        }
View Full Code Here

        if ( bundle != null )
        {
            MetaTypeService mts = this.getMetaTypeService();
            if ( mts != null )
            {
                MetaTypeInformation mti = mts.getMetaTypeInformation( bundle );
                if ( mti != null )
                {
                    // see #getObjectClasses( final IdGetter idGetter, final String locale )
                    try
                    {
                        return mti.getObjectClassDefinition( pid, locale );
                    }
                    catch ( IllegalArgumentException e )
                    {
                        // MetaTypeProvider.getObjectClassDefinition might throw illegal
                        // argument exception. So we must catch it here, otherwise the
View Full Code Here

    }
  }
 
  private PreferenceOCD[] extractOCDs(ServiceReference prefHolder, String ocdID) {
    Bundle bundle = prefHolder.getBundle();
    MetaTypeInformation bundleMetaTypeInfo = mts.getMetaTypeInformation(bundle);
    List extractedOCDList = new ArrayList();
    //go through ocdID, ocdID + "2", ocdID + "3", etc..., until we try to get an OCD that doesn't exist.
    PreferenceOCD extractedOCD = extractOCD(bundleMetaTypeInfo, ocdID);
    int ii = 2;
    while (extractedOCD != null) {
View Full Code Here

  }
 
  //returning multiple OCDs just for the sake of symmetry, actually can only return 1 (or 0 on error)
  private PreferenceOCD[] extractParamOCDs(ServiceReference prefHolder, String ocdID) {
    Bundle bundle = prefHolder.getBundle();
    MetaTypeInformation bundleMetaTypeInfo = mts.getMetaTypeInformation(bundle);
    PreferenceOCD paramOCD = extractOCD(bundleMetaTypeInfo, ocdID);
    if (paramOCD != null) {
      return new PreferenceOCD[]{paramOCD};
    } else {
      return new PreferenceOCD[0];
View Full Code Here

        if (providingBundle != null)
        {
            final MetaTypeService mts = this.getMetaTypeService();
            if (mts != null)
            {
                final MetaTypeInformation mti = mts.getMetaTypeInformation(providingBundle);
                if (mti != null)
                {
                    try {
                        return mti.getObjectClassDefinition(pid, null) != null;
                    } catch (IllegalArgumentException e) {
                        return false;
                    }
                }
            }
View Full Code Here

    private ObjectClassDefinition getMetaTypeOCD(MetaData data, Designate designate) throws ResourceProcessorException {
      ObjectClassDefinition ocd = null;
      String ocdRef = designate.getObject().getOcdRef();
      Bundle bundle = getBundle(designate.getBundleLocation(), isFactoryConfig(designate));
      if (bundle != null) {
        MetaTypeInformation mti = m_metaService.getMetaTypeInformation(bundle);
        if (mti != null) {
          String pid = isFactoryConfig(designate) ? pid = designate.getFactoryPid() : designate.getPid();
          try {
            ObjectClassDefinition tempOcd = mti.getObjectClassDefinition(pid, null);
            // tempOcd will always have a value, if pid was not known IAE will be thrown
            if (ocdRef.equals(tempOcd.getID())) {
              ocd = tempOcd;
            }
          }
View Full Code Here

TOP

Related Classes of org.osgi.service.metatype.MetaTypeInformation

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.