Examples of AdapterFactory


Examples of org.apache.sling.api.adapter.AdapterFactory

        // get the factory for the target type
        final List<AdapterFactoryDescriptor> descList = factories.get(type.getName());

        if (descList != null && descList.size() > 0) {
            for (AdapterFactoryDescriptor desc : descList) {
                final AdapterFactory factory = desc == null ? null : desc.getFactory();

                // have the factory adapt the adaptable if the factory exists
                if (factory != null) {
                    log.debug("Trying adapter factory {} to map {} to {}",
                            new Object [] { factory, adaptable, type });

                    AdapterType adaptedObject = factory.getAdapter(adaptable, type);
                    if (adaptedObject != null) {
                        log.debug("Using adapter factory {} to map {} to {}",
                                new Object [] { factory, adaptable, type });
                        return adaptedObject;
                    }
View Full Code Here

Examples of org.apache.sling.api.adapter.AdapterFactory

        assertNull(sampleObject.adaptTo(String.class));

        BundleContext bundleContext = MockOsgi.newBundleContext();
        MockSling.setAdapterManagerBundleContext(bundleContext);

        bundleContext.registerService(AdapterFactory.class.getName(), new AdapterFactory() {
            @SuppressWarnings("unchecked")
            @Override
            public <AdapterType> AdapterType getAdapter(final Object adaptable, final Class<AdapterType> type) {
                if (adaptable instanceof AdaptableTest && type.isAssignableFrom(String.class)) {
                    return (AdapterType) ((AdaptableTest) adaptable).toString();
View Full Code Here

Examples of org.apache.sling.api.adapter.AdapterFactory

        if (this.bundleContext != null) {
            try {
                ServiceReference[] references = bundleContext
                        .getServiceReferences(AdapterFactory.class.getName(), null);
                for (ServiceReference serviceReference : references) {
                    AdapterFactory adapterFactory = (AdapterFactory) bundleContext.getService(serviceReference);
                    AdapterType instance = adapterFactory.getAdapter(adaptable, type);
                    if (instance != null) {
                        return instance;
                    }
                }
            } catch (InvalidSyntaxException ex) {
View Full Code Here

Examples of org.apache.sling.api.adapter.AdapterFactory

public class MockComponentContext implements ComponentContext {

    private Map<ServiceReference, AdapterFactory> services = new HashMap<ServiceReference, AdapterFactory>();

    public Object locateService(String name, ServiceReference reference) {
        AdapterFactory af = services.get(reference);
        if (af == null) {
            af = new MockAdapterFactory();
            services.put(reference, af);
        }
        return af;
View Full Code Here

Examples of org.apache.sling.api.adapter.AdapterFactory

        // get the adapter factories for the type of adaptable object
        Map<String, AdapterFactory> factories = getAdapterFactories(adaptable.getClass());

        // get the factory for the target type
        AdapterFactory factory = factories.get(type.getName());

        // have the factory adapt the adaptable if the factory exists
        if (factory != null) {
            if (debug) {
                log(LogService.LOG_DEBUG, "Using adapter factory " + factory
                    + " to map " + adaptable + " to " + type, null);
            }

            return factory.getAdapter(adaptable, type);
        }

        // no factory has been found, so we cannot adapt
        if (debug) {
            log(LogService.LOG_DEBUG, "No adapter factory found to map "
View Full Code Here

Examples of org.apache.sling.api.adapter.AdapterFactory

        if (adaptables == null || adaptables.length == 0 || adapters == null
            || adapters.length == 0) {
            return;
        }

        AdapterFactory factory = (AdapterFactory) context.locateService(
            "AdapterFactory", reference);

        AdapterFactoryDescriptorKey factoryKey = new AdapterFactoryDescriptorKey(
            reference);
        AdapterFactoryDescriptor factoryDesc = new AdapterFactoryDescriptor(
View Full Code Here

Examples of org.eclipse.emf.common.notify.AdapterFactory

   */
  public IPropertySource getPropertySource(Object object) {
    if (object instanceof IPropertySource) {
      return (IPropertySource) object;
    }
    AdapterFactory af = getAdapterFactory(object);
    if (af != null) {
      IItemPropertySource ips = (IItemPropertySource) af.adapt(object,
          IItemPropertySource.class);
      if (ips != null) {
        return new PropertySource(object, ips);
      }
    }
View Full Code Here

Examples of org.eclipse.emf.common.notify.AdapterFactory

    }

    @Test
    public void testGetImageObject() {

        AdapterFactory adapterFactoryImpl = new ProjectItemProviderAdapterFactory();
        LayerItemProvider itemProvider = new LayerItemProvider(adapterFactoryImpl);
        AdapterFactoryLabelProvider fac=new AdapterFactoryLabelProvider(adapterFactoryImpl);
       
        Image image = null;
        Image image2 = null;
View Full Code Here

Examples of org.eclipse.emf.common.notify.AdapterFactory

   */
  public IPropertySource getPropertySource(Object object) {
    if (object instanceof IPropertySource) {
      return (IPropertySource) object;
    }
    AdapterFactory af = getAdapterFactory(object);
    if (af != null) {
      IItemPropertySource ips = (IItemPropertySource) af.adapt(object,
          IItemPropertySource.class);
      if (ips != null) {
        return new PropertySource(object, ips);
      }
    }
View Full Code Here

Examples of org.eclipse.emf.common.notify.AdapterFactory

   */
  public IPropertySource getPropertySource(Object object) {
    if (object instanceof IPropertySource) {
      return (IPropertySource) object;
    }
    AdapterFactory af = getAdapterFactory(object);
    if (af != null) {
      IItemPropertySource ips = (IItemPropertySource) af.adapt(object,
          IItemPropertySource.class);
      if (ips != null) {
        return new PropertySource(object, ips);
      }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.