Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
package org.apache.felix.karaf.deployer.blueprint;
A deployment listener that listens for spring xml applications and creates bundles for these.
    private static final Log LOGGER = LogFactory.getLog(BlueprintDeploymentListener.class);
    private DocumentBuilderFactory dbf;
    public boolean canHandle(File artifact) {
        try {
            if (artifact.isFile() && artifact.getName().endsWith(".xml")) {
                Document doc = parse(artifact);
                String name = doc.getDocumentElement().getLocalName();
                String uri  = doc.getDocumentElement().getNamespaceURI();
                if ("blueprint".equals(name) && "http://www.osgi.org/xmlns/blueprint/v1.0.0".equals(uri)) {
                    return true;
                }
            }
        } catch (Exception e) {
            .error("Unable to parse deployed file " + artifact.getAbsolutePath(), e);
        }
        return false;
    }
    public URL transform(URL artifact) {
        try {
            return new URL("blueprint"nullartifact.toString());
        } catch (Exception e) {
            .error("Unable to build blueprint application bundle"e);
            return null;
        }
    }
    protected Document parse(File artifactthrows Exception {
        if ( == null) {
             = DocumentBuilderFactory.newInstance();
            .setNamespaceAware(true);
        }
        DocumentBuilder db = .newDocumentBuilder();
        db.setErrorHandler(new ErrorHandler() {
            public void warning(SAXParseException exceptionthrows SAXException {
            }
            public void error(SAXParseException exceptionthrows SAXException {
            }
            public void fatalError(SAXParseException exceptionthrows SAXException {
                throw exception;
            }
        });
        return db.parse(artifact);
    }
New to GrepCode? Check out our FAQ X