001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one
003     * or more contributor license agreements. See the NOTICE file
004     * distributed with this work for additional information
005     * regarding copyright ownership. The ASF licenses this file
006     * to you under the Apache License, Version 2.0 (the  "License");
007     * you may not use this file except in compliance with the License.
008     * You may obtain a copy of the License at
009     *
010     *     http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing, software
013     * distributed under the License is distributed on an "AS IS" BASIS,
014     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015     * See the License for the specific language governing permissions and
016     * limitations under the License.
017     */
018    /*
019     * $Id: UnparsedEntityUriCall.java 478670 2006-11-23 20:52:22Z minchau $
020     */
021    
022    package org.apache.xalan.xsltc.compiler;
023    
024    import java.util.Vector;
025    
026    import org.apache.bcel.generic.ConstantPoolGen;
027    import org.apache.bcel.generic.INVOKEINTERFACE;
028    import org.apache.bcel.generic.InstructionList;
029    import org.apache.xalan.xsltc.compiler.util.ClassGenerator;
030    import org.apache.xalan.xsltc.compiler.util.MethodGenerator;
031    import org.apache.xalan.xsltc.compiler.util.StringType;
032    import org.apache.xalan.xsltc.compiler.util.Type;
033    import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
034    
035    /**
036     * @author Jacek Ambroziak
037     * @author Santiago Pericas-Geertsen
038     * @author Morten Jorgensen
039     */
040    final class UnparsedEntityUriCall extends FunctionCall {
041        private Expression _entity;
042    
043        public UnparsedEntityUriCall(QName fname, Vector arguments) {
044            super(fname, arguments);
045            _entity = argument();
046        }
047    
048        public Type typeCheck(SymbolTable stable) throws TypeCheckError {
049            final Type entity = _entity.typeCheck(stable);
050            if (entity instanceof StringType == false) {
051                _entity = new CastExpr(_entity, Type.String);
052            }
053            return _type = Type.String;
054        }
055        
056        public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
057            final ConstantPoolGen cpg = classGen.getConstantPool();
058            final InstructionList il = methodGen.getInstructionList();
059            // Push the this pointer on the stack...
060            il.append(methodGen.loadDOM());
061            // ...then the entity name...
062            _entity.translate(classGen, methodGen);
063            // ...to get the URI from the DOM object.
064            il.append(new INVOKEINTERFACE(
065                             cpg.addInterfaceMethodref(DOM_INTF,
066                                                       GET_UNPARSED_ENTITY_URI,
067                                                       GET_UNPARSED_ENTITY_URI_SIG),
068                             2));
069        }
070    }