1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 package basicrunner.basichelper; 24 25 import com.sun.star.lang.XInitialization; 26 import com.sun.star.lang.XSingleServiceFactory; 27 import com.sun.star.lang.XServiceInfo; 28 import com.sun.star.uno.Type; 29 import com.sun.star.lang.XTypeProvider; 30 import util.XMLTools; 31 32 /** 33 * The class provides an implementation of the service 34 * <code>com.sun.star.xml.sax.XAttributeList</code>. 35 * @see com.sun.star.xml.sax.XAttributeList 36 * @see com.sun.star.lang.XServiceInfo 37 * @see com.sun.star.lang.XSingleServiceFactory 38 */ 39 public class AttributeList implements XServiceInfo, XSingleServiceFactory { 40 /** The service name of this class **/ 41 static final String __serviceName = "basichelper.AttributeList"; 42 43 /** 44 * Returns True, of the service is supported. 45 * @param name The service name. 46 * @return True, if the service is supported. 47 */ supportsService(String name)48 public boolean supportsService(String name) { 49 return __serviceName.equals(name); 50 } 51 52 /** 53 * Get all supported services. 54 * @return The supported services. 55 */ getSupportedServiceNames()56 public String[] getSupportedServiceNames() { 57 return new String[] {__serviceName}; 58 } 59 60 /** 61 * Ask for the implementation name. 62 * @return The implementation name. 63 */ getImplementationName()64 public String getImplementationName() { 65 return getClass().getName(); 66 } 67 68 /** 69 * Create an instance of the actual implementation of the AttributeList. 70 * Arguments are not supported, so they will bge ignored. 71 * @param args The arguments. 72 * @return A new instance of this class. 73 */ createInstanceWithArguments(Object[] args)74 public Object createInstanceWithArguments(Object[] args) { 75 return new AttributeListImpl(); 76 } 77 78 /** 79 * Create an instance of this class. 80 * @return A new instance of this class. 81 */ createInstance()82 public Object createInstance() { 83 return createInstanceWithArguments(null); 84 } 85 } 86 87 /** 88 * The actual implementation of the service 89 * <code>com.sun.star.xml.sax.XAttributeList</code>. 90 * Extends the class util.XMLTools.AttributeList. 91 * @see util.XMLTools.AttributeList 92 * @see com.sun.star.xml.sax.XAttributeList 93 * @see com.sun.star.lang.XTypeProvider 94 * @see com.sun.star.lang.XInitialization 95 */ 96 class AttributeListImpl extends XMLTools.AttributeList 97 implements XTypeProvider, XInitialization { 98 99 /** 100 * Initialize this class. 101 * @param p0 An array of XML attributes that are added to the list. 102 * @throws Exception Initialize failed. 103 */ initialize(Object[] p0)104 public void initialize(Object[] p0) throws com.sun.star.uno.Exception { 105 for(int i = 0; i + 2 < p0.length; i += 3) { 106 add((String)p0[i], (String)p0[i + 1], (String)p0[i + 2]); 107 } 108 } 109 110 /** 111 * Return all implemented types of this class. 112 * @return All UNO types of this class. 113 */ getTypes()114 public Type[] getTypes() { 115 Class interfaces[] = getClass().getInterfaces(); 116 Class superInterfaces[] = getClass().getSuperclass().getInterfaces(); 117 118 Type types[] = new Type[interfaces.length + superInterfaces.length]; 119 int i = 0; 120 for(; i < interfaces.length; ++ i) 121 types[i] = new Type(interfaces[i]); 122 for(; i < interfaces.length + superInterfaces.length; ++ i) 123 types[i] = new Type(superInterfaces[i - interfaces.length]); 124 return types; 125 } 126 127 /** 128 * Get a unique id for this class 129 * @return The id. 130 */ getImplementationId()131 public byte[] getImplementationId() { 132 return toString().getBytes(); 133 } 134 } 135