public static void main(String[] args) { Subject proxy = new Proxy(); proxy.showImage(); proxy.showImage(); proxy.showImage(); }
public SubjectAcl( @NotNull String domain, @NotNull String node, @NotNull Subject subject, @NotNull String permission) { this(domain, node, subject.getPrincipal(), subject.getType(), permission); }
public SubjectMessage createSubjectMessage( String sHead, String sBody, Long nID_subject, String sMail, String sContacts, String sData, Long nID_subjectMessageType) { SubjectContact subjectContact = null; Subject subject = new Subject(); if (sMail != null && !sMail.isEmpty()) { if (nID_subject != null) subjectContact = syncMail(sMail, nID_subject); if (nID_subject == null) subjectContact = syncMail(sMail, subject); } SubjectMessage message = new SubjectMessage(); message.setHead(sHead); message.setBody(sBody == null ? "" : sBody); message.setId_subject( (nID_subject == null) ? ((subject.getId() == null) ? 0 : subject.getId()) : nID_subject); message.setoMail((subjectContact == null) ? null : subjectContact); // message.setMail((sMail == null) ? "" : sMail); message.setContacts((sContacts == null) ? "" : sContacts); message.setData((sData == null) ? "" : sData); message.setDate(new DateTime()); if (nID_subjectMessageType != null) { SubjectMessageType subjectMessageType = subjectMessageTypeDao.findByIdExpected(nID_subjectMessageType); message.setSubjectMessageType(subjectMessageType); } return message; }
/** * Logout the user * * <p>This method removes the Principals associated with the <code>Subject</code>. * * <p> * * @exception LoginException if the logout fails * @return true in all cases (this <code>LoginModule</code> should not be ignored). */ public boolean logout() throws LoginException { if (subject.isReadOnly()) { throw new LoginException("logout Failed: Subject is Readonly"); } // remove the added Principals from the Subject subject.getPrincipals().remove(userPrincipal); subject.getPrincipals().remove(UIDPrincipal); subject.getPrincipals().remove(GIDPrincipal); for (int i = 0; i < supplementaryGroups.size(); i++) { subject.getPrincipals().remove(supplementaryGroups.get(i)); } // clean out state ss = null; succeeded = false; commitSucceeded = false; userPrincipal = null; UIDPrincipal = null; GIDPrincipal = null; supplementaryGroups = new LinkedList<UnixNumericGroupPrincipal>(); if (debug) { System.out.println("\t\t[UnixLoginModule]: " + "logged out Subject"); } return true; }
private void cardinality(Subject subject, String min, String max) { if ("0".equals(min) && "1".equals(max)) subject.predicate("os:occurs", "os:Zero-or-one"); else if ("0".equals(min) && "*".equals(max)) subject.predicate("os:occurs", "os:Zero-or-many"); else if ("1".equals(min) && "1".equals(max)) subject.predicate("os:occurs", "os:Exactly-one"); else if ("1".equals(min) && "*".equals(max)) subject.predicate("os:occurs", "os:One-or-many"); else throw new Error("Unhandled cardinality combination (" + min + "/" + max + ")"); }
public static void main(String[] args) { Subject subject = new MySubject(); subject.add(new Observer1()); subject.add(new Observer2()); subject.operation(); }
@RequestMapping(value = "/setDocument", method = RequestMethod.GET) public @ResponseBody Long setDocument( @RequestParam(value = "nID_Subject", required = false) long nID_Subject, @RequestParam(value = "sID_Subject_Upload") String sID_Subject_Upload, @RequestParam(value = "sSubjectName_Upload") String sSubjectName_Upload, @RequestParam(value = "sName") String sName, // @RequestParam(value = "sFile", required = false) String fileName, @RequestParam(value = "nID_DocumentType") Long nID_DocumentType, // @RequestParam(value = "nID_DocumentContentType", required = false) Integer // nID_DocumentContentType, @RequestParam(value = "sDocumentContentType", required = false) String documentContentTypeName, @RequestParam(value = "soDocumentContent") String sContent, @RequestParam(value = "oSignData") String oSignData, // todo required?? (issue587) // @RequestParam(value = "oFile", required = false) MultipartFile oFile, // @RequestBody byte[] content, HttpServletRequest request, HttpServletResponse httpResponse) throws IOException { // MultipartFile oFile = new MockMultipartFile("filename.txt", "fullfilename.txt", "text/plain", // sContent.getBytes()); String sFileName = "filename.txt"; String sFileContentType = "text/plain"; byte[] aoContent = sContent.getBytes(); documentContentTypeName = request.getHeader("Content-Type") != null ? request.getHeader("filename") : documentContentTypeName; DocumentContentType documentContentType = null; if (documentContentTypeName != null) { documentContentType = documentContentTypeDao.getDocumentContentType(documentContentTypeName); if (documentContentType == null) { documentContentType = new DocumentContentType(); documentContentType.setName(documentContentTypeName); documentContentType.setId(documentContentTypeDao.setDocumentContent(documentContentType)); } } else { throw new ActivitiObjectNotFoundException( "RequestParam 'nID_DocumentContentType' not found!", DocumentContentType.class); } Subject subject_Upload = syncSubject_Upload(sID_Subject_Upload); return documentDao.setDocument( nID_Subject, subject_Upload.getId(), sID_Subject_Upload, sSubjectName_Upload, sName, nID_DocumentType, documentContentType.getId(), sFileName, sFileContentType, aoContent, oSignData); }
public String toString() { Subject subject = null; try { subject.setSubject(ReadSubjects.getSubj(subjectId)); } catch (ClassNotFoundException e) { logger.error(e); } return testId + testName + " " + subject.getSubject(); }
public static void main(String[] args) { Subject subject = new RealSubject(); InvocationHandler handler = new SubjectHandler(subject); ClassLoader cl = subject.getClass().getClassLoader(); Subject proxy = (Subject) Proxy.newProxyInstance(cl, subject.getClass().getInterfaces(), handler); proxy.request(); }
public static void main(String[] args) { Subject subject = new Subject(); new HexObserver(subject); new OctalObserver(subject); new BinaryObserver(subject); System.out.println("First state change: 15"); subject.setState(15); System.out.println("Second state change: 10"); subject.setState(10); }
/** * Commit the authentication (second phase). * * <p>This method is called if the LoginContext's overall authentication succeeded (the relevant * REQUIRED, REQUISITE, SUFFICIENT and OPTIONAL LoginModules succeeded). * * <p>If this LoginModule's own authentication attempt succeeded (the importing of the Unix * authentication information succeeded), then this method associates the Unix Principals with the * <code>Subject</code> currently tied to the <code>LoginModule</code>. If this LoginModule's * authentication attempted failed, then this method removes any state that was originally saved. * * <p> * * @exception LoginException if the commit fails * @return true if this LoginModule's own login and commit attempts succeeded, or false otherwise. */ public boolean commit() throws LoginException { if (succeeded == false) { if (debug) { System.out.println( "\t\t[UnixLoginModule]: " + "did not add any Principals to Subject " + "because own authentication failed."); } return false; } else { if (subject.isReadOnly()) { throw new LoginException("commit Failed: Subject is Readonly"); } if (!subject.getPrincipals().contains(userPrincipal)) subject.getPrincipals().add(userPrincipal); if (!subject.getPrincipals().contains(UIDPrincipal)) subject.getPrincipals().add(UIDPrincipal); if (!subject.getPrincipals().contains(GIDPrincipal)) subject.getPrincipals().add(GIDPrincipal); for (int i = 0; i < supplementaryGroups.size(); i++) { if (!subject.getPrincipals().contains(supplementaryGroups.get(i))) subject.getPrincipals().add(supplementaryGroups.get(i)); } if (debug) { System.out.println("\t\t[UnixLoginModule]: " + "added UnixPrincipal,"); System.out.println("\t\t\t\tUnixNumericUserPrincipal,"); System.out.println("\t\t\t\tUnixNumericGroupPrincipal(s),"); System.out.println("\t\t\t to Subject"); } commitSucceeded = true; return true; } }
@Test public void testNotApplicable() { Subject subject = Subject.newInstance("John Smith"); subject.addAttribute("urn:oasis:names:tc:xacml:1.0:subject:role-id", "ROLE_DOCUMENT_WRITER"); Action action = Action.newInstance("write"); Document doc = new Document(2, "OnBoarding Document", "XYZ Corporation", "Jim Doe"); PepResponse response = getPepAgent().decide(subject, action, doc); Assert.assertNotNull(response); Assert.assertEquals(false, response.allowed()); }
@Test public void testErrorThrownIssue1685() { Subject<Object, Object> subject = ReplaySubject.create(); Observable.error(new RuntimeException("oops")) .materialize() .delay(1, TimeUnit.SECONDS) .dematerialize() .subscribe(subject); subject.subscribe(); subject.materialize().toBlocking().first(); System.out.println("Done"); }
@Test public void testVarArgsPermit() { Subject subject = Subject.newInstance("John Smith"); subject.addAttribute("urn:oasis:names:tc:xacml:1.0:subject:role-id", "ROLE_DOCUMENT_READER"); BusinessRequestContext bc = new BusinessRequestContext("USA", "05:00 EST"); Action action = Action.newInstance("read"); List<Object> resources = new ArrayList<Object>(); resources.add(new Document(1, "OnBoarding Document", "XYZ Corporation", "Jim Doe")); resources.add(new Client("XYZ Corporation", "USA")); PepResponse response = getPepAgent().decide(subject, action, resources, bc); Assert.assertNotNull(response); Assert.assertEquals(true, response.allowed()); }
private void gen(PrimitiveType t) { Section section = section(t.getCode()); section.triple("fhir:" + t.getCode(), "rdfs:subClassOf", "fhir:Primitive"); section.comment("fhir:" + t.getCode(), t.getDefinition()); nilInstance.predicate("a", "fhir:" + t.getCode()); section.triple("fhir:" + t.getCode() + ".value", "rdfs:subPropertyOf", "fhir:Primitive.value"); section.triple("fhir:" + t.getCode() + ".value", "rdfs:domain", "fhir:" + t.getCode()); if (t.getSchemaType().endsWith("+")) { section.triple( "fhir:" + t.getCode() + ".value", "rdfs:range", "xs:" + t.getSchemaType().substring(0, t.getSchemaType().length() - 1)); section.triple( "fhir:" + t.getCode() + ".value", "owl:withRestriction", complex().predicate("xs:pattern", literal(t.getRegex()))); } else if (t.getSchemaType().contains(",")) { section.triple( "fhir:" + t.getCode() + ".value", "rdfs:range", complex() .predicate("a", "owl:Class") .predicate("owl:unionOf", "(" + t.getSchemaType().replace(",", "") + ")"), "xs:union of " + t.getSchemaType()); } else section.triple("fhir:" + t.getCode() + ".value", "rdfs:range", "xs:" + t.getSchemaType()); }
public void onClick(View v) { int id = v.getId(); switch (id) { case R.id.add_rating_dialog_add: String d = etDescription.getText().toString(); String m = etMark.getText().toString(); if (d.length() > 0) { try { int mark = Integer.parseInt(m); subject.rating += mark; DBStorage dbStorage = new DBStorage(context); dbStorage.addRating(subject.id, mark, d); dbStorage.changeSubject(subject); dbStorage.destroy(); listener.onDialogDismissed(); dismiss(); } catch (NumberFormatException ignored) { } } break; case R.id.add_rating_dialog_cancel: dismiss(); break; } }
protected void codedTriple(Subject subject, String predicate, CodeableConcept cc) { for (Coding c : cc.getCoding()) { String s = getLinkedForm(c); if (s != null) subject.predicate( predicate, new StringType(s), c.hasDisplay() ? c.getDisplay() : cc.getText()); } }
@Test(expected = PepException.class) public void testMix() { Subject subject = Subject.newInstance("John Smith"); subject.addAttribute("urn:oasis:names:tc:xacml:1.0:subject:role-id", "ROLE_DOCUMENT_WRITER"); Action action = Action.newInstance("write"); Document doc1 = new Document(1, "OnBoarding Document", "ABC Corporation", "John Smith"); Document doc2 = new Document(2, "OnBoarding Document", "XYZ Corporation", "Jim Doe"); List<Object> resourceList = new ArrayList<Object>(); resourceList.add(doc1); resourceList.add(doc2); PepResponse response = getPepAgent().decide(subject, action, resourceList); Assert.assertNotNull(response); response.allowed(); }
@Test public void testInterface() throws Exception { ApplicationContext ctx = new AnnotationConfigApplicationContext(AppConfig.class); subject = (Subject) ctx.getBean("junior"); System.out.println(subject.getName() + "sdasd"); // Assert.assertEquals(juniorYear.getYear(),2015); }
/** @param args */ public static void main(String[] args) { sub = new Subject(); // Client configures the number and type of Observers observerA = new ConcreteObserverA(sub); observerB = new ConcreteObserverB(sub); sub.setState(100); }
// @Override public void loyalty(int discountPercent, Subject s) { System.out.println( "Hello, " + getName() + ". You have " + discountPercent + "% discount from " + s.toString()); }
private void gen(ProfiledType t) throws Exception { Section section = section(t.getName()); section.triple("fhir:" + t.getName(), "rdfs:subClassOf", "fhir:" + t.getBaseType()); nilInstance.predicate("a", "fhir:" + t.getName()); section.label("fhir:" + t.getName(), t.getDescription()); section.comment("fhir:" + t.getName(), t.getDefinition()); if (!Utilities.noString(t.getInvariant().getTurtle())) section.importTtl(t.getInvariant().getTurtle()); }
@Override public double distance(Subject b, double[] r) { // TODO use Math abs instead of sq and s double rt = 0; for (int i = 0; i < numAttribute; i++) { rt = +Math.abs(this.attributes[i] - b.getAttribute(i)) / r[i]; } return rt; }
public NewJFrame(Socket s) { this(); echoSocket = s; try { out = new PrintWriter(echoSocket.getOutputStream(), true); in = new BufferedReader(new InputStreamReader(echoSocket.getInputStream())); clientId = Integer.parseInt(in.readLine()); jLabel1.setText("Client " + clientId); Subject sub = new Subject(); sub.addObserver(this); Thread t = new Thread(sub); t.start(); } catch (IOException e) { System.err.println("Couldn't get I/O for the connection to host name"); System.exit(1); } }
public static void main(String[] args) throws Exception { Subject sub = new RealSubject(); Subject proxySub = (Subject) Proxy.newProxyInstance( Subject.class.getClassLoader(), new Class[] {Subject.class}, new ProxyHandler(sub)); proxySub.say("fengxiang"); byte[] buffer = ProxyGenerator.generateProxyClass("ProxyClass", new Class[] {Subject.class}); FileOutputStream out = new FileOutputStream("ProxyClass.class"); out.write(buffer); out.close(); // 从这里可以看到具体的接口创建代理的时候, 只会创建一个代理类, 而当前代理类的构造方法的参数就是InvocationHandler接口的对象, 所以如果 // 想要生成不同的对象, 并且有不同的功能, 此时直接设置不同的InvocationHandler就可以了, 就可以表现出完全不一样的行为。 // 从这里可以看到类肯定只是生成一次, 剩下的仅仅只是生成对象, 仅此而已, 所以一般情况下来说并不会有太大的性能影响的。 Subject proxySub2 = (Subject) Proxy.newProxyInstance( Subject.class.getClassLoader(), new Class[] {Subject.class}, new ProxyHandler(sub)); System.out.println(proxySub.getClass() == proxySub2.getClass()); // true }
public void close() { try { System.out.println("Removing observer #" + number); server.removeObserver(this); System.out.println("Closing client #" + number); clientThread.interrupt(); inputStream.close(); outputStream.close(); socket.close(); } catch (IOException e) { e.printStackTrace(); } }
private void gen(TypeDefn t) throws Exception { Section section = section(t.getName()); if (t.getTypes().isEmpty()) section.triple("fhir:" + t.getName(), "a", "rdfs:Class"); else section.triple("fhir:" + t.getName(), "rdfs:subClassOf", "fhir:Element"); section.label("fhir:" + t.getName(), t.getShortDefn()); section.comment("fhir:" + t.getName(), t.getDefinition()); if (t.getName().equals("Reference")) section.triple( "fhir:" + t.getName(), "a", "fhir:Resource"); // This is so that a reference can be replaced by a direct reference to // it's target nilInstance.predicate("a", "fhir:" + t.getName()); processMappings(section, "fhir:" + t.getName(), t); for (ElementDefn e : t.getElements()) { if (e.getName().endsWith("[x]")) { String cn = e.getName().substring(0, e.getName().length() - 3); section.triple("fhir:" + t.getName() + "." + cn, "a", "rdf:Property"); section.label("fhir:" + t.getName() + "." + cn, e.getShortDefn()); section.comment("fhir:" + t.getName() + "." + cn, e.getDefinition()); processMappings(section, "fhir:" + t.getName() + "." + cn, e); for (TypeRef tr : e.typeCode().equals("*") ? getAnyTypes() : e.getTypes()) { String en = cn + Utilities.capitalize(tr.getName()); section.triple( "fhir:" + t.getName() + "." + en, "rdfs:subPropertyOf", "fhir:" + t.getName() + "." + cn); section.triple("fhir:" + t.getName() + "." + en, "rdfs:domain", "fhir:" + t.getName()); genRange(section, t.getName(), en, e, tr, true); } } else { section.triple("fhir:" + t.getName() + "." + e.getName(), "a", "rdf:Property"); section.comment("fhir:" + t.getName() + "." + e.getName(), e.getDefinition()); section.triple( "fhir:" + t.getName() + "." + e.getName(), "rdfs:domain", "fhir:" + t.getName()); processMappings(section, "fhir:" + t.getName() + "." + e.getName(), e); genRange( section, t.getName(), e.getName(), e, e.getTypes().isEmpty() ? null : e.getTypes().get(0), true); } } processAnonTypes(); }
// при параметре nID_Subject == null private SubjectContact syncMail(String sMail, Subject oSubject) { SubjectContact res = null; SubjectHuman oSubjectHuman = subjectHumanDao.getSubjectHuman(SubjectHumanIdType.Email, sMail); Subject subject = (oSubjectHuman != null) ? oSubjectHuman.getoSubject() : null; if (subject != null) { oSubject.setId(subject.getId()); oSubject.setsID(subject.getsID()); oSubject.setsLabel(subject.getsLabel()); oSubject.setsLabelShort(subject.getsLabelShort()); res = subjectContactDao.findByExpected("sValue", sMail); if (res != null) { res.setSubject(subject); res.setsDate(); subjectContactDao.saveOrUpdate(res); } } return res; }
public double distance(Subject b, double[] r, double[] w) { // TODO use Math abs instead of sq and s double rt = 0; for (int i = 0; i < numAttribute; i++) { rt = +w[i] * Math.abs(this.attributes[i] - b.getAttribute(i)) / r[i]; } return rt; // return Math.sqrt( // pow(w[0] *(this.attributes[0] - b.attributes[0]),2) /pow(r[0],2)+ // pow(w[1] *(this.attributes[0] - b.attributes[1]),2) /pow(r[1],2)+ // pow(w[2] *(this.attributes[0] - b.attributes[2]),2) /pow(r[2],2)+ // pow(w[3]* (this.attributes[0] - b.attributes[3]),2) /pow(r[3],2) // ) // ; }
private void gen(DefinedStringPattern t) { Section section = section(t.getCode()); section.triple("fhir:" + t.getCode(), "rdfs:subClassOf", "fhir:" + t.getBase()); section.comment("fhir:" + t.getCode(), t.getDefinition()); nilInstance.predicate("a", "fhir:" + t.getCode()); section.triple( "fhir:" + t.getCode() + ".value", "rdfs:subPropertyOf", "fhir:" + t.getBase() + ".value"); if (t.getSchema().endsWith("+")) { section.triple( "fhir:" + t.getCode() + ".value", "rdfs:range", t.getSchema().substring(0, t.getSchema().length() - 1)); section.triple( "fhir:" + t.getCode() + ".value", "owl:withRestriction", complex().predicate("xs:pattern", literal(t.getRegex()))); } else section.triple("fhir:" + t.getCode() + ".value", "rdfs:range", t.getSchema()); }