1 /*
   2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.internal.ws.processor.model.java;
  27 
  28 import com.sun.tools.internal.ws.processor.model.ModelException;
  29 import com.sun.tools.internal.ws.util.ClassNameInfo;
  30 
  31 import java.util.ArrayList;
  32 import java.util.Iterator;
  33 import java.util.List;
  34 
  35 /**
  36  *
  37  * @author WS Development Team
  38  */
  39 public class JavaInterface {
  40 
  41     public JavaInterface() {}
  42 
  43     public JavaInterface(String name) {
  44         this(name, null);
  45     }
  46 
  47     public JavaInterface(String name, String impl) {
  48         this.realName = name;
  49         this.name = name.replace('$', '.');
  50         this.impl = impl;
  51     }
  52 
  53     public String getName() {
  54         return name;
  55     }
  56 
  57     public String getFormalName() {
  58         return name;
  59     }
  60 
  61     public void setFormalName(String s) {
  62         name = s;
  63     }
  64 
  65     public String getRealName() {
  66         return realName;
  67     }
  68 
  69     public void setRealName(String s) {
  70         realName = s;
  71     }
  72 
  73     public String getImpl() {
  74         return impl;
  75     }
  76 
  77     public void setImpl(String s) {
  78         impl = s;
  79     }
  80 
  81     public Iterator getMethods() {
  82         return methods.iterator();
  83     }
  84 
  85     public boolean hasMethod(JavaMethod method) {
  86         for (int i=0; i<methods.size();i++) {
  87             if (method.equals(((JavaMethod)methods.get(i)))) {
  88                 return true;
  89             }
  90         }
  91         return false;
  92     }
  93 
  94     public void addMethod(JavaMethod method) {
  95 
  96         if (hasMethod(method)) {
  97             throw new ModelException("model.uniqueness");
  98         }
  99         methods.add(method);
 100     }
 101 
 102     /* serialization */
 103     public List getMethodsList() {
 104         return methods;
 105     }
 106 
 107     /* serialization */
 108     public void setMethodsList(List l) {
 109         methods = l;
 110     }
 111 
 112     public boolean hasInterface(String interfaceName) {
 113         for (int i=0; i<interfaces.size();i++) {
 114             if (interfaceName.equals((String)interfaces.get(i))) {
 115                 return true;
 116             }
 117         }
 118         return false;
 119     }
 120 
 121     public void addInterface(String interfaceName) {
 122 
 123         // verify that an exception with this name does not already exist
 124         if (hasInterface(interfaceName)) {
 125             return;
 126         }
 127         interfaces.add(interfaceName);
 128     }
 129 
 130     public Iterator getInterfaces() {
 131         return interfaces.iterator();
 132     }
 133 
 134     /* serialization */
 135     public List getInterfacesList() {
 136         return interfaces;
 137     }
 138 
 139     /* serialization */
 140     public void setInterfacesList(List l) {
 141         interfaces = l;
 142     }
 143 
 144     public String getSimpleName() {
 145         return ClassNameInfo.getName(name);
 146     }
 147 
 148     /* NOTE - all these fields (except "interfaces") were final, but had to
 149      * remove this modifier to enable serialization
 150      */
 151     private String javadoc;
 152 
 153     public String getJavaDoc() {
 154         return javadoc;
 155     }
 156 
 157     public void setJavaDoc(String javadoc) {
 158         this.javadoc = javadoc;
 159     }
 160 
 161     private String name;
 162     private String realName;
 163     private String impl;
 164     private List methods = new ArrayList();
 165     private List interfaces = new ArrayList();
 166 }