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