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