Example usage for java.lang Package getName

List of usage examples for java.lang Package getName

Introduction

In this page you can find the example usage for java.lang Package getName.

Prototype

public String getName() 

Source Link

Document

Return the name of this package.

Usage

From source file:de.uzk.hki.da.model.ObjectPremisXmlWriter.java

/**
 * Creates the package event element./*from ww w .  j  av  a 2  s  .c o m*/
 *
 * @param object the object
 * @param pkg the pkg
 * @param event the event
 * @throws XMLStreamException the XML stream exception
 * @author Daniel M. de Oliveira
 * @author Sebastian Cuy
 */
private void createPackageEventElement(Object object, Package pkg, Event event) throws XMLStreamException {

    logger.debug("Start serializing event /" + event.getIdType().toString() + "/" + event.getIdentifier());

    createOpenElement("event", 1);
    createOpenElement("eventIdentifier", 2);
    createTextElement("eventIdentifierType", event.getIdType().toString(), 3);
    createTextElement("eventIdentifierValue", event.getIdentifier(), 3);
    createCloseElement(2);
    createTextElement("eventType", event.getType().toString(), 2);
    if (event.getDate() != null)
        createTextElement("eventDateTime", formatDate(event.getDate()), 2);

    if (event.getDetail() != null)
        createTextElement("eventDetail", event.getDetail(), 2);

    if (event.getOutcome() != null) {
        createOpenElement("eventOutcomeInformation", 2);
        createTextElement("eventOutcome", event.getOutcome(), 3);
        createCloseElement(2);
    }

    createOpenElement("linkingAgentIdentifier", 2);

    Agent a = new Agent();
    a.setType(event.getAgent_type());
    a.setName(event.getAgent_name());
    agents.add(a);

    createTextElement("linkingAgentIdentifierType", a.getIdentifierType(), 3);
    createTextElement("linkingAgentIdentifierValue", a.getName(), 3);
    createCloseElement(2);

    createOpenElement("linkingObjectIdentifier", 2);
    createTextElement("linkingObjectIdentifierType", "PACKAGE_NAME", 3);
    createTextElement("linkingObjectIdentifierValue",
            object.getIdentifier() + ".pack_" + pkg.getName() + ".tar", 3);

    createCloseElement(2);

    createCloseElement(1);

    logger.trace("Serialized event " + event.getId());
}

From source file:org.apache.axis.wsdl.fromJava.Emitter.java

/**
 * Invoked prior to building a definition to ensure parms
 * and data are set up.//w  w  w.j  a v  a  2 s  .co m
 * 
 * @param mode 
 */
protected void init(int mode) {

    // Default use depending on setting of style
    if (use == null) {
        if (style == Style.RPC) {
            use = Use.ENCODED;
        } else {
            use = Use.LITERAL;
        }
    }

    if (tm == null) {
        String encodingStyle = "";
        if (use == Use.ENCODED) {
            encodingStyle = Constants.URI_SOAP11_ENC;
            /** TODO : Set this correctly if we do SOAP 1.2 support here */
        }
        tm = (TypeMapping) tmr.getTypeMapping(encodingStyle);
    }

    // Set up a ServiceDesc to use to introspect the Service
    if (serviceDesc == null) {
        JavaServiceDesc javaServiceDesc = new JavaServiceDesc();
        serviceDesc = javaServiceDesc;

        javaServiceDesc.setImplClass(cls);

        // Set the typeMapping to the one provided.
        serviceDesc.setTypeMapping(tm);

        javaServiceDesc.setStopClasses(stopClasses);
        serviceDesc.setAllowedMethods(allowedMethods);
        javaServiceDesc.setDisallowedMethods(disallowedMethods);
        serviceDesc.setStyle(style);
        serviceDesc.setUse(use);

        // If the class passed in is a portType,
        // there may be an implClass that is used to
        // obtain the method parameter names.  In this case,
        // a serviceDesc2 is built to get the method parameter names.
        if ((implCls != null) && (implCls != cls) && (serviceDesc2 == null)) {
            serviceDesc2 = new JavaServiceDesc();

            serviceDesc2.setImplClass(implCls);

            // Set the typeMapping to the one provided.
            serviceDesc2.setTypeMapping(tm);

            serviceDesc2.setStopClasses(stopClasses);
            serviceDesc2.setAllowedMethods(allowedMethods);
            serviceDesc2.setDisallowedMethods(disallowedMethods);
            serviceDesc2.setStyle(style);
        }
    }

    if (encodingList == null) {

        // if cls contains a Class object with the service implementation use the Name of the
        // class else use the service name
        if (cls != null) {
            clsName = cls.getName();
            clsName = clsName.substring(clsName.lastIndexOf('.') + 1);
        } else {
            clsName = getServiceDesc().getName();
        }

        // Default the portType name
        if (getPortTypeName() == null) {
            setPortTypeName(clsName);
        }

        // Default the serviceElementName
        if (getServiceElementName() == null) {
            setServiceElementName(getPortTypeName() + "Service");
        }

        // If service port name is null, construct it from location or className
        if (getServicePortName() == null) {
            String name = getLocationUrl();

            if (name != null) {
                if (name.lastIndexOf('/') > 0) {
                    name = name.substring(name.lastIndexOf('/') + 1);
                } else if (name.lastIndexOf('\\') > 0) {
                    name = name.substring(name.lastIndexOf('\\') + 1);
                } else {
                    name = null;
                }

                // if we got the name from the location, strip .jws from it
                if ((name != null) && name.endsWith(".jws")) {
                    name = name.substring(0, (name.length() - ".jws".length()));
                }
            }

            if ((name == null) || name.equals("")) {
                name = clsName;
            }

            setServicePortName(name);
        }

        // Default the bindingName
        if (getBindingName() == null) {
            setBindingName(getServicePortName() + "SoapBinding");
        }

        encodingList = new ArrayList();

        encodingList.add(Constants.URI_DEFAULT_SOAP_ENC);

        if (intfNS == null) {
            Package pkg = cls.getPackage();

            intfNS = namespaces.getCreate((pkg == null) ? null : pkg.getName());
        }

        // Default the implementation namespace to the interface
        // namespace if not split wsdl mode.
        if (implNS == null) {
            if (mode == MODE_ALL) {
                implNS = intfNS;
            } else {
                implNS = intfNS + "-impl";
            }
        }

        // set the namespaces in the serviceDesc(s)
        serviceDesc.setDefaultNamespace(intfNS);

        if (serviceDesc2 != null) {
            serviceDesc2.setDefaultNamespace(implNS);
        }

        if (cls != null) {
            String clsName = cls.getName();
            int idx = clsName.lastIndexOf(".");
            if (idx > 0) {
                String pkgName = clsName.substring(0, idx);
                namespaces.put(pkgName, intfNS, "intf");
            }
        }

        namespaces.putPrefix(implNS, "impl");
    }
}

