Search in sources :

Example 21 with Descriptor

use of org.apache.felix.service.command.Descriptor in project felix by apache.

the class Basic method update.

@Descriptor("update bundle from URL")
public void update(@Descriptor("command session") CommandSession session, @Descriptor("target bundle") Bundle bundle, @Descriptor("URL from where to retrieve bundle") String location) throws IOException {
    if (location != null) {
        location = Util.resolveUri(session, location.trim());
        try {
            // Get the bundle.
            if (bundle != null) {
                InputStream is = new URL(location).openStream();
                bundle.update(is);
            } else {
                System.err.println("Please specify a bundle to update");
            }
        } catch (MalformedURLException ex) {
            System.err.println("Unable to parse URL");
        } catch (IOException ex) {
            System.err.println("Unable to open input stream: " + ex);
        } catch (BundleException ex) {
            if (ex.getNestedException() != null) {
                System.err.println(ex.getNestedException().toString());
            } else {
                System.err.println(ex.toString());
            }
        } catch (Exception ex) {
            System.err.println(ex.toString());
        }
    } else {
        System.err.println("Must specify a location.");
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) InputStream(java.io.InputStream) IOException(java.io.IOException) BundleException(org.osgi.framework.BundleException) URL(java.net.URL) BundleException(org.osgi.framework.BundleException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) Descriptor(org.apache.felix.service.command.Descriptor)

Example 22 with Descriptor

use of org.apache.felix.service.command.Descriptor in project felix by apache.

the class Basic method frameworklevel.

@Descriptor("set framework active start level")
public void frameworklevel(@Descriptor("target start level") int level) {
    // Keep track of service references.
    List<ServiceReference<?>> refs = new ArrayList<ServiceReference<?>>();
    // Get start level service.
    StartLevel sl = Util.getService(m_bc, StartLevel.class, refs);
    if (sl == null) {
        System.out.println("Start Level service is unavailable.");
    }
    sl.setStartLevel(level);
    Util.ungetServices(m_bc, refs);
}
Also used : ArrayList(java.util.ArrayList) StartLevel(org.osgi.service.startlevel.StartLevel) ServiceReference(org.osgi.framework.ServiceReference) Descriptor(org.apache.felix.service.command.Descriptor)

Example 23 with Descriptor

use of org.apache.felix.service.command.Descriptor in project felix by apache.

the class Basic method refresh.

@Descriptor("refresh bundles")
public void refresh(@Descriptor("target bundles (can be null or empty)") Bundle[] bundles) {
    if ((bundles != null) && (bundles.length == 0)) {
        bundles = null;
    }
    // Keep track of service references.
    List<ServiceReference<?>> refs = new ArrayList<ServiceReference<?>>();
    // Get package admin service.
    PackageAdmin pa = Util.getService(m_bc, PackageAdmin.class, refs);
    if (pa == null) {
        System.out.println("Package Admin service is unavailable.");
    }
    pa.refreshPackages((bundles == null) ? null : bundles);
    Util.ungetServices(m_bc, refs);
}
Also used : PackageAdmin(org.osgi.service.packageadmin.PackageAdmin) ArrayList(java.util.ArrayList) ServiceReference(org.osgi.framework.ServiceReference) Descriptor(org.apache.felix.service.command.Descriptor)

Example 24 with Descriptor

use of org.apache.felix.service.command.Descriptor in project felix by apache.

the class Basic method resolve.

@Descriptor("resolve bundles")
public void resolve(@Descriptor("target bundles (can be null or empty)") Bundle[] bundles) {
    if ((bundles != null) && (bundles.length == 0)) {
        bundles = null;
    }
    // Keep track of service references.
    List<ServiceReference<?>> refs = new ArrayList<ServiceReference<?>>();
    // Get package admin service.
    PackageAdmin pa = Util.getService(m_bc, PackageAdmin.class, refs);
    if (pa == null) {
        System.out.println("Package Admin service is unavailable.");
    }
    if (!pa.resolveBundles(bundles)) {
        System.out.println("Not all bundles could be resolved.");
    }
    Util.ungetServices(m_bc, refs);
}
Also used : PackageAdmin(org.osgi.service.packageadmin.PackageAdmin) ArrayList(java.util.ArrayList) ServiceReference(org.osgi.framework.ServiceReference) Descriptor(org.apache.felix.service.command.Descriptor)

Example 25 with Descriptor

use of org.apache.felix.service.command.Descriptor in project felix by apache.

the class Basic method frameworklevel.

@Descriptor("query framework active start level")
public void frameworklevel() {
    // Keep track of service references.
    List<ServiceReference<?>> refs = new ArrayList<ServiceReference<?>>();
    // Get start level service.
    StartLevel sl = Util.getService(m_bc, StartLevel.class, refs);
    if (sl == null) {
        System.out.println("Start Level service is unavailable.");
    }
    System.out.println("Level is " + sl.getStartLevel());
    Util.ungetServices(m_bc, refs);
}
Also used : ArrayList(java.util.ArrayList) StartLevel(org.osgi.service.startlevel.StartLevel) ServiceReference(org.osgi.framework.ServiceReference) Descriptor(org.apache.felix.service.command.Descriptor)

Aggregations

Descriptor (org.apache.felix.service.command.Descriptor)31 ArrayList (java.util.ArrayList)13 ServiceReference (org.osgi.framework.ServiceReference)8 IOException (java.io.IOException)6 Bundle (org.osgi.framework.Bundle)6 StartLevel (org.osgi.service.startlevel.StartLevel)5 URL (java.net.URL)4 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)4 PrintStream (java.io.PrintStream)3 Method (java.lang.reflect.Method)3 MalformedURLException (java.net.MalformedURLException)3 List (java.util.List)3 TreeMap (java.util.TreeMap)3 HandlerFactory (org.apache.felix.ipojo.HandlerFactory)3 TypeDeclaration (org.apache.felix.ipojo.extender.TypeDeclaration)3 BundleException (org.osgi.framework.BundleException)3 File (java.io.File)2 InputStream (java.io.InputStream)2 URI (java.net.URI)2 Factory (org.apache.felix.ipojo.Factory)2