001/* 002 * (C) Copyright 2006-2007 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Nuxeo - initial API and implementation 018 * 019 * $Id$ 020 */ 021 022package org.nuxeo.runtime.deployment.preprocessor; 023 024import java.io.IOException; 025import java.util.ArrayList; 026import java.util.HashMap; 027import java.util.List; 028import java.util.Map; 029 030import org.apache.commons.logging.Log; 031import org.apache.commons.logging.LogFactory; 032import org.nuxeo.common.xmap.annotation.XContent; 033import org.nuxeo.common.xmap.annotation.XNode; 034import org.nuxeo.common.xmap.annotation.XNodeList; 035import org.nuxeo.common.xmap.annotation.XNodeMap; 036import org.nuxeo.common.xmap.annotation.XObject; 037import org.nuxeo.runtime.deployment.preprocessor.install.CommandProcessor; 038import org.nuxeo.runtime.deployment.preprocessor.install.DOMCommandsParser; 039import org.nuxeo.runtime.deployment.preprocessor.template.TemplateContribution; 040import org.w3c.dom.DocumentFragment; 041 042/** 043 * @author <a href="mailto:[email protected]">Bogdan Stefanescu</a> 044 */ 045@XObject("fragment") 046public class FragmentDescriptor { 047 048 private static final Log log = LogFactory.getLog(FragmentDescriptor.class); 049 050 /** 051 * Marker used for better control on requirements. see "all" marker in FragmentRegistry 052 */ 053 public static final FragmentDescriptor ALL = new FragmentDescriptor("all", true); 054 055 // the name is the name of the XML fragment file for XML fragments 056 // or the name of the JAR container for archive or directory fragments 057 @XNode("@name") 058 public String name; 059 060 @XNode("@version") 061 public int version = 0; 062 063 public String fileName; 064 065 public String filePath; 066 067 /** 068 * The start level is used to control bundle start order. The following levels are defined: 069 * <ul> 070 * <li>0 - system level - used by the OSGi framework itself 071 * <li>1 - runtime level - used by nuxeo-runtime bundles 072 * <li>2 - core level - used for core bundles 073 * <li>3 - platform level - used for platform service bundles 074 * <li>4 - presentation level - used for UI service bundles (e.g. seam components etc) 075 * <li>5 - UI level -used for UI bundles (e.g. war / web, widgets contribs) 076 * <li>6 - user level 077 * </ul> 078 * The start level is overwritten by the one specified at MANIFEST level using the Nuxeo-StartLevel header. If the 079 * start header is missing it will be initialized from the OSGi Bundle-Category (if any) as follows: 080 * <ul> 081 * <li><code>nuxeo-framework</code> 082 * <li><code>nuxeo-runtime</code> 083 * <li><code>nuxeo-service</code> 084 * <li><code>nuxeo-core</code> 085 * <li><code>nuxeo-platform</code> 086 * <li><code>nuxeo-presentation</code> 087 * <li><code>nuxeo-ui</code> 088 * <li><code>nuxeo-plugin</code> 089 * </ul> 090 * If the start level could not be computed then the default value of 6 (user level) is used The recommended method 091 * of specifying the start level is to use the <code>Bundle-Category</code> since start level numbering may change 092 * (this header has the advantage of using symbolic names) 093 */ 094 @XNode("@startLevel") 095 @Deprecated 096 public int startLevel; 097 098 @XNodeList(value = "extension", type = TemplateContribution[].class, componentType = TemplateContribution.class) 099 public TemplateContribution[] contributions; 100 101 @XNodeList(value = "require", type = ArrayList.class, componentType = String.class) 102 public List<String> requires; 103 104 @XNodeList(value = "requiredBy", type = String[].class, componentType = String.class) 105 public String[] requiredBy; 106 107 @XNodeMap(value = "template", key = "@name", type = HashMap.class, componentType = TemplateDescriptor.class) 108 public Map<String, TemplateDescriptor> templates; 109 110 public CommandProcessor install; 111 112 public CommandProcessor uninstall; 113 114 protected boolean isMarker; 115 116 /** 117 * 118 */ 119 public FragmentDescriptor() { 120 // TODO Auto-generated constructor stub 121 } 122 123 public FragmentDescriptor(String name, boolean isMarker) { 124 this.name = name; 125 this.isMarker = isMarker; 126 } 127 128 public boolean isMarker() { 129 return isMarker; 130 } 131 132 @XContent("install") 133 public void setInstallCommands(DocumentFragment df) { 134 try { 135 install = DOMCommandsParser.parse(df); 136 } catch (IOException e) { 137 log.error("Failed to set install commands"); 138 } 139 } 140 141 @XContent("uninstall") 142 public void setUninstallCommands(DocumentFragment df) { 143 try { 144 uninstall = DOMCommandsParser.parse(df); 145 } catch (IOException e) { 146 log.error("Failed to set uninstall commands"); 147 } 148 } 149 150 @Override 151 public String toString() { 152 return name + " [" + fileName + ']'; 153 } 154 155}