From source file:org.codehaus.enunciate.modules.xfire.EnunciatedJAXWSOperationBinding.java

/**
 * Loads the set of input properties for the specified operation.
 *
 * @param op The operation.//from  ww w  .  jav  a  2  s  .co m
 * @return The input properties, or null if none were found.
 */
protected OperationBeanInfo getRequestInfo(OperationInfo op) throws XFireFault {
    Method method = op.getMethod();
    Class ei = method.getDeclaringClass();
    Package pckg = ei.getPackage();
    SOAPBinding.ParameterStyle paramStyle = SOAPBinding.ParameterStyle.WRAPPED;
    if (method.isAnnotationPresent(SOAPBinding.class)) {
        SOAPBinding annotation = method.getAnnotation(SOAPBinding.class);
        paramStyle = annotation.parameterStyle();
    } else if (ei.isAnnotationPresent(SOAPBinding.class)) {
        SOAPBinding annotation = ((SOAPBinding) ei.getAnnotation(SOAPBinding.class));
        paramStyle = annotation.parameterStyle();
    }

    boolean schemaValidate = method.isAnnotationPresent(SchemaValidate.class)
            || ei.isAnnotationPresent(SchemaValidate.class) || pckg.isAnnotationPresent(SchemaValidate.class);

    if (paramStyle == SOAPBinding.ParameterStyle.BARE) {
        //return a bare operation info.
        //it's not necessarily the first parameter type! there could be a header or OUT parameter...
        int paramIndex;
        WebParam annotation = null;
        Annotation[][] parameterAnnotations = method.getParameterAnnotations();
        if (parameterAnnotations.length == 0) {
            throw new IllegalStateException("A BARE web service must have input parameters.");
        }

        PARAM_ANNOTATIONS: for (paramIndex = 0; paramIndex < parameterAnnotations.length; paramIndex++) {
            Annotation[] annotations = parameterAnnotations[paramIndex];
            for (Annotation candidate : annotations) {
                if (candidate instanceof WebParam && !((WebParam) candidate).header()) {
                    WebParam.Mode mode = ((WebParam) candidate).mode();
                    switch (mode) {
                    case OUT:
                    case INOUT:
                        annotation = (WebParam) candidate;
                        break PARAM_ANNOTATIONS;
                    }
                }
            }
        }

        if (annotation == null) {
            paramIndex = 0;
        }

        return new OperationBeanInfo(method.getParameterTypes()[paramIndex], null, op.getInputMessage(),
                schemaValidate);
    } else {
        String requestWrapperClassName;
        RequestWrapper requestWrapperInfo = method.getAnnotation(RequestWrapper.class);
        if ((requestWrapperInfo != null) && (requestWrapperInfo.className() != null)
                && (requestWrapperInfo.className().length() > 0)) {
            requestWrapperClassName = requestWrapperInfo.className();
        } else {
            StringBuilder builder = new StringBuilder(pckg == null ? "" : pckg.getName());
            if (builder.length() > 0) {
                builder.append(".");
            }

            builder.append("jaxws.");

            String methodName = method.getName();
            builder.append(capitalize(methodName));
            requestWrapperClassName = builder.toString();
        }

        Class wrapperClass;
        try {
            wrapperClass = ClassLoaderUtils.loadClass(requestWrapperClassName, getClass());
        } catch (ClassNotFoundException e) {
            LOG.error("Unabled to find request wrapper class " + requestWrapperClassName + "... Operation "
                    + op.getQName() + " will not be able to recieve...");
            return null;
        }

        return new OperationBeanInfo(wrapperClass, loadOrderedProperties(wrapperClass), op.getInputMessage(),
                schemaValidate);
    }

}

From source file:de.uzk.hki.da.model.ObjectPremisXmlWriter.java

/**
 * Creates the file element./* ww  w.jav a2  s. c  om*/
 *
 * @param f the f
 * @param object the object
 * @throws XMLStreamException the xML stream exception
 * @author Daniel M. de Oliveira
 * @author Thomas Kleinke
 * @throws FileNotFoundException 
 */
