java try { setBackground(Color.decode(getParameter("Color"))); } catch (Exception e) { getAppletContext().showStatus(e.getLocalizedMessage()); } setView(ViewFactory.getDefault().createMainView()); getView().setEnabled(false); getView().addListener(this); java getView().setStatus("Discovering platform..."); final PlatformOntology ont = new PlatformOntology(); setOntology(ont); final String javaVendor = System.getProperty("java.vendor", "unknown"); final String javaVersion = System .getProperty("java.version", "unknown"); final String javaSpecName = System.getProperty( "java.specification.name", "unknown"); final String javaSpecVersion = System.getProperty( "java.specification.version", "unknown"); final String javaVmName = System.getProperty("java.vm.name", "unknown"); final String javaVmVersion = System.getProperty("java.vm.version", "unknown"); final String javaVmSpecName = System.getProperty( "java.vm.specification.name", "unknown"); final String javaVmSpecVersion = System.getProperty( "java.vm.specification.version", "unknown"); final String osName = System.getProperty("os.name", "unknown"); final String osArch = System.getProperty("os.arch", "unknown"); final String osVersion = System.getProperty("os.version", "unknown"); final Individual platform = new Individual(); platform.setClassNS("platform"); platform.setClassName("Platform"); platform.setName("DynamicallyDiscoveredPlatform"); ont.addIndividual(platform); final Individual jre = new Individual(); jre.setClassNS("java"); jre.setClassName("JRE"); final StringBuffer jreName = new StringBuffer(); jreName.append(javaVendor.replace(' ', '-')); jreName.append("-JRE-"); jreName.append(javaVersion.replace(' ', '-')); jre.setName(jreName.toString()); ont.addIndividual(jre); final Slot prJre = new Slot(); prJre.setIndividual(platform); prJre.setClassNS("platform"); prJre.setClassName("providesFeature"); prJre.setValue(jre); final Individual clsLib = new Individual(); clsLib.setClassNS("java"); clsLib.setClassName("JavaClassLibrary"); clsLib.setName(jre.getName() + "-ClassLibrary"); ont.addIndividual(clsLib); final Slot prClsLib = new Slot(); prClsLib.setIndividual(jre); prClsLib.setClassNS("platform"); prClsLib.setClassName("providesFeature"); prClsLib.setValue(clsLib); final Individual jvm = new Individual(); jvm.setClassNS("java"); jvm.setClassName("JavaVM"); final StringBuffer jvmName = new StringBuffer(); jvmName.append(javaVmName.replace(' ', '-')); jvmName.append("-"); jvmName.append(javaVmVersion.replace(' ', '-')); jvm.setName(jvmName.toString()); ont.addIndividual(jvm); final Slot prJVM = new Slot(); prJVM.setIndividual(jre); prJVM.setClassNS("platform"); prJVM.setClassName("providesFeature"); prJVM.setValue(jvm); final Individual bcformat = new Individual(); bcformat.setNamespace("j2me-midp-1_0"); bcformat.setName("theJ2MEMIDP1_0BytecodeFormat"); final Slot implJBC = new Slot(); implJBC.setIndividual(jvm); implJBC.setClassNS("platform"); implJBC.setClassName("implementsInterface"); implJBC.setValue(bcformat); final Individual os = new Individual(); os.setClassNS("platform"); os.setClassName("OperatingSystem"); final StringBuffer osId = new StringBuffer(); osId.append(osName.replace(' ', '-')); osId.append("-"); osId.append(osArch.replace(' ', '-')); osId.append("-"); osId.append(osVersion.replace(' ', '-')); os.setName(osId.toString()); ont.addIndividual(os); final Slot prOS = new Slot(); prOS.setIndividual(platform); prOS.setClassNS("platform"); prOS.setClassName("providesFeature"); prOS.setValue(os); final Individual cpu = new Individual(); cpu.setClassNS("platform"); cpu.setClassName("ProcessingResource"); cpu.setName("SomeKindOf" + osArch); ont.addIndividual(cpu); final Slot prCPU = new Slot(); prCPU.setIndividual(platform); prCPU.setClassNS("platform"); prCPU.setClassName("providesFeature"); prCPU.setValue(cpu); final Individual isa = new Individual(); final Slot implISA = new Slot(); implISA.setClassNS("platform"); implISA.setClassName("implementsInterface"); implISA.setValue(isa); if ("Java Platform API Specification".equals(javaSpecName)) { // JDK // JavaWebApplet final Individual jwa = new Individual(); jwa.setClassNS("java"); jwa.setClassName("WebApplet"); jwa.setName(jre.getName() + "-WebApplet"); ont.addIndividual(jwa); // JRE providesFeature WebApplet final Slot prJWA = new Slot(); prJWA.setIndividual(jre); prJWA.setClassNS("platform"); prJWA.setClassName("providesFeature"); prJWA.setValue(jwa); // JavaWebStart final Individual jws = new Individual(); jws.setClassNS("java"); jws.setClassName("WebStart"); jws.setName(jre.getName() + "-WebStart"); // JRE providesFeature WebStart final Slot prJWS = new Slot(); prJWS.setClassNS("java"); prJWS.setClassName("providesFeature"); prJWS.setValue(jws); // parse version number try { final int jv = Integer.parseInt(javaSpecVersion.replace('.', '0')); if (jv >= 101) { String javaName; String javaNamespace; switch (jv) { case 101 : javaNamespace = "jdk-1_1"; javaName = "JDK1_1"; break; case 102 : javaNamespace = "j2se-1_2"; javaName = "J2SE1_2"; break; case 103 : javaNamespace = "j2se-1_3"; javaName = "J2SE1_3"; break; case 104 : javaNamespace = "j2se-1_4"; javaName = "J2SE1_4"; ont.addIndividual(jws); prJWS.setIndividual(jre); break; case 105 : javaNamespace = "j2se-5_0"; javaName = "J2SE5_0"; ont.addIndividual(jws); prJWS.setIndividual(jre); break; default : // 1.6 and up javaNamespace = "java-se-6"; javaName = "JavaSE6"; ont.addIndividual(jws); prJWS.setIndividual(jre); break; } jre.setClassNS(javaNamespace); jre.setClassName(javaName + "JRE"); bcformat.setNamespace(javaNamespace); bcformat.setName("the" + javaName + "BytecodeFormat"); clsLib.setClassNS(javaNamespace); clsLib.setClassName(javaName + "ClassLibrary"); } } catch (NumberFormatException e) { } } else if (javaSpecName.startsWith("J2ME Personal Profile")) { try { final int jv = Integer.parseInt(javaSpecVersion.replace('.', '0')); String javaName; String javaNamespace; switch (jv) { case 100 : javaNamespace = "j2me-pp-1_0"; javaName = "J2MEPP1_0"; break; default : // 1.1 and up javaNamespace = "j2me-pp-1_1"; javaName = "J2MEPP1_1"; break; } jre.setClassNS(javaNamespace); jre.setClassName(javaName + "JRE"); bcformat.setNamespace(javaNamespace); bcformat.setName("the" + javaName + "BytecodeFormat"); clsLib.setClassNS(jre.getClassNS()); clsLib.setClassName(jre.getClassName() + "ClassLibrary"); } catch (NumberFormatException e) { } } else if (javaVendor.equals("Insignia Solutions Inc.")) { // Jeode try { final int jv = Integer.parseInt(javaVersion.replace('.', '0')); if (jv >= 301) { // Jeode 3.1 == PersonalJava 1.2 jre.setClassNS("personaljava-1_1"); jre.setClassName("PersonalJava1_1JRE"); bcformat.setNamespace(jre.getClassNS()); bcformat.setName("thePersonalJava1_1BytecodeFormat"); clsLib.setClassNS(jre.getClassNS()); clsLib.setClassName("PersonalJava1_1ClassLibrary"); } } catch (NumberFormatException e) { } } else { System.out.println("java.vendor = " + javaVendor); System.out.println("java.version = " + javaVersion); System.out.println("java.specification.name = " + javaSpecName); System.out.println("java.specification.version = " + javaSpecVersion); System.out.println("java.vm.name = " + javaVmName); System.out.println("java.vm.version = " + javaVmVersion); System.out .println("java.vm.specification.name = " + javaVmSpecName); System.out.println("java.vm.specification.version = " + javaVmSpecVersion); } if ("i386".equals(osArch)) { isa.setNamespace("x86"); isa.setName("theIntel_i386"); implISA.setIndividual(cpu); } else if (osArch.startsWith("arm")) { isa.setNamespace("arm"); if ("armv7-a".equals(osArch)) { isa.setName("theARMv7-A"); } else if ("armv7-r".equals(osArch)) { isa.setName("theARMv7-R"); } else if (osArch.startsWith("armv7")) { isa.setName("theARMv7-M"); } else if ("armv6".equals(osArch) || "armv6j".equals(osArch)) { isa.setName("theARMv6"); } else if ("armv6t2".equals(osArch)) { isa.setName("theARMv6T2"); } else if ("armv6z".equals(osArch)) { isa.setName("theARMv6KZ"); } else if ("armv6zk".equals(osArch)) { isa.setName("theARMv6K"); } else if ("armv6-m".equals(osArch)) { isa.setName("theARMv6-M"); } else if (osArch.startsWith("armv5")) { isa.setName("theARMv5TE"); } else if ("armv4t".equals(osArch)) { isa.setName("theARMv4T"); } else if ("armv4".equals(osArch)) { isa.setName("theARMv4"); } else if (osArch.startsWith("armv3")) { isa.setName("theARMv3"); } else if ("armv2a".equals(osArch)) { isa.setName("theARMv2a"); } else if ("armv2".equals(osArch)) { isa.setName("theARMv2"); } else { isa.setName("theARMv1"); } implISA.setIndividual(cpu); } else { System.out.println("os.arch = " + osArch); } getView().setStatus("Platform discovered"); getView().setEnabled(true); java getView().setEnabled(false); java System.out.println("Submit clicked"); if (getOntology() != null) { final String owl = getOWL(); try { Toolkit tk = Toolkit.getDefaultToolkit(); Clipboard cb = tk.getSystemClipboard(); cb.setContents(new Transferable() { public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException { if (DataFlavor.stringFlavor.equals(flavor)) { return owl; } return null; } public DataFlavor[] getTransferDataFlavors() { DataFlavor[] df = {DataFlavor.stringFlavor}; return df; } public boolean isDataFlavorSupported(DataFlavor flavor) { return (DataFlavor.stringFlavor.equals(flavor)); } }, new ClipboardOwner() { public void lostOwnership(Clipboard clipboard, Transferable contents) { } }); getView().setStatus("Platform copied"); } catch (java.security.AccessControlException e) { CopyToClipboardView ctcbView = ViewFactory.getDefault() .createCopyToClipboardView(); ctcbView.setCopyText(owl); } } java if (getOntology() != null) { final ByteArrayOutputStream out = new ByteArrayOutputStream(); getOntology().toOWL(out); return out.toString(); } return null; java try { InputStream header = getClass().getResourceAsStream( "PlatformOntologyHeader.txt"); int data; while ((data = header.read()) > -1) { out.write(data); } header.close(); for (Enumeration e = getIndividuals(); e.hasMoreElements();) { Individual i = (Individual) e.nextElement(); i.toOWL(out); } InputStream footer = getClass().getResourceAsStream( "PlatformOntologyFooter.txt"); while ((data = footer.read()) > -1) { out.write(data); } footer.close(); out.flush(); } catch (IOException e) { e.printStackTrace(); } java PrintStream pout = new PrintStream(out); pout.print(" <"); pout.print(getClassRef()); pout.print(" rdf:ID=\""); pout.print(getName()); pout.println("\">"); pout.flush(); for (Enumeration e = getSlots(); e.hasMoreElements();) { Slot s = (Slot) e.nextElement(); s.toOWL(out); } pout.print(" </"); pout.print(getClassRef()); pout.println(">"); pout.flush(); java PrintStream pout = new PrintStream(out); pout.print(" <"); pout.print(getClassRef()); boolean dataTypeProperty = false; if (getValue() != null) { if ("xsd".equals(getValue().getClassNS())) { dataTypeProperty = true; } } if (dataTypeProperty) { pout.print(" rdf:datatype=\"&"); pout.print(getValue().getClassNS()); pout.print(";#"); pout.print(getValue().getClassName()); pout.print("\">"); pout.print(getValue().getName()); pout.print("</"); pout.print(getClassRef()); pout.println(">"); } else { pout.print(" rdf:resource=\""); if (getValue() != null) { pout.print(getValue().getRef()); } else { pout.print("NULL"); } pout.println("\"/>"); } pout.flush(); java StringBuffer buf = new StringBuffer(); if (getNamespace() != null) { buf.append('&'); buf.append(getNamespace()); buf.append(';'); } else { buf.append('#'); } buf.append(getName()); return buf.toString(); java StringBuffer buf = new StringBuffer(); buf.append(getClassNS()); buf.append(':'); buf.append(getClassName()); return buf.toString(); java new Button("Copy to Clipboard") java new Label("Discovery Applet") java submitBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { notifySubmitClicked(); } }); setLayout(new FlowLayout()); add(status); add(submitBtn); be.ac.vub.platformkit.discovery.DiscoveryApplet.getInstance() .setLayout(new BorderLayout()); be.ac.vub.platformkit.discovery.DiscoveryApplet.getInstance().add(this, BorderLayout.CENTER); java for (java.util.Enumeration ls = getListeners(); ls.hasMoreElements();) { ((MainViewListener) ls.nextElement()).onSubmit(); } java this.status.setText(status); java Class.forName("java.awt.Toolkit"); java new TextArea() java new Panel() java new Label("Use your standard keyboard shortcut (e.g. Ctrl-C) to copy the above platform description to your clipboard") java textField.setText(text); textField.setSelectionStart(0); textField.setSelectionEnd(text.length()); textField.requestFocus(); java addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { setVisible(false); } }); setTitle("Platform description"); setLayout(new BorderLayout()); textField.setEditable(false); add(textField, BorderLayout.CENTER); bottomPanel.setLayout(new FlowLayout()); bottomPanel.add(instructionsLabel); add(bottomPanel, BorderLayout.SOUTH); pack(); setVisible(true); java String[] options = { "be.ac.vub.platformkit.discovery.view.swing.SwingViewFactory", "be.ac.vub.platformkit.discovery.view.awt.AWTViewFactory", "be.ac.vub.platformkit.discovery.view.lcdui.LCDUIViewFactory"}; ViewFactory factory = null; for (int i = 0; i < options.length && factory == null; i++) { try { factory = (ViewFactory) Class.forName(options[i]).newInstance(); } catch (Exception e) { } } return factory; java new JButton("Copy to Clipboard") java new JLabel("Discovery Applet") java submitBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { notifySubmitClicked(); } }); setLayout(new FlowLayout()); add(status); add(submitBtn); be.ac.vub.platformkit.discovery.DiscoveryApplet.getInstance() .setLayout(new BorderLayout()); be.ac.vub.platformkit.discovery.DiscoveryApplet.getInstance().add(this, BorderLayout.CENTER); setBackground(be.ac.vub.platformkit.discovery.DiscoveryApplet .getInstance().getBackground()); java for (java.util.Enumeration ls = getListeners(); ls.hasMoreElements();) { ((MainViewListener) ls.nextElement()).onSubmit(); } java this.status.setText(status); java Class.forName("javax.swing.UIManager"); java new JTextPane() java new JPanel() java new JLabel("Use your standard keyboard shortcut (e.g. Ctrl-C) to copy the above platform description to your clipboard") java new JScrollPane() java textField.setText(text); textField.setSelectionStart(0); textField.setSelectionEnd(text.length()); textField.requestFocus(); java addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { setVisible(false); } }); setTitle("Platform description"); setLayout(new BorderLayout()); textField.setEditable(false); textScroll.getViewport().setView(textField); textScroll.setPreferredSize(new Dimension(500, 300)); add(textScroll, BorderLayout.CENTER); bottomPanel.setLayout(new FlowLayout()); bottomPanel.add(instructionsLabel); add(bottomPanel, BorderLayout.SOUTH); pack(); setVisible(true);