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