private void createFileElement(DAFile f, Object object, Package pkg)
        throws XMLStreamException, FileNotFoundException {

    logger.debug("Start serializing file \"" + f.toString() + "\" as object element to PREMIS");

    createOpenElement("object", 1);
    createAttribute(C.XSI_NS, "type", "file");
    createOpenElement("objectIdentifier", 2);
    createTextElement("objectIdentifierType", "FILE_PATH", 3);
    createTextElement("objectIdentifierValue", f.getRep_name() + "/" + f.getRelative_path(), 3);
    createCloseElement(2);

    createOpenElement("objectCharacteristics", 2);
    createTextElement("compositionLevel", "0", 3);

    createOpenElement("fixity", 3);
    createTextElement("messageDigestAlgorithm", "MD5", 4);
    createTextElement("messageDigest", f.getChksum(), 4);
    createTextElement("messageDigestOriginator", "ContentBroker", 4);

    createCloseElement(3);
    createTextElement("size", f.getSize(), 3);

    createOpenElement("format", 3);
    createOpenElement("formatRegistry", 4);
    createTextElement("formatRegistryName", "PRONOM", 5);
    createTextElement("formatRegistryKey", f.getFormatPUID(), 5);
    createTextElement("formatRegistryRole", "specification", 5);
    createCloseElement(4);
    createCloseElement(3);

    if (f.getRelative_path().toLowerCase().equals("premis.xml")
            || !f.getRelative_path().toLowerCase().endsWith(".xml")) {
        createOpenElement("objectCharacteristicsExtension", 3);
        createOpenElement("mdSec", 4);
        createAttribute("ID", "_" + jhoveMDSecIdCounter);
        jhoveMDSecIdCounter++;
        createOpenElement("mdWrap", 5);
        createAttribute("MDTYPE", "OTHER");
        createAttribute("OTHERMDTYPE", "JHOVE");
        createOpenElement("xmlData", 6);
        integrateJhoveData(
                Path.make(jhoveDataPath, f.getRep_name(), DigestUtils.md5Hex(f.getRelative_path())).toString(),
                7);
        createCloseElement(6);
        createCloseElement(5);
        createCloseElement(4);
        createCloseElement(3);
    }

    createCloseElement(2);// close objectCharacteristics

    String originalName = null;
    for (Event e : pkg.getEvents()) {
        if (e.getType().toUpperCase().equals(C.EVENT_TYPE_CONVERT)
                && e.getTarget_file().getRelative_path().equals(f.getRelative_path()))
            originalName = FilenameUtils.getName(e.getSource_file().getRelative_path());
    }

    if (originalName == null)
        originalName = FilenameUtils.getName(f.getRelative_path());

    createTextElement("originalName", originalName, 2);

    createOpenElement("storage", 2);
    createOpenElement("contentLocation", 3);
    createTextElement("contentLocationType", "FILE_PATH", 4);
    createTextElement("contentLocationValue", f.getRep_name() + "/" + f.getRelative_path(), 4);
    createCloseElement(3);
    createCloseElement(2);

    createOpenElement("relationship", 2);
    createTextElement("relationshipType", "structural", 3);
    createTextElement("relationshipSubType", "is included in", 3);
    createOpenElement("relatedObjectIdentification", 3);
    createTextElement("relatedObjectIdentifierType", "PACKAGE_NAME", 4);
    createTextElement("relatedObjectIdentifierValue",
            object.getIdentifier() + ".pack_" + pkg.getName() + ".tar", 4);
    createCloseElement(3);
    createCloseElement(2);

    createCloseElement(1);
}

From source file:lu.fisch.unimozer.Diagram.java

private void saveBlueJPackages() throws FileNotFoundException, UnsupportedEncodingException, IOException {
    if (directoryName != null) {
        String base = directoryName + System.getProperty("file.separator") + "src";
        for (Package pack : packages.values()) {
            String filename = base + System.getProperty("file.separator") + Unimozer.B_PACKAGENAME;
            if (!pack.getName().equals("<default>")) {
                filename = base + System.getProperty("file.separator")
                        + pack.getName().replace('.', System.getProperty("file.separator").charAt(0))
                        + System.getProperty("file.separator") + Unimozer.B_PACKAGENAME;
            }/*from w  ww .  ja  v a 2s  . co m*/
            StringList content = getBlueJSaveContent(pack);

            // #PackBo
            if ((new File(base + System.getProperty("file.separator")
                    + pack.getName().replace('.', System.getProperty("file.separator").charAt(0)))).exists())
                content.saveToFile(filename);
        }
    }
}

From source file:lu.fisch.unimozer.Diagram.java

