1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir package basicrunner.basichelper;
28*cdf0e10cSrcweir 
29*cdf0e10cSrcweir import com.sun.star.lang.XInitialization;
30*cdf0e10cSrcweir import com.sun.star.lang.XSingleServiceFactory;
31*cdf0e10cSrcweir import com.sun.star.lang.XServiceInfo;
32*cdf0e10cSrcweir import com.sun.star.uno.Type;
33*cdf0e10cSrcweir import com.sun.star.lang.XTypeProvider;
34*cdf0e10cSrcweir import util.XMLTools;
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir /**
37*cdf0e10cSrcweir * The class provides an implementation of the service
38*cdf0e10cSrcweir * <code>com.sun.star.xml.sax.XAttributeList</code>.
39*cdf0e10cSrcweir * @see com.sun.star.xml.sax.XAttributeList
40*cdf0e10cSrcweir * @see com.sun.star.lang.XServiceInfo
41*cdf0e10cSrcweir * @see com.sun.star.lang.XSingleServiceFactory
42*cdf0e10cSrcweir */
43*cdf0e10cSrcweir public class AttributeList implements XServiceInfo, XSingleServiceFactory {
44*cdf0e10cSrcweir     /** The service name of this class  **/
45*cdf0e10cSrcweir     static final String __serviceName = "basichelper.AttributeList";
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir     /**
48*cdf0e10cSrcweir      * Returns True, of the service is supported.
49*cdf0e10cSrcweir      * @param name The service name.
50*cdf0e10cSrcweir      * @return True, if the service is supported.
51*cdf0e10cSrcweir      */
52*cdf0e10cSrcweir     public boolean supportsService(String name) {
53*cdf0e10cSrcweir         return __serviceName.equals(name);
54*cdf0e10cSrcweir     }
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir     /**
57*cdf0e10cSrcweir      * Get all supported services.
58*cdf0e10cSrcweir      * @return The supported services.
59*cdf0e10cSrcweir      */
60*cdf0e10cSrcweir     public String[] getSupportedServiceNames() {
61*cdf0e10cSrcweir         return new String[] {__serviceName};
62*cdf0e10cSrcweir     }
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir     /**
65*cdf0e10cSrcweir      * Ask for the implementation name.
66*cdf0e10cSrcweir      * @return The implementation name.
67*cdf0e10cSrcweir      */
68*cdf0e10cSrcweir     public String getImplementationName() {
69*cdf0e10cSrcweir         return getClass().getName();
70*cdf0e10cSrcweir     }
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir     /**
73*cdf0e10cSrcweir      * Create an instance of the actual implementation of the AttributeList.
74*cdf0e10cSrcweir      * Arguments are not supported, so they will bge ignored.
75*cdf0e10cSrcweir      * @param args The arguments.
76*cdf0e10cSrcweir      * @return A new instance of this class.
77*cdf0e10cSrcweir      */
78*cdf0e10cSrcweir     public Object createInstanceWithArguments(Object[] args) {
79*cdf0e10cSrcweir         return new AttributeListImpl();
80*cdf0e10cSrcweir     }
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir     /**
83*cdf0e10cSrcweir      * Create an instance of this class.
84*cdf0e10cSrcweir      * @return A new instance of this class.
85*cdf0e10cSrcweir      */
86*cdf0e10cSrcweir     public Object createInstance() {
87*cdf0e10cSrcweir         return createInstanceWithArguments(null);
88*cdf0e10cSrcweir     }
89*cdf0e10cSrcweir }
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir /**
92*cdf0e10cSrcweir  * The actual implementation of the service
93*cdf0e10cSrcweir  * <code>com.sun.star.xml.sax.XAttributeList</code>.
94*cdf0e10cSrcweir  * Extends the class util.XMLTools.AttributeList.
95*cdf0e10cSrcweir  * @see util.XMLTools.AttributeList
96*cdf0e10cSrcweir  * @see com.sun.star.xml.sax.XAttributeList
97*cdf0e10cSrcweir  * @see com.sun.star.lang.XTypeProvider
98*cdf0e10cSrcweir  * @see com.sun.star.lang.XInitialization
99*cdf0e10cSrcweir  */
100*cdf0e10cSrcweir class AttributeListImpl extends XMLTools.AttributeList
101*cdf0e10cSrcweir                             implements XTypeProvider, XInitialization {
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir                                 /**
104*cdf0e10cSrcweir                                  * Initialize this class.
105*cdf0e10cSrcweir                                  * @param p0 An array of XML attributes that are added to the list.
106*cdf0e10cSrcweir                                  * @throws Exception Initialize failed.
107*cdf0e10cSrcweir                                  */
108*cdf0e10cSrcweir     public void initialize(Object[] p0) throws com.sun.star.uno.Exception {
109*cdf0e10cSrcweir         for(int i = 0; i + 2 < p0.length; i += 3) {
110*cdf0e10cSrcweir             add((String)p0[i], (String)p0[i + 1], (String)p0[i + 2]);
111*cdf0e10cSrcweir         }
112*cdf0e10cSrcweir     }
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir     /**
115*cdf0e10cSrcweir      * Return all implemented types of this class.
116*cdf0e10cSrcweir      * @return All UNO types of this class.
117*cdf0e10cSrcweir      */
118*cdf0e10cSrcweir     public Type[] getTypes() {
119*cdf0e10cSrcweir         Class interfaces[] = getClass().getInterfaces();
120*cdf0e10cSrcweir         Class superInterfaces[] = getClass().getSuperclass().getInterfaces();
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir         Type types[] = new Type[interfaces.length + superInterfaces.length];
123*cdf0e10cSrcweir         int i = 0;
124*cdf0e10cSrcweir         for(; i < interfaces.length; ++ i)
125*cdf0e10cSrcweir             types[i] = new Type(interfaces[i]);
126*cdf0e10cSrcweir         for(; i < interfaces.length + superInterfaces.length; ++ i)
127*cdf0e10cSrcweir             types[i] = new Type(superInterfaces[i - interfaces.length]);
128*cdf0e10cSrcweir         return types;
129*cdf0e10cSrcweir     }
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir     /**
132*cdf0e10cSrcweir      * Get a unique id for this class
133*cdf0e10cSrcweir      * @return The id.
134*cdf0e10cSrcweir      */
135*cdf0e10cSrcweir     public byte[] getImplementationId() {
136*cdf0e10cSrcweir         return toString().getBytes();
137*cdf0e10cSrcweir     }
138*cdf0e10cSrcweir }
139