當前位置: 首頁>>代碼示例>>Java>>正文


Java BundleWiring類代碼示例

本文整理匯總了Java中org.osgi.framework.wiring.BundleWiring的典型用法代碼示例。如果您正苦於以下問題:Java BundleWiring類的具體用法?Java BundleWiring怎麽用?Java BundleWiring使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


BundleWiring類屬於org.osgi.framework.wiring包,在下文中一共展示了BundleWiring類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: processClass

import org.osgi.framework.wiring.BundleWiring; //導入依賴的package包/類
@Override
public byte[] processClass(String className, byte[] bytes, ClasspathEntry ce, BundleEntry be, ClasspathManager cm) {
    final BaseData bd = ce.getBaseData();
    if (bd == null) {
        return bytes;
    }
    final Bundle b = bd.getBundle();
    if (b == null) {
        return bytes;
    }
    BundleWiring w = b.adapt(org.osgi.framework.wiring.BundleWiring.class);
    if (w == null) {
        return bytes;
    }
    ClassLoader loader = w.getClassLoader();
    return archive.patchByteCode(loader, className, ce.getDomain(), bytes);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:NetbinoxHooks.java

示例2: isRequiredBundle

import org.osgi.framework.wiring.BundleWiring; //導入依賴的package包/類
/**
 * Checks if is required bundle.
 *
 * @param bundle the bundle
 * @param className the class name
 * @return true, if is required bundle
 */
private boolean isRequiredBundle(Bundle bundle, String className) {
	
	// --- 1. Simply try to load the class ----------------------
	try {
		Class<?> classInstance = bundle.loadClass(className);
		if (classInstance!=null)  return true;
	
	} catch (ClassNotFoundException cnfEx) {
		//cnfEx.printStackTrace();
	}
	
	// --- 2. Try to check the resources of the bundle ----------
	String simpleClassName = className.substring(className.lastIndexOf(".")+1);
	String packagePath = className.substring(0, className.lastIndexOf("."));
	packagePath = packagePath.replace(".", "/");
	if (packagePath.startsWith("/")==false) packagePath = "/" + packagePath;
	if (packagePath.endsWith("/")  ==false) packagePath = packagePath + "/";
	
	BundleWiring bundleWiring = bundle.adapt(BundleWiring.class);
	Collection<String> resources = bundleWiring.listResources(packagePath, simpleClassName + ".class", BundleWiring.LISTRESOURCES_LOCAL);
	if (resources!=null && resources.size()>0) {
		return true;
	}
	return false;
}
 
開發者ID:EnFlexIT,項目名稱:AgentWorkbench,代碼行數:33,代碼來源:AbstractClassLoadServiceUtilityImpl.java

示例3: incompatibleExtender

import org.osgi.framework.wiring.BundleWiring; //導入依賴的package包/類
private boolean incompatibleExtender(Bundle bundle) {
   	
	List<BundleWire> requiredWires = bundle.adapt(BundleWiring.class)
			.getRequiredWires(OSGI_EXTENDER_NS);
	
	for(BundleWire bw : requiredWires) {
		BundleCapability capability = bw.getCapability();
		if(EntityManagerFactoryBuilder.JPA_CAPABILITY_NAME.equals(
				capability.getAttributes().get(OSGI_EXTENDER_NS))) {
			
			// If the persistence bundle requires a different revision for the 
			// JPA extender then we are incompatible, otherwise we are
			return !capability.getRevision().equals(wiring.getRevision());
		}
	}
	
	// If there is no requirement then we must assume that it's safe
	return false;
}
 
開發者ID:apache,項目名稱:aries-jpa,代碼行數:20,代碼來源:PersistenceBundleTracker.java

示例4: WrappingTransformer

import org.osgi.framework.wiring.BundleWiring; //導入依賴的package包/類
public WrappingTransformer(ClassTransformer delegate, ServiceReference<?> persistenceProvider) {
    validate(delegate, persistenceProvider);
    this.delegate = delegate;

    Object packages = persistenceProvider.getProperty("org.apache.aries.jpa.container.weaving.packages");
    if (packages instanceof String[]) {
        for (String s : (String[])packages) {
            packageImportsToAdd.add(s);
        }
    } else {
        Bundle provider = persistenceProvider.getBundle();
        String suffix = ";" + Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE + "=" + provider.getSymbolicName()
                        + ";" + Constants.BUNDLE_VERSION_ATTRIBUTE + "=" + provider.getVersion();

        BundleRevision br = provider.adapt(BundleWiring.class).getRevision();
        for (BundleCapability bc : br.getDeclaredCapabilities(BundleRevision.PACKAGE_NAMESPACE)) {
            packageImportsToAdd.add(bc.getAttributes().get(BundleRevision.PACKAGE_NAMESPACE) + suffix);
        }
    }
}
 
開發者ID:apache,項目名稱:aries-jpa,代碼行數:21,代碼來源:WrappingTransformer.java

示例5: weave

import org.osgi.framework.wiring.BundleWiring; //導入依賴的package包/類
@Override
public void weave(WovenClass wovenClass) {
    BundleWiring wiring = wovenClass.getBundleWiring();
    Bundle bundle = wiring.getBundle();
    ClassLoader cl = wiring.getClassLoader();
    Collection<ClassTransformer> transformersToTry = getTransformers(bundle);
    for (ClassTransformer transformer : transformersToTry) {
        if (transformClass(wovenClass, cl, transformer)) {
            LOGGER.info("Weaving " + wovenClass.getClassName() + " using " + transformer.getClass().getName());
            break;
        }
    }
    Class<?> dClass = wovenClass.getDefinedClass();
    if (transformersToTry.isEmpty() && dClass != null && dClass.getAnnotation(Entity.class) != null) {
        LOGGER.warn("Loading " + wovenClass.getClassName() + " before transformer is present");
    }
}
 
開發者ID:apache,項目名稱:aries-jpa,代碼行數:18,代碼來源:JPAWeavingHook.java

示例6: getJPAPackages

import org.osgi.framework.wiring.BundleWiring; //導入依賴的package包/類
/**
 * Get all the relevant packages that the EclipseLink JPA provider exports or persistence packages it uses itself. These are needed
 * so that the woven proxy (for runtime enhancement) can be used later on :)
 * 
 * Note that differently to OpenJPA the relevant classes are actually in more than just one bundle (org.eclipse.persistence.jpa and org.eclipse.persistence.core
 * at the time of this writing). Hence, we have to take more than just the packages of the JPA provider bundle into account ...
 * 
 * @param jpaBundle
 * @return
 */
private String[] getJPAPackages(Bundle jpaBundle) {
    Set<String> result = new HashSet<String>();

    for (Bundle b : context.getBundles()) {
        BundleWiring bw = b.adapt(BundleWiring.class);
        if (bw == null) {
            continue;
        }
        boolean isJpaBundle = b.equals(jpaBundle);
        List<BundleWire> wires = bw.getProvidedWires(BundleRevision.PACKAGE_NAMESPACE);
        for (BundleWire w : wires) {
            String pkgName = (String)w.getCapability().getAttributes().get(BundleRevision.PACKAGE_NAMESPACE);
            boolean add = isJpaBundle || pkgName.startsWith("org.eclipse.persistence");
            if (add) {
                result.add(getPkg(b, pkgName));
            }
        }
    }
    
    result.add(getPkg(context.getBundle(), "org.apache.aries.jpa.eclipselink.adapter.platform"));
    LOG.debug("Found JPA packages {}", result);
    return result.toArray(new String[0]);
}
 
開發者ID:apache,項目名稱:aries-jpa,代碼行數:34,代碼來源:Activator.java

示例7: findSubTypesOf

import org.osgi.framework.wiring.BundleWiring; //導入依賴的package包/類
<T> List<Class<? extends T>> findSubTypesOf(Bundle bundle, Collection<Class<T>> superclasses) {
    BundleWiring wiring = bundle.adapt(BundleWiring.class);
    Collection<String> names = wiring
            .listResources("/", "*", BundleWiring.LISTRESOURCES_RECURSE);
    return names.stream().map(new Function<String, Class<?>>() {
        @Override @SneakyThrows
        public Class<?> apply(String name) {
            String n = name.replaceAll("\\.class$", "").replace('/', '.');
            try {
                return bundle.loadClass(n);
            } catch (ClassNotFoundException | NoClassDefFoundError e) {
                return null;
            }
        }
    }).filter(c -> c != null)
                .filter(c -> superclasses.stream().anyMatch(sc -> sc.isAssignableFrom(c)))
                .filter(c -> c.isAnnotationPresent(GraphQLMutation.class))
                .filter(c -> !c.isInterface() && !Modifier.isAbstract(c.getModifiers()))
                .map((Function<Class<?>, Class<? extends T>>) aClass -> (Class<? extends T>) aClass)
                .collect(Collectors.toList());
}
 
開發者ID:eventsourcing,項目名稱:es4j-graphql,代碼行數:22,代碼來源:OSGiMutationProvider.java

示例8: getClassNames

import org.osgi.framework.wiring.BundleWiring; //導入依賴的package包/類
static Set<String> getClassNames(Bundle bundle) {
    BundleWiring bundleWiring = bundle.adapt(BundleWiring.class);
    if (bundleWiring == null)
        return Collections.emptySet();
    Collection<String> resources = bundleWiring.listResources("/", "*.class", BundleWiring.LISTRESOURCES_RECURSE);
    Set<String> classNamesOfCurrentBundle = new HashSet<>();
    for (String resource : resources) {
        URL localResource = bundle.getEntry(resource);
        // Bundle.getEntry() returns null if the resource is not located in the specific bundle
        if (localResource != null) {
            String className = resource.replaceAll("/", ".").replaceAll("^(.*?)(\\.class)$", "$1");
            classNamesOfCurrentBundle.add(className);
        }
    }

    return classNamesOfCurrentBundle;
}
 
開發者ID:andyphillips404,項目名稱:awplab-core,代碼行數:18,代碼來源:JacksonManagerService.java

示例9: findSubTypesOf

import org.osgi.framework.wiring.BundleWiring; //導入依賴的package包/類
private <T> List<Class<? extends T>> findSubTypesOf(Bundle bundle, Collection<Class<T>> superclasses) {
    BundleWiring wiring = bundle.adapt(BundleWiring.class);
    Collection<String> names = wiring
            .listResources("/", "*", BundleWiring.LISTRESOURCES_RECURSE);
    return names.stream().map(new Function<String, Class<?>>() {
        @Override @SneakyThrows
        public Class<?> apply(String name) {
            String n = name.replaceAll("\\.class$", "").replace('/', '.');
            try {
                return bundle.loadClass(n);
            } catch (ClassNotFoundException | NoClassDefFoundError e) {
                return null;
            }
        }
    }).filter(c -> c != null).filter(c -> superclasses.stream().anyMatch(sc -> sc.isAssignableFrom(c)))
                .filter(c -> !c.isInterface() && !Modifier.isAbstract(c.getModifiers()))
                .map((Function<Class<?>, Class<? extends T>>) aClass -> (Class<? extends T>) aClass)
                .collect(Collectors.toList());
}
 
開發者ID:eventsourcing,項目名稱:es4j,代碼行數:20,代碼來源:OSGiEntitiesProvider.java

示例10: testGetService

import org.osgi.framework.wiring.BundleWiring; //導入依賴的package包/類
@SuppressWarnings({
 "rawtypes"
})
public void testGetService() throws ClassNotFoundException {
    final Object myTestProxyObject = new Object();

    IMocksControl control = EasyMock.createControl();
    EndpointDescription endpoint = createTestEndpointDesc();
    ImportRegistrationImpl iri = new ImportRegistrationImpl(endpoint, null);

    BundleContext consumerContext = control.createMock(BundleContext.class);
    Bundle consumerBundle = control.createMock(Bundle.class);
    BundleWiring bundleWiring = control.createMock(BundleWiring.class);
    EasyMock.expect(bundleWiring.getClassLoader()).andReturn(this.getClass().getClassLoader());
    EasyMock.expect(consumerBundle.adapt(BundleWiring.class)).andReturn(bundleWiring);
    EasyMock.expect(consumerBundle.getBundleContext()).andReturn(consumerContext);
    ServiceRegistration sreg = control.createMock(ServiceRegistration.class);


    DistributionProvider handler = mockDistributionProvider(myTestProxyObject);
    control.replay();

    ClientServiceFactory csf = new ClientServiceFactory(endpoint, handler, iri);
    assertSame(myTestProxyObject, csf.getService(consumerBundle, sreg));
}
 
開發者ID:apache,項目名稱:aries-rsa,代碼行數:26,代碼來源:ClientServiceFactoryTest.java

示例11: getBundleClasses

import org.osgi.framework.wiring.BundleWiring; //導入依賴的package包/類
@Override
public BundleClasses getBundleClasses(ComponentSpecification bundleSpec, Set<String> packagesToScan) {
    //Not written in an OO way since FelixFramework resides in JDisc core which for now is pure java,
    //and to load from classpath one needs classes from scalalib.

    //Temporary hack: Using class name since ClassLoaderOsgiFramework is not available at compile time in this bundle.
    if (osgiFramework.getClass().getName().equals("com.yahoo.application.container.impl.ClassLoaderOsgiFramework")) {
        Bundle syntheticClassPathBundle = first(osgiFramework.bundles());
        ClassLoader classLoader = syntheticClassPathBundle.adapt(BundleWiring.class).getClassLoader();

        return new BundleClasses(
                syntheticClassPathBundle,
                OsgiUtil.getClassEntriesForBundleUsingProjectClassPathMappings(classLoader, bundleSpec, packagesToScan));
    } else {
        Bundle bundle = getBundle(bundleSpec);
        if (bundle == null)
            throw new RuntimeException("No bundle matching " + quote(bundleSpec));

        return new BundleClasses(bundle, OsgiUtil.getClassEntriesInBundleClassPath(bundle, packagesToScan));
    }
}
 
開發者ID:vespa-engine,項目名稱:vespa,代碼行數:22,代碼來源:HandlersConfigurerDi.java

示例12: LayerFactoryImpl

import org.osgi.framework.wiring.BundleWiring; //導入依賴的package包/類
public LayerFactoryImpl(Activator activator, BundleContext context, Module systemModule) {
	String layerTypeProp = context.getProperty("osgi.jpms.layer.type");
	this.layerType = layerTypeProp == null ? LayerType.OneBundlePerLayerWithHierarchy : LayerType.valueOf(layerTypeProp);
	this.activator = activator;
	this.context = context;
	this.systemModule = systemModule;
	long startTime = System.nanoTime();
	privatesCache = loadPrivatesCache(context, activator);
	System.out.println("Time loadPrivatesCache: " + TimeUnit.MILLISECONDS.convert((System.nanoTime() - startTime), TimeUnit.NANOSECONDS));
	Bundle systemBundle = context.getBundle(Constants.SYSTEM_BUNDLE_LOCATION);
	fwkWiring = systemBundle.adapt(FrameworkWiring.class);
	ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
	layersWrite = lock.writeLock();
	layersRead = lock.readLock();

	BundleWiring systemWiring = systemBundle.adapt(BundleWiring.class);
	addToResolutionGraph(Collections.singleton(systemWiring));
	wiringToModule.put(systemWiring, systemModule);
}
 
開發者ID:tjwatson,項目名稱:osgi-jpms-layer,代碼行數:20,代碼來源:LayerFactoryImpl.java

示例13: getInUseBundleWirings

import org.osgi.framework.wiring.BundleWiring; //導入依賴的package包/類
private Set<BundleWiring> getInUseBundleWirings() {
	Set<BundleWiring> wirings = new HashSet<>();
	Collection<BundleCapability> bundles = fwkWiring.findProviders(ALL_BUNDLES_REQUIREMENT);
	for (BundleCapability bundleCap : bundles) {
		// Only pay attention to non JPMS boot modules.
		// NOTE this means we will not create a real JPMS Module or Layer for this bundle
		if (bundleCap.getAttributes().get(BOOT_JPMS_MODULE) == null) {
			BundleRevision revision = bundleCap.getRevision();
			BundleWiring wiring = revision.getWiring();
			if (wiring != null && wiring.isInUse()) {
				wirings.add(wiring);
			}
			if (revision.getBundle().getBundleId() == 0) {
				// also store the system.bundle fragments because they may have exports unknown to JPMS
				List<BundleWire> hostWires = wiring.getProvidedWires(HostNamespace.HOST_NAMESPACE);
				for (BundleWire hostWire : hostWires) {
					wirings.add(hostWire.getRequirerWiring());
				}
			}
		}
	}
	return wirings;
}
 
開發者ID:tjwatson,項目名稱:osgi-jpms-layer,代碼行數:24,代碼來源:LayerFactoryImpl.java

示例14: addReadsNest

import org.osgi.framework.wiring.BundleWiring; //導入依賴的package包/類
private void addReadsNest(Map<BundleWiring, Module> wiringToModule) {
	long addReadsNestStart = System.nanoTime();
	Set<Module> bootModules = ModuleLayer.boot().modules();
	Collection<Module> allBundleModules = wiringToModule.values();
	// Not checking for existing edges for simplicity.
	for (Module module : allBundleModules) {
		if (!systemModule.equals(module)) {
			// First add reads to all boot modules.
			addReads(module, bootModules);
			// Now ensure bidirectional read of all bundle modules.
			addReads(module, allBundleModules);
			// Add read to the system.bundle module.
			addReads(module, Collections.singleton(systemModule));
		}
	}
	System.out.println("Time to addReadsNest: " + TimeUnit.MILLISECONDS.convert((System.nanoTime() - addReadsNestStart), TimeUnit.NANOSECONDS));
}
 
開發者ID:tjwatson,項目名稱:osgi-jpms-layer,代碼行數:18,代碼來源:LayerFactoryImpl.java

示例15: addToResolutionGraph

import org.osgi.framework.wiring.BundleWiring; //導入依賴的package包/類
private void addToResolutionGraph(Set<BundleWiring> currentWirings) {
	long startAddToGraph = System.nanoTime();
	currentWirings.forEach((w) -> addToGraph(w));
	System.out.println("Time addToGraph: " + TimeUnit.MILLISECONDS.convert((System.nanoTime() - startAddToGraph), TimeUnit.NANOSECONDS));

	long startAddWires = System.nanoTime();
	for (Iterator<ResolutionGraph.Node> nodes = graph.iterator(); nodes.hasNext();) {
		ResolutionGraph.Node n = nodes.next();
		if (!currentWirings.contains(n.getValue()) && n.getValue().getBundle().getBundleId() != 0) {
			nodes.remove();
		} else {
			addWires(n);
		}
	}
	System.out.println("Time addWires: " + TimeUnit.MILLISECONDS.convert((System.nanoTime() - startAddWires), TimeUnit.NANOSECONDS));

	long startPopulateSources = System.nanoTime();
	graph.populateSources();
	System.out.println("Time populateSources: " + TimeUnit.MILLISECONDS.convert((System.nanoTime() - startPopulateSources), TimeUnit.NANOSECONDS));
}
 
開發者ID:tjwatson,項目名稱:osgi-jpms-layer,代碼行數:21,代碼來源:LayerFactoryImpl.java


注:本文中的org.osgi.framework.wiring.BundleWiring類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。