public void cleanUp(String dirname) {
    if (dirname != null) {
        if (!dirname.endsWith(System.getProperty("file.separator"))) {
            dirname += System.getProperty("file.separator");
        }/*from   w  ww  . j  ava 2s.com*/

        // delete all "class" and "ctxt" files (BlueJ)
        // delete all BlueJ package files
        // delete .java files in the root
        /*File path = new File(dirname);
        if(path.exists())
        {
        File[] files = path.listFiles();
        for(int i=0; i<files.length; i++)
        {
            if(
                files[i].getName().endsWith(".class")
                ||
                files[i].getName().endsWith(".ctxt")
                ||
                files[i].getName().endsWith(".java")
                ||
                files[i].getName().equals("package.bluej")
                ||
                files[i].getName().equals("bluej.pkg")
            )
            {
                files[i].delete();
            }
        }
        }*/
        cleanUpSub(dirname);

        // delete packages from the root
        for (Package pack : packages.values()) {
            File f = new File(dirname + System.getProperty("file.separator")
                    + pack.getName().replace('.', System.getProperty("file.separator").charAt(0)));
            if (f.exists()) {
                try {
                    deleteDirectory(f);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }

    }
}

From source file:lu.fisch.unimozer.Diagram.java

@Override
public void paint(Graphics graphics) {
    super.paint(graphics);
    Graphics2D g = (Graphics2D) graphics;
    // set anti-aliasing rendering
    ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g.setFont(new Font(g.getFont().getFontName(), Font.PLAIN, Unimozer.DRAW_FONT_SIZE));

    // clear background
    g.setColor(Color.WHITE);// w w  w .  j  a  v a2s . co  m
    g.fillRect(0, 0, getWidth() + 1, getHeight() + 1);
    g.setColor(Color.BLACK);

    /*Set<String> set;
    Iterator<String> itr;
    // draw classes a first time
    for(MyClass clas : classes.values())
    {
      clas.setEnabled(this.isEnabled());
      clas.draw(graphics,showFields,showMethods);
    }*/

    /* let's try this one ... */
    for (Entry<String, MyClass> entry : classes.entrySet()) {
        // get the actual class ...
        MyClass clas = entry.getValue();
        clas.setEnabled(this.isEnabled());
        clas.draw(graphics, showFields, showMethods);
    }

    // draw packages
    packages.clear();
    for (MyClass myClass : classes.values()) {
        if (myClass.isDisplayUML()) {
            Package myPackage = null;
            if (!packages.containsKey(myClass.getPackagename())) {
                myPackage = new Package(myClass.getPackagename(), myClass.getPosition().y,
                        myClass.getPosition().x, myClass.getWidth(), myClass.getHeight());
                packages.put(myPackage.getName(), myPackage);
            } else
                myPackage = packages.get(myClass.getPackagename());

            if (myClass.getPosition().x + myClass.getWidth() > myPackage.getRight())
                myPackage.setRight(myClass.getPosition().x + myClass.getWidth());
            if (myClass.getPosition().y + myClass.getHeight() > myPackage.getBottom())
                myPackage.setBottom(myClass.getPosition().y + myClass.getHeight());

            if (myClass.getPosition().x < myPackage.getLeft())
                myPackage.setLeft(myClass.getPosition().x);
            if (myClass.getPosition().y < myPackage.getTop())
                myPackage.setTop(myClass.getPosition().y);
        }
    }

    // draw classes
    /*
    set = classes.keySet();
    itr = set.iterator();
    while (itr.hasNext())
    {
      String str = itr.next();
      classes.get(str).draw(graphics);
    }/**/

    mostRight = 0;
    mostBottom = 0;

    // ??
    /*
    set = classes.keySet();
    itr = set.iterator();
    while (itr.hasNext())
    {
      String str = itr.next();
      MyClass thisClass = classes.get(str);
    }
    */

    // init topLeft & bottomRight
    topLeft = new Point(this.getWidth(), this.getHeight());
    bottomRight = new Point(0, 0);

    // draw packages
    if (packages.size() > 0)
        if ((packages.size() == 1 && packages.get(Package.DEFAULT) == null) || packages.size() > 1)
            for (Package pack : packages.values()) {
                pack.draw(graphics);
                // push outer box
                if (pack.getTopAbs() < topLeft.y)
                    topLeft.y = pack.getTopAbs();
                if (pack.getLeftAbs() < topLeft.x)
                    topLeft.x = pack.getLeftAbs();
                if (pack.getBottomAbs() > bottomRight.y)
                    bottomRight.y = pack.getBottomAbs();
                if (pack.getRightAbs() > bottomRight.x)
                    bottomRight.x = pack.getRightAbs();
            }

    // draw implmementations
    if (isShowHeritage()) {
        Stroke oldStroke = g.getStroke();
        g.setStroke(dashed);

        /*itr = set.iterator();
        while (itr.hasNext())
        {
          String str = itr.next();
        */

        /* let's try this one ... */
        for (Entry<String, MyClass> entry : classes.entrySet()) {
            // get the actual class ...
            String str = entry.getKey();

            MyClass thisClass = classes.get(str);

            if (thisClass.getPosition().x + thisClass.getWidth() > mostRight)
                mostRight = thisClass.getPosition().x + thisClass.getWidth();
            if (thisClass.getPosition().y + thisClass.getHeight() > mostBottom)
                mostBottom = thisClass.getPosition().y + thisClass.getHeight();

            if (thisClass.getImplements().size() > 0)
                for (String extendsClass : thisClass.getImplements()) {
                    MyClass otherClass = classes.get(extendsClass);
                    if (otherClass == null)
                        otherClass = findByShortName(extendsClass);
                    //if(otherClass==null) System.err.println(extendsClass+" not found (1)");
                    //if (otherClass==null) otherClass=findByShortName(extendsClass);
                    //if(otherClass==null) System.err.println(extendsClass+" not found (2)");
                    if (otherClass != null && thisClass.isDisplayUML() && otherClass.isDisplayUML()) {
                        thisClass.setExtendsMyClass(otherClass);
                        // draw arrow from thisClass to otherClass

                        // get the center point of each class
                        Point fromP = new Point(thisClass.getPosition().x + thisClass.getWidth() / 2,
                                thisClass.getPosition().y + thisClass.getHeight() / 2);
                        Point toP = new Point(otherClass.getPosition().x + otherClass.getWidth() / 2,
                                otherClass.getPosition().y + otherClass.getHeight() / 2);

                        // get the corner 4 points of the desstination class
                        // (outer margin = 4)
                        Point toP1 = new Point(otherClass.getPosition().x - 4, otherClass.getPosition().y - 4);
                        Point toP2 = new Point(otherClass.getPosition().x + otherClass.getWidth() + 4,
                                otherClass.getPosition().y - 4);
                        Point toP3 = new Point(otherClass.getPosition().x + otherClass.getWidth() + 4,
                                otherClass.getPosition().y + otherClass.getHeight() + 4);
                        Point toP4 = new Point(otherClass.getPosition().x - 4,
                                otherClass.getPosition().y + otherClass.getHeight() + 4);

                        // get the intersection with the center line an one of the
                        // sedis of the destination class
                        Point2D toDraw = getIntersection(fromP, toP, toP1, toP2);
                        if (toDraw == null)
                            toDraw = getIntersection(fromP, toP, toP2, toP3);
                        if (toDraw == null)
                            toDraw = getIntersection(fromP, toP, toP3, toP4);
                        if (toDraw == null)
                            toDraw = getIntersection(fromP, toP, toP4, toP1);

                        // draw the arrowed line
                        if (toDraw != null)
                            drawExtends(g, fromP, new Point((int) toDraw.getX(), (int) toDraw.getY()));

                    }
                }

        }
        g.setStroke(oldStroke);
    }

    // draw inheritance
    if (isShowHeritage()) {
        /*itr = set.iterator();
        while (itr.hasNext())
        {
          String str = itr.next();
        */

        /* let's try this one ... */
        for (Entry<String, MyClass> entry : classes.entrySet()) {
            // get the actual class ...
            String str = entry.getKey();

            MyClass thisClass = classes.get(str);

            if (thisClass.getPosition().x + thisClass.getWidth() > mostRight)
                mostRight = thisClass.getPosition().x + thisClass.getWidth();
            if (thisClass.getPosition().y + thisClass.getHeight() > mostBottom)
                mostBottom = thisClass.getPosition().y + thisClass.getHeight();

            String extendsClass = thisClass.getExtendsClass();
            //System.out.println(thisClass.getFullName()+" extends "+extendsClass);
            if (!extendsClass.equals("") && thisClass.isDisplayUML()) {
                MyClass otherClass = classes.get(extendsClass);
                if (otherClass == null)
                    otherClass = findByShortName(extendsClass);
                //if(otherClass==null) System.err.println(extendsClass+" not found (1)");
                //if (otherClass==null) otherClass=findByShortName(extendsClass);
                //if(otherClass==null) System.err.println(extendsClass+" not found (2)");
                if (otherClass != null) {
                    if (otherClass != thisClass) {
                        thisClass.setExtendsMyClass(otherClass);
                        // draw arrow from thisClass to otherClass

                        // get the center point of each class
                        Point fromP = new Point(thisClass.getPosition().x + thisClass.getWidth() / 2,
                                thisClass.getPosition().y + thisClass.getHeight() / 2);
                        Point toP = new Point(otherClass.getPosition().x + otherClass.getWidth() / 2,
                                otherClass.getPosition().y + otherClass.getHeight() / 2);

                        // get the corner 4 points of the desstination class
                        // (outer margin = 4)
                        Point toP1 = new Point(otherClass.getPosition().x - 4, otherClass.getPosition().y - 4);
                        Point toP2 = new Point(otherClass.getPosition().x + otherClass.getWidth() + 4,
                                otherClass.getPosition().y - 4);
                        Point toP3 = new Point(otherClass.getPosition().x + otherClass.getWidth() + 4,
                                otherClass.getPosition().y + otherClass.getHeight() + 4);
                        Point toP4 = new Point(otherClass.getPosition().x - 4,
                                otherClass.getPosition().y + otherClass.getHeight() + 4);

                        // get the intersection with the center line an one of the
                        // sedis of the destination class
                        Point2D toDraw = getIntersection(fromP, toP, toP1, toP2);
                        if (toDraw == null)
                            toDraw = getIntersection(fromP, toP, toP2, toP3);
                        if (toDraw == null)
                            toDraw = getIntersection(fromP, toP, toP3, toP4);
                        if (toDraw == null)
                            toDraw = getIntersection(fromP, toP, toP4, toP1);

                        // draw in red if there is a cclic inheritance problem
                        if (thisClass.hasCyclicInheritance()) {
                            ((Graphics2D) graphics).setStroke(new BasicStroke(2));
                            graphics.setColor(Color.RED);
                        }

                        // draw the arrowed line
                        if (toDraw != null)
                            drawExtends((Graphics2D) graphics, fromP,
                                    new Point((int) toDraw.getX(), (int) toDraw.getY()));

                    } else {
                        ((Graphics2D) graphics).setStroke(new BasicStroke(2));
                        graphics.setColor(Color.RED);

                        // line
                        graphics.drawLine(thisClass.getPosition().x + thisClass.getWidth() / 2,
                                thisClass.getPosition().y, thisClass.getPosition().x + thisClass.getWidth() / 2,
                                thisClass.getPosition().y - 32);
                        graphics.drawLine(thisClass.getPosition().x + thisClass.getWidth() / 2,
                                thisClass.getPosition().y - 32,
                                thisClass.getPosition().x + thisClass.getWidth() + 32,
                                thisClass.getPosition().y - 32);
                        graphics.drawLine(thisClass.getPosition().x + thisClass.getWidth() + 32,
                                thisClass.getPosition().y - 32,
                                thisClass.getPosition().x + thisClass.getWidth() + 32,
                                thisClass.getPosition().y + thisClass.getHeight() + 32);
                        graphics.drawLine(thisClass.getPosition().x + thisClass.getWidth() + 32,
                                thisClass.getPosition().y + thisClass.getHeight() + 32,
                                thisClass.getPosition().x + thisClass.getWidth() / 2,
                                thisClass.getPosition().y + thisClass.getHeight() + 32);
                        drawExtends((Graphics2D) graphics,
                                new Point(thisClass.getPosition().x + thisClass.getWidth() / 2,
                                        thisClass.getPosition().y + thisClass.getHeight() + 32),
                                new Point(thisClass.getPosition().x + thisClass.getWidth() / 2,
                                        thisClass.getPosition().y + thisClass.getHeight()));
                    }

                    // reset the stroke and the color
                    ((Graphics2D) graphics).setStroke(new BasicStroke(1));
                    graphics.setColor(Color.BLACK);
                }
            }
        }
    }

    // setup a hastable to store the relations
    //Hashtable<String,StringList> classUsage = new Hashtable<String,StringList>();

    // store compositions
    Hashtable<MyClass, Vector<MyClass>> classCompositions = new Hashtable<MyClass, Vector<MyClass>>();
    // store aggregations
    Hashtable<MyClass, Vector<MyClass>> classAggregations = new Hashtable<MyClass, Vector<MyClass>>();
    // store all relations
    Hashtable<MyClass, Vector<MyClass>> classUsings = new Hashtable<MyClass, Vector<MyClass>>();

    /*
    // iterate through all classes to find compositions
    itr = set.iterator();
    while (itr.hasNext())
    {
      // get the actual classname
      String str = itr.next();
    */

    /* let's try this one ... */
    for (Entry<String, MyClass> entry : classes.entrySet()) {
        // get the actual class ...
        String str = entry.getKey();

        // get the corresponding "MyClass" object
        MyClass thisClass = classes.get(str);
        // setup a list to store the relations with this class
        Vector<MyClass> theseCompositions = new Vector<MyClass>();

        // get all fields of this class
        StringList uses = thisClass.getFieldTypes();
        for (int u = 0; u < uses.count(); u++) {
            // try to find the other (used) class
            MyClass otherClass = classes.get(uses.get(u));
            if (otherClass == null)
                otherClass = findByShortName(uses.get(u));
            if (otherClass != null) // means this class uses the other ones
            {
                // add the other class to the list
                theseCompositions.add(otherClass);
            }
        }

        // add the list of used classes to the MyClass object
        thisClass.setUsesMyClass(theseCompositions);
        // store the composition in the general list
        classCompositions.put(thisClass, theseCompositions);
        // store the compositions int eh global relation list
        classUsings.put(thisClass, new Vector<MyClass>(theseCompositions));
        //                        ^^^^^^^^^^^^^^^^^^^^
        //    important !! => create a new vector, otherwise the list
        //                    are the same ...
    }

    /*
    // iterate through all classes to find aggregations
    itr = set.iterator();
    while (itr.hasNext())
    {
      // get the actual class
      String str = itr.next();
    */

    /* let's try this one ... */
    for (Entry<String, MyClass> entry : classes.entrySet()) {
        // get the actual class ...
        String str = entry.getKey();

        // get the corresponding "MyClass" object
        MyClass thisClass = classes.get(str);
        // we need a list to store the aggragations with this class
        Vector<MyClass> theseAggregations = new Vector<MyClass>();
        // try to get the list of compositions for this class
        // init if not present
        Vector<MyClass> theseCompositions = classCompositions.get(thisClass);
        if (theseCompositions == null)
            theseCompositions = new Vector<MyClass>();
        // try to get the list of all relations for this class
        // init if not present
        Vector<MyClass> theseClasses = classUsings.get(thisClass);
        if (theseClasses == null)
            theseClasses = new Vector<MyClass>();

        // get the names of the classes that thisclass uses
        StringList foundUsage = thisClass.getUsesWho();
        // go through the list an check to find a corresponding MyClass
        for (int f = 0; f < foundUsage.count(); f++) {
            // get the name of the used class
            String usedClass = foundUsage.get(f);

            MyClass otherClass = classes.get(usedClass);
            if (otherClass == null)
                otherClass = findByShortName(usedClass);
            if (otherClass != null && thisClass != otherClass)
            // meanint "otherClass" is a class used by thisClass
            {
                if (!theseCompositions.contains(otherClass))
                    theseAggregations.add(otherClass);
                if (!theseClasses.contains(otherClass))
                    theseClasses.add(otherClass);
            }
        }

        // get all method types of this class
        StringList uses = thisClass.getMethodTypes();
        for (int u = 0; u < uses.count(); u++) {
            // try to find the other (used) class
            MyClass otherClass = classes.get(uses.get(u));
            if (otherClass == null)
                otherClass = findByShortName(uses.get(u));
            if (otherClass != null) // means this class uses the other ones
            {
                // add the other class to the list
                theseAggregations.add(otherClass);
            }
        }

        // store the relations to the class
        thisClass.setUsesMyClass(theseClasses);
        // store the aggregation to the global list
        classAggregations.put(thisClass, theseAggregations);
        // store all relations to the global list
        classUsings.put(thisClass, theseClasses);
    }

    if (isShowComposition()) {
        /*Set<MyClass> set2 = classCompositions.keySet();
        Iterator<MyClass> itr2 = set2.iterator();
        while (itr2.hasNext())
        {
          MyClass thisClass = itr2.next();
        */

        /* let's try this one ... */
        for (Entry<MyClass, Vector<MyClass>> entry : classCompositions.entrySet()) {
            // get the actual class ...
            MyClass thisClass = entry.getKey();
            if (thisClass.isDisplayUML()) {
                Vector<MyClass> otherClasses = classCompositions.get(thisClass);
                for (MyClass otherClass : otherClasses)
                    drawComposition(g, thisClass, otherClass, classUsings);
            }
        }
    }

    if (isShowAggregation()) {
        /*Set<MyClass> set2 = classAggregations.keySet();
        Iterator<MyClass> itr2 = set2.iterator();
        while (itr2.hasNext())
        {
          MyClass thisClass = itr2.next();
        */

        /* let's try this one ... */
        for (Entry<MyClass, Vector<MyClass>> entry : classAggregations.entrySet()) {
            // get the actual class ...
            MyClass thisClass = entry.getKey();
            if (thisClass.isDisplayUML()) {
                Vector<MyClass> otherClasses = classAggregations.get(thisClass);
                for (MyClass otherClass : otherClasses)
                    drawAggregation(g, thisClass, otherClass, classUsings);
            }
        }
    }

    // draw classes again to put them on top
    // of the arrows
    /*set = classes.keySet();
    itr = set.iterator();
    while (itr.hasNext())
    {
      String str = itr.next();
    */

    /* let's try this one ... */
    for (Entry<String, MyClass> entry : classes.entrySet()) {
        // get the actual class ...
        String str = entry.getKey();

        classes.get(str).setEnabled(this.isEnabled());
        classes.get(str).draw(graphics, showFields, showMethods);

        // push outer box
        MyClass thisClass = classes.get(str);
        if (thisClass.getPosition().y < topLeft.y)
            topLeft.y = thisClass.getPosition().y;
        if (thisClass.getPosition().x < topLeft.x)
            topLeft.x = thisClass.getPosition().x;
        if (thisClass.getPosition().y + thisClass.getHeight() > bottomRight.y)
            bottomRight.y = thisClass.getPosition().y + thisClass.getHeight();
        if (thisClass.getPosition().x + thisClass.getWidth() > bottomRight.x)
            bottomRight.x = thisClass.getPosition().x + thisClass.getWidth();

    }

    // comments
    if (commentString != null) {
        String fontName = g.getFont().getName();
        g.setFont(new Font("Courier", g.getFont().getStyle(), Unimozer.DRAW_FONT_SIZE));

        if (!commentString.trim().equals("")) {
            String myCommentString = new String(commentString);
            Point myCommentPoint = new Point(commentPoint);
            //System.out.println(myCommentString);

            // adjust comment
            myCommentString = myCommentString.trim();
            // adjust position
            myCommentPoint.y = myCommentPoint.y + 16;

            // explode comment
            StringList sl = StringList.explode(myCommentString, "\n");
            // calculate totals
            int totalHeight = 0;
            int totalWidth = 0;
            for (int i = 0; i < sl.count(); i++) {
                String line = sl.get(i).trim();
                int h = (int) g.getFont().getStringBounds(line, g.getFontRenderContext()).getHeight();
                int w = (int) g.getFont().getStringBounds(line, g.getFontRenderContext()).getWidth();
                totalHeight += h;
                totalWidth = Math.max(totalWidth, w);
            }

            // get comment size
            // draw background
            g.setColor(new Color(255, 255, 128, 255));
            g.fillRoundRect(myCommentPoint.x, myCommentPoint.y, totalWidth + 8, totalHeight + 8, 4, 4);
            // draw border
            g.setColor(Color.BLACK);
            g.drawRoundRect(myCommentPoint.x, myCommentPoint.y, totalWidth + 8, totalHeight + 8, 4, 4);

            // draw text
            totalHeight = 0;
            for (int i = 0; i < sl.count(); i++) {
                String line = sl.get(i).trim();
                int h = (int) g.getFont().getStringBounds(myCommentString, g.getFontRenderContext())
                        .getHeight();
                g.drawString(line, myCommentPoint.x + 4, myCommentPoint.y + h + 2 + totalHeight);
                totalHeight += h;
            }

        }

        g.setFont(new Font(fontName, Font.PLAIN, Unimozer.DRAW_FONT_SIZE));

    }

    /*
    if(!isEnabled())
    {
        g.setColor(new Color(128,128,128,128));
        g.fillRect(0,0,getWidth(),getHeight());
            
    }
    */

    this.setPreferredSize(new Dimension(mostRight + 32, mostBottom + 32));
    // THE NEXT LINE MAKES ALL DIALOGUES DISAPEAR!!
    //this.setSize(mostRight+32, mostBottom+32);
    this.validate();
    ((JScrollPane) this.getParent().getParent()).revalidate();

    if (mode == MODE_EXTENDS && extendsFrom != null && extendsDragPoint != null) {
        graphics.setColor(Color.BLUE);
        ((Graphics2D) graphics).setStroke(new BasicStroke(2));
        drawExtends(g, new Point(extendsFrom.getPosition().x + extendsFrom.getWidth() / 2,
                extendsFrom.getPosition().y + extendsFrom.getHeight() / 2), extendsDragPoint);
        graphics.setColor(Color.BLACK);
        ((Graphics2D) graphics).setStroke(new BasicStroke(1));
    }
}

From source file:lu.fisch.unimozer.Diagram.java

private StringList getBlueJSaveContent(Package pack) {
    StringList content = new StringList();
    content.add("#BlueJ package file");

    // dependency
    int dependencyCounter = 0;
    // composition

    Hashtable<String, StringList> classUsage = new Hashtable<String, StringList>();

    /*        Set<String> set = classes.keySet();
            Iterator<String> itr = set.iterator();
            while (itr.hasNext())// ww  w . j a  va 2  s  .  c  om
            {
              String str = itr.next();
    */

    /* let's try this one ... */
    for (Entry<String, MyClass> entry : classes.entrySet()) {
        // get the actual class ...
        String str = entry.getKey();

        MyClass thisClass = classes.get(str);
        Vector<MyClass> useWho = new Vector<MyClass>();
        StringList usesClassNames = new StringList();

        StringList uses = thisClass.getFieldTypes();
        for (int u = 0; u < uses.count(); u++) {
            MyClass otherClass = classes.get(uses.get(u));
            if (otherClass != null) // means this class uses the other ones
            {
                useWho.add(otherClass);
                usesClassNames.add(otherClass.getShortName());

                dependencyCounter++;
                content.add("dependency" + dependencyCounter + ".from=" + thisClass.getShortName());
                content.add("dependency" + dependencyCounter + ".to=" + otherClass.getShortName());
                content.add("dependency" + dependencyCounter + ".type=UsesDependency");
            }
        }
        thisClass.setUsesMyClass(useWho);
        classUsage.put(thisClass.getShortName(), usesClassNames);
    }
    // usage

    /*itr = set.iterator();
    while (itr.hasNext())
    {
      String str = itr.next();*/

    /* let's try this one ... */
    for (Entry<String, MyClass> entry : classes.entrySet()) {
        // get the actual class ...
        String str = entry.getKey();

        MyClass thisClass = classes.get(str);
        Vector<MyClass> useWho = new Vector<MyClass>();
        useWho.addAll(thisClass.getUsesMyClass());
        StringList usesClassNames = classUsage.get(thisClass.getShortName());

        StringList foundUsage = thisClass.getUsesWho();
        for (int f = 0; f < foundUsage.count(); f++) {
            String usage = foundUsage.get(f);
            if (!usesClassNames.contains(usage)) {
                MyClass otherClass = getClass(usage);
                if (otherClass != null) // menange "otherClass" is a class used by thisClass
                {
                    useWho.add(otherClass);

                    dependencyCounter++;
                    content.add("dependency" + dependencyCounter + ".from=" + thisClass.getShortName());
                    content.add("dependency" + dependencyCounter + ".to=" + otherClass.getShortName());
                    content.add("dependency" + dependencyCounter + ".type=UsesDependency");
                }
            }
        }
        thisClass.setUsesMyClass(useWho);
    }
    /**/

    content.add("package.editor.height=900");
    content.add("package.editor.width=700");
    content.add("package.editor.x=0");
    content.add("package.editor.y=0");
    content.add("package.numDependencies=" + dependencyCounter);
    content.add("package.showExtends=true");
    content.add("package.showUses=true");

    int count = 0;

    /* itr = set.iterator();
    while (itr.hasNext())
    {
        String str = itr.next();*/

    /* let's try this one ... */
    for (Entry<String, MyClass> entry : classes.entrySet()) {
        // get the actual class ...
        String str = entry.getKey();

        MyClass thisClass = classes.get(str);
        if (thisClass.getPackagename().equals(pack.getName())) {
            count++;
            String type = "ClassTarget";
            if (thisClass.getName().contains("abstract"))
                type = "AbstractTarget";
            content.add("target" + count + ".editor.height=700");
            content.add("target" + count + ".editor.width=400");
            content.add("target" + count + ".editor.x=0");
            content.add("target" + count + ".editor.y=0");
            content.add("target" + count + ".height=50");
            content.add("target" + count + ".name=" + thisClass.getShortName());
            content.add("target" + count + ".showInterface=false");
            content.add("target" + count + ".type=" + type);
            content.add("target" + count + ".width=80");
            content.add("target" + count + ".x=" + thisClass.getPosition().x);
            content.add("target" + count + ".y=" + thisClass.getPosition().y);
        }
    }

    StringList added = new StringList();
    int i = 0;
    for (Package myPack : packages.values()) {
        //System.out.println("Saving package: "+pack.getName());
        //System.out.println("Is: "+myPack.getName()+" contained in: "+pack.getName()+" ? "+pack.contains(myPack));

        String addPack = myPack.getRelativeName(pack);
        if (pack.contains(myPack) && !added.contains(addPack)) {
            /*
             target2.height=62
             target2.name=lu
             target2.type=PackageTarget
             target2.width=80
             target2.x=200
             target2.y=40
            */
            count++;
            i++;
            content.add("target" + count + ".height=80");
            content.add("target" + count + ".name=" + addPack);
            content.add("target" + count + ".type=PackageTarget");
            content.add("target" + count + ".width=80");
            content.add("target" + count + ".x=" + (i * 100) + "");
            content.add("target" + count + ".y=10");
            added.add(addPack);
        }
    }

    content.add("package.numTargets=" + (count));

    return content;
}