001/*
002 * (C) Copyright 2006-2017 Nuxeo (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 */
019package org.nuxeo.runtime.model;
020
021import java.net.URL;
022import java.util.Map;
023import java.util.Optional;
024import java.util.Set;
025import java.util.stream.Stream;
026
027import org.nuxeo.runtime.Version;
028import org.nuxeo.runtime.model.impl.ComponentRegistry;
029
030/**
031 * The component registration info.
032 * <p>
033 * A registration info object is keeping all the information needed to deploy a component, like the component
034 * implementation, properties, dependencies and also the defined extension points and contributed extensions.
035 * <p>
036 * When a component is activated the registration info is creating a component instance using the current runtime
037 * context.
038 *
039 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
040 */
041public interface RegistrationInfo {
042
043    int UNREGISTERED = 0;
044
045    int REGISTERED = 1;
046
047    /**
048     * Component dependencies are resolved
049     */
050    int RESOLVED = 2;
051
052    /**
053     * Before component activation
054     */
055    int ACTIVATING = 3;
056
057    int DEACTIVATING = 4;
058
059    /**
060     * Component activation successful
061     */
062    int ACTIVATED = 5;
063
064    /**
065     * Notification of applicationStarted fails
066     *
067     * @since 7.4
068     */
069    int START_FAILURE = 6;
070
071    /**
072     * Component was started
073     *
074     * @since 9.2
075     */
076    int STARTED = 7;
077
078    /**
079     * The component is being started
080     */
081    int STARTING = 8;
082
083    /**
084     * The component is being stopped
085     */
086    int STOPPING = 9;
087
088    /**
089     * Gets the component version.
090     */
091    Version getVersion();
092
093    /**
094     * Get the owner bundle symbolic name of that component. If null the default owner is used.
095     */
096    String getBundle();
097
098    /**
099     * Gets any comments on this component.
100     */
101    String getDocumentation();
102
103    /**
104     * Gets the runtime context that created this registration info.
105     *
106     * @return the runtime context
107     */
108    RuntimeContext getContext();
109
110    /**
111     * Gets the component properties.
112     *
113     * @return the component properties
114     */
115    Map<String, Property> getProperties();
116
117    /**
118     * Gets the list of aliases.
119     *
120     * @return the aliases
121     */
122    Set<ComponentName> getAliases();
123
124    /**
125     * Gets the list of the required components.
126     *
127     * @return the required components
128     */
129    Set<ComponentName> getRequiredComponents();
130
131    /**
132     * Gets the defined extension points.
133     *
134     * @return the defined extension points
135     */
136    ExtensionPoint[] getExtensionPoints();
137
138    /**
139     * Gets the defined extension points with name.
140     *
141     * @param name the extension point name to retrieve
142     * @return the defined extension points with name
143     * @since 9.3
144     */
145    default Optional<ExtensionPoint> getExtensionPoint(String name) {
146        return Stream.of(getExtensionPoints()).filter(xp -> xp.getName().equals(name)).findFirst();
147    }
148
149    /**
150     * Gets the extensions contributed by this component.
151     *
152     * @return the contributed extensions
153     */
154    Extension[] getExtensions();
155
156    /**
157     * Gets the name of the component.
158     *
159     * @return the component name
160     */
161    ComponentName getName();
162
163    /**
164     * Whether this component is disabled. For now this is used only for persistent components.
165     */
166    boolean isDisabled();
167
168    /**
169     * Gets the component instance or null if the component was not yet activated.
170     *
171     * @return the component instance
172     */
173    ComponentInstance getComponent();
174
175    /**
176     * Gets the component state.
177     *
178     * @return the component state
179     */
180    int getState();
181
182    /**
183     * Gets the component manager.
184     *
185     * @return the component manager
186     */
187    ComponentManager getManager();
188
189    /**
190     * Checks whether this component is activated.
191     *
192     * @return true if the component is activated, false otherwise
193     */
194    boolean isActivated();
195
196    /**
197     * Checks whether this component is resolved (i.e. all its dependencies are satisfied).
198     *
199     * @return true if the component is resolved, false otherwise
200     */
201    boolean isResolved();
202
203    /**
204     * Checks whether this component is started
205     *
206     * @since 9.2
207     */
208    boolean isStarted();
209
210    /**
211     * Gets the list of provided services or null if no service is provided.
212     *
213     * @return an array containing the service class names or null if no service are provided
214     */
215    String[] getProvidedServiceNames();
216
217    /**
218     * Whether or not this registration is persisted by the user (not part of a real bundle).
219     *
220     * @return true if persisted, false otherwise
221     */
222    boolean isPersistent();
223
224    /**
225     * Set the persistent flag on this registration
226     */
227    void setPersistent(boolean isPersistent);
228
229    /**
230     * Give the class name for the component implementation if this is a java component
231     *
232     * @return class name
233     */
234    String getImplementation();
235
236    /**
237     * Retrieve the URL of the XML file used to declare the component
238     *
239     * @return the XML file URL
240     */
241    URL getXmlFileUrl();
242
243    /**
244     * The id of the content source used to create the registration (usually a StreamRef id)
245     *
246     * @since 9.2
247     */
248    String getSourceId();
249
250    /**
251     * The component notification order for {@link ComponentManager#start()}.
252     *
253     * @return the order, 1000 by default
254     * @since 5.6
255     */
256    int getApplicationStartedOrder();
257
258    /**
259     * DON'T USE THIS METHOD - INTERNAL API.
260     *
261     * @param state the state to set in this registration info
262     * @since 9.3
263     */
264    void setState(int state);
265
266    /**
267     * DON'T USE THIS METHOD - INTERNAL API.
268     * <p>
269     * This flag is used to introduce a new component lifecycle mechanism in order to introduce java pojo contribution.
270     * This allow us to rework how component manager handles the component, without changing how it handles component
271     * created by XML contributions (current behavior).
272     *
273     * @return whether or not {@link ComponentManager} or {@link ComponentRegistry} should use the former way to manage
274     *         component lifecycle.
275     * @since 9.3
276     */
277    default boolean useFormerLifecycleManagement() {
278        return false;
279    }
280
281}