001    //
002    // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-2 
003    // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
004    // Any modifications to this file will be lost upon recompilation of the source schema. 
005    // Generated on: 2012.04.01 at 02:20:36 AM CEST 
006    //
007    
008    
009    package org.jomc.modlet;
010    
011    import java.util.ArrayList;
012    import java.util.Iterator;
013    import java.util.List;
014    import javax.annotation.Generated;
015    import javax.xml.bind.annotation.XmlAccessType;
016    import javax.xml.bind.annotation.XmlAccessorType;
017    import javax.xml.bind.annotation.XmlElement;
018    import javax.xml.bind.annotation.XmlType;
019    
020    
021    /**
022     * List of modlets.
023     * 
024     * <p>Java class for Modlets complex type.
025     * 
026     * <p>The following schema fragment specifies the expected content contained within this class.
027     * 
028     * <pre>
029     * &lt;complexType name="Modlets">
030     *   &lt;complexContent>
031     *     &lt;extension base="{http://jomc.org/modlet}ModletObject">
032     *       &lt;sequence>
033     *         &lt;element ref="{http://jomc.org/modlet}modlet" maxOccurs="unbounded" minOccurs="0"/>
034     *       &lt;/sequence>
035     *     &lt;/extension>
036     *   &lt;/complexContent>
037     * &lt;/complexType>
038     * </pre>
039     * 
040     * 
041     */
042    @XmlAccessorType(XmlAccessType.FIELD)
043    @XmlType(name = "Modlets", namespace = "http://jomc.org/modlet", propOrder = {
044        "modlet"
045    })
046    @Generated(value = "com.sun.tools.xjc.Driver", date = "2012-04-01T02:20:36+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
047    public class Modlets
048        extends ModletObject
049        implements Cloneable
050    {
051    
052        @XmlElement(namespace = "http://jomc.org/modlet")
053        @Generated(value = "com.sun.tools.xjc.Driver", date = "2012-04-01T02:20:36+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
054        protected List<Modlet> modlet;
055    
056        /**
057         * Creates a new {@code Modlets} instance.
058         * 
059         */
060        public Modlets() {
061            // CC-XJC Version 2.0 Build 2011-09-16T18:27:24+0000
062            super();
063        }
064    
065        /**
066         * Creates a new {@code Modlets} instance by deeply copying a given {@code Modlets} instance.
067         * 
068         * 
069         * @param o
070         *     The instance to copy.
071         * @throws NullPointerException
072         *     if {@code o} is {@code null}.
073         */
074        public Modlets(final Modlets o) {
075            // CC-XJC Version 2.0 Build 2011-09-16T18:27:24+0000
076            super(o);
077            if (o == null) {
078                throw new NullPointerException("Cannot create a copy of 'Modlets' from 'null'.");
079            }
080            // 'Modlet' collection.
081            if (o.modlet!= null) {
082                copyModlet(o.getModlet(), this.getModlet());
083            }
084        }
085    
086        /**
087         * Gets the value of the modlet property.
088         * 
089         * <p>
090         * This accessor method returns a reference to the live list,
091         * not a snapshot. Therefore any modification you make to the
092         * returned list will be present inside the JAXB object.
093         * This is why there is not a <CODE>set</CODE> method for the modlet property.
094         * 
095         * <p>
096         * For example, to add a new item, do as follows:
097         * <pre>
098         *    getModlet().add(newItem);
099         * </pre>
100         * 
101         * 
102         * <p>
103         * Objects of the following type(s) are allowed in the list
104         * {@link Modlet }
105         * 
106         * 
107         */
108        @Generated(value = "com.sun.tools.xjc.Driver", date = "2012-04-01T02:20:36+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
109        public List<Modlet> getModlet() {
110            if (modlet == null) {
111                modlet = new ArrayList<Modlet>();
112            }
113            return this.modlet;
114        }
115    
116        /**
117         * Copies all values of property {@code Modlet} deeply.
118         * 
119         * @param source
120         *     The source to copy from.
121         * @param target
122         *     The target to copy {@code source} to.
123         * @throws NullPointerException
124         *     if {@code target} is {@code null}.
125         */
126        @SuppressWarnings("unchecked")
127        @Generated(value = "com.sun.tools.xjc.Driver", date = "2012-04-01T02:20:36+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
128        private static void copyModlet(final List<Modlet> source, final List<Modlet> target) {
129            // CC-XJC Version 2.0 Build 2011-09-16T18:27:24+0000
130            if ((source!= null)&&(!source.isEmpty())) {
131                for (final Iterator<?> it = source.iterator(); it.hasNext(); ) {
132                    final Object next = it.next();
133                    if (next instanceof Modlet) {
134                        // CClassInfo: org.jomc.modlet.Modlet
135                        target.add(((Modlet) next).clone());
136                        continue;
137                    }
138                    // Please report this at https://apps.sourceforge.net/mantisbt/ccxjc/
139                    throw new AssertionError((("Unexpected instance '"+ next)+"' for property 'Modlet' of class 'org.jomc.modlet.Modlets'."));
140                }
141            }
142        }
143    
144        /**
145         * Creates and returns a deep copy of this object.
146         * 
147         * 
148         * @return
149         *     A deep copy of this object.
150         */
151        @Override
152        @Generated(value = "com.sun.tools.xjc.Driver", date = "2012-04-01T02:20:36+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
153        public Modlets clone() {
154            {
155                // CC-XJC Version 2.0 Build 2011-09-16T18:27:24+0000
156                final Modlets clone = ((Modlets) super.clone());
157                // 'Modlet' collection.
158                if (this.modlet!= null) {
159                    clone.modlet = null;
160                    copyModlet(this.getModlet(), clone.getModlet());
161                }
162                return clone;
163            }
164        }
165        
166        /**
167         * Gets a modlet for a given name from the list of modlets.
168         *
169         * @param name The name of the modlet to return.
170         *
171         * @return The first matching modlet or {@code null}, if no such modlet is found.
172         *
173         * @throws NullPointerException if {@code name} is {@code null}.
174         *
175         * @see #getModlet()
176         * @see Modlet#getName()
177         */
178        public Modlet getModlet( final String name )
179        {
180            if ( name == null )
181            {
182                throw new NullPointerException( "name" );
183            }
184    
185            for ( int i = 0, s0 = this.getModlet().size(); i < s0; i++ )
186            {
187                final Modlet m = this.getModlet().get( i );
188    
189                if ( name.equals( m.getName() ) )
190                {
191                    return m;
192                }
193            }
194    
195            return null;
196        }
197    
198        /**
199         * Merges modlets of a model from this list of modlets to a single modlet.
200         *
201         * @param name The name of the modlet to return.
202         * @param model The identifier of the model of the modlet to return.
203         *
204         * @return A modlet holding all modlet objects of the model identified by {@code model} from the list.
205         *
206         * @throws NullPointerException if {@code name} or {@code model} is {@code null}.
207         *
208         * @see #getModlet()
209         * @see Modlet#getModel()
210         */
211        public Modlet getMergedModlet( final String name, final String model )
212        {
213            if ( name == null )
214            {
215                throw new NullPointerException( "name" );
216            }
217            if ( model == null )
218            {
219                throw new NullPointerException( "model" );
220            }
221    
222            final Modlet mergedModlet = new Modlet();
223            mergedModlet.setName( name );
224            mergedModlet.setModel( model );
225    
226            for ( int i = 0, s0 = this.getModlet().size(); i < s0; i++ )
227            {
228                final Modlet m = this.getModlet().get( i );
229    
230                if ( model.equals( m.getModel() ) )
231                {
232                    if ( m.getSchemas() != null )
233                    {
234                        if ( mergedModlet.getSchemas() == null )
235                        {
236                            mergedModlet.setSchemas( new Schemas() );
237                        }
238    
239                        for ( int j = 0, s1 = m.getSchemas().getSchema().size(); j < s1; j++ )
240                        {
241                            final Schema s = m.getSchemas().getSchema().get( j );
242    
243                            if ( mergedModlet.getSchemas().getSchemaBySystemId( s.getSystemId() ) == null )
244                            {
245                                mergedModlet.getSchemas().getSchema().add( s );
246                            }
247                        }
248                    }
249    
250                    if ( m.getServices() != null )
251                    {
252                        if ( mergedModlet.getServices() == null )
253                        {
254                            mergedModlet.setServices( new Services() );
255                        }
256    
257                        for ( int j = 0, s1 = m.getServices().getService().size(); j < s1; j++ )
258                        {
259                            final Service s = m.getServices().getService().get( j );
260                            boolean merged = false;
261    
262                            for ( Service mergedService : mergedModlet.getServices().getServices( s.getIdentifier() ) )
263                            {
264                                if ( mergedService.getClazz().equals( s.getClazz() ) )
265                                {
266                                    if ( mergedService.getOrdinal() < s.getOrdinal() )
267                                    {
268                                        mergedService.setOrdinal( s.getOrdinal() );
269                                    }
270    
271                                    merged = true;
272                                }
273                            }
274    
275                            if ( !merged )
276                            {
277                                mergedModlet.getServices().getService().add( s );
278                            }
279                        }
280                    }
281                }
282            }
283    
284            return mergedModlet;
285        }
286    
287        /**
288         * Gets schemas for a model from this list of modlets.
289         *
290         * @param model The identifier of the model to return schemas of.
291         *
292         * @return A list of schemas for {@code model} or {@code null}, if no such schemas are found.
293         *
294         * @throws NullPointerException if {@code model} is {@code null}.
295         *
296         * @see #getModlet()
297         * @see Modlet#getModel()
298         */
299        public Schemas getSchemas( final String model )
300        {
301            if ( model == null )
302            {
303                throw new NullPointerException( "model" );
304            }
305    
306            final Schemas schemas = new Schemas();
307            final String projectName = getMessage( "projectName" );
308    
309            for ( int i = 0, s0 = this.getModlet().size(); i < s0; i++ )
310            {
311                final Modlet m = this.getModlet().get( i );
312    
313                if ( m.getSchemas() != null && ( m.getName().equals( projectName ) || model.equals( m.getModel() ) ) )
314                {
315                    for ( int j = 0, s1 = m.getSchemas().getSchema().size(); j < s1; j++ )
316                    {
317                        schemas.getSchema().add( m.getSchemas().getSchema().get( j ) );
318                    }
319                }
320            }
321    
322            return schemas.getSchema().isEmpty() ? null : schemas;
323        }
324    
325        /**
326         * Gets schemas for a public identifier from this list of modlets.
327         *
328         * @param publicId The public identifier of the schemas to return.
329         *
330         * @return A list of schemas matching {@code publicId} or {@code null}, if no such schemas are found.
331         *
332         * @throws NullPointerException if {@code publicId} is {@code null}.
333         *
334         * @see #getModlet()
335         * @see Modlet#getSchemas()
336         * @see Schemas#getSchemasByPublicId(java.net.URI)
337         * @since 1.2
338         */
339        public Schemas getSchemas( final java.net.URI publicId )
340        {
341            if ( publicId == null )
342            {
343                throw new NullPointerException( "publicId" );
344            }
345    
346            final Schemas schemas = new Schemas();
347    
348            for ( int i = 0, s0 = this.getModlet().size(); i < s0; i++ )
349            {
350                final Modlet m = this.getModlet().get( i );
351    
352                if ( m.getSchemas() != null )
353                {
354                    schemas.getSchema().addAll( m.getSchemas().getSchemasByPublicId( publicId ) );
355                }
356            }
357    
358            return schemas.getSchema().isEmpty() ? null : schemas;
359        }
360    
361        /**
362         * Gets services for a model from this list of modlets.
363         *
364         * @param model The identifier of the model to return services of.
365         *
366         * @return A list of services for {@code model} or {@code null}, if no such services are found.
367         *
368         * @throws NullPointerException if {@code model} is {@code null}.
369         *
370         * @see #getModlet()
371         * @see Modlet#getModel()
372         */
373        public Services getServices( final String model )
374        {
375            if ( model == null )
376            {
377                throw new NullPointerException( "model" );
378            }
379    
380            final Services services = new Services();
381            final String projectName = getMessage( "projectName" );
382    
383            for ( int i = 0, s0 = this.getModlet().size(); i < s0; i++ )
384            {
385                final Modlet m = this.getModlet().get( i );
386    
387                if ( m.getServices() != null && ( m.getName().equals( projectName ) || model.equals( m.getModel() ) ) )
388                {
389                    for ( int j = 0, s1 = m.getServices().getService().size(); j < s1; j++ )
390                    {
391                        services.getService().add( m.getServices().getService().get( j ) );
392                    }
393                }
394            }
395    
396            return services.getService().isEmpty() ? null : services;
397        }
398    
399        private static String getMessage( final String key, final Object... args )
400        {
401            return java.text.MessageFormat.format( java.util.ResourceBundle.getBundle(
402                ModelContext.class.getName().replace( '.', '/' ), java.util.Locale.getDefault() ).getString( key ), args );
403    
404        }
405          
406    }