Package org.apache.tuscany.sca.contribution.resolver

Examples of org.apache.tuscany.sca.contribution.resolver.ClassReference


            return modelClass.cast(resolved);
           
        } else if (unresolved instanceof ClassReference) {
           
            // Load a class on demand
            ClassReference classReference = (ClassReference)unresolved;
            Class clazz;
            try {
                clazz = Class.forName(classReference.getClassName(), true, classLoader.get());
            } catch (ClassNotFoundException e) {
               
                // Return the unresolved object
                return unresolved;
            }
           
            // Store a new ClassReference wrappering the loaded class
            resolved = new ClassReference(clazz);
            map.put(resolved, resolved);
           
            // Return the resolved ClassReference
            return modelClass.cast(resolved);
               
View Full Code Here


    }

    public void resolve(JaasAuthenticationPolicy policy, ModelResolver resolver) throws ContributionResolveException {

         if (policy.getCallbackHandlerClassName() != null) {
             ClassReference classReference = new ClassReference(policy.getCallbackHandlerClassName());
             classReference = resolver.resolveModel(ClassReference.class, classReference);
             Class callbackClass = classReference.getJavaClass();
             if (callbackClass == null) {
                 throw new ContributionResolveException(new ClassNotFoundException(policy.getCallbackHandlerClassName()));
             }
             policy.setCallbackHandlerClass(callbackClass);
         }
View Full Code Here

    }

    public void resolve(JavaImplementation javaImplementation, ModelResolver resolver)
        throws ContributionResolveException {

        ClassReference classReference = new ClassReference(javaImplementation.getName());
        classReference = resolver.resolveModel(ClassReference.class, classReference);
        Class javaClass = classReference.getJavaClass();
        if (javaClass == null) {
            throw new ContributionResolveException(new ClassNotFoundException(javaImplementation.getName()));
        }
        javaImplementation.setJavaClass(javaClass);
        javaImplementation.setUnresolved(false);
View Full Code Here

     * @throws Exception
     */
    public void staticClassLoadingTestForVisibleClasses() throws Exception {
       
        Contribution customerContribution = supplyChain.getContribution("Customer");
        ClassReference customerClassRef = new ClassReference("supplychain.customer.Customer");
        customerClassRef = customerContribution.getModelResolver().resolveModel(ClassReference.class, customerClassRef);
        Class<?> customerClass = customerClassRef.getJavaClass();
       
        Class customerClassFromContribution = customerContribution.getClassLoader().loadClass("supplychain.customer.Customer");
        Assert.assertEquals(customerClass, customerClassFromContribution);
       
        Object customer = supplyChain.getCustomer(customerClass);
View Full Code Here

        Contribution retailerContribution = supplyChain.getContribution("Retailer");
        Contribution warehouseContribution = supplyChain.getContribution("Warehouse");
        Contribution shipperContribution = supplyChain.getContribution("Shipper");
        Contribution supplyChainContribution = supplyChain.getContribution("SupplyChain");
       
        ClassReference customerClassRef = new ClassReference("supplychain.customer.Customer");
        customerClassRef = customerContribution.getModelResolver().resolveModel(ClassReference.class, customerClassRef);
        Class customerClass = customerClassRef.getJavaClass();
       
        Class customerClassFromContribution = customerContribution.getClassLoader().loadClass("supplychain.customer.Customer");
        Assert.assertEquals(customerClass, customerClassFromContribution);
       
        Object customer = supplyChain.getCustomer(customerClass);
        Assert.assertTrue(customerClass.isInstance(customer));
       
        ClassReference retailerClassRef = new ClassReference("supplychain.retailer.Retailer");
        retailerClassRef = retailerContribution.getModelResolver().resolveModel(ClassReference.class, retailerClassRef);
        Class retailerClass = retailerClassRef.getJavaClass();
       
        Class retailerClassFromContribution = retailerContribution.getClassLoader().loadClass("supplychain.retailer.Retailer");
        Assert.assertEquals(retailerClass, retailerClassFromContribution);
       
        Class retailerClassFromCustomer = customerContribution.getClassLoader().loadClass("supplychain.retailer.Retailer");
        Assert.assertEquals(retailerClass, retailerClassFromCustomer);
       
        ClassReference warehouseClassRef = new ClassReference("supplychain.warehouse.Warehouse");
        warehouseClassRef = warehouseContribution.getModelResolver().resolveModel(ClassReference.class, warehouseClassRef);
        Class warehouseClass = warehouseClassRef.getJavaClass();
       
        Class warehouseClassFromContribution = warehouseContribution.getClassLoader().loadClass("supplychain.warehouse.Warehouse");
        Assert.assertEquals(warehouseClass, warehouseClassFromContribution);
       
        Class warehouseClassFromRetailer = retailerContribution.getClassLoader().loadClass("supplychain.warehouse.Warehouse");
        Assert.assertEquals(warehouseClass, warehouseClassFromRetailer);
       
        ClassReference shipperClassRef = new ClassReference("supplychain.shipper.Shipper");
        shipperClassRef = shipperContribution.getModelResolver().resolveModel(ClassReference.class, shipperClassRef);
        Class shipperClass = shipperClassRef.getJavaClass();
       
        Class shipperClassFromContribution = shipperContribution.getClassLoader().loadClass("supplychain.shipper.Shipper");
        Assert.assertEquals(shipperClass, shipperClassFromContribution);
       
        Class shipperClassFromWarehouse = shipperContribution.getClassLoader().loadClass("supplychain.shipper.Shipper");
View Full Code Here

    public void testIllegalStaticClassLoading2() throws Exception {
         
        supplyChain.setUp(this.getClass().getClassLoader(), SupplyChain.SUPPLYCHAIN_ILLEGAL_2);
       
        Contribution customerContribution = supplyChain.getContribution("Customer");
        ClassReference customerClassRef = new ClassReference("supplychain.customer.Customer");
        customerClassRef = customerContribution.getModelResolver().resolveModel(ClassReference.class, customerClassRef);
        Class<?> customerClass = customerClassRef.getJavaClass();
       
        Object customer = supplyChain.getCustomer(customerClass);
               
        try {
            Method m = customerClass.getMethod("purchaseGoods");
View Full Code Here

       
    }
   

    private Class getJavaClass(ModelResolver resolver, String className) {
        ClassReference ref = new ClassReference(className);
        ref = resolver.resolveModel(ClassReference.class, ref);
        return ref.getJavaClass();
    }
View Full Code Here

   
    @SuppressWarnings("unchecked")
    public void test() throws Exception {
       
        ClassReference customerClassRef = new ClassReference("supplychain.customer.Customer");
        customerClassRef = supplyChainV1.customerContribution.getModelResolver().resolveModel(ClassReference.class, customerClassRef);
        Class customerClass = customerClassRef.getJavaClass();
       
        Object customer =
            domain.getService(customerClass, "CustomerComponent");
               
        Method m = customerClass.getMethod("purchaseGoods");
        m.invoke(customer);
       
        System.out.println("Sleeping ...");
        Thread.sleep(1000);
       
        ClassReference customerClassRefV2 = new ClassReference("supplychain.customer.Customer");
        customerClassRefV2 = supplyChainV2.customerContribution.getModelResolver().resolveModel(ClassReference.class, customerClassRefV2);
        Class customerClassV2 = customerClassRefV2.getJavaClass();
       
        Object customerV2 =
            domain.getService(customerClassV2, "CustomerComponentV2");
               
        Method mV2 = customerClassV2.getMethod("purchaseGoods");
View Full Code Here

   
    @SuppressWarnings("unchecked")
    public void test() throws Exception {
       
        ClassReference customerClassRef = new ClassReference("supplychain.customer.Customer");
        customerClassRef = supplyChainV1.supplychainContribution.getModelResolver().resolveModel(ClassReference.class, customerClassRef);
        Class customerClass = customerClassRef.getJavaClass();
       
        Object customer =
            domain.getService(customerClass, "CustomerComponent");
               
        Method m = customerClass.getMethod("purchaseGoods");
        m.invoke(customer);
       
        System.out.println("Sleeping ...");
        Thread.sleep(1000);
       
        ClassReference customerClassRefV2 = new ClassReference("supplychain.customer.Customer");
        customerClassRefV2 = supplyChainV2.supplychainContribution.getModelResolver().resolveModel(ClassReference.class, customerClassRefV2);
        Class customerClassV2 = customerClassRefV2.getJavaClass();
       
        Object customerV2 =
            domain.getService(customerClassV2, "CustomerComponentV2");
               
        Method mV2 = customerClassV2.getMethod("purchaseGoods");
View Full Code Here

    /**
     * Resolve a Java class.
     */
    static Class<?> resolve(final String name, final ModelResolver res, final ProcessorContext ctx) throws ContributionResolveException {
        final ClassReference cr = res.resolveModel(ClassReference.class, new ClassReference(name), ctx);
        if(cr.getJavaClass() != null)
            return cr.getJavaClass();
        throw new ContributionResolveException(new ClassNotFoundException(name));
    }
View Full Code Here

TOP

Related Classes of org.apache.tuscany.sca.contribution.resolver.ClassReference

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.